• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MultiPart类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.glassfish.jersey.media.multipart.MultiPart的典型用法代码示例。如果您正苦于以下问题:Java MultiPart类的具体用法?Java MultiPart怎么用?Java MultiPart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MultiPart类属于org.glassfish.jersey.media.multipart包,在下文中一共展示了MultiPart类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getFormPostResponse

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
protected final Response getFormPostResponse(String data,
                                             String endpoint,
                                             Class<? extends OutputStream> compressingClass,
                                             String encoding) throws IOException {
  byte[] bytes;
  if (compressingClass == null) {
    bytes = data.getBytes(StandardCharsets.UTF_8);
  } else {
    bytes = compress(data, compressingClass);
  }
  MediaType type =
      encoding == null ? MediaType.TEXT_PLAIN_TYPE : new MediaType("application", encoding);
  InputStream in = new ByteArrayInputStream(bytes);
  StreamDataBodyPart filePart = new StreamDataBodyPart("data", in, "data", type);
  try (MultiPart multiPart = new MultiPart(MediaType.MULTIPART_FORM_DATA_TYPE)) {
    multiPart.getBodyParts().add(filePart);
    return target(endpoint).request().post(
        Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:21,代码来源:AbstractServingTest.java


示例2: testPassThroughPostMultiPart

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的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"));
}
 
开发者ID:kunai-consulting,项目名称:KeyStor,代码行数:22,代码来源:IntegrationTest.java


示例3: sendFax

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
@Override
public APIResponse sendFax(final String faxNumber,
                           final File[] filesToSendAsFax,
                           final Optional<SendFaxOptions> options) throws IOException, URISyntaxException {

    MultiPart multiPart = new MultiPart();
    int count = 1;
    for (File file : filesToSendAsFax) {
        String contentType = tika.detect(file);
        String entityName = "file"+count++;
        FileDataBodyPart fileDataBodyPart = new FileDataBodyPart(entityName, file, MediaType.valueOf(contentType));
        multiPart.bodyPart(fileDataBodyPart);
    }

    return sendMultiPartFax(faxNumber, multiPart, options);
}
 
开发者ID:interfax,项目名称:interfax-java,代码行数:17,代码来源:DefaultInterFAXClient.java


示例4: testPostDoNotOwn

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
@Test
public void testPostDoNotOwn() throws IOException {
    Focus focus = new Focus();
    focus.setAuthoruserguid("88888888-8888-8888-8888-888888888888");
    currentUser.setGuid("99999999-9999-9999-9999-999999999999");
    
    FormDataMultiPart formDataMultiPart = new FormDataMultiPart();
    MultiPart multipart = formDataMultiPart.bodyPart(new FileDataBodyPart("file", Paths.get("pom.xml").toFile()));

    when(focusRepository.loadOrNotFound("00000000-0000-0000-0000-000000000000")).thenReturn(focus);

    Response response = target().path("/picture/focus/00000000-0000-0000-0000-000000000000").request()
            .post(Entity.entity(multipart, multipart.getMediaType()));

    assertEquals(400, response.getStatus());

    verify(focusRepository).loadOrNotFound("00000000-0000-0000-0000-000000000000");

    formDataMultiPart.close();
}
 
开发者ID:coding4people,项目名称:mosquito-report-api,代码行数:21,代码来源:PictureControllerTest.java


示例5: shouldUploadAFile

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的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());
    }
 
开发者ID:LearnLib,项目名称:alex,代码行数:17,代码来源:FileResourceTest.java


示例6: convertScript

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
/**
 * @{inheritDoc
 */
public ScriptTO convertScript(ScriptUploadRequest request, InputStream in) throws RestServiceException {
	WebTarget webTarget = client.target(urlBuilder.buildUrl(ScriptService.METHOD_CONVERT_SCRIPT));
    MultiPart multiPart = new MultiPart();
    BodyPart bp = new FormDataBodyPart("file", in, MediaType.APPLICATION_OCTET_STREAM_TYPE);
    multiPart.bodyPart(bp);
    multiPart.bodyPart(new FormDataBodyPart("scriptUploadRequest", request, MediaType.APPLICATION_XML_TYPE));
    Response response = webTarget.request().post(Entity.entity(multiPart,MediaType.MULTIPART_FORM_DATA_TYPE));
    exceptionHandler.checkStatusCode(response);

    String loc = response.getHeaders().getFirst("location").toString();
    webTarget = client.target(loc);
    response = webTarget.request(MediaType.APPLICATION_XML_TYPE).get();
    exceptionHandler.checkStatusCode(response);
    return response.readEntity(ScriptTO.class);
}
 
开发者ID:intuit,项目名称:Tank,代码行数:19,代码来源:ScriptServiceClient.java


示例7: runAutomationJob

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
/**
 * @{inheritDoc
 */
public String runAutomationJob(AutomationRequest request, File xmlFile)
        throws RestServiceException {
	WebTarget webTarget = client.target(baseUrl + METHOD_RUN_JOB);
    MultiPart multiPart = new MultiPart();
    if (xmlFile != null) {
        BodyPart bp = new FileDataBodyPart("file", xmlFile);
        multiPart.bodyPart(bp);
    }

    multiPart.bodyPart(new FormDataBodyPart("automationRequest", request,
            MediaType.APPLICATION_XML_TYPE));
    Response response = webTarget.request().post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
    exceptionHandler.checkStatusCode(response);
    return response.readEntity(String.class);
}
 
开发者ID:intuit,项目名称:Tank,代码行数:19,代码来源:AutomationServiceClient.java


示例8: multipartToMap

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
/**
 * Convert multi part body into a map of key value pairs.
 *
 * @param multiPart
 * @return
 * @throws IOException
 */
private Map<String, String> multipartToMap(final MultiPart multiPart) throws IOException {
    final Map<String, String> map = new HashMap<>();
    for (final BodyPart part : multiPart.getBodyParts()) {
        Object value = part.getEntity();

        if (value instanceof BodyPartEntity) {
            value = IOUtils.toString(((BodyPartEntity) value).getInputStream());
        }

        if (value instanceof File) {
            value = IOUtils.toString(new FileInputStream((File) value));
        }

        final String fieldName =
                part.getHeaders().get("Content-Disposition").get(0)
                        .split("form-data;\\s*.*name=\"")[1].replaceFirst("\"$", "");
        map.put(fieldName, ObjectUtils.toString(value));
    }
    return map;
}
 
开发者ID:strandls,项目名称:alchemy-rest-client-generator,代码行数:28,代码来源:AlchemyRestClientFactoryTest.java


示例9: uploadPath

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
private void uploadPath(final String name, final String id, final Path path) {
    final Client client = ClientBuilder.newClient();

    client.register(MultiPartFeature.class);

    final WebTarget target = client.target(uri).path(
            uri.getPath() + "_exposr/publish/" + name + "/" + id);

    final FileDataBodyPart filePart = new FileDataBodyPart("file",
            path.toFile(),
            MediaType.APPLICATION_OCTET_STREAM_TYPE);

    final MultiPart multipart = new FormDataMultiPart().bodyPart(filePart);

    Response response = target.request(MediaType.APPLICATION_JSON_TYPE)
            .put(Entity.entity(multipart, multipart.getMediaType()));
}
 
开发者ID:udoprog,项目名称:exposr,代码行数:18,代码来源:RemotePublisher.java


示例10: upload

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
private void upload(String server, String environment, File file, boolean dryRun) throws Exception {
    JerseyClient client = new JerseyClientBuilder()
    		.register(HttpAuthenticationFeature.basic("user", "pass")) // set.getUser(), set.getPass()
    		.register(MultiPartFeature.class)
    		.build();
    JerseyWebTarget t = client.target(UriBuilder.fromUri(server).build()).path("rest").path("items").path("upload");

    FileDataBodyPart filePart = new FileDataBodyPart("file", file);
    String fn = file.getName();
    fn = fn.substring(0, fn.lastIndexOf("_report") + 7); // die tempnummer am ende des filenamens noch wegoperieren!
	System.out.println(fn);
    filePart.setContentDisposition(FormDataContentDisposition.name("file").fileName(fn).build());

    FormDataMultiPart formDataMultiPart = new FormDataMultiPart();
    MultiPart multipartEntity = formDataMultiPart.field("comment", "Analysis from BfR").bodyPart(filePart);

    if (!dryRun) {
	    Response response = t.queryParam("environment", environment).request().post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA));
	    System.out.println(response.getStatus() + " \n" + response.readEntity(String.class));

	    response.close();
    }

    formDataMultiPart.close();
    multipartEntity.close();
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:27,代码来源:TracingXmlOutNodeModel.java


示例11: multipartPost

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
private Response multipartPost(String path, File resource, String mediaType, Map<String, String> arguments)
  throws ParseException {
  MultiPart formdata = new MultiPart();
  arguments.forEach((key, value) -> formdata.bodyPart(new FormDataBodyPart(key, value)));

  formdata.bodyPart(new FormDataBodyPart(
    new FormDataContentDisposition(
      "form-data; name=\"file\"; filename=\"" + resource.getName().replace("\"", "") + "\""
    ),
    resource,
    MediaType.valueOf(mediaType)
  ));

  Response result = call(path)
    .post(Entity.entity(formdata, "multipart/form-data; boundary=Boundary_1_498293219_1483974344746"));
  return result;
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:18,代码来源:IntegrationTest.java


示例12: createDataStore

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
/**
 * Creates a new data store.
 *
 * @param file      CSV file that should be uploaded (N.B. max 50MB)
 * @param name      name to use in the Load Impact web-console
 * @param fromline  Payload from this line (1st line is 1). Set to value 2, if the CSV file starts with a headings line
 * @param separator field separator, one of {@link com.loadimpact.resource.DataStore.Separator}
 * @param delimiter surround delimiter for text-strings, one of {@link com.loadimpact.resource.DataStore.StringDelimiter}
 * @return {@link com.loadimpact.resource.DataStore}
 */
public DataStore createDataStore(final File file, final String name, final int fromline, final DataStore.Separator separator, final DataStore.StringDelimiter delimiter) {
    return invoke(DATA_STORES,
            new RequestClosure<JsonObject>() {
                @Override
                public JsonObject call(Invocation.Builder request) {
                    MultiPart form = new FormDataMultiPart()
                            .field("name", name)
                            .field("fromline", Integer.toString(fromline))
                            .field("separator", separator.param())
                            .field("delimiter", delimiter.param())
                            .bodyPart(new FileDataBodyPart("file", file, new MediaType("text", "csv")));

                    return request.post(Entity.entity(form, form.getMediaType()), JsonObject.class);
                }
            },
            new ResponseClosure<JsonObject, DataStore>() {
                @Override
                public DataStore call(JsonObject json) {
                    return new DataStore(json);
                }
            }
    );
}
 
开发者ID:loadimpact,项目名称:loadimpact-sdk-java,代码行数:34,代码来源:ApiTokenClient.java


示例13: getEntity

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
@Override
public Entity getEntity(List<MultiPartItem> items, String mediaType) {
    MultiPart multiPart = new MultiPart();
    for (MultiPartItem item : items) {
        if (item.getValue() == null || item.getValue().isNull()) {
            continue;
        }
        String name = item.getName();
        String filename = item.getFilename();
        ScriptValue sv = item.getValue();
        String ct = item.getContentType();                    
        if (ct == null) {
            ct = HttpUtils.getContentType(sv);
        }
        MediaType itemType = MediaType.valueOf(ct);
        if (name == null) { // most likely multipart/mixed
            BodyPart bp = new BodyPart().entity(sv.getAsString()).type(itemType);
            multiPart.bodyPart(bp);
        } else if (filename != null) {
            StreamDataBodyPart part = new StreamDataBodyPart(name, sv.getAsStream(), filename, itemType);
            multiPart.bodyPart(part);
        } else {
            multiPart.bodyPart(new FormDataBodyPart(name, sv.getAsString(), itemType));
        }
    }
    return Entity.entity(multiPart, mediaType);
}
 
开发者ID:intuit,项目名称:karate,代码行数:28,代码来源:JerseyHttpClient.java


示例14: sendMultiPartFax

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
private APIResponse sendMultiPartFax(String faxNumber, MultiPart multiPart, Optional<SendFaxOptions> options)
        throws URISyntaxException {

    final URI uri = getSendFaxUri(faxNumber, options);
    return executePostRequest(
            uri,
            (target) ->
                    target
                            .request()
                            .header("Content-Type", "multipart/mixed")
                            .post(Entity.entity(multiPart, multiPart.getMediaType()))
    );
}
 
开发者ID:interfax,项目名称:interfax-java,代码行数:14,代码来源:DefaultInterFAXClient.java


示例15: uploadSchemaVersion

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
public SchemaIdVersion uploadSchemaVersion(final String schemaBranchName,
                                           final String schemaName,
                                           final String description,
                                           final InputStream schemaVersionInputStream)
        throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException {

    SchemaMetadataInfo schemaMetadataInfo = getSchemaMetadataInfo(schemaName);
    if (schemaMetadataInfo == null) {
        throw new SchemaNotFoundException("Schema with name " + schemaName + " not found");
    }

    StreamDataBodyPart streamDataBodyPart = new StreamDataBodyPart("file", schemaVersionInputStream);

    WebTarget target = currentSchemaRegistryTargets().schemasTarget.path(schemaName).path("/versions/upload").queryParam("branch",schemaBranchName);
    MultiPart multipartEntity =
            new FormDataMultiPart()
                    .field("description", description, MediaType.APPLICATION_JSON_TYPE)
                    .bodyPart(streamDataBodyPart);

    Entity<MultiPart> multiPartEntity = Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA);
    Response response = Subject.doAs(subject, new PrivilegedAction<Response>() {
        @Override
        public Response run() {
            return target.request().post(multiPartEntity, Response.class);
        }
    });
    return handleSchemaIdVersionResponse(schemaMetadataInfo, response);
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:29,代码来源:SchemaRegistryClient.java


示例16: uploadFile

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
@Override
public String uploadFile(InputStream inputStream) {
    MultiPart multiPart = new MultiPart();
    BodyPart filePart = new StreamDataBodyPart("file", inputStream, "file");
    multiPart.bodyPart(filePart);
    return Subject.doAs(subject, new PrivilegedAction<String>() {
        @Override
        public String run() {
            return currentSchemaRegistryTargets().filesTarget.request()
                                                             .post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA), String.class);
        }
    });
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:14,代码来源:SchemaRegistryClient.java


示例17: getMultiPart

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
protected MultiPart getMultiPart(ResourceTestElement resourceToTest, Object entity) {
    MultiPart multiPart = new MultiPart();
    BodyPart filePart = new FileDataBodyPart(resourceToTest.getFileNameHeader(), resourceToTest.getFileToUpload());
    BodyPart entityPart = new FormDataBodyPart(resourceToTest.getEntityNameHeader(), entity, MediaType.APPLICATION_JSON_TYPE);
    multiPart.bodyPart(filePart).bodyPart(entityPart);
    return multiPart;
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:8,代码来源:AbstractRestIntegrationTest.java


示例18: testPost

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
@Test
public void testPost() throws IOException {
    Focus focus = new Focus();
    focus.setGuid("00000000-0000-0000-0000-000000000000");
    focus.setAuthoruserguid("88888888-8888-8888-8888-888888888888");
    currentUser.setGuid("88888888-8888-8888-8888-888888888888");
    FormDataMultiPart formDataMultiPart = new FormDataMultiPart();
    MultiPart multipart = formDataMultiPart.bodyPart(new FileDataBodyPart("file", Paths.get("pom.xml").toFile()));

    when(focusRepository.loadOrNotFound("00000000-0000-0000-0000-000000000000")).thenReturn(focus);
    
    Response response = target().path("/picture/focus/00000000-0000-0000-0000-000000000000").request()
            .post(Entity.entity(multipart, multipart.getMediaType()));
    
    assertEquals(200, response.getStatus());
    
    Picture picture = response.readEntity(Picture.class);
    assertNotNull(picture.getGuid());
    assertNotNull(picture.getCreatedat());
    assertEquals("00000000-0000-0000-0000-000000000000", picture.getFocusguid());
    assertEquals("pictures/00000000-0000-0000-0000-000000000000/" + picture.getGuid() + "/pom.xml", picture.getPath());

    verify(focusRepository).loadOrNotFound("00000000-0000-0000-0000-000000000000");
    verify(pictureRepository).save(any(Picture.class));
    verify(pictureBucket).put(eq(picture.getPath()), any(InputStream.class), any(Long.class));

    formDataMultiPart.close();
}
 
开发者ID:coding4people,项目名称:mosquito-report-api,代码行数:29,代码来源:PictureControllerTest.java


示例19: postUpload

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
public Observable<Response> postUpload(MultiPart multipart) {
  Observable<Response> post = Rx.newClient(RxObservableInvoker.class, mes)
      .register(MultiPartFeature.class)
      .target(UriBuilder.fromPath(config.deviceProxyEndpoint()).path(URL_BUNDLES).build())
      .request(MediaType.APPLICATION_JSON)
      .header("Authorization", "Basic YWRtaW46YWRtaW4=").rx()
      .post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));

  return post;
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:11,代码来源:OSGiApiService.java


示例20: updateTankScript

import org.glassfish.jersey.media.multipart.MultiPart; //导入依赖的package包/类
/**
 * @{inheritDoc
 */
public String updateTankScript(InputStream in) throws RestServiceException {
	WebTarget webTarget = client.target(urlBuilder.buildUrl(ScriptService.METHOD_SCRIPT_UPDATE));
    MultiPart multiPart = new MultiPart();
    BodyPart bp = new FormDataBodyPart("file", in, MediaType.APPLICATION_OCTET_STREAM_TYPE);
    multiPart.bodyPart(bp);
    Response response = webTarget.request(MediaType.TEXT_PLAIN_TYPE).post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
    exceptionHandler.checkStatusCode(response);
    return response.readEntity(String.class);
}
 
开发者ID:intuit,项目名称:Tank,代码行数:13,代码来源:ScriptServiceClient.java



注:本文中的org.glassfish.jersey.media.multipart.MultiPart类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ActivationDataFlavor类代码示例发布时间:2022-05-21
下一篇:
Java UsageType类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap