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


Java ServiceUnavailableException类代码示例

本文整理汇总了Java中javax.ws.rs.ServiceUnavailableException的典型用法代码示例。如果您正苦于以下问题:Java ServiceUnavailableException类的具体用法?Java ServiceUnavailableException怎么用?Java ServiceUnavailableException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServiceUnavailableException类属于javax.ws.rs包,在下文中一共展示了ServiceUnavailableException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setTimeout

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
@Override
public boolean setTimeout(long time, TimeUnit unit) {
  ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
  es.schedule(new Runnable() {
    
    @Override
    public void run() {
      if(!isDone())
      {
        //even if there is an exception, it will be silently ignored
        resume(new ServiceUnavailableException("Timed-out"));
      }
      
    }
  }, time, unit);
  es.shutdown();
  return true;
}
 
开发者ID:javanotes,项目名称:reactive-data,代码行数:19,代码来源:DefaultAsyncResponse.java

示例2: testCreateException

import javax.ws.rs.ServiceUnavailableException; //导入依赖的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

示例3: events

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
@GET
@Path("events")
@Produces(SseFeature.SERVER_SENT_EVENTS)
public EventOutput events() {
    final EventOutput eventOutput = new EventOutput();

    if (!broadcaster.add(eventOutput)) {
        // 503 -> 5s delayed client reconnect attempt.
        throw new ServiceUnavailableException(5L);
    }

    try {
        eventOutput.write(event());
    } catch (final IOException ioe) {
        // NO-OP.
    }

    return eventOutput;
}
 
开发者ID:martinjmares,项目名称:javaone2015-cloudone,代码行数:20,代码来源:SpaceObjectResource.java

示例4: authenticate

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
@Override
public Optional<Account> authenticate(String bearerToken) throws AuthenticationException {
    Response response = client.target(publicAuthUrl).request()
            .header(AUTHORIZATION, "Bearer " + bearerToken)
            .accept(MediaType.APPLICATION_JSON)
            .get();
    if (response.getStatus() == OK.getStatusCode()) {
        JsonNode responseEntity = response.readEntity(JsonNode.class);
        String accountId = responseEntity.get("account_id").asText();
        String tokenType = Optional.ofNullable(responseEntity.get("token_type"))
                .map(JsonNode::asText).orElse(CARD.toString());
        TokenPaymentType tokenPaymentType = fromString(tokenType);
        return Optional.of(new Account(accountId, tokenPaymentType));
    } else if (response.getStatus() == UNAUTHORIZED.getStatusCode()) {
        response.close();
        return Optional.empty();
    } else {
        response.close();
        logger.warn("Unexpected status code " + response.getStatus() + " from auth.");
        throw new ServiceUnavailableException();
    }
}
 
开发者ID:alphagov,项目名称:pay-publicapi,代码行数:23,代码来源:AccountAuthenticator.java

示例5: testOverwriteWhileMigrating

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
@Test
public void testOverwriteWhileMigrating() throws Exception {
    String blobName = UtilsTest.createRandomBlobName();
    int size = 10 * 1024 * 1024;
    Blob oldBlob = UtilsTest.makeBlob(policy, blobName, ByteSource.wrap(new byte[size]));
    Blob newBlob = UtilsTest.makeBlob(policy, blobName, ByteSource.empty());

    policy.getSource().putBlob(containerName, oldBlob);

    BounceService.BounceTaskStatus status = bounceService.bounce(containerName);
    // sleep a little to wait for migration to start
    Utils.waitUntil(() -> status.getTotalObjectCount() == 1);
    assertThat(status.getMovedObjectCount()).isEqualTo(0);
    assertThatThrownBy(() -> policy.putBlob(containerName, newBlob))
            .isInstanceOf(ServiceUnavailableException.class);

    status.future().get();
    assertStatus(status, status::getMovedObjectCount).isEqualTo(1);
}
 
开发者ID:bouncestorage,项目名称:bouncestorage,代码行数:20,代码来源:MigrationPolicyTest.java

示例6: toResponse

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Response toResponse(final ServiceUnavailableException exception) {
    if (L.isDebugEnabled()) {
        L.debug(R.getString("D-REST-JERSEY-MAPPER#0011"));
    }
    ErrorMessage error = ErrorMessages.create(exception)
        .id()
        .code(ErrorCode.SERVICE_UNAVAILABLE.code())
        .resolve()
        .get();
    L.error(error.log(), exception);
    return Response.status(exception.getResponse().getStatusInfo())
        .entity(error)
        .type(MediaType.APPLICATION_JSON)
        .build();
}
 
开发者ID:ctc-g,项目名称:sinavi-jfw,代码行数:20,代码来源:ServiceUnavailableExceptionMapper.java

示例7: processLogin

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
@HiveWebsocketAuth
@PreAuthorize("permitAll")
public void processLogin(JsonObject request, WebSocketSession session) throws IOException {
    JwtRequestVO loginRequest = new JwtRequestVO();
    if (request.get("login") != null) {
        loginRequest.setLogin(request.get("login").getAsString());
    }
    if (request.get("password") != null) {
        loginRequest.setPassword(request.get("password").getAsString());
    }
    
    String loginRequestStr = gson.toJson(loginRequest);

    JwtTokenVO jwtToken = null;
    try {
        jwtToken = httpRestHelper.post(authBaseUrl + "/token", loginRequestStr, JwtTokenVO.class, null);
    } catch (ServiceUnavailableException e) {
        throw new HiveException(e.getMessage(), SC_SERVICE_UNAVAILABLE);
    }
    
    WebSocketResponse response = new WebSocketResponse();
    response.addValue("accessToken", jwtToken.getAccessToken());
    response.addValue("refreshToken", jwtToken.getRefreshToken());
    clientHandler.sendMessage(request, response, session);
}
 
开发者ID:devicehive,项目名称:devicehive-java-server,代码行数:26,代码来源:CommonHandlers.java

示例8: hasPermission

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
@HiveWebsocketAuth
@PreAuthorize("isAuthenticated() and hasPermission(null, 'MANAGE_TOKEN')")
public void processTokenCreate(JsonObject request, WebSocketSession session) throws IOException {
    JsonObject payload = request.get(Constants.PAYLOAD).getAsJsonObject();
    if (payload == null) {
        logger.warn("JwtToken: payload was not found");
        throw new HiveException(Messages.PAYLOAD_NOT_FOUND, SC_BAD_REQUEST);
    }
    hiveValidator.validate(payload);
    
    String jwtTokenStr = (String) session.getAttributes().get(WebSocketAuthenticationManager.SESSION_ATTR_JWT_TOKEN);
    
    JwtTokenVO jwtToken = null;
    try {
        jwtToken = httpRestHelper.post(authBaseUrl + "/token/create", payload.toString(), JwtTokenVO.class, jwtTokenStr);
    } catch (ServiceUnavailableException e) {
        throw new HiveException(e.getMessage(), SC_SERVICE_UNAVAILABLE);
    }
    
    WebSocketResponse response = new WebSocketResponse();
    response.addValue("accessToken", jwtToken.getAccessToken());
    response.addValue("refreshToken", jwtToken.getRefreshToken());
    clientHandler.sendMessage(request, response, session);
}
 
开发者ID:devicehive,项目名称:devicehive-java-server,代码行数:25,代码来源:CommonHandlers.java

示例9: processRefresh

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
@HiveWebsocketAuth
@PreAuthorize("permitAll")
public void processRefresh(JsonObject request, WebSocketSession session) throws IOException {
    if (request.get("refreshToken") == null) {
        logger.warn("JwtToken: payload was not found");
        throw new HiveException(Messages.PAYLOAD_NOT_FOUND, SC_BAD_REQUEST);
    }

    JwtRefreshTokenVO refreshTokenVO = new JwtRefreshTokenVO();
    refreshTokenVO.setRefreshToken(request.get("refreshToken").getAsString());

    String refreshTokenStr = gson.toJson(refreshTokenVO);

    JwtTokenVO jwtToken = null;
    try {
        jwtToken = httpRestHelper.post(authBaseUrl + "/token/refresh", refreshTokenStr, JwtTokenVO.class, null);
    } catch (ServiceUnavailableException e) {
        throw new HiveException(e.getMessage(), SC_SERVICE_UNAVAILABLE);
    }

    WebSocketResponse response = new WebSocketResponse();
    response.addValue("accessToken", jwtToken.getAccessToken());
    clientHandler.sendMessage(request, response, session);
}
 
开发者ID:devicehive,项目名称:devicehive-java-server,代码行数:25,代码来源:CommonHandlers.java

示例10: testToResponseServer

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
@Test
public void testToResponseServer() throws Exception {
	Response r = uut.toResponse(new ServiceUnavailableException());
	assertEquals(503, r.getStatus());
	assertEquals(new SimpleExceptionJson("Service Unavailable", 503, "HTTP 503 Service Unavailable"),
			r.getEntity());
}
 
开发者ID:Mercateo,项目名称:rest-jersey-utils,代码行数:8,代码来源:RFCExceptionMapper0Test.java

示例11: getApiException

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
public PulsarAdminException getApiException(Throwable e) {
    if (e instanceof ServiceUnavailableException) {
        if (e.getCause() instanceof java.net.ConnectException) {
            return new ConnectException(e.getCause());
        } else {
            return new HttpErrorException(e);
        }
    } else if (e instanceof WebApplicationException) {
        // Handle 5xx exceptions
        if (e instanceof ServerErrorException) {
            ServerErrorException see = (ServerErrorException) e;
            return new ServerSideErrorException(see);
        }

        // Handle 4xx exceptions
        ClientErrorException cee = (ClientErrorException) e;
        int statusCode = cee.getResponse().getStatus();
        switch (statusCode) {
        case 401:
        case 403:
            return new NotAuthorizedException(cee);
        case 404:
            return new NotFoundException(cee);
        case 405:
            return new NotAllowedException(cee);
        case 409:
            return new ConflictException(cee);
        case 412:
            return new PreconditionFailedException(cee);

        default:
            return new PulsarAdminException(cee);
        }
    } else {
        return new PulsarAdminException(e);
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:38,代码来源:BaseResource.java

示例12: getResponseCode

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
/**
 * Check if the message processing is done
 * @param id
 * @return
 */
synchronized int getResponseCode(String id)
{
  if(hzService.contains(id, WebbitRestServerBean.ASYNC_REST_EVENT_RESPONSE_MAP))
  {
    String resp = (String) hzService.get(id, WebbitRestServerBean.ASYNC_REST_EVENT_RESPONSE_MAP);
    if(resp != null)
    {
      if(resp.contains(WebbitRestServerBean.ASYNC_REST_RESPONSE_PROCESS_ERR))
      {
        if(resp.contains(ServiceUnavailableException.class.getName()))
        {
          return HttpResponseStatus.SERVICE_UNAVAILABLE.getCode();
        }
        else
        {
          return HttpResponseStatus.INTERNAL_SERVER_ERROR.getCode();
        }
      }
      else
      {
        return HttpResponseStatus.OK.getCode();
      }
    }
    
  }
  if(hzService.contains(id, WebbitRestServerBean.ASYNC_REST_EVENT_MAP))
  {
    return HttpResponseStatus.NO_CONTENT.getCode();//response not yet ready
  }
  return HttpResponseStatus.NOT_FOUND.getCode();
}
 
开发者ID:javanotes,项目名称:reactive-data,代码行数:37,代码来源:AsyncEventReceiverBean.java

示例13: testOpeningCircuitBreaker

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
@Test(expected = ServiceUnavailableException.class)
public void testOpeningCircuitBreaker() {
    final HelloService proxy = createProxy();
    for (int i = 0; i < 20; ++i) {
        try {
            proxy.sayHello("Dr. Evil");
        } catch (InternalServerErrorException e) {
            // Ignore!
        }
    }
    proxy.sayHello("Microbule");
}
 
开发者ID:Microbule,项目名称:microbule,代码行数:13,代码来源:CircuitBreakerFilterTest.java

示例14: validateResponse

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
/**
 * Private method to help validate and parse a request response.
 *
 * @param response object to be validated
 * @param parser the parser that is executed if no errors occurred
 * @param <T> the return type of the response, e.g. {@link AuthenticationResponse} or {@link GeocodingResponse}
 * @return interpreted/parsed response of type T
 * @throws Route360ClientException when an unexpected error occurs during request
 */
private <T> T validateResponse(final Response response, final Function<String,T> parser) throws Route360ClientException {
    // compare the HTTP status codes, NOT the route 360 code
    if (response.getStatus() == Response.Status.OK.getStatusCode()) {
        // parse the results
        String jsonString = response.readEntity(String.class);
        return parser.apply(jsonString);
    } else if(response.getStatus() == Response.Status.SERVICE_UNAVAILABLE.getStatusCode() )
        throw new ServiceUnavailableException(); // Some clients (e.g. jBoss) return SERVICE_UNAVAILABLE while others will wait
    else
        throw new Route360ClientException("Request failed with response: \n" + response.readEntity(String.class));
}
 
开发者ID:route360,项目名称:r360-java,代码行数:21,代码来源:GeocodingRequest.java

示例15: fetch

import javax.ws.rs.ServiceUnavailableException; //导入依赖的package包/类
@GET
@Produces(SseFeature.SERVER_SENT_EVENTS)
public EventOutput fetch(
        @HeaderParam(SseFeature.LAST_EVENT_ID_HEADER) String lastEventId) {
    if (!Strings.isNullOrEmpty(lastEventId)) {
        LOGGER.debug("Found Last-Event-ID header: {}", lastEventId);
    }

    final EventOutput output = new EventOutput();
    if (!broadcaster.add(output)) {
        throw new ServiceUnavailableException(RETRY_AFTER.toSeconds());
    }
    return output;
}
 
开发者ID:smoketurner,项目名称:pipeline,代码行数:15,代码来源:EventResource.java


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