當前位置: 首頁>>代碼示例>>Java>>正文


Java FormDataMultiPart.getField方法代碼示例

本文整理匯總了Java中org.glassfish.jersey.media.multipart.FormDataMultiPart.getField方法的典型用法代碼示例。如果您正苦於以下問題:Java FormDataMultiPart.getField方法的具體用法?Java FormDataMultiPart.getField怎麽用?Java FormDataMultiPart.getField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.glassfish.jersey.media.multipart.FormDataMultiPart的用法示例。


在下文中一共展示了FormDataMultiPart.getField方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFormDataFromMultiPartRequestAs

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的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

示例2: uploadScript

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的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

示例3: executeMultiPartPut

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
@CheckPermissionsForPath
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@JSONP
@Produces({MediaType.APPLICATION_JSON, "application/javascript"})
@Override
public ApiResponse executeMultiPartPut(@Context UriInfo ui,
    @QueryParam("callback") @DefaultValue("callback") String callback,
    FormDataMultiPart multiPart) throws Exception {

    if (logger.isTraceEnabled()) {
        logger.trace("NotifierResource.executeMultiPartPut");
    }

    String certInfoParam = getValueOrNull(multiPart, "certInfo");
    if (certInfoParam != null){
        throw new IllegalArgumentException("Cannot create or update with certInfo parameter.  It is derived.");
    }

    String name =         getValueOrNull(multiPart, "name");
    String provider =     getValueOrNull(multiPart, "provider");
    String certPassword = getValueOrNull(multiPart, "certificatePassword");

    InputStream is = null;
    Map<String, Object> certAttributes = null;
    String filename = null;
    byte[] certBytes = null;
    if (multiPart.getField("p12Certificate") != null) {
        filename = multiPart.getField("p12Certificate").getContentDisposition().getFileName();
        is = multiPart.getField("p12Certificate").getEntityAs(InputStream.class);
        if (is != null) {
            certBytes = IOUtils.toByteArray(is);
            certAttributes = CertificateUtils.getCertAtrributes(certBytes, certPassword);
        }
    }else{
        throw new IllegalArgumentException("Certificate is invalid .p12 file or incorrect certificatePassword");
    }

    // check to see if the certificate is valid
    if(!CertificateUtils.isValid(certAttributes)){
        throw new IllegalArgumentException("p12Certificate is expired");
    }

    HashMap<String, Object> certProps = new LinkedHashMap<String, Object>();
    certProps.put("name", name);
    certProps.put("provider", provider);
    certProps.put("environment", "production");
    certProps.put("certificatePassword", certPassword);

    if(certBytes != null && certBytes.length > 0 ){
        certProps.put("p12Certificate", certBytes);
    }
    HashMap<String, Object> certInfo = new LinkedHashMap<String, Object>();
    if (certAttributes != null){
        certInfo.put("filename", filename);
        certInfo.put("details", certAttributes);
    }
    certProps.put("certInfo", certInfo);


    ApiResponse response = createApiResponse();
    response.setAction("put");
    response.setApplication(services.getApplication());
    response.setParams(ui.getQueryParameters());
    ServicePayload payload = getPayload(certProps);
    executeServiceRequest(ui, response, ServiceAction.PUT, payload);

    return response;
}
 
開發者ID:apache,項目名稱:usergrid,代碼行數:70,代碼來源:NotifierResource.java

示例4: getValueOrNull

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
private String getValueOrNull(FormDataMultiPart multiPart, String name) {
    if (multiPart.getField(name) != null) {
        return multiPart.getField(name).getValue();
    }
    return null;
}
 
開發者ID:apache,項目名稱:usergrid,代碼行數:7,代碼來源:NotifierResource.java

示例5: executeMultiPartPost

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的package包/類
@CheckPermissionsForPath
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Override
@JSONP
@Produces({MediaType.APPLICATION_JSON, "application/javascript"})
public ApiResponse executeMultiPartPost(
        @Context UriInfo ui,
        @QueryParam("callback") @DefaultValue("callback") String callback,
        FormDataMultiPart multiPart)
        throws Exception {

    if (logger.isTraceEnabled()) {
        logger.trace("Notifiers.executeMultiPartPost");
    }

    String certInfoParam = getValueOrNull(multiPart, "certInfo");
    if (certInfoParam != null){
        throw new IllegalArgumentException("Cannot create or update with certInfo parameter.  It is derived.");
    }

    String name =         getValueOrNull(multiPart, "name");
    String provider =     getValueOrNull(multiPart, "provider");
    String environment =  getValueOrNull(multiPart, "environment");
    String certPassword = getValueOrNull(multiPart, "certificatePassword");

    InputStream is = null;
    Map<String, Object> certAttributes = null;
    String filename = null;
    byte[] certBytes = null;
    if (multiPart.getField("p12Certificate") != null) {
        filename = multiPart.getField("p12Certificate").getContentDisposition().getFileName();
        is = multiPart.getField("p12Certificate").getEntityAs(InputStream.class);
        if (is != null) {
            certBytes = IOUtils.toByteArray(is);
            certAttributes = CertificateUtils.getCertAtrributes(certBytes, certPassword);
        }
    }else{
        throw new IllegalArgumentException("Certificate is invalid .p12 file or incorrect certificatePassword");
    }

    // check to see if the certificate is valid
    if(!CertificateUtils.isValid(certAttributes)){
        throw new IllegalArgumentException("p12Certificate is expired.");
    }


    HashMap<String, Object> certProps = new LinkedHashMap<String, Object>();

    certProps.put("name", name);
    certProps.put("provider", provider);
    certProps.put("environment", environment);
    certProps.put("certificatePassword", certPassword);

    if(certBytes != null && certBytes.length > 0 ){
        certProps.put("p12Certificate", certBytes);
    }
    HashMap<String, Object> certInfo = new LinkedHashMap<String, Object>();
    if (certAttributes != null){
        certInfo.put("filename", filename);
        certInfo.put("details", certAttributes);
    }
    certProps.put("certInfo", certInfo);

    ApiResponse response = createApiResponse();
    response.setAction("post");
    response.setApplication(services.getApplication());
    response.setParams(ui.getQueryParameters());
    ServicePayload payload = getPayload(certProps);
    executeServiceRequest(ui, response, ServiceAction.POST, payload);

    return response;
}
 
開發者ID:apache,項目名稱:usergrid,代碼行數:74,代碼來源:NotifiersResource.java

示例6: executeMultiPart

import org.glassfish.jersey.media.multipart.FormDataMultiPart; //導入方法依賴的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;
}
 
開發者ID:apache,項目名稱:usergrid,代碼行數:65,代碼來源:ServiceResource.java


注:本文中的org.glassfish.jersey.media.multipart.FormDataMultiPart.getField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。