當前位置: 首頁>>代碼示例>>Java>>正文


Java FormDataMultiPart.bodyPart方法代碼示例

本文整理匯總了Java中org.glassfish.jersey.media.multipart.FormDataMultiPart.bodyPart方法的典型用法代碼示例。如果您正苦於以下問題:Java FormDataMultiPart.bodyPart方法的具體用法?Java FormDataMultiPart.bodyPart怎麽用?Java FormDataMultiPart.bodyPart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.glassfish.jersey.media.multipart.FormDataMultiPart的用法示例。


在下文中一共展示了FormDataMultiPart.bodyPart方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: uploadHomeFile

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
private void uploadHomeFile() throws Exception {
  final FormDataMultiPart form = new FormDataMultiPart();
  final FormDataBodyPart fileBody = new FormDataBodyPart("file", com.dremio.common.util.FileUtils.getResourceAsString("/testfiles/yelp_biz.json"), MediaType.MULTIPART_FORM_DATA_TYPE);
  form.bodyPart(fileBody);
  form.bodyPart(new FormDataBodyPart("fileName", "biz"));

  com.dremio.file.File file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_start/").queryParam("extension", "json"))
      .buildPost(Entity.entity(form, form.getMediaType())), com.dremio.file.File.class);
  file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_finish/biz"))
      .buildPost(Entity.json(file1.getFileFormat().getFileFormat())), com.dremio.file.File.class);

  FileFormat fileFormat = file1.getFileFormat().getFileFormat();
  assertEquals(physicalFileAtHome.getLeaf().getName(), fileFormat.getName());
  assertEquals(physicalFileAtHome.toPathList(), fileFormat.getFullPath());
  assertEquals(FileType.JSON, fileFormat.getFileType());

  fileBody.cleanup();
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:19,代碼來源:TestAccelerationResource.java

示例2: formatChangeForUploadedHomeFile

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
@Test // DX-5410
public void formatChangeForUploadedHomeFile() throws Exception {
  FormDataMultiPart form = new FormDataMultiPart();
  FormDataBodyPart fileBody = new FormDataBodyPart("file", FileUtils.getResourceAsFile("/datasets/csv/pipe.csv"), MediaType.MULTIPART_FORM_DATA_TYPE);
  form.bodyPart(fileBody);
  form.bodyPart(new FormDataBodyPart("fileName", "pipe"));

  doc("uploading a text file");
  File file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_start/").queryParam("extension", "csv"))
      .buildPost(Entity.entity(form, form.getMediaType())), File.class);
  file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_finish/pipe"))
      .buildPost(Entity.json(file1.getFileFormat().getFileFormat())), File.class);
  final FileFormat defaultFileFormat = file1.getFileFormat().getFileFormat();

  assertTrue(defaultFileFormat instanceof TextFileConfig);
  assertEquals(",", ((TextFileConfig)defaultFileFormat).getFieldDelimiter());

  doc("change the format settings of uploaded file");
  final TextFileConfig newFileFormat = (TextFileConfig)defaultFileFormat;
  newFileFormat.setFieldDelimiter("|");

  final FileFormat updatedFileFormat = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/file_format/pipe"))
      .buildPut(Entity.json(newFileFormat)), FileFormatUI.class).getFileFormat();
  assertTrue(updatedFileFormat instanceof TextFileConfig);
  assertEquals("|", ((TextFileConfig)updatedFileFormat).getFieldDelimiter());
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:27,代碼來源:TestHomeFiles.java

示例3: testPostDoNotOwn

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的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

示例4: update

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的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

示例5: notifyEvent

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
/**
 * Notifies the http end point about the event. Callers can choose the media type
 *
 * @param httpEndPoint
 * @param eventDetails
 * @param mediaType
 * @return response code in case of success
 * @throws LensException in case of exception or http response status != 2XX
 */
private int notifyEvent(String httpEndPoint, Map<String, Object> eventDetails, MediaType mediaType)
  throws LensException {
  final WebTarget target = buildClient().target(httpEndPoint);
  FormDataMultiPart mp = new FormDataMultiPart();
  for (Map.Entry<String, Object> eventDetail : eventDetails.entrySet()) {
    //Using plain format for primitive data types.
    MediaType resolvedMediaType = (eventDetail.getValue() instanceof Number
      || eventDetail.getValue() instanceof String) ? MediaType.TEXT_PLAIN_TYPE : mediaType;
    mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name(eventDetail.getKey()).build(),
      eventDetail.getValue(), resolvedMediaType));
  }
  Response response;
  try {
    response = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
  } catch (Exception e) {
    throw new LensException("Error while publishing Http notification", e);
  }

  //2XX = SUCCESS
  if (!response.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) {
    throw new LensException("Error while publishing Http notification. Response code " + response.getStatus());
  }
  return response.getStatus();
}
 
開發者ID:apache,項目名稱:lens,代碼行數:34,代碼來源:QueryEventHttpNotifier.java

示例6: createFormDataMultiPartForQuery

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
public static FormDataMultiPart createFormDataMultiPartForQuery(final Optional<LensSessionHandle> sessionId,
    final Optional<String> query, final Optional<String> operation, final LensConf lensConf, MediaType mt) {

  final FormDataMultiPart mp = new FormDataMultiPart();

  if (sessionId.isPresent()) {
    mp.bodyPart(getSessionIdFormDataBodyPart(sessionId.get(), mt));
  }

  if (query.isPresent()) {
    mp.bodyPart(getFormDataBodyPart("query", query.get(), mt));
  }

  if (operation.isPresent()) {
    mp.bodyPart(getFormDataBodyPart("operation", operation.get(), mt));
  }

  mp.bodyPart(getFormDataBodyPart("conf", "conf", lensConf, mt));
  return mp;
}
 
開發者ID:apache,項目名稱:lens,代碼行數:21,代碼來源:FormDataMultiPartFactory.java

示例7: testUploadArchive

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的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

示例8: testQueryRejection

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
@Test(dataProvider = "mediaTypeData")
public void testQueryRejection(MediaType mt) throws InterruptedException, IOException {
  final WebTarget target = target().path("queryapi/queries");

  final FormDataMultiPart mp = new FormDataMultiPart();
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
    mt));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "blah select ID from "
    + TEST_TABLE));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
    mt));

  Response response = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
  assertEquals(response.getStatus(), 400);
}
 
開發者ID:apache,項目名稱:lens,代碼行數:17,代碼來源:TestQueryService.java

示例9: testHiveSemanticFailure

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
/**
 * Test semantic error for hive query on non-existent table.
 *
 * @throws IOException          Signals that an I/O exception has occurred.
 * @throws InterruptedException the interrupted exception
 */
@Test(dataProvider = "mediaTypeData")
public void testHiveSemanticFailure(MediaType mt) throws InterruptedException, IOException {
  final WebTarget target = target().path("queryapi/queries");
  final FormDataMultiPart mp = new FormDataMultiPart();
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, mt));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), " select ID from NOT_EXISTS"));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
    mt));

  Response response = target.request(mt).post(Entity.entity(mp, MediaType
    .MULTIPART_FORM_DATA_TYPE));
  LensAPIResult result = response.readEntity(LensAPIResult.class);
  List<LensErrorTO> childErrors = result.getLensErrorTO().getChildErrors();
  boolean hiveSemanticErrorExists = false;
  for (LensErrorTO error : childErrors) {
    if (error.getCode() == LensDriverErrorCode.SEMANTIC_ERROR.getLensErrorInfo().getErrorCode()) {
      hiveSemanticErrorExists = true;
      break;
    }
  }
  assertTrue(hiveSemanticErrorExists);
}
 
開發者ID:apache,項目名稱:lens,代碼行數:30,代碼來源:TestQueryService.java

示例10: explainQuery

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
/**
 * Explain query.
 *
 * @param sql   the sql
 * @param conf  config to be used for the query
 * @return the query plan
 * @throws LensAPIException
 */
public LensAPIResult<QueryPlan> explainQuery(String sql, LensConf conf) throws LensAPIException {
  if (!connection.isOpen()) {
    throw new IllegalStateException("Lens Connection has to be established before querying");
  }

  Client client = connection.buildClient();
  FormDataMultiPart mp = new FormDataMultiPart();
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), connection
    .getSessionHandle(), MediaType.APPLICATION_XML_TYPE));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), sql));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "explain"));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
    MediaType.APPLICATION_XML_TYPE));
  WebTarget target = getQueryWebTarget(client);

  Response response = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));

  if (response.getStatus() == Response.Status.OK.getStatusCode()) {
    return response.readEntity(new GenericType<LensAPIResult<QueryPlan>>() {});
  }

  throw new LensAPIException(response.readEntity(LensAPIResult.class));
}
 
開發者ID:apache,項目名稱:lens,代碼行數:32,代碼來源:LensStatement.java

示例11: testRewriteFailure

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
@Test(dataProvider = "mediaTypeData")
public void testRewriteFailure(MediaType mt) {
  final WebTarget target = target().path("queryapi/queries");

  // estimate cube query which fails semantic analysis
  final FormDataMultiPart mp = new FormDataMultiPart();
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
    mt));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(),
    "sdfelect ID from cube_nonexist"));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "estimate"));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
    mt));

  final Response response = target.request(mt)
    .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));


  LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(
    LensCubeErrorCode.SYNTAX_ERROR.getLensErrorInfo().getErrorCode(),
    "Syntax Error: line 1:0 cannot recognize input near 'sdfelect' 'ID' 'from'",
    TestDataUtils.MOCK_STACK_TRACE);
  ErrorResponseExpectedData expectedData = new ErrorResponseExpectedData(BAD_REQUEST, expectedLensErrorTO);

  expectedData.verify(response);
}
 
開發者ID:apache,項目名稱:lens,代碼行數:27,代碼來源:TestQueryService.java

示例12: tabularUpload

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的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

示例13: testPost

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的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

示例14: importWorkflowConfig

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
@Override
public WorkflowConfig importWorkflowConfig(
  FormDataContentDisposition contentDispositionHeader, InputStream in,
  Long projectId, String authToken) throws Exception {

  Logger.getLogger(getClass())
      .debug("Workflow Client - import workflow config");
  validateNotEmpty(projectId, "projectId");

  StreamDataBodyPart fileDataBodyPart = new StreamDataBodyPart("file", in,
      "filename.dat", MediaType.APPLICATION_OCTET_STREAM_TYPE);
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.bodyPart(fileDataBodyPart);

  ClientConfig clientConfig = new ClientConfig();
  clientConfig.register(MultiPartFeature.class);
  Client client = ClientBuilder.newClient(clientConfig);

  WebTarget target = client.target(config.getProperty("base.url")
      + "/config/import" + "?projectId=" + projectId);

  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken)
      .post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));

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

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }
  // converting to object
  return ConfigUtility.getGraphForString(resultString,
      WorkflowConfigJpa.class);
}
 
開發者ID:WestCoastInformatics,項目名稱:UMLS-Terminology-Server,代碼行數:37,代碼來源:WorkflowClientRest.java

示例15: importChecklist

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
@Override
public Checklist importChecklist(
  FormDataContentDisposition contentDispositionHeader, InputStream in,
  Long projectId, String checklistName, String authToken) throws Exception {

  Logger.getLogger(getClass()).debug("Workflow Client - import checklist");
  validateNotEmpty(projectId, "projectId");
  validateNotEmpty(checklistName, "checklistName");

  StreamDataBodyPart fileDataBodyPart = new StreamDataBodyPart("file", in,
      "filename.dat", MediaType.APPLICATION_OCTET_STREAM_TYPE);
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.bodyPart(fileDataBodyPart);

  ClientConfig clientConfig = new ClientConfig();
  clientConfig.register(MultiPartFeature.class);
  Client client = ClientBuilder.newClient(clientConfig);

  WebTarget target = client
      .target(config.getProperty("base.url") + "/workflow/checklist/import"
          + "?projectId=" + projectId + "&name=" + checklistName);

  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken)
      .post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));

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

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }
  // converting to object
  return ConfigUtility.getGraphForString(resultString, ChecklistJpa.class);

}
 
開發者ID:WestCoastInformatics,項目名稱:UMLS-Terminology-Server,代碼行數:38,代碼來源:WorkflowClientRest.java


注:本文中的org.glassfish.jersey.media.multipart.FormDataMultiPart.bodyPart方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。