Spring Websocket and 404 status on connection - spring

In a working Spring MVC 4.0.2 project running under Tomcat 7.0.50, I'm trying to implement Spring Websocket with simple broker and sockjs stomp endpoint, following the official reference. So, in the contextConfigLocation (DistpacherServlet property) I've add a value "websocket-config.xml" which contains:
> <websocket:message-broker application-destination-prefix="/app" >
> <websocket:stomp-endpoint path="/monitor">
> <websocket:sockjs />
> </websocket:stomp-endpoint>
> <websocket:simple-broker prefix="/topic"/>
> </websocket:message-broker>
In eclipse console (catalina log) when I start Tomcat, appear the rows
Initializing ExecutorService 'clientInboundChannelExecutor'
Initializing ExecutorService 'clientOutboundChannelExecutor'
Initializing ExecutorService 'messageBrokerSockJsScheduler'
Mapped URL path [/monitor/**] onto handler of type [class org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler]
In the jsp page I put the code
. . . .
var socket = new SockJS("monitor");
var stompClient = Stomp.over(socket);
. . . .
Unfortunately when I load the jsp page from Chrome (v32), I get this error:
Failed to load resource: the server responded with a status of 404 (Not Found)
http ://localhost:8080/(ProjectName)/monitor/info
Obviously I'm doing this test locally, then all other webapp resources are reachable at http ://localhost/(ProjectName) correctly.
What's wrong?
**** Update 20 Feb 2014
I've tried to follow this resolved stack question, which suggests to use Tomcat8 for Spring Websocket, unfortunately it doesn't work

Any log output on the server side as a result of the request to /monitor/info? How is the DispatcherServlet itself mapped? I would expect to "/" from what you have above.
The SockJS endpoint is basically a URL mapped in Spring MVC (with a SimpleUrlHandlerMapping) so try other Spring MVC mapped controller methods. And turn up logging, could there be a filter or something else returning the 404?

For those who struggle with this issue this might helps.
I had following in web.xml:
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
And had 404 response for this url:
http ://localhost:8080/(ProjectName)/monitor
But this one works like charm:
http ://localhost:8080/(ProjectName)/rest/monitor
Cheers!

Related

package web service client together with another service websphere

I have two legacy web services running on WebSphere 8.5.5.
Call them serviceOne and serviceTwo. ServiceOne is invoking serviceTwo.
To do that, serviceOne ear contains the serviceTwo client.
We have a requirement to authenticate serviceTwo. We are trying to use PolicySets/Bindings to configure the username and password and have the serviceTwoClient pass them to the serviceTwo provider.
The way they are packaged right now is:
-- serviceOne.ear
|
-- serviceOneEJB.jar
| |
| -- serviceTwoClient.jar
-- serviceOneWeb.war
The problem we have is with packaging the serviceOne ear in order for WebSphere to detect the serviceTwo client within it and list it under Services -> Client Providers so we can attach the PolicySet.
With the current packaging scheme, the serviceTwo client is not detected.
So I tried pulling the serviceTwoClient.jar at the root level of the ear file. This doesn't help, the serviceTwo client is not listed under Client Providers.
Then I tried to package the serviceTwo client as a war file and pack it at the top level of the ear. This helps, the client gets listed in the client providers on the admin console; but I have two alternatives:
- leave the old jar file packed with the serviceOneEJB. In this case the service invocation works fine but the policyBindings do not send the auth information with the request. I guess that's because the actual call goes through the jar and does not invoke the war, and the policyBinding is not invoked.
- remove the old jar from the serviceOneEJB.jar. In this case the service call fails because application context is not loaded properly (is actually null).
Any help/ideas are greatly appreciated.
so after some more digging I found the solution; add the following to the web.xml of the serviceOneWeb app:
<service-ref>
<service-ref-name>serviceTwo_Service</service-ref-name>
<service-interface>ServiceTwo class name</service-interface>
<wsdl-file>ServiceTwo.wsdl</wsdl-file>
<service-qname xmlns:pfx="service_two_ url">pfx:ServiceTwo</service-qname>
<port-component-ref>
<service-endpoint-interface>ServiceTwoClient_Service class</service-endpoint-interface>
<enable-mtom>false</enable-mtom>
</port-component-ref>
</service-ref>
<security-constraint>
<display-name>SERVICE_ACCESS</display-name>
<web-resource-collection>
<web-resource-name>SERVICE_URLS</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>PUT</http-method>
<http-method>HEAD</http-method>
<http-method>TRACE</http-method>
<http-method>POST</http-method>
<http-method>DELETE</http-method>
<http-method>OPTIONS</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>SERVICE_TWO_USER</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
<security-role>
<role-name>SERVICE_TWO_USER</role-name>
</security-role>

Log4j configured but no sql got printed out

I have latest spring+mybatis
Spring 4.2.3 + MyBatis 3.4+ MyBatis-Spring 1.3
I want to sql got printed out,so configured log4j like this:
# Console output...
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.Threshold = ALL
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %5p [%t] - %m%n
#log4j.logger.com.idpweb = TRACE
log4j.rootLogger = ERROR,stdout
log4j.logger.org.springframework = DEBUG, stdout
# SqlMap logging configuration...
log4j.logger.com.company.dept.mapper.map.SeniorMapper= TRACE
log4j.logger.com.mybatis = TRACE
log4j.logger.java.sql = TRACE
log4j.logger.java.sql.Connection = TRACE
log4j.logger.java.sql.PreparedStatement = TRACE
log4j.logger.java.sql.Statement = TRACE
log4j.logger.java.sql.ResultSet = TRACE
and project struct like this
Project
src
war
WEB-INF
applicationContext.xml
logj.properties
But nothing got printed out when app running,so what is the problem?
Another problem is that after appending "fgsdfgsd" to the end of log4j.properties,then restart web app,no exception got thrown out,so I doubt that spring doesn't take
project/war/WEB-INF/log4j.properties
as it's logging configuration.So I moved log4j.properties to
project/log4j.properties,
nothing changed.
1、if you use maven project,then put the log4j.properties in the resources folder like this:
project/src/main/resources/log4j.properties
this is the default location where log4j try to locate its property file.
2、you can also specify you log4j config file in web.xml like this:
(1)add Log4jConfigListener
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
(2)add context param name 'log4jConfigLocation' to tell Log4jConfigListener where to locate the log4j.proterties
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/conf/log4j.properties</param-value>
</context-param>

Jersey 2.5 and WADL generation : HTTP 404

When I access the WADL with the following URL:
http://localhost:8080/MyApp/application.wadl
Tomcat responds HTTP 404.
My configuration is :
- Tomcat 7
- Jersey 2.5.1
- Jackson 2.3.0
- Spring 3.2.5
I would like to know what to do so that Jeresy generates the WADL file.
Thanks.
I solved my problem :
My servlet mapping is :
<servlet-mapping>
<servlet-name>myapp-web-service-rest-v0</servlet-name>
<url-pattern>/wsrest/v0/*</url-pattern>
</servlet-mapping>
Then the WADL URL is :
http://localhost:8080/MyApp/wsrest/v0/application.wadl
Thanks.

Session not save in bea weblogic 10.3

How to config my web application to work with sessions in bea weblogic?
In the web.xml there are this lines:
<session-config>
<session-timeout>60</session-timeout>
</session-config>
In the weblogic.xml:
<session-descriptor>
<persistent-store-type>memory</persistent-store-type>
<sharing-enabled>true</sharing-enabled>
</session-descriptor>
My question is how to config the server to work with session and when I do this:
_sess.setAttribute("user",user);
...............................
User user = (User ) _sess.getAttribute("user");
The variable user not to be null?

Adding Web App to WebSphere Liberty Profile via Eclipse plugin tools

I'm attempting to get an existing web application working with 'WebSphere Application Server Liberty Profile v8.5 Beta' using the 'IBM WebSphere Liberty Profile Tools for Eclipse'.
I have installed the developer tools for Eclipse as well as the liberty profile runtime by following instructions here:
https://www.ibm.com/developerworks/mydeveloperworks/blogs/wasdev/entry/download?lang=en#comment-1321558450546
I then proceed to create the Liberty Profile Server by following the instructions here:
http://publib.boulder.ibm.com/infocenter/wasinfo/beta/index.jsp?topic=%2Fcom.ibm.websphere.w4d.nd.doc%2Ftopics%2Frw4d_dirs.html
I add my web app to the server and start it with the following console output:
Launching TEST (was4d-1.0.0.20111202-0614/websphere-kernel_1.0.0) on Java HotSpot(TM) 64-Bit Server VM, version 1.6.0_26-b03
Boot properties: file:/home/tbuckley/work/WAS/was4d/usr/servers/TEST/bootstrap.properties
Config document: file:/home/tbuckley/work/WAS/was4d/usr/servers/TEST/server.xml
[AUDIT ] CWWKE0001I: The kernel was launched.
[AUDIT ] CWWKE0002I: The kernel started after 0.91
[AUDIT ] CWWKF0007I: A feature update is starting after 0.92 seconds.
[AUDIT ] CWWKZ0058I: Application monitor started after 1.218 seconds.
[AUDIT ] CWWKO0219I: TCP Channel http-default has been started and is now listening for requests on host localhost (IPv4: 127.0.0.1) port 9080.
[AUDIT ] SRVE9998A: Application myWebApp added to web container.
[AUDIT ] CWWKZ0001I: The application myWebApp has started successfully.
[AUDIT ] CWWKF0008I: The feature update is complete after 2.141 seconds.
When I hit the web app url http://localhost:9080/myWebApp/ via a browser I get a blank page and the following console info:
[ERROR ] SRVE0015E: Failure to initialize Web application myWebApp
If I reload the page I get the following:
[WARNING ] SRVE0274W: Error while adding servlet mapping for path-->/login/*, wrapper-->ServletWrapper[Application Servlet:[/login/*]], application-->myWebApp.
[ERROR ] SRVE0015E: Failure to initialize Web application myWebApp
I also have the following servlets/mappings under my web.xml:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Application Servlet</servlet-name>
<url-pattern>/login/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Any ideas what could be wrong here or how I could get more detailed debug info?
UPDATE
I just created a skeleton 'dynamic web project' there and put an index.html file in it. I added it to the liberty server and it worked by going to localhost:9080/simpleApp/index.html.
The exisiting dynamic web app I am trying to add is very large and complex.
I found the following under was4d/usr/servers/TEST/logs/ffdc/ffdc_12.02.16_16.40.33.0.log:
------Start of DE processing------ = 16/02/12 16:36:06:170 GMT, key = java.lang.NullPointerException com.ibm.ws.webcontainer.osgi.WebContainer 131
Exception = java.lang.NullPointerException
Source = com.ibm.ws.webcontainer.osgi.WebContainer
probeid = 131
S tack Dump = java.lang.NullPointerException
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:142)
at com.ibm.ws.webcontainer.webapp.WebApp.initializeServletContainerInitializers(WebApp.java:1860)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:499)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:5437)
at com.ibm.ws.webcontainer.osgi.WebContainer.discriminate(WebContainer.java:1095)
at com.ibm.ws.webcontainer.osgi.WebContainer.discriminate(WebContainer.java:1009)
at com.ibm.ws.dispatcher.http.internal.channel.HttpDispatcherLink.ready(HttpDispatcherLink.java:143)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:444)
a t com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleNewRequest(HttpInboundLink.java:378)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.processRequest(HttpInboundLink.java:278)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.ready(HttpInboundLink.java:249)
at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:174)
at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:83)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.requestComplete(WorkQueueManager.java:502)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.attemptIO(WorkQueueManager.java:550)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.workerRun(WorkQueueManager.java:899)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager$Worker.run(WorkQueueManager.java:981)
at com.ibm.ws.threading.internal.Worker.executeWork(Worker.java:398)
at com.ibm.ws.threading.internal.Worker.run(Worker.java:380)
at java.lang.Thread.run(Thread.java:662)
The spring setup in the web app appears to be causing some issue?
Thanks
Turns out it is an issue with Spring on certain platforms (WebSphere liberty 8.5 in my case).
Upgrading from Spring 3.1.0 M2 to Spring 3.1.1 fixes the issue:
https://jira.springsource.org/browse/SPR-8496

Resources