当前位置: 首页>>代码示例>>Java>>正文


Java NotAllowedException类代码示例

本文整理汇总了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();
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:21,代码来源:BaseExceptionMapper.java

示例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();
}
 
开发者ID:RoboZonky,项目名称:robozonky,代码行数:9,代码来源:RuntimeExceptionHandler.java

示例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();
}
 
开发者ID:vakinge,项目名称:jeesuite-libs,代码行数:19,代码来源:BaseExceptionMapper.java

示例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);
}
 
开发者ID:Microbule,项目名称:microbule,代码行数:17,代码来源:AbstractErrorResponseStrategyTest.java

示例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;
}
 
开发者ID:yahoo,项目名称:gondola,代码行数:17,代码来源:AdminResource.java

示例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;
}
 
开发者ID:yahoo,项目名称:gondola,代码行数:17,代码来源:AdminResource.java

示例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();
}
 
开发者ID:ctc-g,项目名称:sinavi-jfw,代码行数:19,代码来源:NotAllowedExceptionMapper.java

示例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));
}
 
开发者ID:devicehive,项目名称:devicehive-java-server,代码行数:22,代码来源:AllExceptionMapper.java

示例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));
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:9,代码来源:WebACFilterTest.java

示例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"));
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:15,代码来源:BadRequestTest.java

示例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();
}
 
开发者ID:Crunchy-Torch,项目名称:coddy,代码行数:8,代码来源:NotAllowedMapper.java

示例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);
    }
}
 
开发者ID:RoboZonky,项目名称:robozonky,代码行数:10,代码来源:AppRuntimeExceptionHandler.java

示例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);
}
 
开发者ID:Blazebit,项目名称:blaze-storage,代码行数:32,代码来源:ResponseObjectInvocation.java

示例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");
    }
}
 
开发者ID:wdawson,项目名称:revoker,代码行数:10,代码来源:OCSPResponderResourceTest.java

示例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
  }
}
 
开发者ID:apache,项目名称:lens,代码行数:36,代码来源:ServerModeFilter.java


注:本文中的javax.ws.rs.NotAllowedException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。