org.glassfish.jersey.media.multipart.MultiPart.getMediaType()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中org.glassfish.jersey.media.multipart.MultiPart.getMediaType()方法的一些代码示例,展示了MultiPart.getMediaType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MultiPart.getMediaType()方法的具体详情如下:
包路径:org.glassfish.jersey.media.multipart.MultiPart
类名称:MultiPart
方法名:getMediaType

MultiPart.getMediaType介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public class Slimclient {
  private static final String TARGET_URL = "http://localhost:49158/rest/service/upload";

  public Slimclient() {
    Client client = ClientBuilder.newBuilder()
      .register(MultiPartFeature.class).build();
    WebTarget webTarget = client.target(TARGET_URL);
    MultiPart multiPart = new MultiPart();
    multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

    FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file",
      new File("C:/Users/Nicklas/Desktop/aab.txt"),
      MediaType.APPLICATION_OCTET_STREAM_TYPE);
    multiPart.bodyPart(fileDataBodyPart);

    Response response = webTarget.request(MediaType.APPLICATION_JSON_TYPE)
      .post(Entity.entity(multiPart, multiPart.getMediaType()));

    System.out.println(response.getStatus() + " "
      + response.getStatusInfo() + " " + response);
  }

  public static void main(String[] args) {
    new Slimclient();
  }
}

代码示例来源:origin: stackoverflow.com

final MultiPart multiPartEntity = new MultiPart()
    .bodyPart(new BodyPart().entity("hello"))
    .bodyPart(new BodyPart(new JaxbBean("xml"), MediaType.APPLICATION_XML_TYPE))
    .bodyPart(new BodyPart(new JaxbBean("json"), MediaType.APPLICATION_JSON_TYPE));

final WebTarget target = // Create WebTarget.
final Response response = target
    .request()
    .post(Entity.entity(multiPartEntity, multiPartEntity.getMediaType()));

代码示例来源:origin: JakimLi/pandaria

public Entity<?> requestBody() {
  return hasAttachment() ? entity(attachments, attachments.getMediaType()) : entity(requestBody, contentType());
}

代码示例来源:origin: com.github.jakimli.pandaria/pandaria-core

public Entity<?> requestBody() {
  return hasAttachment() ? entity(attachments, attachments.getMediaType()) : entity(requestBody, contentType());
}

代码示例来源:origin: AdamBien/loadr

public boolean deploy(String archiveFile) {
  FileDataBodyPart archive = new FileDataBodyPart("id", new File(archiveFile));
  MultiPart form = new FormDataMultiPart().
      field("force", "true").bodyPart(archive);
  Response response = applicationTarget.request("application/json").
      header("X-Requested-By", "loadr").
      post(Entity.entity(form, form.getMediaType()));
  return (response.getStatus() == 200);
}

代码示例来源:origin: org.mule.tools.maven/mule-maven-plugin

public void uploadFile(String appName, File file)
{
  FileDataBodyPart applicationPart = new FileDataBodyPart("file", file);
  MultiPart multipart = new FormDataMultiPart().bodyPart(applicationPart);
  Response response = post(uri, String.format(APPLICATIONS_FILES_PATH, appName), Entity.entity(multipart, multipart.getMediaType()));
  if (response.getStatus() != 200)
  {
    throw new ApiException(response);
  }
}

代码示例来源:origin: stackoverflow.com

Client client = ClientBuilder.newClient();
client.register(MultiPartFeature.class);
WebTarget target = client.target("https://apisomeurl.com");

MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

//Image here
FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("image", new File("/some/img/path/img.png"));
multiPart.bodyPart(fileDataBodyPart);

//MediaType.APPLICATION_JSON_TYPE because I'm expecting a JSON response from the server           
String str = target.queryParam("param1", "1")
          .queryParam("param2", "2")
          .queryParam("param3", "3")
          .request(MediaType.APPLICATION_JSON_TYPE)
          .post(Entity.entity(multiPart, multiPart.getMediaType()), String.class);

代码示例来源:origin: org.mule.tools.maven/mule-maven-plugin

public Application deployApplication(File app, String appName, TargetType targetType, String target)
{
  String id = getId(targetType, target);
  FileDataBodyPart applicationPart = new FileDataBodyPart("file", app);
  MultiPart multipart = new FormDataMultiPart()
      .field("artifactName", appName)
      .field("targetId", id)
      .bodyPart(applicationPart);
  Response response = post(uri, APPLICATIONS, Entity.entity(multipart, multipart.getMediaType()));
  validateStatusSuccess(response);
  return response.readEntity(Application.class);
}

代码示例来源:origin: com.eclipsesource.jaxrs/consumer

private Entity<?> getEntity( Method method, Object[] parameter ) {
 Entity<?> result = null;
 if( hasFormParameter( method ) ) {
  Form form = computeForm( method, parameter );
  result = Entity.form( form );
 } else if( hasMultiPartFormParameter( method ) ) {
  MultiPart mp = computeMultiPart( method, parameter );
  result = Entity.entity( mp, mp.getMediaType() );
 } else {
  result = determineBodyParameter( method, parameter );
 }
 return result;
}

代码示例来源:origin: batfish/batfish

webTarget
  .request(MediaType.APPLICATION_JSON)
  .post(Entity.entity(multiPart, multiPart.getMediaType()));

代码示例来源:origin: batfish/batfish

webTarget
  .request(MediaType.APPLICATION_OCTET_STREAM)
  .post(Entity.entity(multiPart, multiPart.getMediaType()));

代码示例来源:origin: gmessner/gitlab4j-api

/**
 * Perform a file upload using multipart/form-data using the HTTP PUT method, returning
 * a ClientResponse instance with the data returned from the endpoint.
 *
 * @param name the name for the form field that contains the file name
 * @param fileToUpload a File instance pointing to the file to upload
 * @param url the fully formed path to the GitLab API endpoint
 * @return a ClientResponse instance with the data returned from the endpoint
 * @throws IOException if an error occurs while constructing the URL
 */
protected Response putUpload(String name, File fileToUpload, URL url) throws IOException {
  try (MultiPart multiPart = new FormDataMultiPart()) {
    multiPart.bodyPart(new FileDataBodyPart(name, fileToUpload, MediaType.APPLICATION_OCTET_STREAM_TYPE));
    final Entity<?> entity = Entity.entity(multiPart, Boundary.addBoundary(multiPart.getMediaType()));
    return (invocation(url, null).put(entity));
  }
}

代码示例来源:origin: org.gitlab4j/gitlab4j-api

/**
 * Perform a file upload using multipart/form-data using the HTTP PUT method, returning
 * a ClientResponse instance with the data returned from the endpoint.
 *
 * @param name the name for the form field that contains the file name
 * @param fileToUpload a File instance pointing to the file to upload
 * @param url the fully formed path to the GitLab API endpoint
 * @return a ClientResponse instance with the data returned from the endpoint
 * @throws IOException if an error occurs while constructing the URL
 */
protected Response putUpload(String name, File fileToUpload, URL url) throws IOException {
  try (MultiPart multiPart = new FormDataMultiPart()) {
    multiPart.bodyPart(new FileDataBodyPart(name, fileToUpload, MediaType.APPLICATION_OCTET_STREAM_TYPE));
    final Entity<?> entity = Entity.entity(multiPart, Boundary.addBoundary(multiPart.getMediaType()));
    return (invocation(url, null).put(entity));
  }
}

代码示例来源:origin: batfish/batfish

webTarget
  .request(MediaType.APPLICATION_JSON)
  .post(Entity.entity(multiPart, multiPart.getMediaType()));

代码示例来源:origin: Texera/texera

@Test
  @Ignore
  public void checkDictionaryUpload() throws Exception {
    Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test client");
    client.property(ClientProperties.CONNECT_TIMEOUT, 5000);
    client.property(ClientProperties.READ_TIMEOUT, 5000);
    client.register(MultiPartFeature.class);

    final MultiPart multiPart = new MultiPart();
    multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
    File testDictionaryFile = new File(ResourceHelpers.resourceFilePath("test_dictionary.txt"));
    final FileDataBodyPart filePart = new FileDataBodyPart("file", testDictionaryFile);
    multiPart.bodyPart(filePart);

    Response response = client.target(
            String.format("http://localhost:%d/api/upload/dictionary", RULE.getLocalPort()))
            .request(MediaType.MULTIPART_FORM_DATA_TYPE)
            .post(Entity.entity(multiPart, multiPart.getMediaType()));
    
    assertThat(response.getStatus()).isEqualTo(200);
  }
}

相关文章