本文整理汇总了Java中com.sun.jersey.api.Responses类的典型用法代码示例。如果您正苦于以下问题:Java Responses类的具体用法?Java Responses怎么用?Java Responses使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Responses类属于com.sun.jersey.api包,在下文中一共展示了Responses类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateStudent
import com.sun.jersey.api.Responses; //导入依赖的package包/类
/**
* Update an existing student
* @param student
* @return
*/
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_XML)
public Response updateStudent(@PathParam("id") String id, JAXBElement<Student> student) {
Student s = student.getValue();
//Id of student cannot be overwritten
if (!id.equals(s.getRegisterNumber())) {
return Response.status(Responses.CONFLICT).entity("Unable to update student. New student has a different ID than the student you want to update.").type("text/plain").build();
}
//Does the student exist?
if (StudentDao.INSTANCE.doesStudentExist(id)) {
StudentDao.INSTANCE.updateStudent(s);
return Response.ok().build();
} else {
//Student does not exist - throw an error
return Response.status(Responses.NOT_FOUND).entity("Unable to update - student does not exist").type("text/plain").build();
}
}
示例2: validate
import com.sun.jersey.api.Responses; //导入依赖的package包/类
/**
* Get the XML for a metadata record.
* @param project the 'webdav' project, i.e. where the validator configuration lies in config/setup.xml
* @param tag reference within the 'internalValidators/[email protected]' in setup.xml
* @param xml the document to validate
* @return The an http-ok response. Returns a HTTP 400 if the record does not validate
*/
@POST
@Path("{project}/{tag}")
@ServiceDescription("Validate a xml-string for a project and a format indicated with a tag")
public Response validate(@PathParam("project") String project, @PathParam("tag") String tag, @FormParam("xml") String xml) throws ValidatorException {
DataStore datastore = DataStoreFactory.getInstance(project);
try {
datastore.getValidator(tag).validate(new SAXSource(new InputSource(new ByteArrayInputStream(xml.getBytes()))));
return Response.ok("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><validation status=\"success\" />", MediaType.TEXT_XML).build();
} catch (IllegalArgumentException e1) {
Logger.getLogger(SimplePutValidator.class.getName()).log(Level.SEVERE, null, e1);
return Responses.notFound().build();
} catch (IOException e) {
Logger.getLogger(SimplePutValidator.class.getName()).log(Level.SEVERE, null, e);
return Response.serverError().build();
}
}
示例3: testFailedEvaluatePreconditions
import com.sun.jersey.api.Responses; //导入依赖的package包/类
@Test
public void testFailedEvaluatePreconditions() throws Exception {
injector.setOauthAuthenticationWithEducationRole();
mockApplicationEntity();
mockBulkExtractEntity(null);
HttpRequestContext context = new HttpRequestContextAdapter() {
@Override
public ResponseBuilder evaluatePreconditions(Date lastModified, EntityTag eTag) {
return Responses.preconditionFailed();
}
};
Response res = bulkExtract.getEdOrgExtractResponse(context, null, null);
assertEquals(412, res.getStatus());
}
示例4: validateModuleSpec
import com.sun.jersey.api.Responses; //导入依赖的package包/类
public void validateModuleSpec(ScriptModuleSpec moduleSpec) {
Set<String> missing = new HashSet<String>(1);
if (moduleSpec == null) {
missing.add("moduleSpec");
} else {
if (moduleSpec.getCompilerPluginIds() == null) missing.add("compilerPluginIds");
if (moduleSpec.getMetadata() == null) missing.add("metadata");
if (moduleSpec.getModuleDependencies() == null) missing.add("moduleDependencies");
if (moduleSpec.getModuleId() == null) missing.add("moduleId");
}
if (!missing.isEmpty()) {
throw new WebApplicationException(
Responses
.clientError()
.entity(Collections.singletonMap("missing", missing))
.build());
}
}
示例5: post
import com.sun.jersey.api.Responses; //导入依赖的package包/类
@POST
public Response post(@FormParam("tokenid") String tokenId) {
if (tokenId == null) {
return Responses.notAcceptable().build();
}
boolean res = (sm.getByToken(tokenId) != null);
String out = "boolean=" + String.valueOf(res);
return Response.ok(out).build();
}
示例6: post
import com.sun.jersey.api.Responses; //导入依赖的package包/类
@POST
@Consumes("application/x-www-form-urlencoded")
public Response post(@FormParam("subjectid") String subjectId) {
if (subjectId == null) {
return Responses.notAcceptable().build();
}
sm.logout(subjectId);
return Response.ok().build();
}
示例7: deploy
import com.sun.jersey.api.Responses; //导入依赖的package包/类
@PUT
@Path("{scriptName: .+}")
@Consumes({"text/x-groovy", TEXT_PLAIN})
@Produces(MediaType.APPLICATION_JSON)
public Response deploy(Reader pluginScript, @PathParam("scriptName") String scriptName) {
ResponseCtx responseCtx = addonsManager.addonByType(RestAddon.class).deployPlugin(pluginScript, scriptName);
if (responseCtx.getStatus() >= 400) {
ErrorResponse errorResponse = new ErrorResponse(responseCtx.getStatus(), responseCtx.getMessage());
return Responses.clientError().type(MediaType.APPLICATION_JSON).entity(errorResponse).build();
} else {
return responseFromResponseCtx(responseCtx);
}
}
示例8: toResponse
import com.sun.jersey.api.Responses; //导入依赖的package包/类
@Override
public Response toResponse(JsonParseException exception) {
ErrorResponse errorResponse = new ErrorResponse(Response.Status.BAD_REQUEST.getStatusCode(),
exception.getMessage());
return Responses.clientError().type(MediaType.APPLICATION_JSON).entity(errorResponse).build();
}
示例9: createNewStudent
import com.sun.jersey.api.Responses; //导入依赖的package包/类
/**
* Create a new student. In case the given student already exists, return an error
*
* @param student
* @return
*/
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response createNewStudent(JAXBElement<Student> student) {
Student s = student.getValue();
//Student already exists - return an error
if (StudentDao.INSTANCE.doesStudentExist(s.getRegisterNumber())) {
return Response.status(Responses.CONFLICT).entity("Unable to create - student already exists").type("text/plain").build();
} else {
StudentDao.INSTANCE.updateStudent(s);
return Response.created(uriInfo.getAbsolutePath()).build();
}
}
示例10: deleteStudent
import com.sun.jersey.api.Responses; //导入依赖的package包/类
/**
* Delete a certain student
*
* @param id
* @return
*/
@DELETE
@Path("{id}")
@Consumes(MediaType.APPLICATION_XML)
public Response deleteStudent(@PathParam("id") String id) {
//Does the student exist?
if (!StudentDao.INSTANCE.doesStudentExist(id)) {
return Response.status(Responses.NOT_FOUND).entity("Unable to delete - student does not exist").type("text/plain").build();
} else {
StudentDao.INSTANCE.deleteStudent(id);
return Response.ok().build();
}
}
示例11: getMetadata
import com.sun.jersey.api.Responses; //导入依赖的package包/类
/**
* Get the XML for a metadata record.
* @param project The project to read from.
* @param record The record to read.
* @return The XML for a metadata record. Returns a HTTP 404 if the record does not exist.
*/
@GET
@Path("{project}/{record}")
@ServiceDescription("Get the XML for the metadata record.")
public Response getMetadata(@PathParam("project") String project, @PathParam("record") String record ){
DataStore datastore = DataStoreFactory.getInstance(project);
if(!datastore.metadataExists(record)){
return Responses.notFound().build();
}
String metadata = datastore.readMetadata(record);
return Response.ok(metadata, MediaType.TEXT_XML).build();
}
示例12: postMetadataNoEdit
import com.sun.jersey.api.Responses; //导入依赖的package包/类
/**
* Posting metadata will cause the record to be created/updated and stored in repository
@param project
* The project the metadata record is in.
* @param record
* The identifier for the record.
* @param metadata
* The new metadata for the record.
* @return HTTP 200 code if either the record created or updated else HTTP 404
* @throws ValidatorException
*/
@POST
@Path("noedit/{project}/{record}")
@ServiceDescription("Post metadata to repository without editing")
public Response postMetadataNoEdit(@PathParam("project") String project,
@PathParam("record") String record,
String metadata) throws ValidatorException
{
Objects.requireNonNull(project, "Project can not be null");
Objects.requireNonNull(record, "Missing record id");
Objects.requireNonNull(metadata, "Missing metadata");
DataStore datastore = DataStoreFactory.getInstance(project);
if( metadata != null && !("".equals(metadata.trim()))){
ValidationClient validationClient = datastore.getValidationClient(metadata);
if (validationClient != null) {
ValidationResponse validationResponse = validationClient.validate(metadata);
if (!validationResponse.success) {
throw new ValidatorException(new SAXException(validationResponse.message));
}
}
}
if (metadata != null && !"".equals(metadata.trim())){
datastore.writeMetadata(record, metadata, datastore.getDefaultUser(), datastore.getDefaultPassword());
return Response.ok().build();
}
return Responses.notFound().build();
}
示例13: post
import com.sun.jersey.api.Responses; //导入依赖的package包/类
@POST
@Consumes("application/x-www-form-urlencoded")
public Response post(@FormParam("username") String username,
@FormParam("fullname") String fullname,
@FormParam("email") String email)
{
if (username == null) {
return Responses.notAcceptable().build();
}
// decode arguments
try {
username = URLDecoder.decode(username, "UTF-8");
if (fullname != null) {
fullname = URLDecoder.decode(fullname, "UTF-8");
} else {
fullname = username;
}
if (email != null) {
email = URLDecoder.decode(email, "UTF-8");
}
} catch (UnsupportedEncodingException uee) {
logger.log(Level.WARNING, "Decoding error", uee);
throw new WebApplicationException(uee,
Response.Status.INTERNAL_SERVER_ERROR);
}
// get or create the record
UserRecord rec = sm.get(username);
if (rec == null) {
// no record exists for this user -- login in
try {
rec = sm.login(username, fullname, email);
} catch (SessionLoginException sle) {
logger.log(Level.WARNING, "Login error", sle);
throw new WebApplicationException(sle,
Response.Status.INTERNAL_SERVER_ERROR);
}
}
// return the token
String res = "string=" + rec.getToken();
return Response.ok(res).build();
}
示例14: toResponse
import com.sun.jersey.api.Responses; //导入依赖的package包/类
@Override
public Response toResponse(ItemNotFoundRuntimeException exception) {
ErrorResponse errorResponse = new ErrorResponse(Response.Status.NOT_FOUND.getStatusCode(),
exception.getMessage());
return Responses.notFound().type(MediaType.APPLICATION_JSON).entity(errorResponse).build();
}
示例15: toResponse
import com.sun.jersey.api.Responses; //导入依赖的package包/类
@Override
public Response toResponse(BadRequestException exception) {
ErrorResponse errorResponse = new ErrorResponse(Response.Status.BAD_REQUEST.getStatusCode(),
exception.getMessage());
return Responses.clientError().type(MediaType.APPLICATION_JSON).entity(errorResponse).build();
}