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


Java FormDataBodyPart.getMediaType方法代码示例

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


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

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

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

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

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

示例5: updateDisseminationImpl

import org.glassfish.jersey.media.multipart.FormDataBodyPart; //导入方法依赖的package包/类
private SmartGwtResponse<Map<String, Object>> updateDisseminationImpl(
        @FormDataParam(DigitalObjectResourceApi.DIGITALOBJECT_PID) String pid,
        @FormDataParam(DigitalObjectResourceApi.BATCHID_PARAM) Integer batchId,
        @FormDataParam(DigitalObjectResourceApi.DISSEMINATION_DATASTREAM) String dsId,
        @FormDataParam(DigitalObjectResourceApi.DISSEMINATION_FILE) InputStream fileContent,
        @FormDataParam(DigitalObjectResourceApi.DISSEMINATION_FILE) FormDataContentDisposition fileInfo,
        @FormDataParam(DigitalObjectResourceApi.DISSEMINATION_FILE) FormDataBodyPart fileBodyPart,
        @FormDataParam(DigitalObjectResourceApi.DISSEMINATION_MIME) String mimeType
        ) throws IOException, DigitalObjectException {

    if (pid == null) {
        return SmartGwtResponse.<Map<String,Object>>asError(DigitalObjectResourceApi.DIGITALOBJECT_PID, "Missing PID!");
    }
    if (fileContent == null) {
        return SmartGwtResponse.<Map<String,Object>>asError(DigitalObjectResourceApi.DISSEMINATION_FILE, "Missing file!");
    }

    if (dsId != null && !dsId.equals(BinaryEditor.RAW_ID)) {
        throw RestException.plainText(Status.BAD_REQUEST, "Missing or unsupported datastream ID: " + dsId);
    }
    String filename = getFilename(fileInfo.getFileName());
    File file = File.createTempFile("proarc_", null);
    try {
        FileUtils.copyToFile(fileContent, file);
        // XXX add config property or user permission
        if (file.length() > 1*1024 * 1024 * 1024) { // 1GB
            throw RestException.plainText(Status.BAD_REQUEST, "File contents too large!");
        }
        MediaType mime;
        try {
            mime = mimeType != null ? MediaType.valueOf(mimeType) : fileBodyPart.getMediaType();
        } catch (IllegalArgumentException ex) {
            return SmartGwtResponse.<Map<String,Object>>asError(
                    DigitalObjectResourceApi.DISSEMINATION_MIME, "Invalid MIME type! " + mimeType);
        }
        LOG.log(Level.FINE, "filename: {0}, user mime: {1}, resolved mime: {2}, {3}/{4}", new Object[]{filename, mimeType, mime, pid, dsId});
        DigitalObjectHandler doHandler = findHandler(pid, batchId);
        DisseminationHandler dissemination = doHandler.dissemination(BinaryEditor.RAW_ID);
        DisseminationInput input = new DisseminationInput(file, filename, mime);
        dissemination.setDissemination(input, session.asFedoraLog());
        doHandler.commit();
    } finally {
        file.delete();
    }
    return new SmartGwtResponse<Map<String,Object>>(Collections.singletonMap("processId", (Object) 0L));
}
 
开发者ID:proarc,项目名称:proarc,代码行数:47,代码来源:DigitalObjectResource.java

示例6: 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.getMediaType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。