Skip to content

Commit

Permalink
[RESTEASY-1532] Disable JsonGenerator.Feature.AUTO_CLOSE_TARGET
Browse files Browse the repository at this point in the history
  • Loading branch information
asoldano committed May 12, 2017
1 parent 145923a commit 55bdd49
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
Expand Up @@ -174,6 +174,7 @@ public void flush() throws IOException {
*/
JsonEncoding enc = findEncoding(mediaType, httpHeaders);
JsonGenerator jg = writer.getFactory().createGenerator(entityStream, enc);
jg.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);

try {
// Want indentation?
Expand Down
Expand Up @@ -6,11 +6,13 @@
import org.jboss.logging.Logger;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.test.providers.jackson2.resource.ExceptionMapperIOExceptionMapper;
import org.jboss.resteasy.test.providers.jackson2.resource.ExceptionMapperMarshalErrorMessage;
import org.jboss.resteasy.test.providers.jackson2.resource.ExceptionMapperMarshalMyCustomException;
import org.jboss.resteasy.test.providers.jackson2.resource.ExceptionMapperMarshalName;
import org.jboss.resteasy.test.providers.jackson2.resource.ExceptionMapperMarshalMyCustomExceptionMapper;
import org.jboss.resteasy.test.providers.jackson2.resource.ExceptionMapperMarshalResource;
import org.jboss.resteasy.test.providers.jackson2.resource.MyEntity;
import org.jboss.resteasy.util.HttpResponseCodes;
import org.jboss.resteasy.util.Types;
import org.jboss.resteasy.utils.PortProviderUtil;
Expand Down Expand Up @@ -47,6 +49,7 @@ public static Archive<?> deploy() {
WebArchive war = TestUtil.prepareArchive(ProxyWithGenericReturnTypeJacksonTest.class.getSimpleName());
war.addClass(Jackson2Test.class);
return TestUtil.finishContainerPrepare(war, null, ExceptionMapperMarshalErrorMessage.class, ExceptionMapperMarshalMyCustomException.class,
MyEntity.class, ExceptionMapperIOExceptionMapper.class,
ExceptionMapperMarshalMyCustomExceptionMapper.class, ExceptionMapperMarshalName.class, ExceptionMapperMarshalResource.class);
}

Expand Down Expand Up @@ -80,4 +83,13 @@ public void testCustomUsed() {
});
Assert.assertEquals("The response has unexpected content", "error", errors.get(0).getError());
}

@Test
public void testMyCustomUsed() {
Response response = client.target(generateURL("/resource/customME")).request().get();
String text = response.readEntity(String.class);

Assert.assertEquals(response.getStatus(), HttpResponseCodes.SC_OK);
Assert.assertTrue("Response does not contain UN_KNOWN_ERR", text.contains("UN_KNOWN_ERR"));
}
}
@@ -0,0 +1,25 @@
package org.jboss.resteasy.test.providers.jackson2.resource;

import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

/**
* User: rsearls
* Date: 10/26/16
*/
@Provider
public class ExceptionMapperIOExceptionMapper implements ExceptionMapper<Throwable> {
@Override
public Response toResponse(Throwable e) {
Map<String, Object> result = new HashMap<>();
result.put("err_msg", "UN_KNOWN_ERR");
result.put("err_detail", "please contact admin for help");
return Response.status(Response.Status.OK).entity(result)
.type(MediaType.APPLICATION_JSON_TYPE).build();

}
}
@@ -1,7 +1,12 @@
package org.jboss.resteasy.test.providers.jackson2.resource;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import java.util.List;

@Path("resource")
Expand All @@ -12,5 +17,12 @@ public List<ExceptionMapperMarshalName> custom() throws Throwable {
throw new ExceptionMapperMarshalMyCustomException("hello");
}


@GET
@Path("customME")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response test() {
MyEntity entity = new MyEntity();
return Response.status(Response.Status.OK).entity(entity).build();
}
}
@@ -0,0 +1,10 @@
package org.jboss.resteasy.test.providers.jackson2.resource;

/**
* A missing JSON annotation is intended. This causes the needed exception
* for testing.
* User: rsearls
* Date: 10/13/16
*/
public class MyEntity {
}

0 comments on commit 55bdd49

Please sign in to comment.