Vaadin 6 and maven integration results in 404 resource not available error - maven

Im developing a vaadin hello user application with vaadin 6.8.5 jar. It works fine. But when i convert the project to maven it shows 404 HTTP status report with error as resource not available.
Please suggest any ideas to fix this issue.
My Vaadin application
public class Testsample extends Application {
/**
*
*/
private static final long serialVersionUID = 1L;
#Override
public void init() {
Window mainWindow = new Window("Sampletest Application");
Label label = new Label("Hello Vaadin user");
mainWindow.addComponent(label);
setMainWindow(mainWindow);
}}
Web.xml
<servlet>
<servlet-name>Testsample Application</servlet-name>
<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
<init-param>
<description>
Vaadin application class to start</description>
<param-name>application</param-name>
<param-value>com.example.services.TestsampleApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Testsample Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Regards,
M.Vignesh

Your application class in web.xml hava name SampletestApplication:
<param-value>com.example.services.SampletestApplication</param-value>
And in your example aplication class have name Testsample :
public class Testsample extends Application {
They should have the same name.

Related

How to make swagger working with jersey2 and JAX-RS on tomcat 7

I am trying to use swagger in order to document my Rest APIs. I use following link to setup with jersey2 and JAX-RS on tomcat
https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-2.X-Project-Setup-1.5
But I could not access either /swagger.json or /api-docs. Its responding with 404.
What am I doing wrong? Is there a workable documentation? Please help....
Probably you can try to better boil down, which part of the documentation is not yet working in your case.
For me, I used Jersey 2.5.1, and swagger-jersey2-jaxrs_2.10 v. 1.3.4.
I went with the solution to initialize Swagger by a bootstrap class which I included in my web.xml.
bootstrap class
public class SwaggerBootstrap extends HttpServlet {
#Override public void init(ServletConfig servletConfig) {
try {
ServletContext sc = servletConfig.getServletContext();
//as of servlet api 2.5
String ctxPath = sc.getContextPath();
String apiversion = "your-api-version";
String hostname = "your-hostname";
ConfigFactory.config().setBasePath("http://"+hostname+":8080"+ctxPath);
ConfigFactory.config().setApiPath("http://"+hostname+":8080"+ctxPath);
ConfigFactory.config().setApiVersion(apiversion);
ConfigFactory.config().setSwaggerVersion(com.wordnik.swagger.core.SwaggerSpec.version());
System.out.println("Swagger:");
System.out.println("api hostname:"+hostname);
System.out.println("context path:"+ctxPath);
System.out.println("api-version:"+apiversion);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Failed to configure swagger");
}
}
web.xml
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.wordnik.swagger.jersey.listing</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>JerseyJaxrsConfig</servlet-name>
<servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>SwaggerBootstrap</servlet-name>
<servlet-class>my.package.swagger.SwaggerBootstrap</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
Hope that helps.

Jersey-Spring #Autowired not working

I'm using Jersey-Spring integration to expose business layer services.
In my web.xml I'm using the SpringServlet:
com.sun.jersey.spi.spring.container.servlet.SpringServlet
My business layer is #Component annotated, so I have #Service's using #Repository's provided via Spring's annotation config.
Repository's are provided to service's via #Autowired annotation.
If I use a repository through a service using my front end MVC classes everithig goes well, but if I use it through Jersey I get a NullPointerException on the repository object.
The version I'm using (through Maven) are:
Spring (and extensions): 3.1.3.RELEASE
Jersey (and extensions): 1.17
There is way to solve this problem using the same version mentioned in your question,
If needed ill mention the second way , the first way is to load sring through web.xml
like shown below as normal spring confifuration:
<servlet>
<servlet-name>project-spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:project-spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>project-spring</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
Now load your jersey Resources through Application as shown below:
#ApplicationPath("/rest")
public class ResourceLoader extends Application
{
/* (non-Javadoc)
* #see javax.ws.rs.core.Application#getClasses()
*/
#Override
public Set<Class<?>> getClasses()
{
Set<Class<?>> classes = new HashSet<Class<?>>();
loadResourceClasses(classes);
return classes;
}
private void loadResourceClasses(Set<Class<?>> classes)
{
classes.add(StudentResource.class);
}
}
Then in your resource:
#Path("student")
class StudentResource
{
private StudentService studentService;
StudentResource(#Context ServletContext servletContext)
{
ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
this.transactionService = applicationContext.getBean(StudentService .class);
}
}
There'r you go Spring has been configured with all dependency injections with Jersey!!!
You should try using #InjectParam

Spring 2.5.5 and jersey with autowired

I am trying to integrate jersey to an existing Spring application (Spring 2.5.5).
Jersey is working fine, but however when I AutoWire an existing spring bean, the object is null.
Below is my web.xml
<servlet>
<servlet-name>fs3web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.fl.fs3.api;org.codehaus.jackson.jaxrs</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>fs3web</servlet-name>
<url-pattern>/fs3/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
And, here my application context xml (obviously this is not complete, since this is a huge application, there is much more bean definitions):
TestPojo is my bean I would like to autowire to my jersey resource.
<context:annotation-config />
<aop:aspectj-autoproxy/>
<context:component-scan base-package="com.fl.fs3.api,com.fl.fs3.integration.*.web"/>
Both my jersey resource class and POJO class is in package com.fl.fs3.api
#Component
#Path("/v1/site")
public class SitesApiControllerV1 {
#Autowired TestPojo testPojo;
#GET
#Path("/{folderName}")
#Produces(MediaType.APPLICATION_JSON)
public Response getSite(#PathParam("folderName") String folderName) {
System.out.println("pojo obj:" + testPojo);
return Response.ok("info for " + folderName).build();
}
}
#Component
public class TestPojo {
}
When I start my tomcat, I do not see the expected line in logs:
INFO: Registering Spring bean, hello, of type ..... as a root resource class
When I invoke my service /v1/site/xyz, testPojo object is null.
However, before integrating this to my existing project, I did a sample jersey+spring application, and it worked perfectly. I was able to see 'Registering Spring bean' line in logs.
Any help is appreciated.
Try this, it may be more simplified:
Load spring through web.xml like shown below as normal spring confifuration:
<servlet>
<servlet-name>project-spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:project-spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>project-spring</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
Now load your jersey Resources through Application as shown below:
#ApplicationPath("/rest")
public class ResourceLoader extends Application
{
/* (non-Javadoc)
* #see javax.ws.rs.core.Application#getClasses()
*/
#Override
public Set<Class<?>> getClasses()
{
Set<Class<?>> classes = new HashSet<Class<?>>();
loadResourceClasses(classes);
return classes;
}
private void loadResourceClasses(Set<Class<?>> classes)
{
classes.add(StudentResource.class);
}
}
Then in your resource:
#Path("student")
class StudentResource
{
private StudentService studentService;
StudentResource(#Context ServletContext servletContext)
{
ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
this.transactionService = applicationContext.getBean(StudentService .class);
}
}
There you go.
Spring has been configured with all dependency injections with Jersey!

How do I get a JAX-RS application running on WebSphere 8.5

So I am tring to get a JAX-RS application working on my WebSphere 8.5 instance. I created the following interface...
#Path("service")
public class RestService {
#GET
#Produces("text/plain")
public int getCount(){
return 1;
}
}
And This is my Application...
public class RESTConfig extends Application{
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new Hashset<?>();
classes.add(RestService.class);
return classes;
}
}
And then this is my web.xml...
<servlet>
<servlet-name>Rest Servlet</servlet-name>
<servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
<init-param>
<param-name>jaxrs.ws.rs.Application</param-name>
<param-value>com.company.rest.RESTConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
....
<servlet-mapping>
<servlet-name>Rest Servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Then I have an EAR configured with the WAR as a module. But when I start everything and try going to http://localhost:[port]/war/rest/app/service I see..
[TIME] 00000115 RequestProces I org.apache.wink.server.internal.RequestProcessor logException The following error occurred during the invocation of the handlers chain: WebApplicationException (404 - Not Found) with message 'null' while processing GET request sent to http://localhost:[port]/war/rest/service
Please Help!
WAS8.5 supports v2.4 and v3 servlets. The reason removing your web.xml contents (and using 3.0 code) worked for you is because you had a mistake in the param-name tag of your web.xml. v2.4 servlet works fine in WAS8.5 when you use the correct param-name.
This is incorrect.
<param-name>jaxrs.ws.rs.Application</param-name>
This is correct:
<param-name>javax.ws.rs.Application</param-name>
Details:
http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/topic/com.ibm.websphere.nd.multiplatform.doc/ae/twbs_jaxrs_configwebxml.html
The RestConfig class (that is defined as the JAX-RS Application) should override getClasses to return the resources:
#Path("app")
public class RESTConfig extends Application{
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new Hashset<?>();
classes.add(RestService.class);
return classes;
}
}
The issue appears to be related to 8.5 only supporting v3 servlets. this seems to fix the issue....
#Path("service")
public class RestService {
#GET
#Produces("text/plain")
public String getCount(){
//Text-Plain cannot be int apparently
return String.valueOf(1);
}
}
#ApplicationPath("rest")
public class RESTConfig extends Application{
//Override no longer needed.
}
This should now deploy fine...
Here was my source IBM
Also, You can try buy changing the below web.xml File
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Also, In Project Facets - Change Web Module version to 3.0
For More Reference Visit: How to deploy a JAX-RS application?

Servlet Mapping Help - Possible to Avoid Referencing Context Name?

I am working on a Spring application using Tomcat 6 and Spring 2.5. I'm trying to get my URL mapping correct. What I would like to have work is the following:
http://localhost:8080/idptest -> doesn't work
But instead, I have to reference the context name in my URL in order to resolve the mapping:
http://localhost:8080/<context_name>/idptest -> works
How can I avoid the requirement of referencing the context name in my URL without using a rewrite/proxy engine e.g. Apache?
Here is the servlet definition and mapping from my web.xml:
<servlet>
<servlet-name>idptest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/conf/idptest.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>idptest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Here's the outline of my controller (showing annotations for request mappings):
#Controller
#RequestMapping("/idptest")
public class MyController {
#RequestMapping(method=RequestMethod.GET)
public String setupForm(Model model){
MyObject someObject = new MyObject();
model.addAttribute("someObject", someObject);
return "myform";
}
#RequestMapping(method = RequestMethod.POST)
public String processSubmit(#ModelAttribute("someObject") MyObject someObject) throws Exception {
// POST logic...
}
}
Thanks!
That's going to depend on your servlet container, for Tomcat - you pretty much have to deploy your webapp as the ROOT webapp, that is, under $CATALINA_HOME/webapps/ROOT/
More info here
Just rename your war file to ROOT.war, then the application runs in root context (i.e. with empty context name)

Resources