Search in sources :

Example 1 with MultiPartFeature

use of org.glassfish.jersey.media.multipart.MultiPartFeature in project jersey by jersey.

the class MultiPartTest method testMultiPartResource.

@Test
public void testMultiPartResource() throws Exception {
    final ResourceConfig resourceConfig = new ResourceConfig(MultiPartResource.class).register(new MultiPartFeature());
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
    Client c = ClientBuilder.newClient(new ClientConfig().register(MultiPartFeature.class));
    final Response response = c.target(baseUri).path("/multipart-simple").request().buildGet().invoke();
    MultiPart result = response.readEntity(MultiPart.class);
    System.out.println("RESULT = " + result);
    checkEntity("This is the only segment", (BodyPartEntity) result.getBodyParts().get(0).getEntity());
    server.shutdownNow();
}
Also used : Response(javax.ws.rs.core.Response) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) Test(org.junit.Test)

Example 2 with MultiPartFeature

use of org.glassfish.jersey.media.multipart.MultiPartFeature in project jersey by jersey.

the class MultiPartJerseyTest method configure.

@Override
protected Application configure() {
    enable(TestProperties.LOG_TRAFFIC);
    enable(TestProperties.DUMP_ENTITY);
    return new ResourceConfig().registerClasses(getResourceClasses()).registerClasses(MultiPartBeanProvider.class).registerInstances(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.PAYLOAD_ANY)).register(new MultiPartFeature());
}
Also used : MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) LoggingFeature(org.glassfish.jersey.logging.LoggingFeature) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 3 with MultiPartFeature

use of org.glassfish.jersey.media.multipart.MultiPartFeature in project Payara by payara.

the class AbstractRestResourceProvider method getResourceConfig.

@Override
public ResourceConfig getResourceConfig(Set<Class<?>> classes, final ServerContext sc, final ServiceLocator habitat, final Set<? extends Binder> additionalBinders) throws EndpointRegistrationException {
    final Reloader r = new Reloader();
    ResourceConfig rc = new ResourceConfig(classes);
    rc.property(ServerProperties.MEDIA_TYPE_MAPPINGS, getMimeMappings());
    rc.register(CsrfProtectionFilter.class);
    // TODO - JERSEY2
    // RestConfig restConf = ResourceUtil.getRestConfig(habitat);
    // if (restConf != null) {
    // if (restConf.getLogOutput().equalsIgnoreCase("true")) { //enable output logging
    // rc.getContainerResponseFilters().add(LoggingFilter.class);
    // }
    // if (restConf.getLogInput().equalsIgnoreCase("true")) { //enable input logging
    // rc.getContainerRequestFilters().add(LoggingFilter.class);
    // }
    // if (restConf.getWadlGeneration().equalsIgnoreCase("false")) { //disable WADL
    // rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
    // }
    // }
    // else {
    // rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
    // }
    // 
    rc.register(r);
    rc.register(ReloadResource.class);
    rc.register(new MultiPartFeature());
    // rc.register(getJsonFeature());
    rc.register(new AbstractBinder() {

        @Override
        protected void configure() {
            AbstractActiveDescriptor<Reloader> descriptor = BuilderHelper.createConstantDescriptor(r);
            descriptor.addContractType(Reloader.class);
            bind(descriptor);
            AbstractActiveDescriptor<ServerContext> scDescriptor = BuilderHelper.createConstantDescriptor(sc);
            scDescriptor.addContractType(ServerContext.class);
            bind(scDescriptor);
            LocatorBridge locatorBridge = new LocatorBridge(habitat);
            AbstractActiveDescriptor<LocatorBridge> hDescriptor = BuilderHelper.createConstantDescriptor(locatorBridge);
            bind(hDescriptor);
            RestSessionManager rsm = habitat.getService(RestSessionManager.class);
            AbstractActiveDescriptor<RestSessionManager> rmDescriptor = BuilderHelper.createConstantDescriptor(rsm);
            bind(rmDescriptor);
        }
    });
    for (Binder b : additionalBinders) {
        rc.register(b);
    }
    rc.property(MessageProperties.LEGACY_WORKERS_ORDERING, true);
    return rc;
}
Also used : Binder(org.glassfish.hk2.utilities.Binder) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ServerContext(org.glassfish.internal.api.ServerContext) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) RestSessionManager(org.glassfish.common.util.admin.RestSessionManager) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) AbstractActiveDescriptor(org.glassfish.hk2.utilities.AbstractActiveDescriptor)

Aggregations

MultiPartFeature (org.glassfish.jersey.media.multipart.MultiPartFeature)3 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)3 Client (javax.ws.rs.client.Client)1 Response (javax.ws.rs.core.Response)1 RestSessionManager (org.glassfish.common.util.admin.RestSessionManager)1 HttpServer (org.glassfish.grizzly.http.server.HttpServer)1 AbstractActiveDescriptor (org.glassfish.hk2.utilities.AbstractActiveDescriptor)1 Binder (org.glassfish.hk2.utilities.Binder)1 AbstractBinder (org.glassfish.hk2.utilities.binding.AbstractBinder)1 ServerContext (org.glassfish.internal.api.ServerContext)1 ClientConfig (org.glassfish.jersey.client.ClientConfig)1 LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)1 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)1 Test (org.junit.Test)1