本文整理汇总了Java中com.sun.jersey.api.Responses类的典型用法代码示例。如果您正苦于以下问题:Java Responses类的具体用法?Java Responses怎么用?Java Responses使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Responses类属于com.sun.jersey.api包,在下文中一共展示了Responses类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
}
开发者ID:pliegl,项目名称:we2014,代码行数:26,代码来源:StudentResource.java
示例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();
}
}
开发者ID:metno,项目名称:metadata-editor,代码行数:25,代码来源:SimplePutValidator.java
示例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());
}
开发者ID:inbloom,项目名称:secure-data-service,代码行数:17,代码来源:BulkExtractTest.java
示例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());
}
}
开发者ID:Netflix,项目名称:Nicobar,代码行数:19,代码来源:ArchiveRepositoryResource.java
示例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();
}
开发者ID:josmas,项目名称:openwonderland,代码行数:11,代码来源:ValidateResource.java
示例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();
}
开发者ID:josmas,项目名称:openwonderland,代码行数:11,代码来源:LogoutResource.java
示例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);
}
}
开发者ID:alancnet,项目名称:artifactory,代码行数:14,代码来源:PluginsResource.java
示例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();
}
开发者ID:alancnet,项目名称:artifactory,代码行数:9,代码来源:JsonParseExceptionMapper.java
示例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();
}
}
开发者ID:pliegl,项目名称:we2014,代码行数:21,代码来源:StudentResource.java
示例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();
}
}
开发者ID:pliegl,项目名称:we2014,代码行数:21,代码来源:StudentResource.java
示例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();
}
开发者ID:metno,项目名称:metadata-editor,代码行数:21,代码来源:RESTApi.java
示例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();
}
开发者ID:metno,项目名称:metadata-editor,代码行数:40,代码来源:RESTApi.java
示例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();
}
开发者ID:josmas,项目名称:openwonderland,代码行数:48,代码来源:NoAuthResource.java
示例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();
}
开发者ID:alancnet,项目名称:artifactory,代码行数:7,代码来源:ItemNotFoundExceptionMapper.java
示例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();
}
开发者ID:alancnet,项目名称:artifactory,代码行数:7,代码来源:BadRequestExceptionMapper.java
示例16: toResponse
import com.sun.jersey.api.Responses; //导入依赖的package包/类
@Override
public Response toResponse(NotFoundException exception) {
ErrorResponse errorResponse = new ErrorResponse(Response.Status.NOT_FOUND.getStatusCode(),
exception.getMessage());
return Responses.notFound().type(MediaType.APPLICATION_JSON).entity(errorResponse).build();
}
开发者ID:alancnet,项目名称:artifactory,代码行数:7,代码来源:NotFoundExceptionMapper.java
示例17: OffWorldException
import com.sun.jersey.api.Responses; //导入依赖的package包/类
/**
* Create a HTTP 400 (Bad Request) exception with a JSON body.
*/
public OffWorldException() {
super(Response.status(Responses.CLIENT_ERROR).entity("[]").type(MediaType.APPLICATION_JSON).build());
}
开发者ID:gbif,项目名称:geocode,代码行数:7,代码来源:OffWorldException.java
示例18: ItemNotFoundException
import com.sun.jersey.api.Responses; //导入依赖的package包/类
public ItemNotFoundException() {
super(Responses.notFound().build());
}
开发者ID:confluence-fourum,项目名称:Fourum-Plugin,代码行数:4,代码来源:ItemNotFoundException.java
示例19: ThreadNotFoundException
import com.sun.jersey.api.Responses; //导入依赖的package包/类
public ThreadNotFoundException() {
super(Responses.notFound().build());
}
开发者ID:confluence-fourum,项目名称:Fourum-Plugin,代码行数:4,代码来源:ThreadNotFoundException.java
示例20: RoleNotFoundException
import com.sun.jersey.api.Responses; //导入依赖的package包/类
public RoleNotFoundException() {
super(Responses.notFound().build());
}
开发者ID:confluence-fourum,项目名称:Fourum-Plugin,代码行数:4,代码来源:RoleNotFoundException.java
注:本文中的com.sun.jersey.api.Responses类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论