3

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!

4 Answers 4

3

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

1

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;
    }
}
3
  • Sorry the original post was supposed to obfuscated and wasn't. Anyway I didn't try the getCount at the end yet. I thought it would use the path in PATH is that not the case? I will try it out again. On another note I will post an update with the problems I have with wink.
    – Jackie
    Dec 14, 2012 at 15:34
  • Yup no dice... localhost:[port]/war/rest/app/service/getCount gives me... [Time] 000000a1 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 [url]
    – Jackie
    Dec 14, 2012 at 16:06
  • I am finishing up looking at it and believe it or not I think it has to do with 8.5 not supporting anything lower that Servlet 3.0. Meaning I have to use the ApplicationPath annotation. I will confirm then answer.
    – Jackie
    Dec 14, 2012 at 17:42
1

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

3
  • Doesn't look like it support only 3.0 but has special integration with it, both should work. The first example shows how to do it the old way. still, its better to do it the new way if you don't plan on supporting older WAS. Dec 15, 2012 at 18:28
  • Actually I couldn't get the old way to work at all. Not sure if it was the hacky way I used Juno and 8.5 or what. But on 8.5 in particular only the new way worked.
    – Jackie
    Dec 15, 2012 at 23:14
  • The's good to hear, I'll probably run into this in a very short time Dec 16, 2012 at 6:18
1

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.