ranjit pa
asked on
Why simple Jax-rs 2.0 example is not working in websphere 9.0 ?
Below is my code.
Web-sphere context path is set to simple slash /.
xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>RestServlet</servlet-name>
<servlet-class>javax.ws.rs.core.Application</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RestServlet</servlet-name>
<url-pattern>/users/*</url-pattern>
</servlet-mapping>
</web-app>
appln
package com.ibm.jaxrs.sample;
import java.util.HashSet;
import java.util.Set;
import javax.json.JsonWriter;
import javax.ws.rs.ApplicationPath;
@ApplicationPath("/users")
public class HelloWorldAppConfig extends javax.ws.rs.core.Application {
public Set<Class<?>> getClasses() {
HashSet<Class<?>> set = new HashSet<Class<?>>();
set.add(HelloWorldResource.class);
System.out.println("Completed application getclasses");
return set;
}
}
resource
package com.ibm.jaxrs.sample;
import javax.ws.rs.core.*;
import javax.ws.rs.*;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Application;
@javax.ws.rs.Path("/show")
public class HelloWorldResource {
private static final String LINK_SELF = "self";
public HelloWorldResource() {
// TODO Auto-generated constructor stub
System.out.println("Got inside constructor");
}
@GET
@POST
@Produces(MediaType.TEXT_PLAIN)
@Path("/show")
public Response getAll(@Context UriInfo uriInfo) {
System.out.println("Completed application getsingleton");
return Response.ok("Hello").build();
}//@Produces( MediaType.APPLICATION_JSON )
}
included jars in WEB-INF\lib foler
com.ibm.jaxrs2.0.thinclient_9.0.jar
com.ibm.jaxws.thinclient_9.0.jar
com.ibm.ws.ejb.portable_9.0.jar
com.ibm.ws.ejb.thinclient_9.0.jar
com.ibm.ws.jaxrs20.tools.jar
cxf-rt-frontend-jaxrs-3.1.12.jar
cxf-rt-rs-client-3.1.12.jar
cxf-rt-rs-extension-providers-3.1.12.jar
cxf-rt-rs-extension-search-3.1.12.jar
cxf-rt-rs-json-basic-3.1.12.jar
javax.ws.rs-api-2.0.jar
All you've said is that it is "not working", can you give more details on what you are doing and what is happening?
ASKER
Hi, This is my hello world program in Jax-rs 2.0.
Im trying to echo hello when with URL. http://localhost/users/show/
System.out.println is working upto application's getClasses() function.
Correct resources are not being called at all. Below is from error log
Im trying to echo hello when with URL. http://localhost/users/show/
System.out.println is working upto application's getClasses() function.
Correct resources are not being called at all. Below is from error log
000001d2 SystemOut O Completed application getclasses[class com.ibm.jaxrs.sample.HelloWorldResource]
000001d2 0(id=126)] I Setting the server's publish address to be /hellpath
000001d2 ServletWrappe I com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0242I: [helloworld_war] [/] [helloworldserv]: Iniitalised successfully.
000001d2 webcontainer I com.ibm.ws.webcontainer.VirtualHostImpl addWebApplication SRVE0250I: Web module null is binded to default_host[*:9080,*:80,*:9443,*:5060,*:5061,*:443]
W org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging Interceptor for {http://sample.jaxrs.ibm.com/}HelloWorldResource has thrown exception, unwinding now
java.lang.NullPointerException
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.