Topic
  • 13 replies
  • Latest Post - ‏2013-09-10T22:22:20Z by RafaelMonomanTeixeira
SystemAdmin
SystemAdmin
37422 Posts

Pinned topic RESTful Web Service Stateless Session Bean throws NullPointerException

‏2013-02-14T03:49:48Z |
I have created a RESTful web services against my local WAS 8.0.0.5 development environment. After exporting the EAR file and deploying to our production server, invoking the web services via the appropriate URL causes a NullPointerException and causes an error 500 from the app server. This error occurs before any web service code is executed. I then created another web service that just returned a string and got the same result.
Updated on 2013-02-15T16:02:51Z at 2013-02-15T16:02:51Z by bpaskin
  • bpaskin
    bpaskin
    4282 Posts

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-02-14T12:06:53Z  
    Hi, You are being a little vague. Can you list you code that is causing the issue?

    Regards,
    Brian
  • SystemAdmin
    SystemAdmin
    37422 Posts

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-02-14T15:30:43Z  
    • bpaskin
    • ‏2013-02-14T12:06:53Z
    Hi, You are being a little vague. Can you list you code that is causing the issue?

    Regards,
    Brian
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;

    import javax.ejb.Stateless;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.DataSource;
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;

    import com.google.gson.Gson;

    /**
    * Session Bean implementation class MobileGateway
    */
    @Stateless
    @Path("/mobilegateway")
    public class MobileGateway {

    private static String DATASOURCE_CONTEXT = "jdbc/mobile";

    /**
    * Default constructor.
    */
    public MobileGateway() {
    // TODO Auto-generated constructor stub
    }

    private DataSource setUpDataSource() throws NamingException {

    try {

    Context initialContext = new InitialContext();
    DataSource ds = (DataSource)initialContext.lookup(DATASOURCE_CONTEXT);
    if(ds == null) {
    initialContext = new javax.naming.InitialContext();
    Context envCtx = (javax.naming.Context) initialContext.lookup("java:comp/env");
    ds = (DataSource) envCtx.lookup(DATASOURCE_CONTEXT);
    }

    return ds;
    }
    catch (Exception e) {
    System.out.println("Error:" + e);
    return null;
    }
    }

    @GET
    @Path("/test")
    @Produces("text/plain")
    public String getTest() {
    return "Returned from the web service!";
    }
    @GET
    @Path("/schedule")
    @Produces("application/json")
    public String getSchedule() {

    String result = "";
    List<Schedule> list = new ArrayList<Schedule>();

    try {
    DataSource ds = setUpDataSource();

    Connection c = ds.getConnection();
    Statement s = c.createStatement();

    ResultSet rs = s.executeQuery("select * from pwlc.schedule");
    while (rs.next()) {
    Schedule sch = new Schedule();
    sch.setEndTime(rs.getDate("schedule_end_time"));
    sch.setGroupId(rs.getInt("schedule_group_id"));
    sch.setId(rs.getInt("schedule_id"));
    sch.setLocation(rs.getString("schedule_location"));
    sch.setStartTime(rs.getDate("schedule_start_time"));
    sch.setSubTitle(rs.getString("schedule_subtitle"));
    sch.setText(rs.getString("schedule_text"));
    sch.setTimeText(rs.getString("schedule_time_text"));
    sch.setTitle(rs.getString("schedule_title"));
    sch.setDay(rs.getString("schedule_day"));

    list.add(sch);
    }

    Gson gson = new Gson();
    result = gson.toJson(list);
    }
    catch (Exception e) {
    result = "{error:" + e.toString() + "}";
    System.out.println("Error:" + e);
    }

    return result;
    }

    }
  • SystemAdmin
    SystemAdmin
    37422 Posts

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-02-14T15:31:52Z  
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;

    import javax.ejb.Stateless;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.DataSource;
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;

    import com.google.gson.Gson;

    /**
    * Session Bean implementation class MobileGateway
    */
    @Stateless
    @Path("/mobilegateway")
    public class MobileGateway {

    private static String DATASOURCE_CONTEXT = "jdbc/mobile";

    /**
    * Default constructor.
    */
    public MobileGateway() {
    // TODO Auto-generated constructor stub
    }

    private DataSource setUpDataSource() throws NamingException {

    try {

    Context initialContext = new InitialContext();
    DataSource ds = (DataSource)initialContext.lookup(DATASOURCE_CONTEXT);
    if(ds == null) {
    initialContext = new javax.naming.InitialContext();
    Context envCtx = (javax.naming.Context) initialContext.lookup("java:comp/env");
    ds = (DataSource) envCtx.lookup(DATASOURCE_CONTEXT);
    }

    return ds;
    }
    catch (Exception e) {
    System.out.println("Error:" + e);
    return null;
    }
    }

    @GET
    @Path("/test")
    @Produces("text/plain")
    public String getTest() {
    return "Returned from the web service!";
    }
    @GET
    @Path("/schedule")
    @Produces("application/json")
    public String getSchedule() {

    String result = "";
    List<Schedule> list = new ArrayList<Schedule>();

    try {
    DataSource ds = setUpDataSource();

    Connection c = ds.getConnection();
    Statement s = c.createStatement();

    ResultSet rs = s.executeQuery("select * from pwlc.schedule");
    while (rs.next()) {
    Schedule sch = new Schedule();
    sch.setEndTime(rs.getDate("schedule_end_time"));
    sch.setGroupId(rs.getInt("schedule_group_id"));
    sch.setId(rs.getInt("schedule_id"));
    sch.setLocation(rs.getString("schedule_location"));
    sch.setStartTime(rs.getDate("schedule_start_time"));
    sch.setSubTitle(rs.getString("schedule_subtitle"));
    sch.setText(rs.getString("schedule_text"));
    sch.setTimeText(rs.getString("schedule_time_text"));
    sch.setTitle(rs.getString("schedule_title"));
    sch.setDay(rs.getString("schedule_day"));

    list.add(sch);
    }

    Gson gson = new Gson();
    result = gson.toJson(list);
    }
    catch (Exception e) {
    result = "{error:" + e.toString() + "}";
    System.out.println("Error:" + e);
    }

    return result;
    }

    }
    The simple /test service causes the exact same problem. I have deployed this code without the other method that is using JDBC and still the same result

    This code works on my local WAS 8.0.0.5 dev server.
  • bpaskin
    bpaskin
    4282 Posts

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-02-14T15:58:23Z  
    The simple /test service causes the exact same problem. I have deployed this code without the other method that is using JDBC and still the same result

    This code works on my local WAS 8.0.0.5 dev server.
    Can you paste the stacktrace of the error?

    Brian
  • bpaskin
    bpaskin
    4282 Posts

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-02-14T16:30:06Z  
    • bpaskin
    • ‏2013-02-14T15:58:23Z
    Can you paste the stacktrace of the error?

    Brian
    A few things. To get it working I had the class extend Application and I added an override in the class for the getClasses() method. It seems to work on my 8.5 instance.

    Brian
  • SystemAdmin
    SystemAdmin
    37422 Posts

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-02-14T17:14:34Z  
    • bpaskin
    • ‏2013-02-14T16:30:06Z
    A few things. To get it working I had the class extend Application and I added an override in the class for the getClasses() method. It seems to work on my 8.5 instance.

    Brian
    Thanks for the replies. I have a separate class that extends Application and added my class there and then made the correct entry in web.xml. What I don't understand is why this works in my local WAS 8.0.0.5 and not on my server. Very frustrating!

    (Is there a better way to format output)

    2/13/13 22:31:51:717 EST 0000005c servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet JAX-RS Servlet in application PWLCMobileEAR. Exception created : [java.lang.NullPointerException
    at org.apache.wink.common.internal.http.Accept.valueOf(Accept.java:139)
    at org.apache.wink.server.internal.contexts.HttpHeadersImpl.getAcceptHeader(HttpHeadersImpl.java:151)
    at org.apache.wink.server.internal.contexts.HttpHeadersImpl.getAcceptableMediaTypes(HttpHeadersImpl.java:105)
    at org.apache.wink.server.internal.registry.ResourceRegistry.filterByProduces(ResourceRegistry.java:558)
    at org.apache.wink.server.internal.registry.ResourceRegistry.filterDispatchMethods(ResourceRegistry.java:482)
    at org.apache.wink.server.internal.registry.ResourceRegistry.findSubResourceMethod(ResourceRegistry.java:391)
    at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleSubResourceMethod(FindResourceMethodHandler.java:168)
    at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleRequest(FindResourceMethodHandler.java:110)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.internal.handlers.FindRootResourceHandler.handleRequest(FindRootResourceHandler.java:95)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.internal.handlers.HeadMethodHandler.handleRequest(HeadMethodHandler.java:53)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.internal.handlers.OptionsMethodWADLHandler.handleRequest(OptionsMethodWADLHandler.java:51)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.internal.handlers.SearchResultHandler.handleRequest(SearchResultHandler.java:33)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.internal.log.ResourceInvocation.handleRequest(ResourceInvocation.java:92)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.internal.log.Requests.handleRequest(Requests.java:76)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:52)
    at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:207)
    at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154)
    at org.apache.wink.server.internal.servlet.RestServlet.service(RestServlet.java:124)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1224)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:774)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:456)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1032)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3751)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1690)
  • bpaskin
    bpaskin
    4282 Posts

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-02-14T20:16:00Z  
    Thanks for the replies. I have a separate class that extends Application and added my class there and then made the correct entry in web.xml. What I don't understand is why this works in my local WAS 8.0.0.5 and not on my server. Very frustrating!

    (Is there a better way to format output)

    2/13/13 22:31:51:717 EST 0000005c servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet JAX-RS Servlet in application PWLCMobileEAR. Exception created : [java.lang.NullPointerException
    at org.apache.wink.common.internal.http.Accept.valueOf(Accept.java:139)
    at org.apache.wink.server.internal.contexts.HttpHeadersImpl.getAcceptHeader(HttpHeadersImpl.java:151)
    at org.apache.wink.server.internal.contexts.HttpHeadersImpl.getAcceptableMediaTypes(HttpHeadersImpl.java:105)
    at org.apache.wink.server.internal.registry.ResourceRegistry.filterByProduces(ResourceRegistry.java:558)
    at org.apache.wink.server.internal.registry.ResourceRegistry.filterDispatchMethods(ResourceRegistry.java:482)
    at org.apache.wink.server.internal.registry.ResourceRegistry.findSubResourceMethod(ResourceRegistry.java:391)
    at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleSubResourceMethod(FindResourceMethodHandler.java:168)
    at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleRequest(FindResourceMethodHandler.java:110)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.internal.handlers.FindRootResourceHandler.handleRequest(FindRootResourceHandler.java:95)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.internal.handlers.HeadMethodHandler.handleRequest(HeadMethodHandler.java:53)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.internal.handlers.OptionsMethodWADLHandler.handleRequest(OptionsMethodWADLHandler.java:51)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.internal.handlers.SearchResultHandler.handleRequest(SearchResultHandler.java:33)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.internal.log.ResourceInvocation.handleRequest(ResourceInvocation.java:92)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.internal.log.Requests.handleRequest(Requests.java:76)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
    at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:52)
    at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:207)
    at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154)
    at org.apache.wink.server.internal.servlet.RestServlet.service(RestServlet.java:124)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1224)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:774)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:456)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1032)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3751)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1690)
    Hi, Are you including your own version of Apache Wink in your ear file?

    Brian
  • SystemAdmin
    SystemAdmin
    37422 Posts

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-02-14T22:11:55Z  
    • bpaskin
    • ‏2013-02-14T20:16:00Z
    Hi, Are you including your own version of Apache Wink in your ear file?

    Brian
    Nope. This is just as simple as it looks. I created a web app, created an EJB 3 Stateless bean and then added the RESTful annotations.
  • bpaskin
    bpaskin
    4282 Posts

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-02-15T11:58:45Z  
    Nope. This is just as simple as it looks. I created a web app, created an EJB 3 Stateless bean and then added the RESTful annotations.
    Hi, Can you try a very simple example? Here is the code that I have working on my system:

    
    
    
    package com.ibm.test.ejb.session;   
    
    import java.util.HashSet; 
    
    import java.util.Set; 
    
    import javax.ejb.Stateless; 
    
    import javax.ws.rs.ApplicationPath; 
    
    import javax.ws.rs.GET; 
    
    import javax.ws.rs.Path; 
    
    import javax.ws.rs.Produces; 
    
    import javax.ws.rs.core.Application;   @Stateless @Path(
    "/mobilegateway") @ApplicationPath(
    "jaxrs") 
    
    public 
    
    class TestSession 
    
    extends Application 
    {   @GET @Produces(
    "text/plain") 
    
    public String getTest() 
    { 
    
    return 
    "GET method received a call"; 
    } @Override 
    
    public Set<Class<?>> getClasses() 
    { Set<Class<?>> classes = 
    
    new HashSet<Class<?>>(); classes.add(TestSession.class); 
    
    return classes; 
    } 
    }
    


    Thanks,
    Brian
  • SystemAdmin
    SystemAdmin
    37422 Posts

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-02-15T14:59:44Z  
    • bpaskin
    • ‏2013-02-15T11:58:45Z
    Hi, Can you try a very simple example? Here is the code that I have working on my system:

    <pre class="jive-pre"> package com.ibm.test.ejb.session; import java.util.HashSet; import java.util.Set; import javax.ejb.Stateless; import javax.ws.rs.ApplicationPath; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Application; @Stateless @Path( "/mobilegateway") @ApplicationPath( "jaxrs") public class TestSession extends Application { @GET @Produces( "text/plain") public String getTest() { return "GET method received a call"; } @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = new HashSet<Class<?>>(); classes.add(TestSession.class); return classes; } } </pre>

    Thanks,
    Brian
    Same exact error in log.

    Thanks again for the help.
  • bpaskin
    bpaskin
    4282 Posts

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-02-15T16:02:51Z  
    Same exact error in log.

    Thanks again for the help.
    Hi, If you are still getting the error, it probably is something in the environment. I tested the example service on AIX 6.1, RH Linux and Windows 7 all running WASv8.0.0.5. What you could do is turn on tracing and see what is happening. I would use this trace string: *=info:com.ibm.ws.webservices.*=all:org.apache.*=all:com.ibm.ws.websvcs.*=all:com.ibm.ws.metadata.*=all.

    Regards,
    Brian
  • Christoph
    Christoph
    1 Post

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-08-27T12:24:31Z  
    Same exact error in log.

    Thanks again for the help.

    Hi,

    I've the exactly same error here.

    Have you found a solution to this problem?

    [27.08.13 14:20:34:868 CEST] 0000001b RequestProces E org.apache.wink.server.internal.RequestProcessor handleRequest Nicht behandelte Ausnahme
                                     java.lang.NullPointerException
        at org.apache.wink.common.internal.http.Accept.valueOf(Accept.java:139)
        at org.apache.wink.server.internal.contexts.HttpHeadersImpl.getAcceptHeader(HttpHeadersImpl.java:151)
        at org.apache.wink.server.internal.contexts.HttpHeadersImpl.getAcceptableMediaTypes(HttpHeadersImpl.java:105)
        at org.apache.wink.server.internal.registry.ResourceRegistry.selectBestMatchingMethod(ResourceRegistry.java:603)
        at org.apache.wink.server.internal.registry.ResourceRegistry.findSubResourceMethod(ResourceRegistry.java:394)
        at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleSubResourceMethod(FindResourceMethodHandler.java:168)
        at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleRequest(FindResourceMethodHandler.java:110)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
        at org.apache.wink.server.internal.handlers.FindRootResourceHandler.handleRequest(FindRootResourceHandler.java:95)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
        at org.apache.wink.server.internal.handlers.HeadMethodHandler.handleRequest(HeadMethodHandler.java:53)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
        at org.apache.wink.server.internal.handlers.OptionsMethodHandler.handleRequest(OptionsMethodHandler.java:46)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
        at org.apache.wink.server.internal.handlers.SearchResultHandler.handleRequest(SearchResultHandler.java:33)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
        at org.apache.wink.server.internal.log.ResourceInvocation.handleRequest(ResourceInvocation.java:92)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
        at org.apache.wink.server.internal.log.Requests.handleRequest(Requests.java:76)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:67)
        at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:52)
        at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:207)
        at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154)
        at org.apache.wink.server.internal.servlet.RestServlet.service(RestServlet.java:124)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1225)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:775)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:457)
        at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter.doFilter(AbstractPreAuthenticatedProcessingFilter.java:88)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
        at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:928)
        at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1025)
        at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3763)
        at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
        at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:975)
        at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
        at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:277)
        at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
        at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
        at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:166)
        at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
        at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
        at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
        at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
        at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
        at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
        at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1691)

    Thanks,

    Christoph

  • RafaelMonomanTeixeira
    1 Post

    Re: RESTful Web Service Stateless Session Bean throws NullPointerException

    ‏2013-09-10T22:22:20Z  

    I've been experiencing such type of error and after turning up the log details as bpaskin suggested I've found some reference to a resteasy (JBoss JAX-RS implementation) class which came from some dependency for form/multi-part serialization that I tried to use.

    I yanked the dependency and reinstalled the app and still the error was occurring and killing previously working rest services from other apps.

    So as WebSphere is known to cache lots of merged configuration data, it seems it doesn't uninstall correctly the apps, so I went to the console and used stopServer/startServer to restart the instance and magically all begun to work again...

    So the bottom line is beware of mixing code from other lineages of JEE servers and beware of WebSphere cache mishandling...