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


Java FormDataBodyPart类代码示例

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


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

示例1: uploadHomeFile

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

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入依赖的package包/类
@Override
public Response addPhone(Map<String, Object> form) {
    String customer;
    String model;
    try {
        customer = ((List<FormDataBodyPart>) form.get("customer")).get(0).getValue();
        model = ((List<FormDataBodyPart>) form.get("model")).get(0).getValue();
    } catch (NullPointerException npe) {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
    Android newPhone = new Android(null, customer, model, false, new Date(), new Date());
    try {
        controller.create(newPhone);
        return Response.created(new URI("//localhost/api/v1.0/android?id=0")).build();
    } catch (Exception ex) {
        logger.error("failed to persist changes " + ex);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
 
开发者ID:korena,项目名称:service-base,代码行数:20,代码来源:AndroidService.java

示例4: convertScript

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

示例5: runAutomationJob

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

示例6: getFileMapFromFormDataBodyPartList

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入依赖的package包/类
protected Map<String, File> getFileMapFromFormDataBodyPartList(List<FormDataBodyPart> parts) {
	Map<String, File> files = new LinkedHashMap<String, File>();
	
	if (parts != null) {
		for (FormDataBodyPart part : parts) {
			String fileName = part.getContentDisposition().getFileName();
			File file = part.getValueAs(File.class);
			
			if (StringUtils.hasText(fileName) && file != null && file.canRead()) {
				files.put(fileName, file);
			}
		}
	}
	
	return files;
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:17,代码来源:AbstractRestServiceImpl.java

示例7: initializeFromXMLFile

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入依赖的package包/类
/**
 * Generates the attack graph and initializes the main objects for other API calls
 * (database, attack graph, attack paths,...).
 * Load the objects from the XML file POST through a form describing the whole network topology
 *
 * @param request             the HTTP request
 * @param uploadedInputStream The input stream of the XML file
 * @param fileDetail          The file detail object
 * @param body                The body object relative to the XML file
 * @return the HTTP response
 * @throws Exception
 */
@POST
@Path("/initialize")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response initializeFromXMLFile(@Context HttpServletRequest request,
                                      @FormDataParam("file") InputStream uploadedInputStream,
                                      @FormDataParam("file") FormDataContentDisposition fileDetail,
                                      @FormDataParam("file") FormDataBodyPart body) throws Exception {

    if (!body.getMediaType().equals(MediaType.APPLICATION_XML_TYPE) && !body.getMediaType().equals(MediaType.TEXT_XML_TYPE)
            && !body.getMediaType().equals(MediaType.TEXT_PLAIN_TYPE))
        return RestApplication.returnErrorMessage(request, "The file is not an XML file");
    String xmlFileString = IOUtils.toString(uploadedInputStream, "UTF-8");

    return initializeFromXMLText(request, xmlFileString);

}
 
开发者ID:fiware-cybercaptor,项目名称:cybercaptor-server,代码行数:29,代码来源:RestJsonAPI.java

示例8: addIDMEFAlerts

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入依赖的package包/类
/**
 * Receive alerts in IDMEF format and add them into a local queue file,
 * before releasing them when the client requests it.
 *
 * @param request             the HTTP request
 * @param uploadedInputStream The input stream of the IDMEF XML file
 * @param fileDetail          The file detail object
 * @param body                The body object relative to the XML file
 * @return the HTTP response
 * @throws Exception
 */
@POST
@Path("/idmef/add")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response addIDMEFAlerts(@Context HttpServletRequest request,
                               @FormDataParam("file") InputStream uploadedInputStream,
                               @FormDataParam("file") FormDataContentDisposition fileDetail,
                               @FormDataParam("file") FormDataBodyPart body) throws Exception {

    if (!body.getMediaType().equals(MediaType.APPLICATION_XML_TYPE) && !body.getMediaType().equals(MediaType.TEXT_XML_TYPE)
            && !body.getMediaType().equals(MediaType.TEXT_PLAIN_TYPE))
        return RestApplication.returnErrorMessage(request, "The file is not an XML file");

    String xmlFileString = IOUtils.toString(uploadedInputStream, "UTF-8");
    return addIDMEFAlertsFromXMLText(request, xmlFileString);
}
 
开发者ID:fiware-cybercaptor,项目名称:cybercaptor-server,代码行数:27,代码来源:RestJsonAPI.java

示例9: addOrUpdateNotifierInfo

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入依赖的package包/类
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/notifiers/{id}")
@Timed
public Response addOrUpdateNotifierInfo(@PathParam("id") Long id,
                                        @FormDataParam("notifierJarFile") final InputStream inputStream,
                                        @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader,
                                        @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig,
                                        @Context SecurityContext securityContext) throws IOException {
    SecurityUtil.checkPermissions(authorizer, securityContext, Notifier.NAMESPACE, id, WRITE);
    MediaType mediaType = notifierConfig.getMediaType();
    LOG.debug("Media type {}", mediaType);
    if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
        throw new UnsupportedMediaTypeException(mediaType.toString());
    }
    Notifier notifier = notifierConfig.getValueAs(Notifier.class);
    String jarFileName = uploadJar(inputStream, notifier.getName());
    notifier.setJarFileName(jarFileName);
    Notifier newNotifier = catalogService.addOrUpdateNotifierInfo(id, notifier);
    return WSUtils.respondEntity(newNotifier, CREATED);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:22,代码来源:NotifierInfoCatalogResource.java

示例10: addUDF

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入依赖的package包/类
/**
 * Add a new UDF.
 * <p>
 * curl -X POST 'http://localhost:8080/api/v1/catalog/udfs' -F udfJarFile=/tmp/foo-function.jar
 * -F udfConfig='{"name":"Foo", "description": "testing", "type":"FUNCTION", "className":"com.test.Foo"};type=application/json'
 * </p>
 */
@Timed
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/udfs")
public Response addUDF(@FormDataParam("udfJarFile") final InputStream inputStream,
                       @FormDataParam("udfJarFile") final FormDataContentDisposition contentDispositionHeader,
                       @FormDataParam("udfConfig") final FormDataBodyPart udfConfig,
                       @FormDataParam("builtin") final boolean builtin,
                       @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_UDF_ADMIN);
    MediaType mediaType = udfConfig.getMediaType();
    LOG.debug("Media type {}", mediaType);
    if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
        throw new UnsupportedMediaTypeException(mediaType.toString());
    }
    UDF udf = udfConfig.getValueAs(UDF.class);
    processUdf(inputStream, udf, true, builtin);
    UDF createdUdf = catalogService.addUDF(udf);
    SecurityUtil.addAcl(authorizer, securityContext, UDF.NAMESPACE, createdUdf.getId(), EnumSet.allOf(Permission.class));
    return WSUtils.respondEntity(createdUdf, CREATED);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:29,代码来源:UDFCatalogResource.java

示例11: testSubmitMissingParams

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入依赖的package包/类
@Test
public void testSubmitMissingParams() throws IOException {
  FormDataMultiPart form = mock(FormDataMultiPart.class);
  for (final String paramKey : requiredSubmitParamKeys) {
    Set<String> keySet =
        requiredSubmitParamKeys
            .stream()
            .filter(s -> s.equals(paramKey))
            .collect(Collectors.toSet());

    Map<String, List<FormDataBodyPart>> map = new HashMap<>();
    keySet.forEach(t -> map.put(t, Collections.emptyList()));
    when(form.getFields()).thenReturn(map);

    Response response = resource.submit(form);
    assertEquals(HTTP_422, response.getStatus());
  }
}
 
开发者ID:twitter,项目名称:heron,代码行数:19,代码来源:TopologyResourceTests.java

示例12: notifyEvent

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

示例13: addResource

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入依赖的package包/类
public static void addResource(WebTarget target, final LensSessionHandle lensSessionHandle, final String
  resourceType, final String resourcePath, MediaType mt) {
  final WebTarget resourceTarget = target.path("session/resources");
  final FormDataMultiPart mp = new FormDataMultiPart();
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionHandle,
    mt));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("type").build(), resourceType));
  mp.bodyPart(
    new FormDataBodyPart(FormDataContentDisposition.name("path").build(), resourcePath));
  APIResult result = resourceTarget.path("add").request(mt)
    .put(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), APIResult.class);

  if (!result.getStatus().equals(APIResult.Status.SUCCEEDED)) {
    throw new RuntimeException("Could not add resource:" + result);
  }
}
 
开发者ID:apache,项目名称:lens,代码行数:17,代码来源:LensServerTestUtil.java

示例14: executeAsync

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入依赖的package包/类
private void executeAsync() {
  final WebTarget target = target().path("queryapi/queries");

  final FormDataMultiPart mp = new FormDataMultiPart();
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
    MediaType.APPLICATION_XML_TYPE));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from "
    + TestQueryService.TEST_TABLE));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
  mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
    MediaType.APPLICATION_XML_TYPE));
  final QueryHandle handle = target.request(mediaType).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
      new GenericType<LensAPIResult<QueryHandle>>() {}).getData();

  Assert.assertNotNull(handle);
}
 
开发者ID:apache,项目名称:lens,代码行数:17,代码来源:TestResourceMethodMetrics.java

示例15: testHiveSemanticFailure

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


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