ActiveMQ AJax Client - ajax

I try to write a simple Ajax client to send and receive messages. It's successfully deployed but I have never received msg from the client. I am beating myself to think out what I am missing, but still can't make it work.
Here is my code:
I creat a dynamic web application named: ActiveMQAjaxService and put activemq-web.jar and all neccessary dependencies in the WEB-INF/lib folder. In this way, AjaxServlet and MessageServlet will be deployed
I start activemq server in command line: ./activemq => activemq successfully created and display:
Listening for connections at: tcp://lilyubuntu:61616
INFO | Connector openwire Started
INFO | ActiveMQ JMS Message Broker (localhost, ID:lilyubuntu-56855-1272317001405-0:0) started
INFO | Logging to org.slf4j.impl.JCLLoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
INFO | jetty-6.1.9
INFO | ActiveMQ WebConsole initialized.
INFO | Initializing Spring FrameworkServlet 'dispatcher'
INFO | ActiveMQ Console at http://0.0.0.0:8161/admin
INFO | Initializing Spring root WebApplicationContext
INFO | Connector vm://localhost Started
INFO | Camel Console at http://0.0.0.0:8161/camel
INFO | ActiveMQ Web Demos at http://0.0.0.0:8161/demo
INFO | RESTful file access application at http://0.0.0.0:8161/fileserver
INFO | Started SelectChannelConnector#0.0.0.0:8161
3) index.xml, which is the html to test the client:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="amq/amq.js"></script>
<script type="text/javascript">amq.uri='amq';</script>
<title>Hello Ajax ActiveMQ</title>
</head>
<body>
<p>Hello World!</p>
<script type="text/javascript">
amq.sendMessage("topic://myDetector", "message");
var myHandler =
{
rcvMessage: function(message)
{
alert("received "+message);
}
};
function myPoll(first)
{
if (first)
{
amq.addListener('myDetector', 'topic://myDetector', myHandler.rcvMessage);
}
}
amq.addPollHandler(myPoll);
4) Web.xml:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<display-name>ActiveMQ Web Demos</display-name>
<description>
Apache ActiveMQ Web Demos
</description>
<!-- context config -->
<context-param>
<param-name>org.apache.activemq.brokerURL</param-name>
<param-value>vm://localhost</param-value> (I also tried tcp://localhost:61616)
<description>The URL of the Message Broker to connect to</description>
</context-param>
<context-param>
<param-name>org.apache.activemq.embeddedBroker</param-name>
<param-value>true</param-value>
<description>Whether we should include an embedded broker or not</description>
</context-param>
<!-- servlet mappings -->
<!-- the subscription REST servlet -->
<servlet>
<servlet-name>AjaxServlet</servlet-name>
<servlet-class>org.apache.activemq.web.AjaxServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>MessageServlet</servlet-name>
<servlet-class>org.apache.activemq.web.MessageServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<!--
Uncomment this parameter if you plan to use multiple consumers over REST
<init-param>
<param-name>destinationOptions</param-name>
<param-value>consumer.prefetchSize=1</param-value>
</init-param>
-->
</servlet>
<!-- the queue browse servlet -->
<filter>
<filter-name>session</filter-name>
<filter-class>org.apache.activemq.web.SessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>session</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
After all of these, I deploy the web-app, and it's successfully deployed, but when I try it out in http://localhost:8080/ActiveMQAjaxService/index.html , nothing happens.
I can run the demo portfolioPublisher demo successfully at http://localhost:8161/demo/portfolio/portfolio.html, and see the numbers updated all the time. But for my simple web-app, nothing really works.
Any suggestion/hint is welcomed. Thanks so much
Lily

Try going to the management web console; web-page, and seeing if you can send a message to your broker from that context, that might go along way towards directing you towards the problem.

I set up the web.xml in web application as following and it works.
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>msg_tomcat_activemq</display-name>
<context-param>
<param-name>org.apache.activemq.brokerURL</param-name>
<param-value>tcp://192.168.1.105:61616</param-value>
</context-param>
<context-param>
<param-name>org.apache.activemq.embeddedBroker</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>AjaxServlet</servlet-name>
<servlet-class>org.apache.activemq.web.AjaxServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>MessageServlet</servlet-name>
<servlet-class>org.apache.activemq.web.MessageServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AjaxServlet</servlet-name>
<url-pattern>/amq/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MessageServlet</servlet-name>
<url-pattern>/message/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>session</filter-name>
<filter-class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>session</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.apache.activemq.web.SessionListener</listener-class>
</listener>
</web-app>

Related

Spring Web MVC Application Cannot Find Resources

I am using netbeans as my IDE for developing basic web application. I successfully added external files as resources such as pictures and CSS files. They were working fine untill today, suddenly they are not being found by netbeans. Following is the error I am getting when debugging
Failed to load resource: the server responded with a status of 405 (Method not allowed).
Here is how I have initialized the MVC resources in XML config file.
<mvc:resources mapping="/resources/**" location="/resources/" cache-period="31556926"/>
<mvc:annotation-driven />
And here is how I am using it, in JSP file.
<link rel="stylesheet" href='<c:url value="/resources/css/bootstrap.min.css"/>'>
So what could be wrong. Why it has stopped suddenly ? Thanks for any pointer.
======== EDIT ===========
Here is my web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Following (already shown) two lines are in applicationContext.xml
<mvc:resources mapping="/resources/**" location="/resources/" cache-period="31556926"/>
<mvc:annotation-driven />
And here is my controller.
#RequestMapping(value = "/myURL", method=RequestMethod.GET)
public String MyControllerGET(HttpServletRequest request, Model model)
{
// some code here....nothing fancy, just harcoding some values
}

How to set Spring root context path

I am a Spring newbie and am putting together a Spring web-app (not Spring-boot - how much difference does this make?). Deployment is on a Tomcat 7 server.
The app is up and running. My problem is that is only accessible via the standard URL:
http://mycompany.com:8081/cwing-0.0.3-SNAPSHOT/index.html
The following do not work:
http://mycompany.com:8081/cwing-0.0.3-SNAPSHOT
http://mycompany.com:8081/cwing-0.0.3-SNAPSHOT/
even though my web.xml lists index.html as the welcome page.
An additional symptom of the problem is that all sorts of links within the application need to be specified as relative, rather than with a prepended '/'.
But even these urls are not what I really want.
I would rather specify
http://mycompany.com:8081/cwing
and have it bring up the index.html.
Following the lead of Add context path to Spring Boot application
I created an application.xml file in src/main/resources with the following content:
server.contextPath=/cwing
server.port=8081
This doesn't work. http://mycompany.com:8081/cwing brings up a blank page, with a 404 error on the server, as does http://mycompany.com:8081/cwing/index.html.
I must be missing something. What else is needed to get this to work as I want it to work?
UPDATE: as asked, here is the web.xml (irrelevant details removed).
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>cwing</display-name>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/context.xml
/WEB-INF/spring/datasource.xml
/WEB-INF/spring/security.xml
</param-value>
</context-param>
<servlet>
<servlet-name>d</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/context.xml
/WEB-INF/spring/datasource.xml
/WEB-INF/spring/security.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>d</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- Disables Servlet Container welcome file handling. Needed for compatibility
with Servlet 3.0 and Tomcat 7.0 -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
...
</web-app>
This is not related to Spring MVC but to specific server, by default Tomcat gets your WAR name as context root. If you want to change this, you can always rename your WAR file or I recommends to change your pom.xml to build your WAR file with final name, here is how to do this:
<build>
<finalName>finalName</finalName>
. . .
</build>

http status 404 hello.jsp (apache tomcat 6)

im new to using apache and spring framework and i've been using this tutorial for learning: http://docs.spring.io/docs/Spring-MVC-step-by-step/part1.html
i made an .jsp file however my browser tells me "The requested resource is not available."
the .jsp file is pretty simple
<html>
<head><title>Hello :: Spring Application</title></head>
<body>
<h1>Hello - Spring Application</h1>
<p>Greetings.</p>
</body>
</html>
entering http://localhost:8080/project/hello.htm gives me a 404.
my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
<servlet>
<servlet-name>project</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>project</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
any idea how to fix this?
404 error means the requested resource is not in the server.
Your problem can be either
1. Not properly matching hello.htm to any controller
bean id="/hello.htm" class="foo.controller" or
2. You have to put your hello.jsp in webcontent folder, along with index.jsp. Not in WEB-INF folder. Refer tutorial.

deploying and running embedded mule in webapp (Mule twitter integration)

Hi I am newbaby to Mule!!
I want to run this simple app (receives input from url and post to my twitter account using twitter connector).
I try first deploying it on CloudHub and it works http://twitterconnector.cloudhub.io/addtweet?mymessage=firsttweet
after that I wanted to try deploying on Tomcat so I created simple webapp using maven and put all required dependences for Mule in pom.xml, set web.xml and mule-config.xml files and when I go to localhost:8181/easymule-test/services/addtweet?mymessage=firsttweet it is not working!
Can someone pls help/explain what is the problem?
than you in advance!!
Here is the flow:
<flow name="twitterconnectorFlow1" doc:name="twitterconnectorFlow1">
<servlet:inbound-endpoint path="addtweet" responseTimeout="10000" doc:name="Servlet"/>
<twitter:update-status config-ref="test_ECAccount" status="#[header:INBOUND:mymessage]" doc:name="Twitter Connector"/>
<expression-transformer evaluator = "groovy" expression="payload.toString()" returnSourceIfNull="true" doc:name="Expression"/>
</flow>
Edit: web.xml configuration fragment
<web-app>
<display-name>easymule-test</display-name>
<context-param>
<param-name>org.mule.config</param-name>
<param-value>/WEB-INF/muleconfig.xml</param-value>
</context-param>
<listener>
<listener-class>org.mule.config.builders.MuleXmlBuilderContextListener</listener-class>
</listener>
<servlet>
<servlet-name>ajax</servlet-name>
<servlet-class>org.mule.transport.ajax.container.MuleAjaxServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>muleServlet</servlet-name>
<servlet-class>org.mule.transport.servlet.MuleReceiverServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>muleResources</servlet-name>
<servlet-class>org.mule.transport.ajax.MuleJarResourcesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>muleServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>muleResources</servlet-name>
<url-pattern>/mule-resource/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ajax</servlet-name>
<url-pattern>/ajax/*</url-pattern>
</servlet-mapping>
</web-app>
A servlet endpoint path is a path not an address, so use:
<servlet:inbound-endpoint path="sendtweet" ...
Assuming:
your web-app is deployed on the /easymule-test context,
and is running on port 8181
and the org.mule.transport.servlet.MuleReceiverServlet is bound to the services path
then you'll access the above endpoint at http://localhost:8181/easymule-test/services/sendtweet.

"Unable to read TLD META-INF/jsf_core.tld from jsf-impl-2.0.jar" error when integrating JSF

We have a Struts+Spring+Hibernate Application and we are trying to integrate JSF. For that we have done some configuration in web.xml and struts-config.xml. I have added some
JAR files to WEB-INF/lib.
The jar files containing in my WEB-INF/lib are listed here:
antlr-2.7.6rc1.jar,asm.jar,asm-attrs.jar,bsh-2.0b2.jar,c3p0-0.9.1.2-jdk1.3.jar,cglib-2.1.3.jar,commons-beanutils-1.7.jar,commons-betwixt-0.8.jar,commons-cli-1.0.jar,commons-codec-1.3.jar,commons-collections-3.jar,commons-dbcp-1.2.1.jar,commons-digester-1.7.jar,commons-discovery-0.2.jar,commons-fileupload.jar,commons-httpclient-3.1.jar,commons-io-1.3.1.jar,commons-lang-2.3.jar,commons-logging-1.1.jar,commons-pool-1.2.jar,commons-validator.jar,connector-1_5.jar,dom4j-1.6.1.jar,ehcache-1.1.jar,el-api-6.0.20.jar,el-impl-2.2.0-SNAPSHOT.jar,hibernate-3.1.3.jar,jetty-util-6.0.0,.jar,servlet-api-2.3.jar,spring-2.5.6.jar,standard.jar,struts.jar,xercesImpl-2.6.2.jar,xmlParserAPIs-2.6.2.jar,xstream-1.3.1
The below jar file are the ones newly added for integrating JSF:
jsf-api-2.0.jar,jsf-impl-2.0.jar,myfaces-jsf-api-1.0.9.jar.jar.jar,struts-faces-1.3.10.jar
My web.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>SSHIntgr</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/config/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/config/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>locale</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- struts-faces configuration start -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- struts-faces configuration start -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
My struts-config.xml is
<struts-config>
<form-beans>
<form-bean name="usrForm" type="com.sshi.web.form.UsrForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/login" type="com.sshi.web.action.LoginAction"
name="usrForm" scope="request">
<forward name="allowUser" path="/pages/Welcome.jsp"/>
<forward name="denyUser" path="/index.jsp"/>
</action>
</action-mappings>
<controller>
<set-property property="processorClass"
value="org.apache.struts.faces.
application.FacesRequestProcessor"/>
</controller>
<message-resources key="MessageResources" parameter="MessageResources" null="false" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/config/validator-rules.xml,/config/validation.xml" />
<set-property property="stopOnFirstError" value="true" />
</plug-in>
</struts-config>
I am using Spring source toll suite, Tomcat 5.5 and JDK 1.5.
My Tomcat 5.5\common\lib contains JAR files
commons-el.jar,jasper-compiler.jar,jasper-compiler-jdt.jar,jasper-runtime.jar,jsp-api.jar,naming-factory.jar,naming-factory-dbcp.jar,
naming-resources.jar,servlet-api.jar
My Server is starting properly but not able to load JSP page, I am getting the exception as
org.apache.jasper.JasperException: Unable to read TLD "META-INF/jsf_core.tld" from JAR file "file:/SSHIntgr/WEB-INF/lib/jsf-impl-2.0.jar": org.apache.jasper.JasperException: Failed to load or instantiate TagLibraryValidator class: com.sun.faces.taglib.jsf_core.CoreValidator
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:50)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:179)
at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:181)
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:418)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:483)
How can I solve this?
You're using tomcat 5.5 which is a Servlet 2.4 container, but JSF 2.0 requires Servlet 2.5 or newer.
So you have 2 options:
Upgrade your servletcontainer to a Servlet 2.5 comparible one (e.g. Tomcat 6.0).
Downgrade JSF to 1.2 which is compatible with Servlet 2.4.
Unrelated to the concrete problem: the file servlet-api-2.3.jar does not belong in WEB-INF/lib. Get rid of it. It's supposed to be already provided by the servletcontainer (in this case, the one in Tomcat's /lib). Keeping this file will only lead to missing class def or abstract method errors during runtime.

Resources