当前位置: 首页>>代码示例>>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;未经允许,请勿转载。