Re: [Resteasy-users] Premature response commiting

2013-12-02 Thread Bill Burke
There's really not anything you can do about this at the Resteasy/JAX-RS 
level.  Buffering responses can also be VERY BAD for performance so 
Resteasy (and really JAX-RS) writes directly to the network output 
stream when marshalling via Jackson.

Depending on what servlet container you are using, you may be able to 
configure it to buffer responses so that if an exception is thrown in 
serialization the response can be reset.

On 11/30/2013 12:52 PM, Przemyslaw Wesolek wrote:
 Hello,

 I'm exposing my application via RESTEasy 3.0.5Final with Jackson JSON
 provider. The serialization is still being written, so sometimes bugs
 creep out. Most often it is some exception being thrown by the Jackson
 serializer.

 However, at the moment it happens, the response is already commited,
 status code set to 200 and partial response is being written to the
 output. This is Very Bad Thing, as from the client perspective the 200
 status code means everything went OK, but the JSON is broken.

 For example, if the Jackson can't serialize field abc, the resulting
 JSON looks like:

 {
// some fields serialized correctly by Jackson, like:
ok_field: 1,
// ...
// and then the erronous one, the name without a value:
abc}


 This is because of the setStatus() call being in ServerResponseWriter in
 line 70:

response.setStatus(jaxrsResponse.getStatus());

 while the serialization (and an exception throw) being in line 99:

writerContext.proceed();

 Is there any way I can defer committing anything in the response until
 the whole response body is prepared?

 Regards,
 Przemek


 --
 Rapidly troubleshoot problems before they affect your business. Most IT
 organizations don't have a clear picture of how application performance
 affects their revenue. With AppDynamics, you get 100% visibility into your
 Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
 http://pubads.g.doubleclick.net/gampad/clk?id=84349351iu=/4140/ostg.clktrk
 ___
 Resteasy-users mailing list
 Resteasy-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/resteasy-users


-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com

--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351iu=/4140/ostg.clktrk
___
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users


[Resteasy-users] Another issue while migrating form RESTEasy 2.4 to 3.0.5 : file upload

2013-12-02 Thread Gabriella Turek
The interface:


  @POST

  @ClientResponseType(entityType = JAXBModule.class)

  @Path(/upload)

  @Consumes(MediaType.MULTIPART_FORM_DATA)

  @Produces(MediaType.APPLICATION_XML)

  public Response upload(@MultipartForm FileUploadForm form);


The FileUploadForm class


public class FileUploadForm {


  @FormParam(file)

  @PartType(MediaType.APPLICATION_OCTET_STREAM)

  private InputStream data;


  @FormParam(user)

  @PartType(MediaType.TEXT_PLAIN)

  private String user;


  @FormParam(password)

  @PartType(MediaType.TEXT_PLAIN)

  private String password;


  @FormParam(filename)

  @PartType(MediaType.TEXT_PLAIN)

  private String filename;


  public FileUploadForm() {

  }


  public InputStream getData() {

return data;

  }


  public void setData(InputStream data) {

this.data = data;

  }


  public String getUser() {

return user;

  }


  public void setUser(String user) {

this.user = user;

  }


  public String getPassword() {

return password;

  }


  public void setPassword(String password) {

this.password = password;

  }


  public String getFilename() {

return filename;

  }


  public void setFilename(String filename) {

this.filename = filename;

  }

The client:


ModuleArchiveService client = getArchiveService();

FileUploadForm upload = new FileUploadForm();

upload.setUser(gaby);

upload.setPassword(pwd);

upload.setFilename(hb-tsunami.rksh);

String fileToUpload = testdata/hb-tsunami.rksh;

upload.setData(new FileInputStream(fileToUpload));

Response response = client.upload(upload);


The error message:


javax.ws.rs.ProcessingException: Unable to invoke request

at 
org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:249)

at 
org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:407)

at 
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:102)

at 
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:62)

at com.sun.proxy.$Proxy26.upload(Unknown Source)

at 
nz.org.riskscape.archive.rest.LiveModuleArchiveServiceTest.testUploadFile(LiveModuleArchiveServiceTest.java:68)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)

at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)

at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)

at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)

at org.junit.runners.ParentRunner.run(ParentRunner.java:300)

at 
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: javax.ws.rs.ProcessingException: could not find writer for 
content-type multipart/form-data type: 
nz.org.riskscape.archive.rest.domain.FileUploadForm

at 
org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40)

at 
org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:138)

at 
org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:117)

at 
org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.aroundWriteTo(GZIPEncodingInterceptor.java:100)

at