Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RESTEASY-1930] NullEntityProxyTest, VariantAcceptTest #1618

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import javax.annotation.Priority;
import javax.json.bind.Jsonb;
import javax.validation.constraints.Null;
import javax.ws.rs.Consumes;
import javax.ws.rs.Priorities;
import javax.ws.rs.ProcessingException;
Expand Down Expand Up @@ -71,9 +72,11 @@ public Object readFrom(Class<Object> type, Type genericType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws java.io.IOException, javax.ws.rs.WebApplicationException {
Jsonb jsonb = getJsonb(type);
try
{
try {
return jsonb.fromJson(entityStream, genericType);
// If null is returned, considered to be empty stream
} catch (NullPointerException ex) {
return null;
} catch (Throwable e)
{
// detail text provided in logger message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@ public static void after() throws Exception {

@Deployment
public static Archive<?> deployUriInfoSimpleResource() {
WebArchive war = TestUtil.prepareArchive(GenericProxyTest.class.getSimpleName());
WebArchive war = TestUtil.prepareArchive(NullEntityProxyTest.class.getSimpleName());
war.addClasses(NullEntityProxy.class, NullEntityProxyGreeting.class, NullEntityProxyGreeter.class);
//FIXME - This is only a workaround for RESTEASY-1930
Map<String, String> contextParam = new HashMap<>();
contextParam.put(ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB, "true");
return TestUtil.finishContainerPrepare(war, contextParam, NullEntityProxyResource.class);
return TestUtil.finishContainerPrepare(war, null, NullEntityProxyResource.class);
}

private static String generateBaseUrl() {
return PortProviderUtil.generateBaseUrl(GenericProxyTest.class.getSimpleName());
return PortProviderUtil.generateBaseUrl(NullEntityProxyTest.class.getSimpleName());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ public class VariantAcceptTest {
public static Archive<?> deploy() {
WebArchive war = TestUtil.prepareArchive(VariantAcceptTest.class.getSimpleName());
war.addClass(VariantAcceptTest.class);
//FIXME - This is only a workaround for RESTEASY-1930
Map<String, String> contextParam = new HashMap<>();
contextParam.put(ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB, "true");
return TestUtil.finishContainerPrepare(war, contextParam, VariantAcceptResource.class);
return TestUtil.finishContainerPrepare(war, null, VariantAcceptResource.class);
}

private String generateURL(String path) {
Expand Down Expand Up @@ -105,6 +102,11 @@ public void testVariantWithParameters() throws Exception {
assertEquals("Wrong media type on response", TEXT_HTML_WITH_PARAMS.toString(), entity);
}

/**
* @tpTestDetails Verifies that the q/qs factors are stripped from the response Content-type header if they are provided
* in the request/@Produces. See RESTEASY-1765.
* @tpSince RESTEasy 3.0.25
*/
@Test
public void testVariantWithQParameter() throws Exception {
ResteasyClient client = new ResteasyClientBuilder().build();
Expand All @@ -114,8 +116,7 @@ public void testVariantWithQParameter() throws Exception {
assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
assertEquals("application/json", response.getHeaderString("Content-Type"));

request = client.target(generateURL("/simple")).request();
request.accept("application/json;qs=0.5, application/xml;qs=0.9");
request = client.target(generateURL("/simpleqs")).request();
response = request.get();
assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
assertEquals("application/xml;charset=UTF-8", response.getHeaderString("Content-Type"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
Expand Down Expand Up @@ -43,4 +44,18 @@ public String params() {
public String simple() {
return "Hello";
}

@GET
@Path("simpleqs")
@Produces("application/json;qs=0.5")
public String simpleqs1() {
return "Hello";
}

@GET
@Path("simpleqs")
@Produces("application/xml;qs=0.9")
public String simpleqs2() {
return "Hello";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<property name="jbossHome">${jboss.home}</property>
<property name="jbossArguments">${securityManagerArg}</property>
<property name="serverConfig">${jboss.server.config.file.name:standalone-full.xml}</property>

<property name="javaVmArguments">-server -Xms256m -Xmx1G -Djboss.bind.address=${node} -Djboss.bind.address.management=${node} -Dnode=${node} -Dipv6=${ipv6} ${additionalJvmArgs} ${ipv6ArquillianSettings} ${jacoco.agent} -Djboss.socket.binding.port-offset=0</property>
<property name="managementAddress">${node}</property>
<property name="managementPort">9990</property>
Expand All @@ -21,7 +20,7 @@
<property name="jbossHome">${jboss.home}</property>
<property name="jbossArguments">${securityManagerArg}</property>
<property name="serverConfig">${jboss.server.config.file.name:standalone-full.xml}</property>
<property name="javaVmArguments">-server -Xms256m -Xmx1G -Djboss.bind.address=${node} -Djboss.bind.address.management=${node} -Dnode=${node} -Dipv6=${ipv6} ${additionalJvmArgs} ${ipv6ArquillianSettings} ${jacoco.agent} -Dee8.preview.mode=${ee8.preview.mode} -Djboss.socket.binding.port-offset=1000 -Dresteasy.allowGzip=true</property>
<property name="javaVmArguments">-server -Xms256m -Xmx1G -Djboss.bind.address=${node} -Djboss.bind.address.management=${node} -Dnode=${node} -Dipv6=${ipv6} ${additionalJvmArgs} ${ipv6ArquillianSettings} ${jacoco.agent} -Djboss.socket.binding.port-offset=1000 -Dresteasy.allowGzip=true</property>
<property name="managementAddress">${node}</property>
<property name="managementPort">10990</property><!-- keep in sync with port-offset -->
</configuration>
Expand Down