Package javax.ws.rs

Examples of javax.ws.rs.WebApplicationException


   */
  public static void assertNotConflicted(Optional obj, String fieldName) {
    assertNotNull(obj, fieldName);
    if (obj.isPresent()) {
      log.warn("Field '{}' should be absent to avoid conflict", fieldName);
      throw new WebApplicationException(Response.Status.CONFLICT);
    }
  }
View Full Code Here


   * @param condition The condition message
   */
  public static void assertTrue(boolean state, String condition) {
    if (!state) {
      log.warn("Condition '{}' should be true", condition);
      throw new WebApplicationException(Response.Status.BAD_REQUEST);
    }
  }
View Full Code Here

    return defaultResponse;

  }

  private Response handleWebApplicationException(RuntimeException exception, Response defaultResponse) {
    WebApplicationException webAppException = (WebApplicationException) exception;

    // No logging
    if (webAppException.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) {
      return Response
        .status(Response.Status.UNAUTHORIZED)
        .entity(publicErrorResource.view401())
        .build();
    }
    if (webAppException.getResponse().getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {
      return Response
        .status(Response.Status.NOT_FOUND)
        .entity(publicErrorResource.view404())
        .build();
    }
View Full Code Here

      // Get the data
      FieldAccessor<F> fir = JAXB.unmarshal(inputStream, featureInfoResponse);

      return fir.getFields();
    } catch (MalformedURLException e) {
      throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
    } catch (IOException e) {
      throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    } finally {
      if (connection != null) {
        connection.disconnect();
      }
    }
View Full Code Here

      // Get the data
      return JAXB.unmarshal(inputStream, returnType);

    } catch (MalformedURLException e) {
      throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
    } catch (IOException e) {
      throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    } finally {
      if (connection != null) {
        connection.disconnect();
      }
    }
View Full Code Here

    try {

      // Get the Authorization header
      final Map<String,Cookie> cookieMap = httpContext.getRequest().getCookies();
      if (!cookieMap.containsKey(SiteConfiguration.SESSION_TOKEN_NAME)) {
        throw new WebApplicationException(Response.Status.UNAUTHORIZED);
      }

      UUID sessionToken = UUID.fromString(cookieMap.get(SiteConfiguration.SESSION_TOKEN_NAME).getValue());

      if (sessionToken != null) {

        final OpenIDCredentials credentials = new OpenIDCredentials(sessionToken, requiredAuthorities);

        final Optional<User> result = authenticator.authenticate(credentials);
        if (result.isPresent()) {
          return result.get();
        }
      }
    } catch (IllegalArgumentException e) {
      log.warn("Error decoding credentials",e);
    } catch (AuthenticationException e) {
      log.warn("Error authenticating credentials",e);
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }

    // Must have failed to be here
    throw new WebApplicationException(Response.Status.UNAUTHORIZED);
  }
View Full Code Here

            final Response.ResponseBuilder responseBuilder = Response.status(HttpServletResponse.SC_FOUND);

            String redirectUri = e.getRedirectUri();

            if (OAuthUtils.isEmpty(redirectUri)) {
                throw new WebApplicationException(
                    responseBuilder.entity("OAuth callback url needs to be provided by client!!!").build());
            }
            final OAuthResponse response = OAuthASResponse.errorResponse(HttpServletResponse.SC_FOUND)
                .error(e)
                .location(redirectUri).buildQueryMessage();
View Full Code Here

      return commitData;
    } catch (ParseException e) {
      ExceptionUtils.throwError(e);
      return null;
    } catch (IOException e) {
      throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    } catch (SAXException e) {
      throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    }
  }
View Full Code Here

      }
    }
  }

  public static void throwError(String errorText) throws WebApplicationException {
    throw new WebApplicationException(Response.status(Status.OK).entity("{error: \"" + errorText + "\"}").build());
  }
View Full Code Here

  public static void throwError(String errorText) throws WebApplicationException {
    throw new WebApplicationException(Response.status(Status.OK).entity("{error: \"" + errorText + "\"}").build());
  }
 
  public static void throwError(Exception e) throws WebApplicationException {
    throw new WebApplicationException(e, Status.OK);
  }
View Full Code Here

TOP

Related Classes of javax.ws.rs.WebApplicationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.