deploying felix webconsole in spring mvc over felix http bridge - spring-mvc

I've Spring MVC webapplication which starts osgi container using ServletContextListener (osgi http bridge). I am trying to deploy felix webconsole along with other bundles, bundle gets started, but I am not able to access it.
In my web.xml
Spring DispatherServlet is configured for URL '/'
Felix ProxyServlet is configured for URL '/ext/*'
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>extension</servlet-name>
<url-pattern>/ext/*</url-pattern>
</servlet-mapping>
I tried to access webconsole using "http://localhost:8080/my-app/ext/system/console" (results 503) and "http://localhost:8080/my-app/system/console" (results 404) with no luck.
Upon debugging I see that for 'ext/system/console' URL, org.apache.felix.http.proxy.DispatcherTracker.DispatcherTracker#getDispatcher() method call in ProxyServlet#service() method returns NULL.
Can anybody point me, what I am missing here ?

Related

Spring MVC 4 File Upload Failing Silently

I'm using Spring MVC (Version 4.1) on Tomcat 8, and am desperately trying to make the file upload functionality work. Currently, I have a controller configured like this:
#RequestMapping(value={"/TestCase/Upload"}, method=RequestMethod.POST)
#ResponseBody
public ResponseEntity<String> uploadFile(HttpServletRequest request,
#RequestParam("file") MultipartFile file) {
System.out.println("Hit this location.");
return new ResponseEntity("Success");
}
My web.xml has the appropriate server configuration:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
<!-- Configuration for file upload (configuring Multipart file) -->
<multipart-config>
<location>/tmp</location>
<max-file-size>500000</max-file-size>
<max-request-size>505000</max-request-size>
<file-size-threshold>10485</file-size-threshold>
</multipart-config>
</servlet>
And finally, my Spring xml configuration file has the necessary resolver specified:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="500000" />
</bean>
The Apache commons-fileupload JAR is on the classpath.
I have used this approach successfully in the past on non-Tomcat servers, but now the application isn't working - but it's failing quietly. The response has a status code of 200, but nothing inside of the file upload controller method is executed. There are no exceptions thrown in the server logs, and the only way I can get the controller method to print anything out is if I remove the "Multipart" parameter entirely. At first I thought that the controller method wasn't being hit at all, but if I change the URL mapping, then the calling code throws a 404 - so it is definitely hitting the correct mapping/method - it's just that nothing inside of the method is executing (with no exceptions thrown!)
What am I doing wrong?
It turns out Spring MVC will hide noClassDef's from the console when booting itself up. The issue was that apache-commons-io.jar was missing on the classpath. Including that JAR caused everything to work properly.
So in the future if Spring is quietly misbehaving - check to ensure all necessary libraries are explicitly included, because it certainly won't tell you!

Skipping view files/pages without going through Dispatcher Servlet?

I am using Spring MVC framework for writing a web application. The first step is to modify the web.xml to make entry for the dispatcher servlet.
The snippet of the web.xml which has this change:
<servlet>
<servlet-name>MediumScaleProject</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<servlet-mapping>
<servlet-name>MediumScaleProject</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I have following questions:
1) Does this mean anything with respect to context root has to go through this servlet mapping? (assume context root for this web application is /contextroot)
2) I want to capture user details in userDetails.html; with the above arrangement it is not working, that is if I access like this: /contextroot/userDetails.html; it is giving HTTP 404 error. What is the best strategy for handling these kind of scenarios?
If you want to make a project with the use of Spring MVC framework, you will need the Model, View and Controller.
yes everything will pass through
you better start to implement the MVC-idea

spring MVC servlet mapping

I am trying a sample spring MVC application. My web.xml has
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
so my question is how I can call my test controller if I just type in the url
http://localhost:8080/MySpringProject/test
Where do i need to make change to call exactly this type of URL so that my test controller called. I don't know what I am asking is correct or not but my requirement is that I don't want to end my UrL with "/" or "test.htm".
Please help and thanks in advance
You usually map your dispatcher servlet to /, and then you have controllers with #RequestMapping("/foo/bar"). But if you define a servlet with a more specific url, it will get picked up.

Servlet mapping in jetty server

I am trying to edit a website:
server : Jetty
framework : spring
index.html page is in ./web/
From this, mapping to webpages in ./web/WEB_INF/template using Servlet. We would like to add one more module in this index.html.. requests help on Servlet mapping.
A servlet is mapped in web.xml:
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.myclass.etcetera.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
It is thus accessible through http://localhost:8080/app/MyServlet
If you are using the latest version of the servlet API (3.0), you can map it using the #WebServlet annotation on the servlet itself (and of course, specify there the url-pattern on which the servlet will respond)

Servlet mapping url mapping issue with spring and BIRT

In my application I'm using spring MVC(3.0.5) architecture along with BIRT reporting framework.
I'm trying to serve all requests including the static resources like css, js, html and image files using the spring DispatcherServlet.
For this purpose I added the following entries to my web.xml
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
...............
...............
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
This will direct all request to the DispatcherServlet and in my context file I added
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/docs/**" location="/docs/" />
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources mapping="/js/**" location="/js/" />
<mvc:resources mapping="/themes/**" location="/themes/" />
so that these resources will be loaded from the file system.
These configurations are working fine. But I'm facing issues with my BIRT reporting engine now.
The BIRT reporting engine uses some jsp files located in a folder called webcontent which is located at the root of the application. Since we are directing all request to DispatcherServlet even the request for these jsp pages are going to the spring servlet. As I understand from some posts the jsp files are normally handled by org.apache.jasper.servlet.JspServlet which is registered in the Apache Tomcat's web.xml file and it has a servlet mapping as follows
<!-- The mapping for the JSP servlet -->
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
What are the changes that I should make in my servlet mapping to work in this environment? I need the jsp files to be handled by the default jsp servlet not by the spring servlet. How can I achieve this?
For this post I understood that the second priority in servlet matching is for the url prefix, so my url pattern / for spring servelt is overriding the default jsp servlet mapping, Is this assumption correct? If it is correct then how to overcome this?
Thank you.
The typical mapping of DispatcherServlet is <url-pattern>/</url-pattern>. In this case it still handles all requests except for requests handled by other servlets (in particular, requests to *.jsp), so that it should solve the problem.

Resources