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


Java FormDataBodyPart.getValueAs方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: getFileFromFormDataBodyPart

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入方法依赖的package包/类
protected File getFileFromFormDataBodyPart(FormDataBodyPart part) {
	File file = part.getValueAs(File.class);
	if (file != null && file.canRead()) {
		return file;
	} else {
		return null;
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:9,代码来源:AbstractRestServiceImpl.java

示例5: getFormDataFromMultiPartRequestAs

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入方法依赖的package包/类
private <T> T getFormDataFromMultiPartRequestAs (Class<T> clazz, FormDataMultiPart form, String paramName) {
    T result = null;
    try {
        FormDataBodyPart part = form.getField(paramName);
        if (part != null) {
            result = part.getValueAs(clazz);
        }
    } catch (Exception e) {
        LOG.debug("Cannot get param " + paramName + " as" + clazz + " from multipart form" );
    }
    return result;
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:13,代码来源:TopologyComponentBundleResource.java

示例6: addNotifier

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入方法依赖的package包/类
/**
 * Sample request :
 * <pre>
 * curl -X POST 'http://localhost:8080/api/v1/catalog/notifiers' -F notifierJarFile=/tmp/email-notifier.jar
 * -F notifierConfig='{
 *  "name":"email_notifier",
 *  "description": "testing",
 * "className":"com.hortonworks.streamline.streams.notifiers.EmailNotifier",
 *   "properties": {
 *     "username": "[email protected]",
 *     "password": "testing12",
 *     "host": "smtp.gmail.com",
 *     "port": "587",
 *     "starttls": "true",
 *     "debug": "true"
 *     },
 *   "fieldValues": {
 *     "from": "[email protected]",
 *     "to": "[email protected]",
 *     "subject": "Testing email notifications",
 *     "contentType": "text/plain",
 *     "body": "default body"
 *     }
 * };type=application/json'
 * </pre>
 */
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/notifiers")
@Timed
public Response addNotifier(@FormDataParam("notifierJarFile") final InputStream inputStream,
                            @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader,
                            @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig,
                            @Context SecurityContext securityContext) throws IOException {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_NOTIFIER_ADMIN);
    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);
    Collection<Notifier> existing = null;
    existing = catalogService.listNotifierInfos(Collections.singletonList(new QueryParam(Notifier.NOTIFIER_NAME, notifier.getName())));
    if (existing != null && !existing.isEmpty()) {
        LOG.warn("Received a post request for an already registered notifier. Not creating entity for " + notifier);
        return WSUtils.respondEntity(notifier, CONFLICT);
    }
    String jarFileName = uploadJar(inputStream, notifier.getName());
    notifier.setJarFileName(jarFileName);
    Notifier createdNotifier = catalogService.addNotifierInfo(notifier);
    SecurityUtil.addAcl(authorizer, securityContext, Notifier.NAMESPACE, createdNotifier.getId(),
            EnumSet.allOf(Permission.class));
    return WSUtils.respondEntity(createdNotifier, CREATED);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:55,代码来源:NotifierInfoCatalogResource.java

示例7: uploadFile

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入方法依赖的package包/类
static File uploadFile(FormDataBodyPart part, String directory) throws IOException {
  try (InputStream in = part.getValueAs(InputStream.class)) {
    Path path = Paths.get(directory, part.getFormDataContentDisposition().getFileName());
    FileHelper.copy(in, path);
    return path.toFile();
  }
}
 
开发者ID:twitter,项目名称:heron,代码行数:8,代码来源:Forms.java

示例8: updateTankScript

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入方法依赖的package包/类
/**
 * @{inheritDoc
 */
@Override
public Response updateTankScript(FormDataMultiPart formData) {
    ScriptTO scriptTo = null;
    InputStream is = null;
    Map<String, List<FormDataBodyPart>> fields = formData.getFields();
    ScriptDao dao = new ScriptDao();
    for (Entry<String, List<FormDataBodyPart>> entry : fields.entrySet()) {
        String formName = entry.getKey();
        LOG.debug("Entry name: " + formName);
        for (FormDataBodyPart part : entry.getValue()) {
            MediaType mediaType = part.getMediaType();
            LOG.debug("MediaType " + mediaType);
            if (MediaType.APPLICATION_OCTET_STREAM_TYPE.equals(mediaType)) {
                // get the file
                is = part.getValueAs(InputStream.class);
            }
        }
    }
    ResponseBuilder responseBuilder = null;
    if (is != null) {
        try {
            //Source: https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet#Unmarshaller
            SAXParserFactory spf = SAXParserFactory.newInstance();
            spf.setNamespaceAware(true);
            spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
            spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
            spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
            
            Source xmlSource = new SAXSource(spf.newSAXParser().getXMLReader(), new InputSource(is));
            
            JAXBContext ctx = JAXBContext.newInstance(ScriptTO.class.getPackage().getName());
            scriptTo = (ScriptTO) ctx.createUnmarshaller().unmarshal(xmlSource);
            Script script = ScriptServiceUtil.transferObjectToScript(scriptTo);
            if (script.getId() > 0) {
                Script existing = dao.findById(script.getId());
                if (existing == null) {
                    LOG.error("Error updating script: Script passed with unknown id.");
                    throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
                }
                if (!existing.getName().equals(script.getName())) {
                    LOG.error("Error updating script: Cannot change the name of an existing Script.");
                    throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
                }
            }
            script = dao.saveOrUpdate(script);
            responseBuilder = Response.ok();
            responseBuilder.entity(Integer.toString(script.getId()));
        } catch (Exception e) {
            LOG.error("Error unmarshalling script: " + e.getMessage(), e);
            throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
    return responseBuilder.build();
}
 
开发者ID:intuit,项目名称:Tank,代码行数:60,代码来源:ScriptServiceV1.java

示例9: uploadScript

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入方法依赖的package包/类
/**
 * @{inheritDoc
 */
@Override
@Nonnull
public Response uploadScript(@Nonnull FormDataMultiPart formData) {
	ResponseBuilder responseBuilder = Response.ok();
	FormDataBodyPart scriptId = formData.getField("scriptId");
	FormDataBodyPart newScriptName = formData.getField("scriptName");
	FormDataBodyPart filePart = formData.getField("file");
	InputStream is = filePart.getValueAs(InputStream.class);
	Script script = null;
	try {
		if ("0".equals(scriptId.getValue())) {
			script = new Script();
			script.setName("New");
			script.setCreator("System");
		} else {
			script = new ScriptDao().findById(Integer.parseInt(scriptId.getValue()));
		}
		ScriptProcessor scriptProcessor = new ServletInjector<ScriptProcessor>().getManagedBean(servletContext,
				ScriptProcessor.class);

		scriptProcessor.setScript(script);
		if (StringUtils.isNotEmpty(newScriptName.getValue())) {
			script.setName(newScriptName.getValue());
		}
		List<ScriptStep> scriptSteps = scriptProcessor.getScriptSteps(new BufferedReader(new InputStreamReader(is)),
				new ArrayList<>());
		List<ScriptStep> newSteps = new ArrayList<>();
		for (ScriptStep step : scriptSteps) {
			newSteps.add(step);
		}
		script = new ScriptDao().saveOrUpdate(script);
		sendMsg(script, ModificationType.UPDATE);
		responseBuilder.entity(Integer.toString(script.getId()));
	} catch (Exception e) {
		LOG.error("Error starting script: " + e, e);
		responseBuilder = Response.status(Status.INTERNAL_SERVER_ERROR);
		responseBuilder.entity("An External Script failed with Exception: " + e.toString());
	} finally {
		IOUtils.closeQuietly(is);
	}

	return responseBuilder.build();
}
 
开发者ID:intuit,项目名称:Tank,代码行数:47,代码来源:AutomationServiceV1.java

示例10: addOrUpdateUDF

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入方法依赖的package包/类
/**
 * Update a udf.
 * <p>
 *     curl -X PUT 'http://localhost:8080/api/v1/catalog/udfs/34'
 *     -F [email protected]/tmp/streams-functions-0.1.0-SNAPSHOT.jar
 *     -F udfConfig='{"name":"stddev", "description": "stddev",
 *                   "type":"AGGREGATE", "className":"com.hortonworks.streamline.streams.rule.udaf.Stddev"};type=application/json'
 * </p>
 * <pre>
 * {
 *   "responseCode": 1000,
 *   "responseMessage": "Success",
 *   "entity": {
 *     "id": 48,
 *     "name": "SUBSTRING",
 *     "description": "Substring",
 *     "type": "FUNCTION",
 *     "className": "builtin"
 *   }
 * }
 * </pre>
 */
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/udfs/{id}")
@Timed
public Response addOrUpdateUDF(@PathParam("id") Long udfId,
                               @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.checkPermissions(authorizer, securityContext, UDF.NAMESPACE, udfId, WRITE);
    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, false, builtin);
    UDF newUdf = catalogService.addOrUpdateUDF(udfId, udf);
    return WSUtils.respondEntity(newUdf, CREATED);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:44,代码来源:UDFCatalogResource.java


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