use of org.glassfish.jersey.server.model.Resource in project jersey by jersey.
the class ResourceMergeTest method testMergingTemplateResources.
private void testMergingTemplateResources(List<Resource> resources) {
assertEquals(2, resources.size());
final Resource resB = ResourceTestUtils.getResource(resources, "root/{b}");
ResourceTestUtils.containsExactMethods(resB, false, "GET");
final Resource resA = ResourceTestUtils.getResource(resources, "root/{a}");
assertTrue(resA.getResourceMethods().isEmpty());
final List<Resource> childResources = resA.getChildResources();
assertEquals(2, childResources.size());
final Resource childQ = ResourceTestUtils.getResource(childResources, "{q}");
ResourceTestUtils.containsExactMethods(childQ, false, "GET", "PUT");
final Resource childPost = ResourceTestUtils.getResource(childResources, "{post}");
ResourceTestUtils.containsExactMethods(childPost, false, "POST");
}
use of org.glassfish.jersey.server.model.Resource in project jersey by jersey.
the class ResourceMergeTest method createResources.
private List<Resource> createResources(Class<?>... resourceClass) {
final ResourceBag.Builder builder = new ResourceBag.Builder();
for (Class<?> clazz : resourceClass) {
final Resource resource = Resource.from(clazz);
builder.registerProgrammaticResource(resource);
}
final ResourceBag bag = builder.build();
return bag.getRootResources();
}
use of org.glassfish.jersey.server.model.Resource in project jersey by jersey.
the class ResourceMergeTest method testResourceMerge.
@Test
public void testResourceMerge() {
final List<Resource> rootResources = createRootResources();
assertEquals(2, rootResources.size());
final Resource resourceC = ResourceTestUtils.getResource(rootResources, "different-path");
ResourceTestUtils.containsExactMethods(resourceC, false, "POST");
final Resource resourceAB = ResourceTestUtils.getResource(rootResources, "a");
ResourceTestUtils.containsExactMethods(resourceAB, false, "POST", "GET");
}
use of org.glassfish.jersey.server.model.Resource in project jersey by jersey.
the class WadlModelProcessor method processResourceModel.
@Override
public ResourceModel processResourceModel(final ResourceModel resourceModel, final Configuration configuration) {
final boolean disabled = PropertiesHelper.isProperty(configuration.getProperty(ServerProperties.WADL_FEATURE_DISABLE));
if (disabled) {
return resourceModel;
}
final ResourceModel.Builder builder = ModelProcessorUtil.enhanceResourceModel(resourceModel, false, methodList, true);
// Do not add WadlResource if already present in the classes (i.e. added during scanning).
if (!configuration.getClasses().contains(WadlResource.class)) {
final Resource wadlResource = Resource.builder(WadlResource.class).build();
builder.addResource(wadlResource);
}
return builder.build();
}
use of org.glassfish.jersey.server.model.Resource in project jersey by jersey.
the class AbstractJsonTest method configureJaxrsApplication.
/**
* Creates and configures a JAX-RS {@link Application} for given {@link JsonTestSetup}. The {@link Application} will
* contain one resource that can be accessed via {@code POST} method at {@code <jsonProviderName>/<entityClassName>} path.
* The resource also checks whether is the incoming JSON same as the one stored in a appropriate file.
*
* @param jsonTestSetup configuration to create a JAX-RS {@link Application} for.
* @return an {@link Application} instance.
*/
private static Application configureJaxrsApplication(final JsonTestSetup jsonTestSetup) {
final Resource.Builder resourceBuilder = Resource.builder();
final String providerName = getProviderPathPart(jsonTestSetup);
final String testName = getEntityPathPart(jsonTestSetup);
resourceBuilder.path("/" + providerName + "/" + testName).addMethod("POST").consumes(MediaType.APPLICATION_JSON_TYPE).produces(MediaType.APPLICATION_JSON_TYPE).handledBy(new Inflector<ContainerRequestContext, Response>() {
@Override
public Response apply(final ContainerRequestContext containerRequestContext) {
final ContainerRequest containerRequest = (ContainerRequest) containerRequestContext;
// Check if the JSON is the same as in the previous version.
containerRequest.bufferEntity();
try {
String json = JsonTestHelper.getResourceAsString(PKG_NAME, providerName + "_" + testName + (moxyJaxbProvider() || runningOnJdk7AndLater() ? "_MOXy" : "") + ".json").trim();
final InputStream entityStream = containerRequest.getEntityStream();
String retrievedJson = JsonTestHelper.getEntityAsString(entityStream).trim();
entityStream.reset();
// JAXB-RI and MOXy generate namespace prefixes differently - unify them (ns1/ns2 into ns0)
if (jsonTestSetup.getJsonProvider() instanceof JsonTestProvider.JettisonBadgerfishJsonTestProvider) {
if (retrievedJson.contains("\"ns1\"")) {
json = json.replace("ns1", "ns0");
retrievedJson = retrievedJson.replace("ns1", "ns0");
} else if (retrievedJson.contains("\"ns2\"")) {
json = json.replace("ns2", "ns0");
retrievedJson = retrievedJson.replace("ns2", "ns0");
}
}
if (!json.equals(retrievedJson)) {
LOGGER.log(Level.SEVERE, "Expected: " + json);
LOGGER.log(Level.SEVERE, "Actual: " + retrievedJson);
return Response.ok("{\"error\":\"JSON values doesn't match.\"}").build();
}
} catch (final IOException e) {
return Response.ok("{\"error\":\"Cannot find original JSON file.\"}").build();
}
final Object testBean = containerRequest.readEntity(jsonTestSetup.getEntityClass());
return Response.ok(testBean).build();
}
});
final ResourceConfig resourceConfig = new ResourceConfig().registerResources(resourceBuilder.build()).register(jsonTestSetup.getJsonProvider().getFeature());
resourceConfig.registerInstances(getJaxbContextResolver(jsonTestSetup));
if (jsonTestSetup.getProviders() != null) {
resourceConfig.registerInstances(jsonTestSetup.getProviders());
}
return resourceConfig;
}
Aggregations