title: Upload binary file with RESTful web service in Glassfish
body: <p>I am trying to send a binary file (picture) to my RESTful web service running in Glassfish.
  I have found code that supposed to do that in 
  <a href="https://stackoverflow.com/questions/5496023/upload-data-method-in-rest-web-service">Upload data method in REST web service</a>
  and several other similar posts but neither work.
  Here is my code:</p>
  
  <pre><code>@POST
  @Consumes(MediaType.APPLICATION_OCTET_STREAM)
  public String post( InputStream payload ) throws IOException
  {
      return "Payload size="+payload.available();
  }
  
  @POST
  @Path("bytes")
  @Consumes(MediaType.APPLICATION_OCTET_STREAM)
  public String post( byte[] payload )
  {
      return "Payload size="+payload.length;
  }
  </code></pre>
  
  <p>The method that receives InputStream returns:</p>
  
  <pre><code>Payload size=0
  </code></pre>
  
  <p>The method that receives byte[] returns:</p>
  
  <pre><code>Error 500 - Internal Server Error
  </code></pre>
  
  <p>The Error 500 is caused by this exception:</p>
  
  <pre><code>Caused by: java.lang.NullPointerException
  at com.sun.jersey.moxy.MoxyMessageBodyWorker.typeIsKnown(MoxyMessageBodyWorker.java:110)
  at com.sun.jersey.moxy.MoxyMessageBodyWorker.isReadable(MoxyMessageBodyWorker.java:133)
  at com.sun.jersey.core.spi.factory.MessageBodyFactory._getMessageBodyReader(MessageBodyFactory.java:345)
  at com.sun.jersey.core.spi.factory.MessageBodyFactory._getMessageBodyReader(MessageBodyFactory.java:315)
  at com.sun.jersey.core.spi.factory.MessageBodyFactory.getMessageBodyReader(MessageBodyFactory.java:294)
  at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:449)
  at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
  at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)
  ... 40 more
  </code></pre>
  
  <p>Any advice greatly appreciated.</p>