本文整理汇总了Java中javax.ws.rs.NotAllowedException类的典型用法代码示例。如果您正苦于以下问题:Java NotAllowedException类的具体用法?Java NotAllowedException怎么用?Java NotAllowedException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NotAllowedException类属于javax.ws.rs包,在下文中一共展示了NotAllowedException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toResponse
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
@Override
public Response toResponse(Exception e) {
WrapperResponseEntity response = null;
if (e instanceof NotFoundException) {
response = new WrapperResponseEntity(ResponseCode.NOT_FOUND);
} else if (e instanceof NotAllowedException) {
response = new WrapperResponseEntity(ResponseCode.FORBIDDEN);
} else if (e instanceof JsonProcessingException) {
response = new WrapperResponseEntity(ResponseCode.ERROR_JSON);
} else if (e instanceof NotSupportedException) {
response = new WrapperResponseEntity(ResponseCode.UNSUPPORTED_MEDIA_TYPE);
} else {
response = excetionWrapper != null ? excetionWrapper.toResponse(e) : null;
if (response == null)
response = new WrapperResponseEntity(ResponseCode.INTERNAL_SERVER_ERROR);
}
return Response.status(response.httpStatus()).type(MediaType.APPLICATION_JSON)
.entity(response).build();
}
示例2: getHandler
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
private Consumer<Throwable> getHandler(final Throwable t) {
if (t instanceof ProcessingException || t instanceof NotAllowedException || t instanceof ServerErrorException) {
return this.getCommunicationFailureHandler();
} else if (t instanceof WebApplicationException) {
return this.getRemoteFailureHandler();
}
return this.getOtherFailureHandler();
}
示例3: toResponse
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
@Override
public Response toResponse(Exception e) {
WrapperResponseEntity response = null;
if (e instanceof NotFoundException) {
response = new WrapperResponseEntity(ResponseCode.NOT_FOUND);
} else if (e instanceof NotAllowedException) {
response = new WrapperResponseEntity(ResponseCode.FORBIDDEN);
} else if (e instanceof JsonProcessingException) {
response = new WrapperResponseEntity(ResponseCode.ERROR_JSON);
} else if (e instanceof NotSupportedException) {
response = new WrapperResponseEntity(ResponseCode.UNSUPPORTED_MEDIA_TYPE);
} else {
response = excetionWrapper != null ? excetionWrapper.toResponse(e) : null;
if(response == null)response = new WrapperResponseEntity(ResponseCode.INTERNAL_SERVER_ERROR);
}
return Response.status(response.httpStatus()).type(MediaType.APPLICATION_JSON).entity(response).build();
}
示例4: testCreateException
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
@Test
public void testCreateException() {
assertExceptionType(Response.Status.INTERNAL_SERVER_ERROR, InternalServerErrorException.class);
assertExceptionType(Response.Status.NOT_FOUND, NotFoundException.class);
assertExceptionType(Response.Status.FORBIDDEN, ForbiddenException.class);
assertExceptionType(Response.Status.BAD_REQUEST, BadRequestException.class);
assertExceptionType(Response.Status.METHOD_NOT_ALLOWED, NotAllowedException.class);
assertExceptionType(Response.Status.UNAUTHORIZED, NotAuthorizedException.class);
assertExceptionType(Response.Status.NOT_ACCEPTABLE, NotAcceptableException.class);
assertExceptionType(Response.Status.UNSUPPORTED_MEDIA_TYPE, NotSupportedException.class);
assertExceptionType(Response.Status.SERVICE_UNAVAILABLE, ServiceUnavailableException.class);
assertExceptionType(Response.Status.TEMPORARY_REDIRECT, RedirectionException.class);
assertExceptionType(Response.Status.LENGTH_REQUIRED, ClientErrorException.class);
assertExceptionType(Response.Status.BAD_GATEWAY, ServerErrorException.class);
assertExceptionType(Response.Status.NO_CONTENT, WebApplicationException.class);
}
示例5: setSlave
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
@Path("/setSlave")
@POST
public Map setSlave(@QueryParam("shardId") String shardId, @QueryParam("masterShardId") String masterShardId) {
if (shardManagerClient == null) {
throw new NotAllowedException("The operation only supported in multi-shard mode");
}
Map<Object, Object> map = new LinkedHashMap<>();
try {
shardManagerClient.startObserving(shardId, masterShardId, 5000);
map.put("success", true);
} catch (ShardManagerProtocol.ShardManagerException | InterruptedException e) {
map.put("success", false);
map.put("reason", e.getMessage());
}
return map;
}
示例6: unsetSlave
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
@Path("/unsetSlave")
@POST
public Map unsetSlave(@QueryParam("shardId") String shardId, @QueryParam("masterShardId") String masterShardId) {
Map<Object, Object> map = new LinkedHashMap<>();
if (shardManagerClient == null) {
throw new NotAllowedException("The operation only supported in multi-shard mode");
}
try {
shardManagerClient.stopObserving(shardId, masterShardId, 5000);
map.put("success", true);
} catch (ShardManagerProtocol.ShardManagerException | InterruptedException e) {
map.put("success", false);
map.put("reason", e.getMessage());
}
return map;
}
示例7: toResponse
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Response toResponse(final NotAllowedException exception) {
if (L.isDebugEnabled()) {
L.debug(R.getString("D-REST-JERSEY-MAPPER#0006"));
}
ErrorMessage error = ErrorMessages.create(exception)
.code(ErrorCode.METHOD_NOT_ALLOWED.code())
.resolve()
.get();
L.warn(error.log(), exception);
return Response.status(exception.getResponse().getStatusInfo())
.entity(error)
.type(MediaType.APPLICATION_JSON)
.build();
}
示例8: toResponse
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
@Override
public Response toResponse(Exception exception) {
logger.error("Error: {}", exception.getMessage());
Response.Status responseCode = Response.Status.INTERNAL_SERVER_ERROR;
String message = exception.getMessage();
if (exception instanceof NotFoundException) {
responseCode = Response.Status.NOT_FOUND;
message = exception.getMessage();
} else if (exception instanceof BadRequestException) {
responseCode = Response.Status.BAD_REQUEST;
message = exception.getMessage();
} else if (exception instanceof NotAllowedException) {
responseCode = Response.Status.METHOD_NOT_ALLOWED;
} else if (exception instanceof WebApplicationException) {
WebApplicationException realException = (WebApplicationException) exception;
int response = realException.getResponse().getStatus();
responseCode = Response.Status.fromStatusCode(response);
}
return ResponseFactory.response(responseCode, new ErrorResponse(responseCode.getStatusCode(), message));
}
示例9: testFilterUnknownMethod
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
@Test
public void testFilterUnknownMethod() throws Exception {
when(mockContext.getMethod()).thenReturn("FOO");
final WebAcFilter filter = new WebAcFilter(emptyList(), mockAccessControlService);
assertThrows(NotAllowedException.class, () -> filter.filter(mockContext));
}
示例10: badMethod
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
/**
* Tests the response for a request with a bad method.
*/
@Test
public void badMethod() {
WebTarget wt = target();
try {
wt.path("hosts").request().delete(String.class);
fail("Fetch of non-existent URL did not throw an exception");
} catch (NotAllowedException ex) {
assertThat(ex.getMessage(),
containsString("HTTP 405 Method Not Allowed"));
}
}
示例11: toResponse
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
@Override
public Response toResponse(NotAllowedException e) {
return Response.status(Response.Status.METHOD_NOT_ALLOWED)
.entity(new org.crunchytorch.coddy.application.data.Response(e.getMessage()))
.type(MediaType.APPLICATION_JSON)
.build();
}
示例12: handleException
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
private static void handleException(final Throwable ex, final boolean faultTolerant) {
final Throwable cause = ex.getCause();
if (ex instanceof NotAllowedException || ex instanceof ServerErrorException ||
cause instanceof SocketException || cause instanceof UnknownHostException) {
AppRuntimeExceptionHandler.handleZonkyMaintenanceError(ex, faultTolerant);
} else {
AppRuntimeExceptionHandler.handleUnexpectedException(ex);
}
}
示例13: handleErrorStatus
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
private static <T> T handleErrorStatus(Response response) {
final int status = response.getStatus();
switch (status) {
case 400:
throw new BadRequestException(response);
case 401:
throw new NotAuthorizedException(response);
case 404:
throw new NotFoundException(response);
case 405:
throw new NotAllowedException(response);
case 406:
throw new NotAcceptableException(response);
case 415:
throw new NotSupportedException(response);
case 500:
throw new InternalServerErrorException(response);
case 503:
throw new ServiceUnavailableException(response);
default:
break;
}
if (status >= 400 && status < 500){
throw new ClientErrorException(response);
} else if (status >= 500) {
throw new ServerErrorException(response);
}
throw new WebApplicationException(response);
}
示例14: getWithNoDataIsNotAllowed
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
@Test
public void getWithNoDataIsNotAllowed() {
try {
resources.client().target("/ocsp/").request().get(OCSPResp.class);
failBecauseExceptionWasNotThrown(NotAllowedException.class);
} catch (NotAllowedException e) {
assertThat(e).hasMessageEndingWith("HTTP 405 Method Not Allowed");
}
}
示例15: filter
import javax.ws.rs.NotAllowedException; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
switch (LensServices.get().getServiceMode()) {
case READ_ONLY:
// Allows all requests on session and only GET everywhere
if (!requestContext.getUriInfo().getPath().startsWith("session")) {
if (!requestContext.getMethod().equals("GET")) {
throw new NotAllowedException("Server is in readonly mode. Request on path:"
+ requestContext.getUriInfo().getPath(), "GET", (String[]) null);
}
}
break;
case METASTORE_READONLY:
// Allows GET on metastore and all other requests
if (requestContext.getUriInfo().getPath().startsWith("metastore")) {
if (!requestContext.getMethod().equals("GET")) {
throw new NotAllowedException("Metastore is in readonly mode. Request on path:"
+ requestContext.getUriInfo().getPath(), "GET", (String[]) null);
}
}
break;
case METASTORE_NODROP:
// Does not allows DROP on metastore, all other request are allowed
if (requestContext.getUriInfo().getPath().startsWith("metastore")) {
if (requestContext.getMethod().equals("DELETE")) {
throw new NotAllowedException("Metastore is in nodrop mode. Request on path:"
+ requestContext.getUriInfo().getPath(), "GET", new String[]{"PUT", "POST"});
}
}
break;
case OPEN:
// nothing to do
}
}