本文整理了Java中org.glassfish.jersey.media.multipart.MultiPart.bodyPart()
方法的一些代码示例,展示了MultiPart.bodyPart()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MultiPart.bodyPart()
方法的具体详情如下:
包路径:org.glassfish.jersey.media.multipart.MultiPart
类名称:MultiPart
方法名:bodyPart
[英]Builder pattern method to add a newly configured BodyPartto this MultiPart.
[中]Builder pattern方法将新配置的BodyPart添加到此多部件。
代码示例来源:origin: jersey/jersey
/**
* Builder pattern method to add a newly configured {@link BodyPart}
* to this {@link MultiPart}.
*
* @param entity entity object for this body part.
* @param mediaType content type for this body part.
*/
public MultiPart bodyPart(Object entity, MediaType mediaType) {
BodyPart bodyPart = new BodyPart(entity, mediaType);
return bodyPart(bodyPart);
}
代码示例来源: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: org.glassfish.jersey.media/jersey-media-multipart
/**
* Builder pattern method to add a newly configured {@link BodyPart}
* to this {@link MultiPart}.
*
* @param entity entity object for this body part.
* @param mediaType content type for this body part.
*/
public MultiPart bodyPart(Object entity, MediaType mediaType) {
BodyPart bodyPart = new BodyPart(entity, mediaType);
return bodyPart(bodyPart);
}
代码示例来源:origin: hstaudacher/osgi-jax-rs-connector
/**
* Builder pattern method to add a newly configured {@link BodyPart}
* to this {@link MultiPart}.
*
* @param entity entity object for this body part.
* @param mediaType content type for this body part.
*/
public MultiPart bodyPart(Object entity, MediaType mediaType) {
BodyPart bodyPart = new BodyPart(entity, mediaType);
return bodyPart(bodyPart);
}
代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all
/**
* Builder pattern method to add a newly configured {@link BodyPart}
* to this {@link MultiPart}.
*
* @param entity entity object for this body part.
* @param mediaType content type for this body part.
*/
public MultiPart bodyPart(Object entity, MediaType mediaType) {
BodyPart bodyPart = new BodyPart(entity, mediaType);
return bodyPart(bodyPart);
}
代码示例来源:origin: hstaudacher/osgi-jax-rs-connector
/**
* Builder pattern method to add a newly configured {@link BodyPart}
* to this {@link MultiPart}.
*
* @param entity entity object for this body part.
* @param mediaType content type for this body part.
*/
public MultiPart bodyPart(Object entity, MediaType mediaType) {
BodyPart bodyPart = new BodyPart(entity, mediaType);
return bodyPart(bodyPart);
}
代码示例来源:origin: stackoverflow.com
@Produces("multipart/mixed")
public Response multiPartResponder(){
MultiPart multiPart = new MultiPart();
BodyPart bodyPart = new BodyPart(myFileInputStream, MediaType.APPLICATION_OCTET_STREAM_TYPE);
multiPart.bodyPart(bodyPart);
return Response.status(OK).entity(multiPart);
}
代码示例来源:origin: batfish/batfish
private static void addFileMultiPart(MultiPart multiPart, String key, String filename) {
multiPart.bodyPart(
new FormDataBodyPart(key, new File(filename), MediaType.APPLICATION_OCTET_STREAM_TYPE));
}
代码示例来源:origin: batfish/batfish
private static void addTextMultiPart(MultiPart multiPart, String key, String value) {
multiPart.bodyPart(new FormDataBodyPart(key, value, MediaType.TEXT_PLAIN_TYPE));
}
代码示例来源:origin: hortonworks/registry
@Override
public String uploadFile(InputStream inputStream) {
MultiPart multiPart = new MultiPart();
BodyPart filePart = new StreamDataBodyPart("file", inputStream, "file");
multiPart.bodyPart(filePart);
return Subject.doAs(subject, new PrivilegedAction<String>() {
@Override
public String run() {
return currentSchemaRegistryTargets().filesTarget.request()
.post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA), String.class);
}
});
}
代码示例来源:origin: com.github.jakimli.pandaria/pandaria-core
public void attachment(String attachment) {
File file = file(attachment);
this.attachments.bodyPart(new FileDataBodyPart(file.getName(), file, APPLICATION_OCTET_STREAM_TYPE));
}
代码示例来源:origin: JakimLi/pandaria
public void attachment(String attachment) {
File file = file(attachment);
this.attachments.bodyPart(new FileDataBodyPart(file.getName(), file, APPLICATION_OCTET_STREAM_TYPE));
}
代码示例来源:origin: stackoverflow.com
byte[] bin = some binary data...
Book b = new Book();
b.setAuthor("John");
b.setTitle("wild stuff");
b.setYear(2012);
MultiPart multiPart = new MultiPart();
multiPart.bodyPart(new BodyPart(b, MediaType.APPLICATION_XML_TYPE));
multiPart.bodyPart(new BodyPart(bin, MediaType.APPLICATION_OCTET_STREAM_TYPE));
response = service.path("rest").path("multipart").
type(MultiPartMediaTypes.MULTIPART_MIXED).
post(ClientResponse.class, multiPart);
代码示例来源: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: ga4gh/dockstore
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
.fileName(file.getName()).size(file.length()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
} else {
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
代码示例来源:origin: iterate-ch/cyberduck
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
.fileName(file.getName()).size(file.length()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
} else {
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
代码示例来源: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: 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: hortonworks/registry
protected MultiPart getMultiPart(ResourceTestElement resourceToTest, Object entity) {
MultiPart multiPart = new MultiPart();
BodyPart filePart = new FileDataBodyPart(resourceToTest.getFileNameHeader(), resourceToTest.getFileToUpload());
BodyPart entityPart = new FormDataBodyPart(resourceToTest.getEntityNameHeader(), entity, MediaType.APPLICATION_JSON_TYPE);
multiPart.bodyPart(filePart).bodyPart(entityPart);
return multiPart;
}
代码示例来源: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);
}
}
内容来源于网络,如有侵权,请联系作者删除!