下面列出了javax.ws.rs.core.MediaType#TEXT_XML 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* a method to get xml representation of primary id card attached to a person
*/
@GET
@Produces({MediaType.APPLICATION_XML})
@Consumes({MediaType.TEXT_XML})
public IdCardRepresentation getIdCard(@PathParam("personId") String personId){
final Person person = findPersonOrThrowNotFoundException(personId);
if( person.getPrimaryIdCard()==null){
//HTTP 404
logger.info("ID card Not not found.");
throw new NotFoundException(
String.format("The primary Id card for person identified by /people/%s URI does not exist",
personId));
}
return buildIdCardRepresentation(person,person.getPrimaryIdCard());
}
/**
* Gets job info.
*
* @param id the job identifier associated with this instance.
* @return a response which includes the info of the job.
* @since 1.0
*/
@GET
@Path("/jobs/{jobid}")
@Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getJob(
@Context final HttpServletRequest request,
@PathParam("jobid") final Integer jobid) {
LOGGER.debug(MessageCatalog._00025_GET_JOB_REQUEST);
if (jobid == null) {
LOGGER.error(MessageCatalog._00022_MISSING_INPUT_PARAM, "jobid");
return Response.status(Status.BAD_REQUEST).build();
}
final DBConnectionManager dbConn = (DBConnectionManager) context.getAttribute("db");
final Job job = dbConn.getJob(jobid);
return Response.status(Response.Status.ACCEPTED).entity(job).build();
}
/**
* Gets job info.
*
* @param id the job identifier associated with this instance.
* @return a response which includes the info of the job.
* @since 1.0
*/
@GET
@Path("/jobs/{jobid}")
@Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getJob(
@Context final HttpServletRequest request,
@PathParam("jobid") final Integer jobid) {
LOGGER.debug(MessageCatalog._00025_GET_JOB_REQUEST);
if (jobid == null) {
LOGGER.error(MessageCatalog._00022_MISSING_INPUT_PARAM, "jobid");
return Response.status(Status.BAD_REQUEST).build();
}
final DBConnectionManager dbConn = (DBConnectionManager) context.getAttribute("db");
final Job job = dbConn.getJob(jobid);
return Response.status(Response.Status.ACCEPTED).entity(job).build();
}
@GET
@Path("/age/{j}")
@Produces(MediaType.TEXT_XML)
public String userAge(@PathParam("j") int j) {
int age = j;
return "<User>" + "<Age>" + age + "</Age>" + "</User>";
}
@Path("/xml/marshal")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_XML)
public String xstreamXmlMarshal(PojoA pojo) {
return producerTemplate.requestBody("direct:xstream-xml-marshal", pojo, String.class);
}
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
log.info("Content Type: text/xml");
return XML_HEADER + MESSAGE + XML_FOOTER;
}
/**
* Move the provided rules to the target priority. Rules will be sorted by their priority, first rule will be updated with a priority equal to the
* target priority and the next ones will get an incremented priority value.
*/
@GET
@Path("/move")
@Produces(MediaType.TEXT_XML)
Response move(
@QueryParam("rulesIds") String rulesIds,
@QueryParam("targetPriority") Integer targetPriority
) throws BadRequestRestEx, InternalErrorRestEx;
/**
* Creates a new job on the Linked Data Server Component.
*
* @param id the job identifier associated with this instance.
* @return a response which includes the info of the new job.
* @since 1.0
*/
@POST
@Path("/jobs")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response newJob(
@Context final HttpServletRequest request,
@FormParam("jobid") final Integer jobid) {
LOGGER.debug(MessageCatalog._00021_NEW_JOB_REQUEST);
if (jobid == null) {
LOGGER.error(MessageCatalog._00022_MISSING_INPUT_PARAM, "jobid");
return Response.status(Status.BAD_REQUEST).build();
}
//Get configuration parameters
final DBConnectionManager dbConn = (DBConnectionManager) context.getAttribute("db");
final JobConfiguration jobConf = dbConn.getJobConfiguration(jobid);
if (jobConf == null) {
LOGGER.error(MessageCatalog._00023_JOB_CONFIGURATION_NOT_FOUND, jobid);
return Response.status(Status.BAD_REQUEST).build();
}
//Program linking processes
final LinkedDataServerSetup ldsSetup = new LinkedDataServerSetup();
final Job job = ldsSetup.setup(jobConf, dbConn);
return Response.created(uriInfo.getAbsolutePathBuilder().build()).entity(job).build();
}
/**
* Returns a short summary of all jobs managed by this RDFizer instance.
* Jobs are divided by status: running and completed.
* For each job a minimal set of information are returned, if caller wants to know more about
* a specific job then a call to {@link #getJob(Integer)} must be issued.
*
* @return a short summary of all jobs managed by this RDFizer instance.
*/
@GET
@Path("/jobs")
@Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getJobs() {
return Response.ok()
.entity(
new Jobs(
jobInstanceRepository.findAll(
new Sort(
Sort.Direction.DESC,
"startDate"))))
.build();
}
@POST
@Path("/orders/")
// @Produces(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON) // produces application/json
@Consumes({ MediaType.TEXT_XML, MediaType.APPLICATION_XML }) // consumes text/xml
public Response addOrder(Order orderBean);
/**
* @deprecated used for testing only
*/
@POST
@Path("/rules/short")
@Consumes({MediaType.APPLICATION_XML, MediaType.TEXT_XML})
void setRules(@Multipart("rules")RESTOutputRuleList rules)
throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx;
@POST
@Produces({ MediaType.TEXT_XML })
public Response post(@QueryParam(LumongoConstants.ID) String uniqueId, @QueryParam(LumongoConstants.FILE_NAME) String fileName,
@QueryParam(LumongoConstants.INDEX) String indexName, @QueryParam(LumongoConstants.COMPRESSED) Boolean compressed,
@QueryParam(LumongoConstants.META) List<String> meta, InputStream is) {
if (uniqueId != null && fileName != null && indexName != null) {
HashMap<String, String> metaMap = new HashMap<>();
if (meta != null) {
for (String m : meta) {
int colonIndex = m.indexOf(":");
if (colonIndex != -1) {
String key = m.substring(0, colonIndex);
String value = m.substring(colonIndex + 1).trim();
metaMap.put(key, value);
}
else {
throw new WebApplicationException("Meta must be in the form key:value");
}
}
}
try {
if (compressed == null) {
compressed = false;
}
indexManager.storeAssociatedDocument(indexName, uniqueId, fileName, is, compressed, metaMap);
return Response.status(LumongoConstants.SUCCESS)
.entity("Stored associated document with uniqueId <" + uniqueId + "> and fileName <" + fileName + ">").build();
}
catch (Exception e) {
log.error(e.getClass().getSimpleName() + ": ", e);
return Response.status(LumongoConstants.INTERNAL_ERROR).entity(e.getMessage()).build();
}
}
else {
throw new WebApplicationException(LumongoConstants.ID + " and " + LumongoConstants.FILE_NAME + " are required", LumongoConstants.BAD_REQUEST);
}
}
/**
* @deprecated used for testing only
*/
@POST
@Path("/instances/short")
@Consumes({MediaType.APPLICATION_XML, MediaType.TEXT_XML})
void setInstances(@Multipart("instances")RESTShortInstanceList instances)
throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx;
/**
* @deprecated used for testing only
*/
@POST
@Path("/groups")
@Consumes({MediaType.APPLICATION_XML, MediaType.TEXT_XML})
void setUserGroups(@Multipart("groups")RESTFullUserGroupList groups)
throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx;
@DELETE
@Path("/id/{id}")
@Produces(MediaType.TEXT_XML)
Response delete(@PathParam("id") Long id) throws BadRequestRestEx, NotFoundRestEx;
/**
* upload a file into a given derivate
* @param info - the injected Jersey URIInfo object
* @param request - the injected HTTPServletRequest object
*
* @param mcrObjID - a MyCoRe Object ID
* @param mcrDerID - a MyCoRe Derivate ID
*
* @param uploadedInputStream - the inputstream from HTTP Post
* @param fileDetails - file information from HTTP Post
* @param path - the target path inside the derivate
* @param maindoc - true, if the file should be set as maindoc
* @param unzip - true, if the file is a zip file, that should be extracted
* @param md5 - the md5 sum of the uploaded file
* @param size - the size of the uploaded file
* @return a Jersey Response object
* @throws MCRRestAPIException
*/
@POST
@Path("/{" + PARAM_MCRID + "}/derivates/{" + PARAM_DERID + "}/contents{path:(/.*)*}")
@Produces({ MediaType.TEXT_XML + ";charset=UTF-8" })
@Consumes(MediaType.MULTIPART_FORM_DATA)
@MCRRequireTransaction
@MCRAccessControlExposeHeaders(HttpHeaders.LOCATION)
public Response uploadFile(@Context UriInfo info, @Context HttpServletRequest request,
@PathParam(PARAM_MCRID) String mcrObjID,
@PathParam(PARAM_DERID) String mcrDerID,
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetails, @FormDataParam("path") String path,
@FormDataParam("maindoc") @DefaultValue("false") boolean maindoc,
@FormDataParam("unzip") @DefaultValue("false") boolean unzip, @FormDataParam("md5") String md5,
@FormDataParam("size") Long size) throws MCRRestAPIException {
return MCRRestAPIUploadHelper.uploadFile(info, request, mcrObjID, mcrDerID, uploadedInputStream, fileDetails,
path, maindoc, unzip, md5, size);
}
@POST
@Path("/orders/")
// @Produces(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON) // produces application/json
@Consumes({MediaType.TEXT_XML, MediaType.APPLICATION_XML}) // consumes text/xml
public Response addOrder(Order orderBean);
/**
* Processes a request submitted using the POST method. The request entity represents the test subject or provides
* metadata about it. The entity body is written to a local file, the location of which is set as the value of the
* {@code iut} parameter.
*
* @param etsCode
* A String that identifies the test suite to be run.
* @param etsVersion
* A String specifying the desired test suite version.
* @param entityBody
* A File containing the request entity body.
* @return An XML representation of the test results.
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
@Produces("application/xml;qs=0.5;charset='utf-8'")
public Source handlePostXml( @PathParam("etsCode") String etsCode, @PathParam("etsVersion") String etsVersion,
File entityBody ) {
return handlePost( etsCode, etsVersion, entityBody, APPLICATION_XML );
}
/** returns a list of derivates for a given MyCoRe Object
*
* @param info - the injected Jersey URIInfo object
* @param request - the injected JAX-WS request object
*
* @param mcrid - a object identifier of syntax [id] or [prefix]:[id]
* @param derid - a derivate identifier of syntax [id] or [prefix]:[id]
*
* Allowed Prefixes are "mcr" or application specific search keys
* "mcr" is the default prefix for MyCoRe IDs.
*
* @param path - the relative path to a directory inside a derivate
* @param format - specifies the return format, allowed values are:
* * xml (default value)
* * json
*
* @param depth - the level of subdirectories that should be returned
*
* @return a Jersey Response object
* @throws MCRRestAPIException
*/
@GET
@Produces({ MediaType.TEXT_XML + ";charset=UTF-8", MCRJerseyUtil.APPLICATION_JSON_UTF8 })
@Path("/{" + PARAM_MCRID + "}/derivates/{" + PARAM_DERID + "}/contents{path:(/.*)*}")
public Response listContents(@Context UriInfo info,
@Context Request request, @PathParam(PARAM_MCRID) String mcrid,
@PathParam(PARAM_DERID) String derid,
@PathParam("path") @DefaultValue("/") String path, @QueryParam("format") @DefaultValue("xml") String format,
@QueryParam("depth") @DefaultValue("-1") int depth) throws MCRRestAPIException {
return MCRRestAPIObjectsHelper.listContents(info, app, request, mcrid, derid, format, path, depth);
}
/**
* Processes a request submitted using the POST method. The request entity represents the test subject or provides
* metadata about it. The entity body is written to a local file, the location of which is set as the value of the
* {@code iut} parameter.
*
* @param etsCode
* A String that identifies the test suite to be run.
* @param etsVersion
* A String specifying the desired test suite version.
* @param entityBody
* A File containing the request entity body.
* @return An RDF (EARL) representation of the test results.
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
@Produces("application/rdf+xml;qs=0.75;charset='utf-8'")
public Source handlePostRdf( @PathParam("etsCode") String etsCode, @PathParam("etsVersion") String etsVersion,
File entityBody ) {
return handlePost( etsCode, etsVersion, entityBody, APPLICATION_RDF_XML );
}