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

14,858

Solution 1

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

Solution 2

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

Solution 3

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;
    }
}

Solution 4

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?

Share:
14,858
Jackie
Author by

Jackie

C++/C/Java/Android Developer

Updated on June 04, 2022

Comments

  • Jackie
    Jackie about 2 years

    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!