I have a spring4 webapp which works perfectly fine , but after adding spring websocktes configuration xml my app refused to map any http get request.
Error message : Dispatcher servlet doesnt find any handler for this maping.
My web.xml looks like
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/applicationContext*.xml</param-value>
</context-param>
<servlet>
<servlet-name>webapplication</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<async-supported>true</async-supported>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>webapplication</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
My webapplication-servlet.xml looks like
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="1"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="2"/>
Till now every thing works fine as i am getting every request mapping from dispatcher servlet
but after integrating spring websockets in my app my dispatcher servlet doesnt map any http request to my any of the controllers.
I added below code snippet to my webapplication-servlet.xml and i also tried to add this in my application context also.
<websocket:message-broker application-destination-prefix="/app">
<websocket:stomp-endpoint path="/ws">
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic"/>
</websocket:message-broker>
Related
I have my web.xml
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<init-param>
<param-name>static-resources-list</param-name>
<param-value>/myfiles/(\w.*)+(.html|.js)</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
spring config:
<jaxrs:server id="services" address="/">
<jaxrs:serviceBeans>
<bean class="com.abc.MyController"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
</jaxrs:providers>
</jaxrs:server>
My restful resources are working good with URLs http://localhost/appname/resource...
Now I have a src/main/webapp/myfiles/fileOne.html in my source.
I would like to use URL http://localhost/appname/file to redirect to fileOne.html. How do I do that??
EDIT:
I have added static-resources-list in above web.xml cxf configuration. I know that http://localhost/appname/myfiles/fileOne.html works but I want to use URL http://localhost/appname/file to serve the fileOne.html. How do I do that?
Found solution; Just in case anyone needs it.
redirects-list param at CXF servlet configuration didn't serve my purpose. So I added below servlet configuration in web.xml to redirect to my html page.
<servlet>
<servlet-name>swagger-ui</servlet-name>
<jsp-file>/myfiles/fileOne.html</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>swagger-ui</servlet-name>
<url-pattern>/file</url-pattern>
</servlet-mapping>
Your CXFServlet url mapping is the problem. You gave the mapping as /*. So all the requests, even the static resources are routed to CXFServlet. Try making the CXFServlet mapping to something else. It will work just fine. You don't need static-resources-list.
Because you gave the url mapping for CXFServlet as /*, every URL tries to find the response from CXFServlet which is giving the response as not found because it's jax-rs server doesn't know about the static resources.
You can something like this in servlet tag:
<init-param>
<param-name>static-welcome-file</param-name>
<param-value>/index.html</param-value>
</init-param>
I have a simple spring application. The basic implementation is, my app will accept the url's .I have a configuration for dispatcher servlet in web.xml. From there the request is handed over to url handler mapping which maps the url to a controller which is configured in application-web.xml. Normal scenarios it works fine
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application-web.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
application-context.xml
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<!-- Integration: URL Mapping for Page controllers START -->
<!-- DEFAULT URL MAPPING -->
<prop key="/*">pasController</prop>
</props>
</property>
</bean>
But for one particular url I am facing issue.
localhost:7001//..................../etc1/passwd
For the above mentioned url, dispatcher servlet is not able to map it to the controller, so because of this request stuck in weblogic level and thread will be stuck.I mean during the mapping process it is getting stuck, container is not able to know what to do.It is not even reaching the application context level.
How to overgo through this situation?Is there any way to play with the above kind of url's. I tried with both spring 2 ang spring3 web mvc jars.
this is the current configuration i am using for spring mvc:
1- web.xml:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/config/dispatcherServlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
2- dispatcherServlet.xml:
<context:component-scan base-package="com.app" />
<context:annotation-config />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
3- Controller: my web pages are under webapp folder directly
#Controller
public class SearchController {
private Log log = LogFactory.getLog(getClass());
#RequestMapping("/search.jsp")
public String search(Model model, HttpServletRequest request,
HttpSession session) {
log.debug("Search Controller");
return "search";
}
ISSUE: when trying to access the search page as follows:
http://localhost:8080/MyAPP/search.jsp
the controller is not invoked, but when i was mapping the dispatcher servlet to /mapping/* and accessing the search page as follows:
http://localhost:8080/MyAPP/mapping/search.jsp
the controller was invoked correctly, i am using spring 3.0.5.RELEASE.
please advise, thanks.
I think you are forgetting about the built in default servlet configured in your web server/servlet container. For example in Tomcat7/conf/web.xml there exists:
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- The mappings for the JSP servlet -->
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
which is catching the *.jsp before it ever gets to Spring. I tested this locally by removing all of the Spring configuration and could still get the search.jsp.
How DefaultAnnotationHandlerMapping works should be useful in explaining why this works they way it does.
When you had <url-pattern>/mapping/*</url-pattern> you created a more specific match than the simple / so requests were ignored by the default (i.e. Tomcat) servlet and routed to your correctly configured controller.
One way to fix this is to force everything through your servlet by using <url-pattern>/*</url-pattern> but you will also need to make a few other changes to avoid mapping resolution problems.
I moved the *.jsp files into the (standard?) subdirectory /WEB-INF and added
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>/WEB-INF/*</url-pattern>
</servlet-mapping>
to web.xml and changed dispatcherServlet.xml to match like so:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean>
If you do not make these changes, a request to /search.jsp would be resolved by the InternalResourceViewResolver you configured to /search.jsp sending Tomcat into an infinite forwarding loop!
No mapping found for HTTP request with URI [/WEB-INF/pages/apiForm.jsp] may be useful here.
Aside: For most of my Spring XML configured projects I use /WEB-INF/views to keep the view layer separate from any configuration in the /WEB-INF root.
The following mapping will cause the dispatcher servlet to handle urls that were not explicitly mapped by other url mappings within web.xml. Think of this as almost a catch all mapping, as long as the url was not handled by some other mapping.
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
When you configure the ViewResolver as follows:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
The ViewMapping must point to a JSP within your project or else the catch all mapping provided for the dispatcher is going to attempt to handle the forward/redirect to the appropriate view. You must make sure that a view exists within your project for the result of the viewresolver, which is /search.jsp. This means there must be a search.jsp within the root of your projects web content folder. It is much more common to see these views placed within the WEB-INF folder and a mapping of:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean>
I want to be able to disable webservices using spring profile. I have surrounded all the cxf related beans with:
<beans profile="webservices">...</beans>
But what is left is cxf servlet in web.xml:
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
I'm thinking to replace it with:
<servlet>
<servlet-name>webservicesDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>webservicesDispatcher</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
I need to configure webservicesDispather to do the same thing as the CXFServlet does. So far contents of webservicesDispatcher-servlet.xml looks like this:
<beans xmlns="... >
<beans profile="webservices">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
</beans>
</beans>
So, any idea what contents of webservicesDispatcher-servlet.xml should be?
AFAIK CXFServlet will have to be the front controller for CXF flow, DispatcherServlet cannot replace the functionality that CXFServlet performs - any reason why you want the DispatcherServlet alone to handle both Spring MVC flow and CXF WS flow - CXF servlet can refer to the beans in the context file defined by the DispatcherServlet either way.
Following on from How do I inject a Spring bean into Apache Wink?
I'm now using wink-spring-support and I thought I had things set up correctly.
web.xml includes:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:META-INF/wink/wink-core-context.xml
classpath:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>restServlet</servlet-name>
<servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>restServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
META-INF/wink/wink-core-context.xml contains:
<bean class="org.apache.wink.spring.Registrar">
<property name="instances">
<set>
<ref bean="myservice" />
</set>
</property>
</bean>
<bean id="myservice" class="mystuff.ServiceImpl"/>
There's a #Autowired annotation in mystuff.ServiceImpl that injects other Spring stuff, and mystuff.ServiceImpl implements a JAX-RS annotated interface and itself includes a JAX-RS #Path("/services") annotation.
I can see Spring loading up this stuff just fine, including the myservice bean. However when I request my resources, I get a 404 not found. As Wink starts, I can see a couple of log entries that might indicate the problem:
applicationConfigLocation property was not defined
Using application classes null named in init-param applicationConfigLocation
Have I missed something somewhere? Any advice?
The problem was my misunderstanding the docs.
There is a Spring configuration META-INF/server/wink-core-context.xml provided with wink-spring-support. This registers the BeanPostProcessors that actually do the setup and must be referenced from contextConfigLocation.
I thought that I put my configuration in there, which explains why the application didn't get registered with Wink on startup.