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


Java FormDataParam類代碼示例

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


FormDataParam類屬於org.glassfish.jersey.media.multipart包,在下文中一共展示了FormDataParam類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: uploadPdfFile

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
@POST
@Path("/pdf")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public Response uploadPdfFile(  @FormDataParam("file") InputStream fileInputStream,
                                @FormDataParam("file") FormDataContentDisposition fileMetaData) throws Exception
{
    String UPLOAD_PATH = "/tmp/upload/";
    try
    {
        int read = 0;
        byte[] bytes = new byte[1024];
 
        OutputStream out = new FileOutputStream(new File(UPLOAD_PATH + fileMetaData.getFileName()));
        while ((read = fileInputStream.read(bytes)) != -1)
        {
            out.write(bytes, 0, read);
        }
        out.flush();
        out.close();
    } catch (IOException e)
    {
        throw new WebApplicationException("Error while uploading file. Please try again !!");
    }
    return Response.ok("Data uploaded successfully !!").build();
}
 
開發者ID:zekaf,項目名稱:jetty-nodes,代碼行數:26,代碼來源:UploadService.java

示例2: getUpload

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String getUpload(@FormDataParam("upload") InputStream inputStream,
    @FormDataParam("upload") FormDataContentDisposition header, @QueryParam("CKEditorFuncNum") int funcNum,
    @QueryParam("href") String href, @QueryParam("type") String type, @QueryParam("basehref") String basehref) {
    String path = "";
    try {
        path = saveFile(inputStream, href + "/" + header.getFileName());
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    }
    if (type.equals("images")) {
        return "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(" + funcNum + ",'"
            + path.substring(path.lastIndexOf("/") + 1, path.length()) + "', '');</script>";
    }
    return "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(" + funcNum + ",'" + basehref
        + path.substring(path.lastIndexOf("/") + 1, path.length()) + "', '');</script>";
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:21,代碼來源:MCRWCMSFileBrowserResource.java

示例3: importClassification

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
@POST
@Path("import")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML)
public Response importClassification(@FormDataParam("classificationFile") InputStream uploadedInputStream) {
    try {
        MCRClassificationUtils.fromStream(uploadedInputStream);
    } catch (MCRAccessException accessExc) {
        return Response.status(Status.UNAUTHORIZED).build();
    } catch (Exception exc) {
        throw new WebApplicationException(exc);
    }
    // This is a hack to support iframe loading via ajax.
    // The benefit is to load file input form data without reloading the page.
    // Maybe its better to create a separate method importClassificationIFrame.
    // @see http://livedocs.dojotoolkit.org/dojo/io/iframe - Additional Information
    return Response.ok("<html><body><textarea>200</textarea></body></html>").build();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:19,代碼來源:MCRClassificationEditorResource.java

示例4: uploadFile

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
@POST
@Secured
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public UploadResponse uploadFile(@FormDataParam("file") InputStream uploadedInputStream,
		@FormDataParam("file") FormDataContentDisposition fileDetail) {
	
	if (uploadedInputStream == null || fileDetail == null)
		throw new RuntimeException("Invalid arguments");

	AttachmentContainer container =  attachmentManager.createAttachmentContainer();
	String uploadedFileLocation = container.getContainer() + "/" + fileDetail.getFileName();
	try {
		Files.copy(uploadedInputStream, Paths.get(uploadedFileLocation));
	} catch (IOException e) {
		logger.error("Error while saving file "+uploadedFileLocation, e);
		throw new RuntimeException("Error while saving file.");
	}
	UploadResponse response = new UploadResponse();
	response.setAttachmentId(container.getMeta().getId().toString());
	return response;
}
 
開發者ID:denkbar,項目名稱:step,代碼行數:23,代碼來源:FileServices.java

示例5: post

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
/**
 * @api {post} /picture/focus/:guid Attach a picture into a facus
 * @apiGroup Focus
 * 
 * @apiParam {String} guid Focus guid
 *
 * @apiParamExample {json} Request-Example:
 *     {
 *      "TODO": "TODO"
 *     }
 * 
 * @apiSuccessExample Success-Headers:
 *     HTTP/1.1 200 OK
 *
 * @apiSuccessExample Success-Response:
 *     {
 *       "TODO": "TODO"
 *     }
 */
@POST
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces("application/json;charset=UTF-8")
@Path("/focus/{focusguid}")
public Picture post(@PathParam("focusguid") String focusguid, @FormDataParam("file") InputStream fileInputStream,
        @FormDataParam("file") FormDataContentDisposition fileDisposition) {
    Focus focus = focusRepository.loadOrNotFound(focusguid);
    
    if (!user.getGuid().equals(focus.getAuthoruserguid())) {
        throw new BadRequestException("User does not own this item");
    }
    
    Picture picture = new Picture();
    picture.setGuid(UUID.randomUUID().toString());
    picture.setFilename(fileDisposition.getFileName());
    picture.setFocusGuid(focusguid);
    picture.setCreatedat(Long.toString(new Date().getTime()));
    
    pictureBucket.put(picture.getPath(), fileInputStream, fileDisposition.getSize());
    pictureRepository.save(picture);

    return picture;
}
 
開發者ID:coding4people,項目名稱:mosquito-report-api,代碼行數:43,代碼來源:PictureController.java

示例6: setConfiguration

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response setConfiguration(
		@FormDataParam("wineryAddress") String wineryAddress,
		@FormDataParam("containerAddress") String containerAddress,
		@Context ServletContext context) {

	LOG.info("Handling config update request");

	if (wineryAddress != null) {
		LOG.info("Update for wineryAddress requested");
		Configuration.getInstance().setWineryAddress(wineryAddress);
	}

	if (containerAddress != null) {
		LOG.info("Update for containerAddress requested");
		Configuration.getInstance().setContainerAddress(containerAddress);
	}
	UriBuilder builder = UriBuilder.fromResource(MainResource.class);

	// TODO Fetch web app name from context
	builder.path("./XaaSPackager");
	return Response.seeOther(builder.build()).build();
}
 
開發者ID:nyuuyn,項目名稱:XaaSPackager,代碼行數:25,代碼來源:ConfigurationResource.java

示例7: multipartMapEcho

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
/**
 * Echoes a multipart request including file content as a map of strings.
 *
 * @param multiPart
 * @return
 * @throws IOException
 */
@Path("/multipartMapEcho")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Map<String, String> multipartMapEcho(
        @DefaultValue("true") @FormDataParam("enabled") final boolean enabled,
        @FormDataParam("secret") final String secret,
        @FormDataParam("file") final InputStream file,
        @FormDataParam("file") final FormDataContentDisposition fileDisposition)
                throws IOException {
    final Map<String, String> echo = new HashMap<String, String>();
    echo.put("enabled", ObjectUtils.toString(enabled));
    echo.put("secret", secret);
    echo.put("file", IOUtils.toString(file));
    echo.put("filename", fileDisposition.getFileName());
    echo.put("filetype", fileDisposition.getType());
    return echo;
}
 
開發者ID:strandls,項目名稱:alchemy-rest-client-generator,代碼行數:26,代碼來源:TestWebserviceMultipart.java

示例8: initializeFromXMLFile

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
/**
 * Generates the attack graph and initializes the main objects for other API calls
 * (database, attack graph, attack paths,...).
 * Load the objects from the XML file POST through a form describing the whole network topology
 *
 * @param request             the HTTP request
 * @param uploadedInputStream The input stream of the XML file
 * @param fileDetail          The file detail object
 * @param body                The body object relative to the XML file
 * @return the HTTP response
 * @throws Exception
 */
@POST
@Path("/initialize")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response initializeFromXMLFile(@Context HttpServletRequest request,
                                      @FormDataParam("file") InputStream uploadedInputStream,
                                      @FormDataParam("file") FormDataContentDisposition fileDetail,
                                      @FormDataParam("file") FormDataBodyPart body) throws Exception {

    if (!body.getMediaType().equals(MediaType.APPLICATION_XML_TYPE) && !body.getMediaType().equals(MediaType.TEXT_XML_TYPE)
            && !body.getMediaType().equals(MediaType.TEXT_PLAIN_TYPE))
        return RestApplication.returnErrorMessage(request, "The file is not an XML file");
    String xmlFileString = IOUtils.toString(uploadedInputStream, "UTF-8");

    return initializeFromXMLText(request, xmlFileString);

}
 
開發者ID:fiware-cybercaptor,項目名稱:cybercaptor-server,代碼行數:29,代碼來源:RestJsonAPI.java

示例9: addIDMEFAlerts

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
/**
 * Receive alerts in IDMEF format and add them into a local queue file,
 * before releasing them when the client requests it.
 *
 * @param request             the HTTP request
 * @param uploadedInputStream The input stream of the IDMEF XML file
 * @param fileDetail          The file detail object
 * @param body                The body object relative to the XML file
 * @return the HTTP response
 * @throws Exception
 */
@POST
@Path("/idmef/add")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response addIDMEFAlerts(@Context HttpServletRequest request,
                               @FormDataParam("file") InputStream uploadedInputStream,
                               @FormDataParam("file") FormDataContentDisposition fileDetail,
                               @FormDataParam("file") FormDataBodyPart body) throws Exception {

    if (!body.getMediaType().equals(MediaType.APPLICATION_XML_TYPE) && !body.getMediaType().equals(MediaType.TEXT_XML_TYPE)
            && !body.getMediaType().equals(MediaType.TEXT_PLAIN_TYPE))
        return RestApplication.returnErrorMessage(request, "The file is not an XML file");

    String xmlFileString = IOUtils.toString(uploadedInputStream, "UTF-8");
    return addIDMEFAlertsFromXMLText(request, xmlFileString);
}
 
開發者ID:fiware-cybercaptor,項目名稱:cybercaptor-server,代碼行數:27,代碼來源:RestJsonAPI.java

示例10: importTopology

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
/**
 * curl -X POST 'http://localhost:8080/api/v1/catalog/topologies/actions/import' -F [email protected]/tmp/topology.json -F namespaceId=1
 */
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/topologies/actions/import")
@Timed
public Response importTopology(@FormDataParam("file") final InputStream inputStream,
                               @FormDataParam("namespaceId") final Long namespaceId,
                               @FormDataParam("topologyName") final String topologyName,
                               @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_ADMIN);
    if (namespaceId == null) {
        throw new IllegalArgumentException("Missing namespaceId");
    }
    TopologyData topologyData = new ObjectMapper().readValue(inputStream, TopologyData.class);
    if (topologyName != null && !topologyName.isEmpty()) {
        topologyData.setTopologyName(topologyName);
    }
    Topology importedTopology = catalogService.importTopology(namespaceId, topologyData);
    return WSUtils.respondEntity(importedTopology, OK);
}
 
開發者ID:hortonworks,項目名稱:streamline,代碼行數:23,代碼來源:TopologyCatalogResource.java

示例11: addOrUpdateNotifierInfo

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

示例12: addUDF

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

示例13: uploadFile

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
@Path("/file")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@DefaultValue("") @FormDataParam("tags") String tags,
		@FormDataParam("file") InputStream file,
		@FormDataParam("file") FormDataContentDisposition fileDisposition) {

	String fileName = fileDisposition.getFileName();

	saveFile(file, fileName);

	String fileDetails = "File saved at /Volumes/Drive2/temp/file/" + fileName + " with tags " + tags;

	System.out.println(fileDetails);

	return Response.ok(fileDetails).build();
}
 
開發者ID:geekmj,項目名稱:jersey-jax-rs-examples,代碼行數:18,代碼來源:FileUploadResource.java

示例14: appendToDatabase

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
/**
 * This method handles the upload of a TSV movie file and adds it to the
 * database
 * 
 * @param fileInputStream	the inputstream of the data (formdata)
 * @param contentDispositionHeader	Information about the transfered file
 * @return Status information if the import was successful
 */
@POST
@Path("/db/add")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public String appendToDatabase(@FormDataParam("file") InputStream fileInputStream,
		@FormDataParam("file") FormDataContentDisposition contentDispositionHeader) {

	try {
		List<Movie> movies = DatabaseMovieImporter.importToDatabase(fileInputStream, adapter);
		return String.format("Success, inserted %d movies", movies.size());
	} catch (IOException e) {
		// TODO: do not return the error message (security)
		return e.getMessage();
	}

}
 
開發者ID:ratheile,項目名稱:sweng15,代碼行數:25,代碼來源:MovieVisualizerAPI.java

示例15: importDatabase

import org.glassfish.jersey.media.multipart.FormDataParam; //導入依賴的package包/類
/**
 * This method handles the upload of a new TSV movie database
 * 
 * @param fileInputStream	the inputstream of the data (formdata)
 * @param contentDispositionHeader	Information about the transfered file
 * @return Status information if the import was successful
 */
@POST
@Path("/db/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public String importDatabase(@FormDataParam("file") InputStream fileInputStream,
		@FormDataParam("file") FormDataContentDisposition contentDispositionHeader) {

	adapter.deleteDatabase();
	adapter.setupEmptyDatabase();

	try {
		List<Movie> movies = DatabaseMovieImporter.importToDatabase(fileInputStream, adapter);
		return String.format("Success, deleted database and inserted %d movies", movies.size());
	} catch (IOException e) {
		// TODO: do not return the error message (security)
		return e.getMessage();
	}
}
 
開發者ID:ratheile,項目名稱:sweng15,代碼行數:26,代碼來源:MovieVisualizerAPI.java


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