Search in sources :

Example 1 with SoapFault

use of ee.ria.xroad.common.message.SoapFault in project X-Road by nordic-institute.

the class ManagementRequestSender method getResponse.

private static SoapMessageImpl getResponse(HttpSender sender, String expectedContentType) throws Exception {
    String baseContentType = getBaseContentType(sender.getResponseContentType());
    if (baseContentType == null || !baseContentType.equalsIgnoreCase(expectedContentType)) {
        throw new CodedException(X_HTTP_ERROR, "Unexpected or no content type (%s) in response", baseContentType);
    }
    Soap response = new SoapParserImpl().parse(baseContentType, sender.getResponseContent());
    if (response instanceof SoapFault) {
        // Server responded with fault
        throw ((SoapFault) response).toCodedException();
    }
    if (!(response instanceof SoapMessageImpl)) {
        throw new CodedException(X_INTERNAL_ERROR, "Got unexpected response message " + response);
    }
    SoapMessageImpl responseMessage = (SoapMessageImpl) response;
    if (!responseMessage.isResponse()) {
        throw new CodedException(X_INTERNAL_ERROR, "Expected response message");
    }
    return responseMessage;
}
Also used : SoapFault(ee.ria.xroad.common.message.SoapFault) CodedException(ee.ria.xroad.common.CodedException) SoapParserImpl(ee.ria.xroad.common.message.SoapParserImpl) SoapMessageImpl(ee.ria.xroad.common.message.SoapMessageImpl) Soap(ee.ria.xroad.common.message.Soap)

Example 2 with SoapFault

use of ee.ria.xroad.common.message.SoapFault in project X-Road by nordic-institute.

the class ProxyMessageDecoder method handleSignature.

private void handleSignature(BodyDescriptor bd, InputStream is) throws CodedException {
    try {
        LOG.trace("Looking for signature, got '{}'", bd.getMimeType());
        switch(bd.getMimeType() == null ? "" : bd.getMimeType().toLowerCase()) {
            case SIGNATURE_BDOC:
                // We got signature, just as expected.
                signature = new SignatureData(IOUtils.toString(is, UTF_8), signature.getHashChainResult(), signature.getHashChain());
                callback.signature(signature);
                break;
            case TEXT_XML:
                LOG.debug("Got fault instead of signature");
                // It seems that signing failed and the other
                // party sent SOAP fault instead of signature.
                // Parse the fault message.
                Soap soap = new SaxSoapParserImpl().parse(bd.getMimeType(), is);
                if (soap instanceof SoapFault) {
                    callback.fault((SoapFault) soap);
                    // The nextPart will be set to NONE
                    return;
                }
            // $FALL-THROUGH$ If not fault message, fall through to invalid message case.
            default:
                // the parsing is not interrupted.
                throw new CodedException(X_INVALID_CONTENT_TYPE, "Received invalid content type instead of signature: %s", bd.getMimeType());
        }
    } catch (Exception e) {
        throw translateException(e);
    }
}
Also used : SignatureData(ee.ria.xroad.common.signature.SignatureData) SoapFault(ee.ria.xroad.common.message.SoapFault) CodedException(ee.ria.xroad.common.CodedException) SaxSoapParserImpl(ee.ria.xroad.common.message.SaxSoapParserImpl) Soap(ee.ria.xroad.common.message.Soap) MimeException(org.apache.james.mime4j.MimeException) ErrorCodes.translateException(ee.ria.xroad.common.ErrorCodes.translateException) IOException(java.io.IOException) CodedException(ee.ria.xroad.common.CodedException)

Example 3 with SoapFault

use of ee.ria.xroad.common.message.SoapFault in project X-Road by nordic-institute.

the class ProxyMessageDecoder method handleSoap.

private void handleSoap(BodyDescriptor bd, InputStream is, String partContentType, Map<String, String> soapPartHeaders) {
    try {
        LOG.trace("Looking for SOAP, got: {}, {}", bd.getMimeType(), bd.getCharset());
        switch(bd.getMimeType().toLowerCase()) {
            case TEXT_XML:
            case XOP_XML:
                break;
            default:
                throw new CodedException(X_INVALID_CONTENT_TYPE, "Invalid content type for SOAP message: %s", bd.getMimeType());
        }
        Soap soap = new SaxSoapParserImpl().parse(partContentType, is);
        if (soap instanceof SoapFault) {
            callback.fault((SoapFault) soap);
        } else {
            callback.soap((SoapMessageImpl) soap, soapPartHeaders);
            verifier.addMessagePart(getHashAlgoId(), (SoapMessageImpl) soap);
        }
    } catch (Exception ex) {
        throw translateException(ex);
    }
}
Also used : SoapFault(ee.ria.xroad.common.message.SoapFault) CodedException(ee.ria.xroad.common.CodedException) SaxSoapParserImpl(ee.ria.xroad.common.message.SaxSoapParserImpl) Soap(ee.ria.xroad.common.message.Soap) MimeException(org.apache.james.mime4j.MimeException) ErrorCodes.translateException(ee.ria.xroad.common.ErrorCodes.translateException) IOException(java.io.IOException) CodedException(ee.ria.xroad.common.CodedException)

Example 4 with SoapFault

use of ee.ria.xroad.common.message.SoapFault in project X-Road by nordic-institute.

the class ProxyMessageEncoderTest method faultMessage.

/**
 * Test to ensure a SOAP fault message is encoded correctly.
 * @throws Exception in case of any unexpected errors
 */
@Test
public void faultMessage() throws Exception {
    SoapFault fault = createFault(getQuery("fault.query"));
    encoder.fault(fault);
    encoder.close();
    ProxyMessage proxyMessage = decode();
    // assert the required parts are there
    assertNotNull(proxyMessage.getFault());
}
Also used : SoapFault(ee.ria.xroad.common.message.SoapFault) Test(org.junit.Test)

Example 5 with SoapFault

use of ee.ria.xroad.common.message.SoapFault in project X-Road by nordic-institute.

the class ProxyMessageEncoderTest method normalMessageWithFaultInsteadOfSignature.

/**
 * Test to ensure a normal message with fault instead of signature is encoded correctly.
 * @throws Exception in case of any unexpected errors
 */
@Test
public void normalMessageWithFaultInsteadOfSignature() throws Exception {
    SoapMessageImpl message = createMessage(getQuery("getstate.query"));
    SoapFault fault = createFault(getQuery("fault.query"));
    encoder.soap(message, new HashMap<>());
    encoder.fault(fault);
    encoder.close();
    ProxyMessage proxyMessage = decode();
    // assert the required parts are there
    assertNotNull(proxyMessage.getSoap());
    assertNotNull(proxyMessage.getFault());
}
Also used : SoapFault(ee.ria.xroad.common.message.SoapFault) SoapMessageImpl(ee.ria.xroad.common.message.SoapMessageImpl) Test(org.junit.Test)

Aggregations

SoapFault (ee.ria.xroad.common.message.SoapFault)9 CodedException (ee.ria.xroad.common.CodedException)4 Soap (ee.ria.xroad.common.message.Soap)4 SaxSoapParserImpl (ee.ria.xroad.common.message.SaxSoapParserImpl)3 SoapMessageImpl (ee.ria.xroad.common.message.SoapMessageImpl)3 Test (org.junit.Test)3 ErrorCodes.translateException (ee.ria.xroad.common.ErrorCodes.translateException)2 SoapParserImpl (ee.ria.xroad.common.message.SoapParserImpl)2 IOException (java.io.IOException)2 MimeException (org.apache.james.mime4j.MimeException)2 ClientId (ee.ria.xroad.common.identifier.ClientId)1 SecurityServerId (ee.ria.xroad.common.identifier.SecurityServerId)1 SoapMessage (ee.ria.xroad.common.message.SoapMessage)1 SoapMessageDecoder (ee.ria.xroad.common.message.SoapMessageDecoder)1 SoapParser (ee.ria.xroad.common.message.SoapParser)1 SignatureData (ee.ria.xroad.common.signature.SignatureData)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1