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


Java WebApplicationException类代码示例

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


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

示例1: testVersionFilter

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
@SuppressWarnings("boxing")
private MultivaluedMap<String, String> testVersionFilter(String version) throws WebApplicationException, NoSuchMethodException {

    ResourceInfo resourceInfo = mock(ResourceInfo.class);
    ContainerRequestContext request = mock(ContainerRequestContext.class);
    UriInfo uriInfo = mock(UriInfo.class);
    when(request.getUriInfo()).thenReturn(uriInfo);

    Method method = SinceClass.class.getMethod("dummy");

    MultivaluedMap<String, String> prop = new MultivaluedHashMap<>();
    prop.putSingle(CommonParams.PARAM_VERSION, version);
    when(uriInfo.getPathParameters()).thenReturn(prop);

    VersionFilter filter = spy(new VersionFilter());
    when(filter.getResourceInfo()).thenReturn(resourceInfo);
    when(resourceInfo.getResourceMethod()).thenReturn(method);
    filter.filter(request);

    return prop;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:22,代码来源:VersionFilterTest.java

示例2: update

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
@Override
public Response update(UUID id, User user) {
    try {
        final Optional<User> internalUser = this.service.read(id);
        if (internalUser.isPresent()) {
            if (!internalUser.get().getId().equals(id)) {
                mapper.toResponse(new WebApplicationException(new IllegalArgumentException("Invalid unique id"),
                        Response.status(Response.Status.INTERNAL_SERVER_ERROR).build()));
            } else {
                return Response.status(Response.Status.OK).entity(this.service.save(user)).build();
            }
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        return Response.status(Response.Status.CREATED).entity(this.service.save(user)).build();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return mapper.toResponse(new WebApplicationException(e,
                Response.status(Response.Status.INTERNAL_SERVER_ERROR).build()));
    }
}
 
开发者ID:wesleyfuchter,项目名称:user-task,代码行数:22,代码来源:UserResourceImpl.java

示例3: testGetJobCountersAcls

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
@Test
public void testGetJobCountersAcls() {
  HttpServletRequest hsr = mock(HttpServletRequest.class);
  when(hsr.getRemoteUser()).thenReturn(ENEMY_USER);

  try {
    hsWebServices.getJobCounters(hsr, jobIdStr);
    fail("enemy can access job");
  } catch (WebApplicationException e) {
    assertEquals(Status.UNAUTHORIZED,
        Status.fromStatusCode(e.getResponse().getStatus()));
  }

  when(hsr.getRemoteUser()).thenReturn(FRIENDLY_USER);
  hsWebServices.getJobCounters(hsr, jobIdStr);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:TestHsWebServicesAcls.java

示例4: getPlanAsHtml

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
@GET
@Path("{planId}")
@Produces({ MediaType.TEXT_HTML })
public Response getPlanAsHtml(
    @PathParam("serviceProviderId") final String serviceProviderId, @PathParam("planId") final String planId
    ) throws ServletException, IOException, URISyntaxException
{
    // Start of user code getPlanAsHtml_init
    // End of user code

    final Plan aPlan = PlannerReasonerManager.getPlan(httpServletRequest, serviceProviderId, planId);

    if (aPlan != null) {
        httpServletRequest.setAttribute("aPlan", aPlan);
        // Start of user code getPlanAsHtml_setAttributes
        // End of user code

        RequestDispatcher rd = httpServletRequest.getRequestDispatcher("/se/ericsson/cf/scott/sandbox/plan.jsp");
        rd.forward(httpServletRequest,httpServletResponse);
    }

    throw new WebApplicationException(Status.NOT_FOUND);
}
 
开发者ID:EricssonResearch,项目名称:scott-eu,代码行数:24,代码来源:ServiceProviderService1.java

示例5: writeTo

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
@Override
public void writeTo(Model t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
		MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
		throws IOException, WebApplicationException {
	
	Lang lang = null;
	
	if(mediaType.equals(KRFormat.N3_TYPE))
		lang = Lang.N3;
	else if(mediaType.equals(KRFormat.N_TRIPLE_TYPE))
		lang = Lang.NTRIPLES;
	else if(mediaType.equals(KRFormat.RDF_JSON_TYPE))
		lang = Lang.RDFJSON;
	else if(mediaType.equals(new MediaType("application", "json-ld")))
		lang = Lang.JSONLD;
	else lang = Lang.TURTLE;
	
	RDFDataMgr.write(entityStream, t, lang);
	
}
 
开发者ID:teamdigitale,项目名称:ontonethub,代码行数:21,代码来源:ModelWriter.java

示例6: getPlace

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
@GET
@Path("places/{placeId}")
@Produces({OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML, OslcMediaType.APPLICATION_JSON})
public Place getPlace(
            @PathParam("serviceProviderId") final String serviceProviderId, @PathParam("placeId") final String placeId
    ) throws IOException, ServletException, URISyntaxException
{
    // Start of user code getResource_init
    // End of user code

    final Place aPlace = WarehouseControllerManager.getPlace(httpServletRequest, serviceProviderId, placeId);

    if (aPlace != null) {
        // Start of user code getPlace
        // End of user code
        httpServletResponse.addHeader(WarehouseControllerConstants.HDR_OSLC_VERSION, WarehouseControllerConstants.OSLC_VERSION_V2);
        return aPlace;
    }

    throw new WebApplicationException(Status.NOT_FOUND);
}
 
开发者ID:EricssonResearch,项目名称:scott-eu,代码行数:22,代码来源:ServiceProviderService1.java

示例7: testGetJobTasksAcls

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
@Test
public void testGetJobTasksAcls() {
  HttpServletRequest hsr = mock(HttpServletRequest.class);
  when(hsr.getRemoteUser()).thenReturn(ENEMY_USER);

  try {
    hsWebServices.getJobTasks(hsr, jobIdStr, "m");
    fail("enemy can access job");
  } catch (WebApplicationException e) {
    assertEquals(Status.UNAUTHORIZED,
        Status.fromStatusCode(e.getResponse().getStatus()));
  }

  when(hsr.getRemoteUser()).thenReturn(FRIENDLY_USER);
  hsWebServices.getJobTasks(hsr, jobIdStr, "m");
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:TestHsWebServicesAcls.java

示例8: runTestCase

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
@Override
public TestCaseResult runTestCase(String serviceName, String testName, String mode) {
    MDC.put(APP_NAME, RedirectorConstants.Logging.APP_NAME_PREFIX + serviceName);
    TestMode testMode = TestMode.valueOf(mode.toUpperCase());
    RedirectorTestCase testCase = getTestCase(serviceName, testName);
    if (testCase == null) {
        throw new WebApplicationException(Response.Status.NOT_FOUND); // test case not found
    }

    IRedirectorEnvLoader envLoader = getZookeeperRedirectorEnvLoader(serviceName, testMode);

    SelectServer flavorRules = envLoader.getFlavorRules();
    URLRules urlRules = envLoader.getUrlRules();
    Whitelisted whitelisted = envLoader.getWhitelists();
    NamespacedListRepository namespacedLists = new SimpleNamespacedListsHolder(envLoader.getNamespacedListsBatch());
    IRedirectorEngine engine = redirectorEngineFactory.newRedirectorEngine(
            serviceName, flavorRules, urlRules, whitelisted, namespacedLists, envLoader.getStacks(), new RedirectorEngine.SessionLog());
    Context context = TestSuiteUtils.getRedirectorContext(testCase);
    InstanceInfo instanceInfo = engine.redirect(context.asMap());

    TestSuiteResponse actual = TestSuiteUtils.getRedirectorResponse(instanceInfo);
    TestCaseResult testCaseResult = new TestCaseResult();
    testCaseResult.setStatus(TestCaseResult.Status.fromTestCase(testCase.getExpected(), actual));
    testCaseResult.setActual(actual);
    testCaseResult.setLogs(AutoTestRunner.getSessionLogs(context, engine));
    MDC.remove(APP_NAME);
    return testCaseResult;
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:29,代码来源:RedirectorTestSuiteService.java

示例9: deleteUrlRule

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
public OperationResult deleteUrlRule(String appName, String ruleId, ApplicationStatusMode mode) {
    final OperationContextHolder.OperationContext currentContext = OperationContextHolder.getCurrentContext();
    IfExpression current = currentContext.getUrlRule(ruleId);
    PendingChangesStatus pendingChangesStatus = currentContext.getPendingChangesStatus();

    // check for existing rule
    if (current == null && !(pendingChangesStatus != null && getUrlRules(pendingChangesStatus).containsKey(ruleId))) {
        throw new WebApplicationException(Response.Status.NOT_FOUND); // rule not found
    }

    if (current != null) {
        return pendingUrlRuleWriteService.save(appName, ruleId, null, current, mode);
    } else {
        // if admin added rule and decided to remove it right away it's the same as cancel pending addition
        return pendingUrlRuleWriteService.cancel(appName, ruleId, mode);
    }
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:18,代码来源:BaseUrlRulesService.java

示例10: getServiceProvider

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
public static ServiceProvider getServiceProvider(HttpServletRequest httpServletRequest, final String serviceProviderId)
{
    ServiceProvider serviceProvider;

    synchronized(serviceProviders)
    {
        String identifier = serviceProviderIdentifier(serviceProviderId);
        serviceProvider = serviceProviders.get(identifier);

        //One retry refreshing the service providers
        if (serviceProvider == null)
        {
            getServiceProviders(httpServletRequest);
            serviceProvider = serviceProviders.get(identifier);
        }
    }

    if (serviceProvider != null)
    {
        return serviceProvider;
    }

    throw new WebApplicationException(Status.NOT_FOUND);
}
 
开发者ID:EricssonResearch,项目名称:scott-eu,代码行数:25,代码来源:ServiceProviderCatalogSingleton.java

示例11: testValidationNegativeSuspend

import javax.ws.rs.WebApplicationException; //导入依赖的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());
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:DefinitionRepresentationTest.java

示例12: verify

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
/**
 * Verifies that the user's authorization.
 *
 * @param username The username of the user.
 * @param authorization The authorization of the user.
 * @throws IllegalArgumentException When the format of Authorization is unexpected.
 * @throws WebApplicationException When UNAUTHORIZED.
 */
public static void verify(String username, String authorization) {
    final String accessToken;
    if (authorization.startsWith("token")) {
        accessToken = authorization.split(" ")[1];
    } else {
        throw new IllegalArgumentException("The format of Authorization is unexpected.");
    }
    Document user = MongoDBs.users().find(eq(User.USERNAME, username)).limit(1).first();
    if (user == null) {
        throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
    Document auth = user.get(User.AUTHORIZATION, Document.class);
    if (Objects.equals(auth.getString(Authorization.ACCESS_TOKEN), accessToken)) {
        Log.i(TAG, "Verified successfully.");
    } else {
        throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
}
 
开发者ID:drakeet,项目名称:rebase-server,代码行数:27,代码来源:Authorizations.java

示例13: ZNodeResource

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
public ZNodeResource(@DefaultValue("") @QueryParam("session") String session,
        @Context UriInfo ui,
        @Context HttpServletRequest request
        )
        throws IOException {

    String contextPath = request.getContextPath();
    if (contextPath.equals("")) {
        contextPath = "/";
    }
    if (session.equals("")) {
        session = null;
    } else if (!ZooKeeperService.isConnected(contextPath, session)) {
        throw new WebApplicationException(Response.status(
                Response.Status.UNAUTHORIZED).build());
    }
    zk = ZooKeeperService.getClient(contextPath, session);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:19,代码来源:ZNodeResource.java

示例14: toResponse

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
@Override
public Response toResponse(WebApplicationException exception) {
    log.error("Exception happened in RedirectorWebService", exception);

    int exceptionStatusCode = exception.getResponse().getStatus();
    String exceptionMessage = exception.getMessage();
    if (exceptionMessage == null) {
        Response.Status exceptionStatus = Response.Status.fromStatusCode(exceptionStatusCode);
        exceptionMessage = (exceptionStatus != null)
                ? exceptionStatus.getReasonPhrase()
                : String.format("Exception has been thrown with Status Code : %s", exceptionStatusCode);
    }

    return Response.status(exceptionStatusCode)
            .entity(exceptionMessage)
            .type(MediaType.TEXT_PLAIN)
            .build();
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:19,代码来源:DataServiceExceptionMapper.java

示例15: approve

import javax.ws.rs.WebApplicationException; //导入依赖的package包/类
public NamespaceChangesStatus approve(String serviceName, NamespacedList namespacedList) {

        NamespaceChangesStatus namespaceChangesStatus = getNamespaceChangesStatus(serviceName);

        errorList = null;

        if (namespaceChangesStatus != null && namespaceChangesStatus.getNamespaceChanges() != null && namespacedList != null) {

            Map<NamespacedList, ActionType> removedNamespacesChangesMap = namespaceChangesStatus.getNamespaceChanges().entrySet().stream()
                    .filter(filterToSaveAlone(namespacedList))
                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

            namespaceChangesStatus.setNamespaceChanges(removedNamespacesChangesMap);
            save(serviceName, namespaceChangesStatus);
        }

        if (errorList != null) {
            throw new WebApplicationException(FAILED_TO_SAVE_NAMESPACE_DUE_TO_VALIDATION_ERROR,
                    Response.status(Response.Status.BAD_REQUEST).entity(new ErrorMessage(FAILED_TO_SAVE_NAMESPACE_DUE_TO_VALIDATION_ERROR)).build());
        }

        return namespaceChangesStatus;
    }
 
开发者ID:Comcast,项目名称:redirector,代码行数:24,代码来源:NamespacesChangesService.java


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