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

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

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

MultiPart.setMediaType介绍

[英]Sets the MediaType for this MultiPart. If never set, the default MediaType MUST be multipart/mixed.
[中]设置此多部分的媒体类型。如果从未设置,默认的MediaType必须是multipart/mixed。

代码示例

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

/**
 * Builder pattern method to return this {@link MultiPart} after
 * additional configuration.
 *
 * @param type media type to set for this {@link MultiPart}.
 */
@Override
public MultiPart type(MediaType type) {
  setMediaType(type);
  return this;
}

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

/**
 * Disables changing the media type to anything other than {@code multipart/form-data}.
 *
 * @param mediaType the proposed media type.
 * @throws IllegalArgumentException if the proposed media type is not {@code multipart/form-data}.
 */
@Override
public void setMediaType(MediaType mediaType) {
  if (!MediaTypes.typeEqual(mediaType, MediaType.MULTIPART_FORM_DATA_TYPE)) {
    throw new IllegalArgumentException(LocalizationMessages.FORM_DATA_MULTIPART_CANNOT_CHANGE_MEDIATYPE());
  }
  super.setMediaType(mediaType);
}

代码示例来源: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: jersey/jersey

multiPart.setMediaType(mediaType);
  fileNameFix = false;
} else {

代码示例来源:origin: org.glassfish.jersey.media/jersey-media-multipart

/**
 * Builder pattern method to return this {@link MultiPart} after
 * additional configuration.
 *
 * @param type media type to set for this {@link MultiPart}.
 */
@Override
public MultiPart type(MediaType type) {
  setMediaType(type);
  return this;
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

/**
 * Builder pattern method to return this {@link MultiPart} after
 * additional configuration.
 *
 * @param type media type to set for this {@link MultiPart}.
 */
@Override
public MultiPart type(MediaType type) {
  setMediaType(type);
  return this;
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Builder pattern method to return this {@link MultiPart} after
 * additional configuration.
 *
 * @param type media type to set for this {@link MultiPart}.
 */
@Override
public MultiPart type(MediaType type) {
  setMediaType(type);
  return this;
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Builder pattern method to return this {@link MultiPart} after
 * additional configuration.
 *
 * @param type media type to set for this {@link MultiPart}.
 */
@Override
public MultiPart type(MediaType type) {
  setMediaType(type);
  return this;
}

代码示例来源:origin: org.glassfish.jersey.media/jersey-media-multipart

/**
 * Disables changing the media type to anything other than {@code multipart/form-data}.
 *
 * @param mediaType the proposed media type.
 * @throws IllegalArgumentException if the proposed media type is not {@code multipart/form-data}.
 */
@Override
public void setMediaType(MediaType mediaType) {
  if (!MediaTypes.typeEqual(mediaType, MediaType.MULTIPART_FORM_DATA_TYPE)) {
    throw new IllegalArgumentException(LocalizationMessages.FORM_DATA_MULTIPART_CANNOT_CHANGE_MEDIATYPE());
  }
  super.setMediaType(mediaType);
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Disables changing the media type to anything other than {@code multipart/form-data}.
 *
 * @param mediaType the proposed media type.
 * @throws IllegalArgumentException if the proposed media type is not {@code multipart/form-data}.
 */
@Override
public void setMediaType(MediaType mediaType) {
  if (!MediaTypes.typeEqual(mediaType, MediaType.MULTIPART_FORM_DATA_TYPE)) {
    throw new IllegalArgumentException(LocalizationMessages.FORM_DATA_MULTIPART_CANNOT_CHANGE_MEDIATYPE());
  }
  super.setMediaType(mediaType);
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

/**
 * Disables changing the media type to anything other than {@code multipart/form-data}.
 *
 * @param mediaType the proposed media type.
 * @throws IllegalArgumentException if the proposed media type is not {@code multipart/form-data}.
 */
@Override
public void setMediaType(MediaType mediaType) {
  if (!MediaTypes.typeEqual(mediaType, MediaType.MULTIPART_FORM_DATA_TYPE)) {
    throw new IllegalArgumentException(LocalizationMessages.FORM_DATA_MULTIPART_CANNOT_CHANGE_MEDIATYPE());
  }
  super.setMediaType(mediaType);
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Disables changing the media type to anything other than {@code multipart/form-data}.
 *
 * @param mediaType the proposed media type.
 * @throws IllegalArgumentException if the proposed media type is not {@code multipart/form-data}.
 */
@Override
public void setMediaType(MediaType mediaType) {
  if (!MediaTypes.typeEqual(mediaType, MediaType.MULTIPART_FORM_DATA_TYPE)) {
    throw new IllegalArgumentException(LocalizationMessages.FORM_DATA_MULTIPART_CANNOT_CHANGE_MEDIATYPE());
  }
  super.setMediaType(mediaType);
}

代码示例来源: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: batfish/batfish

@Nullable
String checkApiKey() {
 try {
  WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_CHECK_API_KEY);
  MultiPart multiPart = new MultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
  JSONObject jObj = postData(webTarget, multiPart);
  if (jObj == null) {
   return null;
  }
  return Boolean.toString(jObj.getBoolean(CoordConsts.SVC_KEY_API_KEY));
 } catch (Exception e) {
  _logger.errorf("exception: ");
  _logger.error(Throwables.getStackTraceAsString(e) + "\n");
  return null;
 }
}

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

boolean delAnalysis(String networkName, String analysisName) {
 try {
  WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_DEL_ANALYSIS);
  MultiPart multiPart = new MultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_NETWORK_NAME, networkName);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_ANALYSIS_NAME, analysisName);
  return postData(webTarget, multiPart) != null;
 } catch (Exception e) {
  _logger.errorf(
    "Exception when deleting analysis to %s using (%s, %s): %s\n",
    _coordWorkMgr, networkName, analysisName, Throwables.getStackTraceAsString(e));
  return false;
 }
}

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

boolean queueWork(WorkItem wItem) {
 try {
  WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_QUEUE_WORK);
  MultiPart multiPart = new MultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
  addTextMultiPart(
    multiPart, CoordConsts.SVC_KEY_WORKITEM, BatfishObjectMapper.writeString(wItem));
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
  JSONObject jObj = postData(webTarget, multiPart);
  return jObj != null;
 } catch (Exception e) {
  _logger.errorf("exception: ");
  _logger.error(Throwables.getStackTraceAsString(e) + "\n");
  return false;
 }
}

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

boolean delSnapshot(String networkName, String snapshotName) {
 try {
  WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_DEL_SNAPSHOT);
  MultiPart multiPart = new MultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_NETWORK_NAME, networkName);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_SNAPSHOT_NAME, snapshotName);
  JSONObject jObj = postData(webTarget, multiPart);
  return jObj != null;
 } catch (Exception e) {
  _logger.errorf("Exception in delSnapshot for network %s:\n", networkName);
  _logger.error(Throwables.getStackTraceAsString(e) + "\n");
  return false;
 }
}

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

boolean syncSnapshotsSyncNow(String pluginId, String networkName, boolean force) {
 try {
  WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_SYNC_SNAPSHOTS_SYNC_NOW);
  MultiPart multiPart = new MultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_VERSION, Version.getVersion());
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_NETWORK_NAME, networkName);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_PLUGIN_ID, pluginId);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_FORCE, String.valueOf(force));
  JSONObject jObj = postData(webTarget, multiPart);
  return jObj != null;
 } catch (Exception e) {
  _logger.errorf("Exception syncing snapshots in network %s:\n", networkName);
  _logger.error(Throwables.getStackTraceAsString(e) + "\n");
  return false;
 }
}

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

boolean delQuestion(String networkName, String snapshotName, String questionName) {
 try {
  WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_DEL_QUESTION);
  MultiPart multiPart = new MultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_NETWORK_NAME, networkName);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_SNAPSHOT_NAME, snapshotName);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_QUESTION_NAME, questionName);
  JSONObject jObj = postData(webTarget, multiPart);
  return jObj != null;
 } catch (Exception e) {
  _logger.errorf("exception: ");
  _logger.error(Throwables.getStackTraceAsString(e) + "\n");
  return false;
 }
}

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

boolean syncSnapshotsUpdateSettings(
  String pluginId, String networkName, Map<String, String> settings) {
 try {
  String settingsStr = BatfishObjectMapper.writePrettyString(settings);
  WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_SYNC_SNAPSHOTS_UPDATE_SETTINGS);
  MultiPart multiPart = new MultiPart();
  multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_VERSION, Version.getVersion());
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_NETWORK_NAME, networkName);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_PLUGIN_ID, pluginId);
  addTextMultiPart(multiPart, CoordConsts.SVC_KEY_SETTINGS, settingsStr);
  JSONObject jObj = postData(webTarget, multiPart);
  return jObj != null;
 } catch (Exception e) {
  _logger.errorf("Exception syncing snapshots in network %s:\n", networkName);
  _logger.error(Throwables.getStackTraceAsString(e) + "\n");
  return false;
 }
}

相关文章