Search in sources :

Example 1 with SoapResponse

use of uk.gov.ida.hub.samlsoapproxy.soap.SoapResponse in project verify-hub by alphagov.

the class HealthCheckSoapRequestClient method makeSoapRequestForHealthCheck.

public HealthCheckResponse makeSoapRequestForHealthCheck(Element requestElement, URI uri) {
    LOG.info(MessageFormat.format("Making SOAP request to: {0}", uri));
    SoapResponse response;
    try {
        response = makePost(uri, requestElement);
    } catch (ProcessingException e) {
        throw ApplicationException.createUnauditedException(ExceptionType.NETWORK_ERROR, UUID.randomUUID(), e);
    } catch (SOAPRequestError e) {
        throw ApplicationException.createUnauditedException(ExceptionType.REMOTE_SERVER_ERROR, UUID.randomUUID(), e);
    }
    return new HealthCheckResponse(response.getBody(), Optional.fromNullable(response.getHeaders().getFirst(MSA_VERSION_HTTP_HEADER)));
}
Also used : SoapResponse(uk.gov.ida.hub.samlsoapproxy.soap.SoapResponse) HealthCheckResponse(uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with SoapResponse

use of uk.gov.ida.hub.samlsoapproxy.soap.SoapResponse in project verify-hub by alphagov.

the class SoapRequestClient method makePost.

/**
 * Wrap the supplied element in a SOAP wrapper and post to the specified end-point
 *
 * @return Response from the remote server
 * @throws SOAPRequestError            if the remote server returns a non-200 status code
 * @throws ResponseProcessingException in case processing of a received HTTP response fails (e.g. in a filter
 *                                     or during conversion of the response entity data to an instance
 *                                     of a particular Java type).
 * @throws ProcessingException         in case the request processing or subsequent I/O operation fails.
 */
protected SoapResponse makePost(URI uri, Element requestElement) throws SOAPRequestError {
    LOG.info(format("Making SOAP request to: {0}", uri));
    Document requestDocument = soapMessageManager.wrapWithSoapEnvelope(requestElement);
    WebTarget target = client.target(uri);
    final Invocation.Builder request = target.request();
    final Response response = request.post(Entity.entity(requestDocument, MediaType.TEXT_XML_TYPE));
    try {
        if (response.getStatus() != 200) {
            LOG.warn(format("Unexpected status code ({0}) when contacting ({1}))", response.getStatus(), uri));
            // let the calling code handle this issue appropriately
            throw new SOAPRequestError(response);
        } else {
            try {
                return giveMeMySoap(response);
            } catch (BadRequestException e) {
                LOG.warn(format("Couldn't parse SOAP response when contacting ({0}))", uri), e);
                throw new SOAPRequestError(response, e);
            }
        }
    } finally {
        // (e.g. the response body is never read from).
        try {
            response.close();
        } catch (ProcessingException f) {
            LOG.warn("Problem closing Jersey connection.", f);
        }
    }
}
Also used : SoapResponse(uk.gov.ida.hub.samlsoapproxy.soap.SoapResponse) Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) BadRequestException(javax.ws.rs.BadRequestException) WebTarget(javax.ws.rs.client.WebTarget) Document(org.w3c.dom.Document) ProcessingException(javax.ws.rs.ProcessingException) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException)

Example 3 with SoapResponse

use of uk.gov.ida.hub.samlsoapproxy.soap.SoapResponse in project verify-hub by alphagov.

the class SoapRequestClient method giveMeMySoap.

private SoapResponse giveMeMySoap(Response response) {
    Document document = response.readEntity(Document.class);
    Element unwrappedSoap = soapMessageManager.unwrapSoapMessage(document);
    return new SoapResponse(unwrappedSoap, response.getStringHeaders());
}
Also used : SoapResponse(uk.gov.ida.hub.samlsoapproxy.soap.SoapResponse) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Aggregations

SoapResponse (uk.gov.ida.hub.samlsoapproxy.soap.SoapResponse)3 ProcessingException (javax.ws.rs.ProcessingException)2 Document (org.w3c.dom.Document)2 BadRequestException (javax.ws.rs.BadRequestException)1 Invocation (javax.ws.rs.client.Invocation)1 ResponseProcessingException (javax.ws.rs.client.ResponseProcessingException)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1 Element (org.w3c.dom.Element)1 HealthCheckResponse (uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse)1