eclipse-ee4j / eclipse-ee4j/jersey

@Produces on interface ignored by SubResource

Open
#3,484 3 comments 0 reactions 0 assignees View on GitHub
Priority: Minor Type: Bug
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

I'm using interfaces with JAX-RS annotations in combination with SubResources. The @Produces at the class level on the interface seems to be ignored.

@Produces on the method itself in the interface works as expected. Also, annotating the implementation class with @Produces also seems to work as expected.

See the test case below for a minimal example that demonstrates this problem. I'm expecting a 406 response from testGetTextHtmlNotAcceptable but it returns a 200 instead. With any of the workaround described above the test passes.

```
package org.glassfish.jersey.tests.e2e.server;

import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Assert;
import org.junit.Test;

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

public class SubResourceProducesTest extends JerseyTest {

@Path("/")
@Produces("application/json")
public interface ResourceApi {

@Path("subresource")
SubResource subResource();

}

public static class Resource implements ResourceApi {

public SubResource subResource() {
return new SubResource();
}

}

@Produces("application/json")
public interface SubResourceApi {

String GET_STRING = "Stuff";

@GET
String getStuff();

}

public static class SubResource implements SubResourceApi {

public String getStuff() {
return GET_STRING;
}

}

@Override
protected Application configure() {
return new ResourceConfig(Resource.class);
}

@Test
public void testGetApplicationJson() throws Exception {
Response response = target("subresource").request().accept(MediaType.APPLICATION_JSON).get();
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(SubResource.GET_STRING, response.readEntity(String.class));
}

@Test
public void testGetTextHtmlNotAcceptable() throws Exception {
Response response = target("subresource").request().accept(MediaType.TEXT_HTML).get();
Assert.assertEquals(406, response.getStatus());
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.