本文整理汇总了Java中javax.ws.rs.core.Response.Status类的典型用法代码示例。如果您正苦于以下问题:Java Status类的具体用法?Java Status怎么用?Java Status使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Status类属于javax.ws.rs.core.Response包,在下文中一共展示了Status类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFolderPost
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
/**
* @param stagingUuid
* @param parentFolder May or may not be present. This folder must already
* exist.
* @param folder Mandatory
* @return
*/
@Override
public Response createFolderPost(String stagingUuid, String parentFolder, GenericFileBean folder)
{
final StagingFile stagingFile = getStagingFile(stagingUuid);
ensureFileExists(stagingFile, parentFolder);
final String filename = folder.getFilename();
final String newPath = PathUtils.filePath(parentFolder, filename);
boolean exists = fileSystemService.fileExists(stagingFile, newPath);
fileSystemService.mkdir(stagingFile, newPath);
// was: .entity(convertFile(stagingFile, newPath, false))
ResponseBuilder resp = Response.status(exists ? Status.OK : Status.CREATED);
if( !exists )
{
resp = resp.location(itemLinkService.getFileDirURI(stagingFile, URLUtils.urlEncode(newPath, false)));
}
return resp.build();
}
示例2: testVersionFilterVersionNotExisting
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
@SuppressWarnings("boxing")
@Test
public void testVersionFilterVersionNotExisting() {
try {
UriInfo info = mock(UriInfo.class);
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
ContainerRequestContext request = mock(
ContainerRequestContext.class);
when(info.getPathParameters()).thenReturn(map);
when(request.getUriInfo()).thenReturn(info);
VersionFilter filter = new VersionFilter();
filter.filter(request);
} catch (WebApplicationException e) {
assertEquals(Status.NOT_FOUND.getStatusCode(),
e.getResponse().getStatus());
}
}
示例3: mapResponse_withHeaders
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
@Test
public void mapResponse_withHeaders() {
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
headers.add("h", "v");
new Expectations() {
{
jaxrsResponse.getStatusInfo();
result = Status.OK;
jaxrsResponse.getEntity();
result = "result";
jaxrsResponse.getHeaders();
result = headers;
}
};
Response response = mapper.mapResponse(null, jaxrsResponse);
Assert.assertEquals(Status.OK, response.getStatus());
Assert.assertEquals("result", response.getResult());
Assert.assertEquals(1, response.getHeaders().getHeaderMap().size());
Assert.assertThat(response.getHeaders().getHeader("h"), Matchers.contains("v"));
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:22,代码来源:TestJaxrsProducerResponseMapper.java
示例4: get_GetBreweryCollection_ThroughLdApi
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
@Test
public void get_GetBreweryCollection_ThroughLdApi() {
// Arrange
Model model = new ModelBuilder().subject(DBEERPEDIA.BREWERIES).add(RDFS.LABEL,
DBEERPEDIA.BREWERIES_LABEL).build();
SparqlHttpStub.returnGraph(model);
MediaType mediaType = MediaType.valueOf("text/turtle");
// Act
Response response = target.path("/dbp/ld/v1/graph-breweries").request().accept(mediaType).get();
// Assert
assertThat(response.getStatus(), equalTo(Status.OK.getStatusCode()));
assertThat(response.getMediaType(), equalTo(mediaType));
assertThat(response.getLength(), greaterThan(0));
assertThat(response.readEntity(String.class),
containsString(DBEERPEDIA.BREWERIES_LABEL.stringValue()));
}
示例5: unregisterMicroserviceInstance
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
@Override
public boolean unregisterMicroserviceInstance(String microserviceId, String microserviceInstanceId) {
Holder<HttpClientResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.delete(ipPort,
String.format(Const.REGISTRY_API.MICROSERVICE_INSTANCE_OPERATION_ONE, microserviceId, microserviceInstanceId),
new RequestParam(),
syncHandler(countDownLatch, HttpClientResponse.class, holder));
try {
countDownLatch.await();
if (holder.value != null) {
if (holder.value.statusCode() == Status.OK.getStatusCode()) {
return true;
}
LOGGER.warn(holder.value.statusMessage());
}
} catch (Exception e) {
LOGGER.error("unregister microservice instance {}/{} failed",
microserviceId,
microserviceInstanceId,
e);
}
return false;
}
示例6: logout
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
@GET
@Path("/logout")
@Produces("text/plain")
@ApiResponses(value = { @ApiResponse(code = 500, message = "CustomerService Internal Server Error") })
public String logout(@QueryParam("login") String login, @CookieParam("sessionid") String sessionid) {
try {
customerService.invalidateSession(sessionid);
// The following call will trigger query against all partitions, disable for now
// customerService.invalidateAllUserSessions(login);
// TODO: Want to do this with setMaxAge to zero, but to do that I need to have the same path/domain as cookie
// created in login. Unfortunately, until we have a elastic ip and domain name its hard to do that for "localhost".
// doing this will set the cookie to the empty string, but the browser will still send the cookie to future requests
// and the server will need to detect the value is invalid vs actually forcing the browser to time out the cookie and
// not send it to begin with
// NewCookie sessCookie = new NewCookie(SESSIONID_COOKIE_NAME, "");
return "logged out";
}
catch (Exception e) {
throw new InvocationException(Status.INTERNAL_SERVER_ERROR, "Internal Server Error");
}
}
示例7: locate
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
public void locate(String microserviceName, String path, String httpMethod, MicroservicePaths microservicePaths) {
// 在静态路径中查找
operation = locateStaticPathOperation(path, httpMethod, microservicePaths.getStaticPathOperationMap());
if (operation != null) {
// 全部定位完成
return;
}
// 在动态路径中查找
operation = locateDynamicPathOperation(path, microservicePaths.getDynamicPathOperationList(), httpMethod);
if (operation != null) {
return;
}
Status status = Status.NOT_FOUND;
if (resourceFound) {
status = Status.METHOD_NOT_ALLOWED;
}
LOGGER.error("locate path failed, status:{}, http method:{}, path:{}, microserviceName:{}",
status,
httpMethod,
path,
microserviceName);
throw new InvocationException(status, status.getReasonPhrase());
}
示例8: getRobotAsHtml
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
@GET
@Path("{robotId}")
@Produces({ MediaType.TEXT_HTML })
public Response getRobotAsHtml(
@PathParam("serviceProviderId") final String serviceProviderId, @PathParam("robotId") final String robotId
) throws ServletException, IOException, URISyntaxException
{
// Start of user code getRobotAsHtml_init
// End of user code
final Robot aRobot = TwinManager.getRobot(httpServletRequest, serviceProviderId, robotId);
if (aRobot != null) {
httpServletRequest.setAttribute("aRobot", aRobot);
// Start of user code getRobotAsHtml_setAttributes
// End of user code
RequestDispatcher rd = httpServletRequest.getRequestDispatcher("/se/ericsson/cf/scott/sandbox/robot.jsp");
rd.forward(httpServletRequest,httpServletResponse);
}
throw new WebApplicationException(Status.NOT_FOUND);
}
示例9: cancelBookingsByNumber
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
@POST
@Consumes({"application/x-www-form-urlencoded"})
@Path("/cancelbooking")
@Produces("text/plain")
public Response cancelBookingsByNumber(
@FormParam("number") String number,
@FormParam("userid") String userid) {
try {
bs.cancelBooking(userid, number);
return Response.ok("booking " + number + " deleted.").build();
}
catch (Exception e) {
e.printStackTrace();
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}
示例10: assertErrorTest
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
/**
* Common code for handling error and exception tests.
* @param service The REST service path.
*/
private void assertErrorTest(String service) {
Response response = executeRemoteWebServiceRaw(TestServerWebServices.REST_TEST_SERVICE_PATH,
service, Status.INTERNAL_SERVER_ERROR);
response.close();
TestSpanTree spans = executeRemoteWebServiceTracerTree();
Map<String, Object> expectedTags = getExpectedSpanTagsForError(service, Tags.SPAN_KIND_SERVER);
TestSpanTree expectedTree = new TestSpanTree(
new TreeNode<>(
new TestSpan(
getOperationName(
Tags.SPAN_KIND_SERVER,
HttpMethod.GET,
TestServerWebServices.class,
service
),
expectedTags,
Collections.emptyList()
)
)
);
assertEqualTrees(spans, expectedTree);
}
示例11: readAllCsv
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
@Override
public Response readAllCsv ( final String contextId )
{
final DataContext context = this.provider.getContext ( contextId );
if ( context == null )
{
logger.trace ( "Context '{}' not found", contextId ); //$NON-NLS-1$
throw new WebApplicationException ( Status.NOT_FOUND );
}
final SortedMap<String, DataItemValue> values = context.getAllValues ();
final StreamingOutput out = new StreamingOutput () {
@Override
public void write ( final OutputStream output ) throws IOException, WebApplicationException
{
streamAsCSV ( new PrintWriter ( new OutputStreamWriter ( output, StandardCharsets.UTF_8 ) ), values, ",", "\r\n" ); //$NON-NLS-1$ //$NON-NLS-2$
}
};
return Response.ok ( out ).header ( "Content-Disposition", "attachment; filename=\"data.csv\"" ).build (); //$NON-NLS-1$
}
示例12: toResponse
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
@Override
public Response toResponse(Throwable t) {
if (t instanceof WebApplicationException) {
return ((WebApplicationException) t).getResponse();
}
Status status = Status.INTERNAL_SERVER_ERROR;
String message = Messages.ERROR_EXECUTING_REST_API_CALL;
if (t instanceof ContentException) {
status = Status.BAD_REQUEST;
} else if (t instanceof NotFoundException) {
status = Status.NOT_FOUND;
} else if (t instanceof ConflictException) {
status = Status.CONFLICT;
}
if (t instanceof SLException || t instanceof VirusScannerException) {
message = t.getMessage();
}
LOGGER.error(Messages.ERROR_EXECUTING_REST_API_CALL, t);
return Response.status(status).entity(message).type(MediaType.TEXT_PLAIN_TYPE).build();
}
示例13: testValidationNegativeSuspend
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
@Test
public void testValidationNegativeSuspend() throws Exception {
DefinitionRepresentation trigger = new DefinitionRepresentation();
trigger.setAction("SUBSCRIBE_TO_SERVICE");
trigger.setTargetURL("<http://");
trigger.setDescription("abc");
trigger.setType("REST_SERVICE");
trigger.setAction("SUBSCRIBE_TO_SERVICE");
try {
trigger.validateContent();
fail();
} catch (WebApplicationException e) {
assertEquals(Status.BAD_REQUEST.getStatusCode(), e.getResponse()
.getStatus());
}
}
示例14: edit
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
@Override
public Response edit(String uuid, int version, String stagingUuid, String lockId, boolean keepLocked,
String waitForIndex, String taskUuid, ItemBean itemBean)
{
// TODO: remove this HAX
final EquellaItemBean equellaItemBean = EquellaItemBean.copyFrom(itemBean);
replacePlaceholderUuids(equellaItemBean);
equellaItemBean.setUuid(uuid);
equellaItemBean.setVersion(version);
boolean ensureOnIndexList = Boolean.parseBoolean(waitForIndex);
ItemIdKey itemIdKey = itemDeserializerService.edit(equellaItemBean, stagingUuid, lockId, !keepLocked,
ensureOnIndexList);
if( ensureOnIndexList )
{
freeTextService.waitUntilIndexed(itemIdKey);
}
return Response.status(Status.OK).location(itemLinkService.getItemURI(itemIdKey)).build();
}
示例15: getEntity
import javax.ws.rs.core.Response.Status; //导入依赖的package包/类
/**
* Returns the entity with the specified id. Returns null if it does not exist.
* @param id Id of the entity to find.
* @param client The REST client to use.
* @param <T> Type of entity to handle.
* @throws NotFoundException If 404 was returned.
* @throws TimeoutException If 408 was returned.
* @return The entity; null if it does not exist.
*/
public static <T> T getEntity(RESTClient<T> client, long id) throws NotFoundException, TimeoutException {
Response response = client.getService().path(client.getApplicationURI()).path(client.getEndpointURI()).
path(String.valueOf(id)).request(MediaType.APPLICATION_JSON).get();
if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
throw new NotFoundException();
} else if (response.getStatus() == Status.REQUEST_TIMEOUT.getStatusCode()) {
throw new TimeoutException();
}
T entity = null;
try {
entity = response.readEntity(client.getEntityClass());
} catch (NullPointerException | ProcessingException e) {
LOG.warn("Response did not conform to expected entity type.");
}
if (response != null) {
response.close();
}
return entity;
}