本文整理汇总了Java中org.glassfish.jersey.media.multipart.MultiPartFeature类的典型用法代码示例。如果您正苦于以下问题:Java MultiPartFeature类的具体用法?Java MultiPartFeature怎么用?Java MultiPartFeature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MultiPartFeature类属于org.glassfish.jersey.media.multipart包,在下文中一共展示了MultiPartFeature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initClient
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
private static void initClient() {
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
ObjectMapper objectMapper = JSONUtil.prettyMapper();
objectMapper.registerModule(
new SimpleModule()
.addDeserializer(JobDataFragment.class,
new JsonDeserializer<JobDataFragment>() {
@Override
public JobDataFragment deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
return jsonParser.readValueAs(DataPOJO.class);
}
}
)
);
provider.setMapper(objectMapper);
client = ClientBuilder.newBuilder().register(provider).register(MultiPartFeature.class).build();
WebTarget rootTarget = client.target("http://localhost:" + currentDremioDaemon.getWebServer().getPort());
currentApiV2 = rootTarget.path(API_LOCATION);
}
示例2: testPassThroughPostMultiPart
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
/**
* Test to make sure that the proxy can proxy a redirect
* @throws Exception
*/
@Test
public void testPassThroughPostMultiPart() throws Exception {
final FileDataBodyPart filePart = new FileDataBodyPart("test_file", new File(TEST_IMAGE_PATH));
MultiPart multiPart = new FormDataMultiPart()
.field("foo", "bar")
.bodyPart(filePart);
Client multipartClient = ClientBuilder.newBuilder()
.register(MultiPartFeature.class)
.build();
String responseBody = multipartClient.target("http://localhost:" + RULE.getLocalPort() + "/proxy")
.request()
.header("proxy-url", "http://httpbin.org/post")
.post(Entity.entity(multiPart, multiPart.getMediaType()))
.readEntity(String.class);
assertTrue(responseBody.toLowerCase().contains("test_file"));
}
示例3: XbddApplication
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
public XbddApplication() {
packages(getClass().getPackage().getName());
// MVC feature
property(JspMvcFeature.TEMPLATE_BASE_PATH, "/WEB-INF/jsp");
register(JspMvcFeature.class);
register(MultiPartFeature.class);
// Logging.
// register(LoggingFilter.class);
property(ServerProperties.TRACING, TracingConfig.ON_DEMAND.name());
register(new AbstractBinder() {
@Override
protected void configure() {
bindFactory(ServletContextMongoClientFactory.class).to(MongoDBAccessor.class).in(Singleton.class);
}
});
}
示例4: init
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
@BeforeClass
public static void init() throws Exception {
try (TimedBlock b = Timer.time("[email protected]")) {
dremioDaemon = DACDaemon.newDremioDaemon(
DACConfig
.newDebugConfig(DremioTest.DEFAULT_SABOT_CONFIG)
.autoPort(true)
.allowTestApis(true)
.writePath(folder.getRoot().getAbsolutePath())
.clusterMode(ClusterMode.LOCAL)
.serveUI(true),
DremioTest.CLASSPATH_SCAN_RESULT);
dremioDaemon.init();
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(JSONUtil.prettyMapper());
client = ClientBuilder.newBuilder().register(provider).register(MultiPartFeature.class).build();
rootTarget = client.target("http://localhost:" + dremioDaemon.getWebServer().getPort());
}
}
示例5: initMasterClient
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
private static void initMasterClient() {
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
ObjectMapper objectMapper = JSONUtil.prettyMapper();
objectMapper.registerModule(
new SimpleModule()
.addDeserializer(JobDataFragment.class,
new JsonDeserializer<JobDataFragment>() {
@Override
public JobDataFragment deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
return jsonParser.readValueAs(DataPOJO.class);
}
}
)
);
provider.setMapper(objectMapper);
masterClient = ClientBuilder.newBuilder().register(provider).register(MultiPartFeature.class).build();
WebTarget rootTarget = masterClient.target("http://localhost:" + masterDremioDaemon.getWebServer().getPort());
masterApiV2 = rootTarget.path(API_LOCATION);
}
示例6: run
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
@Override
public void run(BlogConfiguration blogConfiguration, Environment environment) throws Exception {
final BlogDao blogDao = new BlogDao(hibernate.getSessionFactory());
// Register all resources here.
environment.jersey().register(new BlogResources(blogDao));
environment.jersey().register(new UploadResources());
environment.jersey().register(new UnitTestResources());
// Register MultiPartFeature.class to support mime type "multipart/form-data."
environment.jersey().getResourceConfig().register(MultiPartFeature.class);
// All Filter
// CORS enable
Dynamic filter = environment.servlets().addFilter("CORS", CrossOriginFilter.class);
filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
filter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,PUT,POST,DELETE,OPTIONS");
filter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
filter.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
filter.setInitParameter("allowedHeaders", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin");
filter.setInitParameter("allowCredentials", "true");
}
示例7: JbrickWSApplication
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
public JbrickWSApplication() {
// Registrazione del package contenente le risorse
packages("it.makeit.jbrick.ws.resources");
packages("it.makeit.profiler.ws.resources");
packages("it.makeit.jbrick.configdb.ws.resources");
packages("it.makeit.jbrick.scheduler.ws.resources");
packages("it.makeit.zefiro.ws.resources");
// Registrazione di jackson-media-provider e configurazione serializzatore
register(JacksonFeature.class);
register(JbrickJacksonConfigurator.class);
// Registrazione del listener delle eccezioni
register(ExceptionListener.class);
// Registrazione exception mapper
register(JbrickExceptionMapper.class);
// Registrazione Multipart Feature per upload file
register(MultiPartFeature.class);
// Registrazione filtri
register(AuthenticationFilter.class);
register(LogFilter.class);
}
示例8: main
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
/**
* <p>main.</p>
*
* @param args an array of {@link java.lang.String} objects.
* @throws java.lang.Exception if any.
*/
@SuppressWarnings("resource")
public static void main(final String[] args) throws Exception
{
final ResourceConfig config = new ResourceConfig();
config.register(PresentationResourceImpl.class);
config.register(MultiPartFeature.class);
final Closeable simpleContainer = SimpleContainerFactory.create(new URI("http://0.0.0.0:8181"),
config);
System.out.println("Strike ENTER to stop...");
new Scanner(System.in).nextLine();
simpleContainer.close();
System.out.println("Bye!");
System.exit(0);
}
示例9: main
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
/**
* <p>main.</p>
*
* @param args an array of {@link java.lang.String} objects.
* @throws java.lang.Exception if any.
*/
@SuppressWarnings("resource")
public static void main(final String[] args) throws Exception
{
final ResourceConfig config = new ResourceConfig();
config.register(OrgsIdResourceImpl.class);
config.register(MultiPartFeature.class);
final Closeable simpleContainer = SimpleContainerFactory.create(new URI("http://0.0.0.0:8181"),
config);
System.out.println("Strike ENTER to stop...");
new Scanner(System.in).nextLine();
simpleContainer.close();
System.out.println("Bye!");
System.exit(0);
}
示例10: main
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
public static void main(String[] args) throws IOException
{
final Client client = ClientBuilder.newBuilder().register(MultiPartFeature.class).build();
final FileDataBodyPart filePart = new FileDataBodyPart("file", new File("/tmp/Sample.pdf"));
FormDataMultiPart formDataMultiPart = new FormDataMultiPart();
final FormDataMultiPart multipart = (FormDataMultiPart) formDataMultiPart.field("foo", "bar").bodyPart(filePart);
final WebTarget target = client.target(getBaseURI());
final Response response = target.request().post(Entity.entity(multipart, multipart.getMediaType()));
//Use response object to verify upload success
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
} else {
System.out.println("Data uploaded successfully !!\n");
}
formDataMultiPart.close();
multipart.close();
}
示例11: SchedulerApiServer
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
public SchedulerApiServer(SchedulerConfig schedulerConfig, Collection<Object> resources) {
this.port = schedulerConfig.getApiServerPort();
this.server = JettyHttpContainerFactory.createServer(
UriBuilder.fromUri("http://0.0.0.0/").port(this.port).build(),
new ResourceConfig(MultiPartFeature.class).registerInstances(new HashSet<>(resources)),
false /* don't start yet. wait for start() call below. */);
this.startTimeout = schedulerConfig.getApiServerInitTimeout();
ServletContextHandler context = new ServletContextHandler();
// Metrics + Prometheus
Metrics.configureMetricsEndpoints(context, "/v1/metrics", "/v1/metrics/prometheus");
// Resources
ResourceConfig resourceConfig = new ResourceConfig(MultiPartFeature.class)
.registerInstances(new HashSet<>(resources));
ServletHolder resourceHolder = new ServletHolder(new ServletContainer(resourceConfig));
context.addServlet(resourceHolder, "/*");
final InstrumentedHandler handler = new InstrumentedHandler(Metrics.getRegistry());
handler.setHandler(context);
server.setHandler(handler);
}
示例12: configure
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
@Override
public boolean configure(FeatureContext context) {
context.register(MoxyJsonFeature.class);
context.register(MoxyXmlFeature.class);
context.register(MultiPartFeature.class);
// internal features
context.register(CacheFilter.class);
context.register(GenericExceptionMapper.class);
context.register(XmlMessageBodyReader.class);
context.register(XmlMessageBodyWriter.class);
Configuration.instance().getStrings("APP.Jersey.Features").forEach(cn -> {
try {
LOGGER.info("Register Jersey Feature: {}", cn);
context.register(this.getClass().getClassLoader().loadClass(cn));
} catch (ClassNotFoundException e) {
LOGGER.error(e.getMessage(), e);
}
});
return true;
}
示例13: ALEXApplication
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
/**
* Constructor where the magic happens.
*/
public ALEXApplication() {
// REST Resources
register(CounterResource.class);
register(FileResource.class);
register(LearnerResource.class);
register(LearnerResultResource.class);
register(ProjectResource.class);
register(SettingsResource.class);
register(SymbolGroupResource.class);
register(SymbolResource.class);
register(UserResource.class);
register(TestResource.class);
// Exceptions
register(NotFoundExceptionMapper.class);
// Other
register(MultiPartFeature.class);
register(AuthenticationFilter.class);
register(RolesAllowedDynamicFeature.class); // allow protecting routes with user roles
register(JacksonConfiguration.class);
}
示例14: shouldUploadAFile
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
@Test
public void shouldUploadAFile() {
Path path = Paths.get(System.getProperty("user.dir"),
"src", "test", "resources", "rest", "IFrameProxyTestData.html");
FileDataBodyPart filePart = new FileDataBodyPart("file", path.toFile());
filePart.setContentDisposition(FormDataContentDisposition.name("file")
.fileName("IFrameProxyTestData.html")
.build());
MultiPart multipartEntity = new FormDataMultiPart().bodyPart(filePart);
Response response = target("/projects/" + PROJECT_TEST_ID + "/files")
.register(MultiPartFeature.class)
.request()
.post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA));
System.out.println(" -> " + response.readEntity(String.class));
// assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
示例15: configure
import org.glassfish.jersey.media.multipart.MultiPartFeature; //导入依赖的package包/类
@Override
protected Application configure() {
final ResourceConfig application =
new ResourceConfig(TestWebserviceWithPath.class, TestWebserviceWithPutDelete.class,
TestWebserviceMultipart.class, TestWebserviceExceptionHandling.class,
JacksonJsonProvider.class);
final Injector injector =
Guice.createInjector(new ClientModule(), new ExceptionObjectMapperModule());
// register multi part feature.
application.register(MultiPartFeature.class);
// register the application mapper.
application.register(injector.getInstance(TestExceptionMapper.class));
return application;
}