本文整理汇总了Java中org.glassfish.jersey.media.multipart.BodyPart类的典型用法代码示例。如果您正苦于以下问题:Java BodyPart类的具体用法?Java BodyPart怎么用?Java BodyPart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BodyPart类属于org.glassfish.jersey.media.multipart包,在下文中一共展示了BodyPart类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertScript
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的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);
}
示例2: runAutomationJob
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的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);
}
示例3: multipartToMap
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的package包/类
/**
* Convert multi part body into a map of key value pairs.
*
* @param multiPart
* @return
* @throws IOException
*/
private Map<String, String> multipartToMap(final MultiPart multiPart) throws IOException {
final Map<String, String> map = new HashMap<>();
for (final BodyPart part : multiPart.getBodyParts()) {
Object value = part.getEntity();
if (value instanceof BodyPartEntity) {
value = IOUtils.toString(((BodyPartEntity) value).getInputStream());
}
if (value instanceof File) {
value = IOUtils.toString(new FileInputStream((File) value));
}
final String fieldName =
part.getHeaders().get("Content-Disposition").get(0)
.split("form-data;\\s*.*name=\"")[1].replaceFirst("\"$", "");
map.put(fieldName, ObjectUtils.toString(value));
}
return map;
}
示例4: uploadFile
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的package包/类
/**
* Upload file to IOResource
*
* @param filename name of file
* @param stream stream of file content
* @return the object ID of that file
* @throws IOException
*/
private String uploadFile(final String filename, final InputStream stream)
throws IOException
{
try (final FormDataMultiPart multiPart = new FormDataMultiPart()) {
multiPart.bodyPart(new BodyPart(stream,
MediaType.MULTIPART_FORM_DATA_TYPE).contentDisposition(
FormDataContentDisposition.name("file").fileName(filename).build()));
final String response = resources.client().register(
MultiPartFeature.class).target("/objects/upload").request().post(Entity
.entity(multiPart, multiPart.getMediaType()), String.class);
final Matcher matcher = Pattern.compile("\\{\"id\":\"([^\"]+)\"\\}")
.matcher(response);
assertTrue(matcher.find());
return matcher.group(1);
}
}
示例5: getEntity
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的package包/类
@Override
public Entity getEntity(List<MultiPartItem> items, String mediaType) {
MultiPart multiPart = new MultiPart();
for (MultiPartItem item : items) {
if (item.getValue() == null || item.getValue().isNull()) {
continue;
}
String name = item.getName();
String filename = item.getFilename();
ScriptValue sv = item.getValue();
String ct = item.getContentType();
if (ct == null) {
ct = HttpUtils.getContentType(sv);
}
MediaType itemType = MediaType.valueOf(ct);
if (name == null) { // most likely multipart/mixed
BodyPart bp = new BodyPart().entity(sv.getAsString()).type(itemType);
multiPart.bodyPart(bp);
} else if (filename != null) {
StreamDataBodyPart part = new StreamDataBodyPart(name, sv.getAsStream(), filename, itemType);
multiPart.bodyPart(part);
} else {
multiPart.bodyPart(new FormDataBodyPart(name, sv.getAsString(), itemType));
}
}
return Entity.entity(multiPart, mediaType);
}
示例6: uploadFile
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的package包/类
@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);
}
});
}
示例7: getMultiPart
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的package包/类
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;
}
示例8: updateTankScript
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的package包/类
/**
* @{inheritDoc
*/
public String updateTankScript(InputStream in) throws RestServiceException {
WebTarget webTarget = client.target(urlBuilder.buildUrl(ScriptService.METHOD_SCRIPT_UPDATE));
MultiPart multiPart = new MultiPart();
BodyPart bp = new FormDataBodyPart("file", in, MediaType.APPLICATION_OCTET_STREAM_TYPE);
multiPart.bodyPart(bp);
Response response = webTarget.request(MediaType.TEXT_PLAIN_TYPE).post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
exceptionHandler.checkStatusCode(response);
return response.readEntity(String.class);
}
示例9: getMultiPart
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的package包/类
private MultiPart getMultiPart(ResourceTestElement resourceToTest, Object entity) {
MultiPart multiPart = new MultiPart();
BodyPart filePart = new FileDataBodyPart(resourceToTest.fileNameHeader, resourceToTest.fileToUpload);
BodyPart entityPart = new FormDataBodyPart(resourceToTest.entityNameHeader, entity, MediaType.APPLICATION_JSON_TYPE);
multiPart.bodyPart(filePart).bodyPart(entityPart);
return multiPart;
}
示例10: handleRequest
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的package包/类
private Response handleRequest(AbstractUploadRequest abstractUploadRequest, BodyPart bodyPart) {
final WebTarget webTarget = client.target(directUploadUrl);
final MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
multiPart.bodyPart(new FormDataBodyPart(DATA_PART, wrapAuth(abstractUploadRequest), MediaType.APPLICATION_JSON_TYPE));
multiPart.bodyPart(bodyPart);
return webTarget.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(multiPart, multiPart.getMediaType()));
}
示例11: directUpload
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的package包/类
private SuccessfulUploadResponse directUpload(AbstractUploadRequest abstractUploadRequest, BodyPart bodyPart) {
return handleResponse(handleRequest(abstractUploadRequest, bodyPart));
}
示例12: directCallbackUrlUpload
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的package包/类
private SuccessfulUploadCallbackUrlResponse directCallbackUrlUpload(AbstractUploadRequest abstractUploadRequest, BodyPart bodyPart) {
return handleCallbackUrlResponse(handleRequest(abstractUploadRequest, bodyPart));
}
示例13: post
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的package包/类
@POST
@Path("/queue/{appname}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String post(final FormDataMultiPart multiPart, @PathParam("appname") String appName) {
File appQueueFolder = new File(queueRoot, appName);
if (!appQueueFolder.exists()) {
System.out.println("Making application queue root: " + appQueueFolder);
appQueueFolder.mkdirs();
}
List<String> files = new ArrayList<String>();
List<BodyPart> parts = multiPart.getBodyParts();
for (BodyPart bodyPart : parts) {
if (bodyPart instanceof FormDataBodyPart) {
FormDataBodyPart part = (FormDataBodyPart) bodyPart;
String fileName = part.getFormDataContentDisposition()
.getFileName();
File resultFile = new File(appQueueFolder, fileName);
if (resultFile.exists()) {
System.err
.println(fileName+" already upLoaded? Same file found in queue root: "
+ appQueueFolder);
} else {
File uploadedTemp = part.getEntityAs(File.class);
try {
FileUtils.copyFile(uploadedTemp, resultFile);
FileUtils.deleteQuietly(uploadedTemp);
files.add(fileName);
} catch (IOException ex) {
Logger.getLogger(QueueService.class.getName()).log(
Level.SEVERE,
"Cannot move: " + uploadedTemp + " to: "
+ appQueueFolder, ex);
System.err.println("Failed to process upload file: "
+ fileName);
}
}
}
}
return "Files: " + files + " queued @ " + getHostName()
+ " in folder: " + appQueueFolder;
}
示例14: executeMultiPart
import org.glassfish.jersey.media.multipart.BodyPart; //导入依赖的package包/类
@JSONP
@Produces({MediaType.APPLICATION_JSON, "application/javascript"})
private ApiResponse executeMultiPart( UriInfo ui, String callback, FormDataMultiPart multiPart,
ServiceAction serviceAction ) throws Exception {
// needed for testing
this.binaryStore = binaryStoreFactory.getBinaryStore( properties.getProperty(PROPERTIES_USERGRID_BINARY_UPLOADER) );
// collect form data values
List<BodyPart> bodyParts = multiPart.getBodyParts();
HashMap<String, Object> data = new HashMap<>();
for ( BodyPart bp : bodyParts ) {
FormDataBodyPart bodyPart = ( FormDataBodyPart ) bp;
if ( bodyPart.getMediaType().equals( MediaType.TEXT_PLAIN_TYPE ) ) {
data.put( bodyPart.getName(), bodyPart.getValue() );
}
else {
if (logger.isTraceEnabled()) {
logger.trace("skipping bodyPart {} of media type {}", bodyPart.getName(), bodyPart.getMediaType());
}
}
}
FormDataBodyPart fileBodyPart = multiPart.getField( FILE_FIELD_NAME );
data.put( AssetUtils.FILE_METADATA, new HashMap() );
// process entity
ApiResponse response = createApiResponse();
response.setAction( serviceAction.name().toLowerCase() );
response.setApplication( services.getApplication() );
response.setParams( ui.getQueryParameters() );
//Updates entity with fields that are in text/plain as per loop above
if(data.get( FILE_FIELD_NAME )==null){
data.put( FILE_FIELD_NAME,null );
}
ServicePayload payload = getPayload( data );
ServiceResults serviceResults = executeServiceRequest( ui, response, serviceAction, payload );
// process file part
if ( fileBodyPart != null ) {
InputStream fileInput = ( (BodyPartEntity) fileBodyPart.getEntity() ).getInputStream();
if ( fileInput != null ) {
Entity entity = serviceResults.getEntity();
EntityManager em = emf.getEntityManager( getApplicationId() );
try {
binaryStore.write( getApplicationId(), entity, fileInput );
}
catch ( AwsPropertiesNotFoundException apnfe){
logger.error( "Amazon Property needed for this operation not found",apnfe );
response.setError( "500","Amazon Property needed for this operation not found",apnfe );
}
catch ( RuntimeException re){
logger.error(re.getMessage());
response.setError( "500", re );
}
//em.update( entity );
entity = serviceResults.getEntity();
serviceResults.setEntity( entity );
}
}
return response;
}