views:

371

answers:

2

My environment is JBOSS AS 5.1.0-GA, Struts 2.1.8 and RESTEasy 1.2.GA

When posting to my service I get a NPE on the Block getter which is being called from the @Consumes annotation. I'm some what at a loss as to what it could be and any help would be greatly appreciated.

Thank you in advance.

Jono

public class MyForm
{
    @FormParam("block")
    @PartType("application/octet-stream")
    private byte[] block;

    public MyForm(){}

    public byte[] getBlock()
    {
        return block;
    }

    public void setBlock(final byte[] block)
    {
        this.block =  block;
    }
}


@Path("/service")  
public class Service
{

    @Consumes("multipart/form-data")
    @POST
    public Response post(@MultipartForm MyForm form)
    {
        System.out.println(" recieved form " + form);
        ......
    }
}

Exception

Note, I removed the line numbers as they do not correspond to line numbers in the example.

java.lang.NullPointerException
    at MyForm.getBlock(MyForm.java:)
    at Service.postFileBlock(Service.java:)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:119)
    at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:211)
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:176)
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:166)
    at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:359)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:336)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:103)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:114)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter.doFilter(StrutsExecuteFilter.java:67)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
    at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter.doFilter(StrutsPrepareFilter.java:82)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:637)

Please note: This is a cross post from with the resteasy developers mailing list.

A: 

I am not familiar with RestEasy, but your stack suggests that you do not have an instance of MyForm... Since it looks like this is based on reflection, I would suggest you look over your configuration (maybe some type of dependency injection?) to ensure that the object is being instantiated.

PaulP1975
+1  A: 

The Binary data was a red herring, I had the annotations in the wrong place, they should have been on the setter methods rather than the member variable.

public class MyForm
{
   private byte[] block;

   public MyForm(){}

   public byte[] getBlock()
   {
       return block;
   }

   @FormParam("block")
   @PartType("application/octet-stream")
   public void setBlock(final byte[] block)
   {
       this.block =  block;
   }
}
Jonoabroad