Search in sources :

Example 1 with HTTPException

use of javax.xml.ws.http.HTTPException in project Rubicon by Rubicon-Bot.

the class Bitly method shorten.

/**
 * Shortens a URL with bit.ly.
 *
 * @param longURL the URL to shorten.
 * @return the shortened URL.
 * @throws IllegalArgumentException if the long URI was invalid.
 * @throws HTTPException            if the bit.ly API returns a response code unlike 200 'OK'.
 * @throws RuntimeException         if the http request threw an unknown error.
 */
public static String shorten(String longURL) {
    HttpRequestBuilder request = new HttpRequestBuilder(API_URL, RequestType.GET);
    request.addParameter("access_token", Info.BITLY_TOKEN);
    request.addParameter("longUrl", longURL);
    request.addParameter("format", "json");
    RequestResponse result;
    try {
        result = request.sendRequest();
    } catch (Exception e) {
        // catch 'anonymous' exceptions
        throw new RuntimeException("An unknown exception occurred while fetching a bit.ly http request", e);
    }
    JSONObject response = new JSONObject(result.getResponseMessage());
    // check if uri was valid
    if (response.getString("status_txt").equals("INVALID_URI"))
        throw new IllegalArgumentException("'" + longURL + "' is not a valid URL.");
    else // ensure 'OK' status response
    if (response.getInt("status_code") == 400)
        throw new HTTPException(response.getInt("status_code"));
    // return shortened url
    return response.getJSONObject("data").getString("url");
}
Also used : HTTPException(javax.xml.ws.http.HTTPException) JSONObject(org.json.JSONObject) HttpRequestBuilder(de.foryasee.httprequest.HttpRequestBuilder) RequestResponse(de.foryasee.httprequest.RequestResponse) HTTPException(javax.xml.ws.http.HTTPException)

Example 2 with HTTPException

use of javax.xml.ws.http.HTTPException in project scout.rt by eclipse.

the class AuthenticationHandler method handleMessage.

@Override
@SuppressWarnings("squid:S1181")
public boolean handleMessage(final SOAPMessageContext messageContext) {
    if (MessageContexts.isOutboundMessage(messageContext)) {
        return true;
    }
    try {
        final HttpServletRequest servletRequest = Assertions.assertNotNull(m_implementorSpecifics.getServletRequest(messageContext), "ServletRequest must not be null");
        // Check whether the request was pre-authenticated, e.g. by application server or Servlet filter.
        final Subject preAuthSubject = BEANS.get(PreAuthenticationMethod.class).getRequestSubject(servletRequest, m_principalProducer);
        if (preAuthSubject != null) {
            MessageContexts.putRunContext(messageContext, m_runContextProducer.produce(preAuthSubject));
            return true;
        }
        // Authenticate the request.
        final Principal principal = authenticateRequest(messageContext);
        if (principal != null) {
            final Subject subject = BEANS.get(ServletFilterHelper.class).createSubject(principal);
            BEANS.get(ServletFilterHelper.class).putPrincipalOnSession(servletRequest, principal);
            MessageContexts.putRunContext(messageContext, m_runContextProducer.produce(subject));
            return true;
        }
        // Ensure HTTP status code to be set.
        final int httpStatusCode;
        final Integer currentHttpResponseCode = m_implementorSpecifics.getHttpResponseCode(messageContext);
        if (currentHttpResponseCode != null) {
            httpStatusCode = currentHttpResponseCode.intValue();
        } else {
            httpStatusCode = HttpServletResponse.SC_FORBIDDEN;
            m_implementorSpecifics.setHttpResponseCode(messageContext, httpStatusCode);
        }
        m_implementorSpecifics.interceptWebServiceRequestRejected(messageContext, httpStatusCode);
        return false;
    } catch (final WebServiceRequestRejectedException e) {
        // NOSONAR
        throw new HTTPException(e.getHttpStatusCode());
    } catch (final Throwable t) {
        m_implementorSpecifics.setHttpResponseCode(messageContext, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        // Log exception with information about the webservice request associated.
        BEANS.get(ExceptionHandler.class).handle(BEANS.get(PlatformExceptionTranslator.class).translate(t).withContextInfo("service", messageContext.get(SOAPMessageContext.WSDL_SERVICE)).withContextInfo("port", messageContext.get(SOAPMessageContext.WSDL_PORT)).withContextInfo("operation", messageContext.get(SOAPMessageContext.WSDL_OPERATION)));
        try {
            m_implementorSpecifics.interceptWebServiceRequestRejected(messageContext, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        } catch (final WebServiceRequestRejectedException e) {
            // SECURITY: Do not propagate cause to the caller.
            throw new HTTPException(e.getHttpStatusCode());
        }
        // SECURITY: Do not propagate cause to the caller.
        return false;
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HTTPException(javax.xml.ws.http.HTTPException) PreAuthenticationMethod(org.eclipse.scout.rt.server.jaxws.provider.auth.method.PreAuthenticationMethod) ServletFilterHelper(org.eclipse.scout.rt.server.commons.authentication.ServletFilterHelper) Subject(javax.security.auth.Subject) Principal(java.security.Principal)

Example 3 with HTTPException

use of javax.xml.ws.http.HTTPException in project hbase by apache.

the class RESTApiClusterManager method getJsonNodeFromURIGet.

// Execute GET against URI, returning a JsonNode object to be traversed.
private JsonNode getJsonNodeFromURIGet(URI uri) throws IOException {
    LOG.info("Executing GET against " + uri + "...");
    ClientResponse response = client.resource(uri).accept(MediaType.APPLICATION_JSON_TYPE).get(ClientResponse.class);
    int statusCode = response.getStatus();
    if (statusCode != Response.Status.OK.getStatusCode()) {
        throw new HTTPException(statusCode);
    }
    // This API folds information as the value to an "items" attribute.
    return new ObjectMapper().readTree(response.getEntity(String.class)).get("items");
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HTTPException(javax.xml.ws.http.HTTPException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 4 with HTTPException

use of javax.xml.ws.http.HTTPException in project cxf by apache.

the class DispatchImpl method mapException.

private RuntimeException mapException(Exception ex) {
    if (ex instanceof Fault && ex.getCause() instanceof IOException) {
        throw new WebServiceException(ex.getMessage(), ex.getCause());
    }
    if (getBinding() instanceof HTTPBinding) {
        HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
        exception.initCause(ex);
        return exception;
    } else if (getBinding() instanceof SOAPBinding) {
        SOAPFault soapFault = null;
        try {
            soapFault = JaxWsClientProxy.createSoapFault((SOAPBinding) getBinding(), ex);
        } catch (SOAPException e) {
        // ignore
        }
        if (soapFault == null) {
            return new WebServiceException(ex);
        }
        SOAPFaultException exception = new SOAPFaultException(soapFault);
        exception.initCause(ex);
        return exception;
    }
    return new WebServiceException(ex);
}
Also used : HTTPException(javax.xml.ws.http.HTTPException) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPBinding(javax.xml.ws.soap.SOAPBinding) SOAPFault(javax.xml.soap.SOAPFault) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IOException(java.io.IOException) HTTPBinding(javax.xml.ws.http.HTTPBinding)

Example 5 with HTTPException

use of javax.xml.ws.http.HTTPException in project cxf by apache.

the class JaxWsClientProxy method mapException.

Exception mapException(Method method, BindingOperationInfo boi, Exception ex) {
    if (method != null) {
        for (Class<?> excls : method.getExceptionTypes()) {
            if (excls.isInstance(ex)) {
                return ex;
            }
        }
    } else if (boi != null) {
        for (BindingFaultInfo fi : boi.getFaults()) {
            Class<?> c = fi.getFaultInfo().getProperty(Class.class.getName(), Class.class);
            if (c != null && c.isInstance(ex)) {
                return ex;
            }
        }
        if (ex instanceof IOException) {
            return ex;
        }
    }
    if (ex instanceof Fault && ex.getCause() instanceof IOException) {
        return new WebServiceException(ex.getMessage(), ex.getCause());
    }
    if (getBinding() instanceof HTTPBinding) {
        HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
        exception.initCause(ex);
        return exception;
    } else if (getBinding() instanceof SOAPBinding) {
        try {
            SOAPFault soapFault = createSoapFault((SOAPBinding) getBinding(), ex);
            if (soapFault == null) {
                throw new WebServiceException(ex);
            }
            SOAPFaultException exception = new SOAPFaultException(soapFault);
            if (ex instanceof Fault && ex.getCause() != null) {
                exception.initCause(ex.getCause());
            } else {
                exception.initCause(ex);
            }
            return exception;
        } catch (SOAPException e) {
            return new WebServiceException(ex);
        }
    }
    return new WebServiceException(ex);
}
Also used : HTTPException(javax.xml.ws.http.HTTPException) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPBinding(javax.xml.ws.soap.SOAPBinding) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault) SoapFault(org.apache.cxf.binding.soap.SoapFault) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IOException(java.io.IOException) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) HTTPBinding(javax.xml.ws.http.HTTPBinding)

Aggregations

HTTPException (javax.xml.ws.http.HTTPException)7 IOException (java.io.IOException)2 SOAPException (javax.xml.soap.SOAPException)2 SOAPFault (javax.xml.soap.SOAPFault)2 WebServiceException (javax.xml.ws.WebServiceException)2 HTTPBinding (javax.xml.ws.http.HTTPBinding)2 SOAPBinding (javax.xml.ws.soap.SOAPBinding)2 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 Fault (org.apache.cxf.interceptor.Fault)2 Response (org.apache.hbase.thirdparty.javax.ws.rs.core.Response)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 HttpRequestBuilder (de.foryasee.httprequest.HttpRequestBuilder)1 RequestResponse (de.foryasee.httprequest.RequestResponse)1 URI (java.net.URI)1 Principal (java.security.Principal)1 Subject (javax.security.auth.Subject)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SoapFault (org.apache.cxf.binding.soap.SoapFault)1 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)1 Invocation (org.apache.hbase.thirdparty.javax.ws.rs.client.Invocation)1