当前位置: 首页>>代码示例>>Java>>正文


Java FileDataBodyPart类代码示例

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


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

示例1: testPassThroughPostMultiPart

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的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

示例2: sendFax

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的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

示例3: saveCreativeMultipleUploads

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的package包/类
private String saveCreativeMultipleUploads(StringBuilder uri, List<T1File> fileList, String collection)
		throws ClientException, IOException {
	if (fileList == null) {
		throw new ClientException("please enter a valid filename and file path");
	}

	String path = t1Service.constructUrl(uri, collection);

	FormDataMultiPart multipart = new FormDataMultiPart();

	for (T1File t1File : fileList) {
		if (t1File != null
				&& (t1File.getFile() != null && t1File.getFilename() != null && t1File.getName() != null)) {
			FileDataBodyPart filePart = new FileDataBodyPart("file", new File(t1File.getFile()));

			multipart.field("filename", t1File.getFilename()).field("name", t1File.getName()).bodyPart(filePart);
		}
	}

	Response responseObj = this.connection.post(path, multipart, this.user);
	String response = responseObj.readEntity(String.class);

	multipart.close();

	return response;
}
 
开发者ID:MediaMath,项目名称:t1-java,代码行数:27,代码来源:PostService.java

示例4: main

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的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();
}
 
开发者ID:zekaf,项目名称:jetty-nodes,代码行数:23,代码来源:UploadFileTest.java

示例5: testPostDoNotOwn

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的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

示例6: shouldUploadAFile

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的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

示例7: runAutomationJob

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的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: update

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的package包/类
public void update(TransifexResource resource, String content) throws IOException {

        Path fileToUpload = Files.createTempFile("fileToUpload", ".tmp");
        Files.write(fileToUpload, content.getBytes(StandardCharsets.UTF_8));

        FormDataMultiPart multiPart = new FormDataMultiPart();
        multiPart.bodyPart(new FileDataBodyPart("file", fileToUpload.toFile()));

        String method;

        StringBuilder url = new StringBuilder();
        url.append(API_ROOT);
        url.append("/project/");
        url.append(resource.getProjectSlug());

        if (resourceExists(resource)) {
            method = "PUT";
            url.append("/resource/");
            url.append(resource.getResourceSlug());
            url.append("/content/");
        } else {
            method = "POST";
            url.append("/resources/");
            multiPart.field("slug", resource.getResourceSlug());
            multiPart.field("name", resource.getSourceFile());
            multiPart.field("i18n_type", resource.getType());
        }

        WebTarget webTarget = client.target(TARGET_URL + url);
        Response response = webTarget.request().method(method, Entity.entity(multiPart, multiPart.getMediaType()));

        String jsonData = response.readEntity(String.class);

        if (response.getStatus() / 100 != 2) {
            LOGGER.debug(jsonData);
            throw new IOException("Transifex API call has failed. Status code: " + response.getStatus());
        }

        LOGGER.debug(jsonData);
    }
 
开发者ID:drifted-in,项目名称:txgh,代码行数:41,代码来源:TransifexApi.java

示例9: uploadFile

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的package包/类
@Override
public String uploadFile(String user, String project, File apk) {
	FormDataMultiPart form = new FormDataMultiPart();
	form.field("userId", user);
	form.field("projectId", project);
	form.bodyPart(new FileDataBodyPart("file", apk, MediaType.APPLICATION_OCTET_STREAM_TYPE));
	MediaType contentType = MediaType.MULTIPART_FORM_DATA_TYPE;
	contentType = Boundary.addBoundary(contentType);

	return target.path("upload").path("file").request().post(Entity.entity(form, contentType), String.class);
}
 
开发者ID:saucelabs,项目名称:testobject-java-api,代码行数:12,代码来源:UploadResourceImpl.java

示例10: testUploadArchive

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的package包/类
@Test
public void testUploadArchive() throws IOException {
	File zip = new File(getClass().getClassLoader()
			.getResource("upload.zip").getFile());

	final FormDataMultiPart multipart = new FormDataMultiPart();
	FileDataBodyPart filePart = new FileDataBodyPart("udc_archive_"
			+ zip.getName(), zip);
	multipart.bodyPart(filePart);
	

	final Response response = target.path("queue/myApp").request()
			.post(Entity.entity(multipart, multipart.getMediaType()));

	String result=response.readEntity(String.class);
	assertTrue(result.contains("Files: [upload.zip] queued")
			|| result.contains("Files: [] queued"));
}
 
开发者ID:eBay,项目名称:mTracker,代码行数:19,代码来源:QueueServiceTest.java

示例11: uploadPath

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的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

示例12: testAddDocument

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的package包/类
/**
 * Tests whether a document can be added by uploading it.
 */
@Test
public void testAddDocument() {
  FileDataBodyPart dataPart = new FileDataBodyPart("file", new File(TEST_FILE_PATH));

  FormDataMultiPart formDataMultiPart = new FormDataMultiPart();
  formDataMultiPart.bodyPart(dataPart);

  Entity<FormDataMultiPart> multiPartEntity = Entity.entity(formDataMultiPart,
                                                            formDataMultiPart.getMediaType());

  DocumentIdResponse actualResponse = target("documents").request()
                                        .post(multiPartEntity, DocumentIdResponse.class);

  assertNotNull(actualResponse);

  // TODO The analyis is not stopped, so it will try to continue until
  // the next test empties the database and it fails. It would be better
  // to stop the analysis here
}
 
开发者ID:vita-us,项目名称:ViTA,代码行数:23,代码来源:DocumentsServiceTest.java

示例13: upload

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的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

示例14: tabularUpload

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的package包/类
@Test
public void tabularUpload() {
  Client client = ClientBuilder.newBuilder().register(MultiPartFeature.class).build();
  String dataSetId = "dataset" + UUID.randomUUID().toString().replace("-", "_");
  WebTarget target = client.target(
    format(
      "http://localhost:%d/v5/" + PREFIX + "/" + dataSetId + "/upload/table?forceCreation=true",
      APP.getLocalPort()
    )
  );

  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
  FileDataBodyPart fileDataBodyPart = new FileDataBodyPart(
    "file",
    new File(getResource(IntegrationTest.class, "2017_04_17_BIA_Clusius.xlsx").getFile()),
    new MediaType("application", "vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  );
  multiPart.bodyPart(fileDataBodyPart);
  multiPart.field("type", "xlsx");


  Response response = target.request()
    .header(HttpHeaders.AUTHORIZATION, "fake")
    .post(Entity.entity(multiPart, multiPart.getMediaType()));

  assertThat(response.getStatus(), Matchers.is(201));
  // assertThat(response.getHeaderString(HttpHeaders.LOCATION), Matchers.is(notNullValue()));
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:30,代码来源:IntegrationTest.java

示例15: createDataStore

import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; //导入依赖的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


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