Search in sources :

Example 66 with CodedException

use of ee.ria.xroad.common.CodedException 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 67 with CodedException

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

the class ProxyMessageDecoder method parse.

/**
 * Attempts to decode the proxy SOAP message from the given input stream.
 *
 * @param is input stream from which to decode the message
 * @throws Exception if the stream content type does not match the expected one
 */
public void parse(InputStream is) throws Exception {
    LOG.trace("parse()");
    String baseContentType = HttpFields.valueParameters(contentType, null);
    if (faultAllowed && baseContentType.equalsIgnoreCase(TEXT_XML)) {
        parseFault(is);
    } else if (baseContentType.equalsIgnoreCase(MULTIPART_MIXED)) {
        parseMultipart(is);
    } else {
        throw new CodedException(X_INVALID_CONTENT_TYPE, "Invalid content type: %s", baseContentType);
    }
}
Also used : CodedException(ee.ria.xroad.common.CodedException)

Example 68 with CodedException

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

the class CustomSSLSocketFactory method connectSocket.

@Override
public Socket connectSocket(int timeout, Socket socket, HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpContext context) throws IOException {
    Socket connected = super.connectSocket(timeout, socket, host, remoteAddress, localAddress, context);
    try {
        if (!(connected instanceof SSLSocket)) {
            throw new Exception("Failed to create SSL socket");
        }
        X509Certificate cert = getPeerCertificate((SSLSocket) connected);
        log.trace("Peer certificate: {}", cert);
        checkServerTrusted(getServiceId(context), cert);
    } catch (Exception e) {
        IOUtils.closeQuietly(connected);
        throw new CodedException(X_SSL_AUTH_FAILED, e);
    }
    return connected;
}
Also used : CodedException(ee.ria.xroad.common.CodedException) SSLSocket(javax.net.ssl.SSLSocket) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket) IOException(java.io.IOException) CodedException(ee.ria.xroad.common.CodedException) X509Certificate(java.security.cert.X509Certificate)

Example 69 with CodedException

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

the class ServerMessageProcessor method verifyClientStatus.

private void verifyClientStatus() {
    ClientId client = requestServiceId.getClientId();
    String status = ServerConf.getMemberStatus(client);
    if (!ClientType.STATUS_REGISTERED.equals(status)) {
        throw new CodedException(X_UNKNOWN_MEMBER, "Client '%s' not found", client);
    }
}
Also used : CodedException(ee.ria.xroad.common.CodedException) ClientId(ee.ria.xroad.common.identifier.ClientId)

Example 70 with CodedException

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

the class ServerMessageProcessor method handleException.

private void handleException(Exception ex) throws Exception {
    if (encoder != null) {
        CodedException exception;
        if (ex instanceof CodedException.Fault) {
            exception = (CodedException.Fault) ex;
        } else {
            exception = translateWithPrefix(SERVER_SERVERPROXY_X, ex);
        }
        monitorAgentNotifyFailure(exception);
        opMonitoringData.setFaultCodeAndString(exception);
        opMonitoringData.setResponseOutTs(getEpochMillisecond(), false);
        encoder.fault(SoapFault.createFaultXml(exception));
        encoder.close();
    } else {
        throw ex;
    }
}
Also used : CodedException(ee.ria.xroad.common.CodedException) SoapFault(ee.ria.xroad.common.message.SoapFault)

Aggregations

CodedException (ee.ria.xroad.common.CodedException)131 X509Certificate (java.security.cert.X509Certificate)28 IOException (java.io.IOException)17 ErrorCodes.translateException (ee.ria.xroad.common.ErrorCodes.translateException)15 SignerNotReachableException (org.niis.xroad.restapi.service.SignerNotReachableException)14 TokenInfo (ee.ria.xroad.signer.protocol.dto.TokenInfo)12 OCSPResp (org.bouncycastle.cert.ocsp.OCSPResp)11 ServiceException (org.niis.xroad.restapi.service.ServiceException)11 ClientId (ee.ria.xroad.common.identifier.ClientId)10 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 KeyInfo (ee.ria.xroad.signer.protocol.dto.KeyInfo)8 InputStream (java.io.InputStream)8 URISyntaxException (java.net.URISyntaxException)7 Date (java.util.Date)7 SoapFault (ee.ria.xroad.common.message.SoapFault)6 ServiceId (ee.ria.xroad.common.identifier.ServiceId)5 Soap (ee.ria.xroad.common.message.Soap)5 SoapMessageImpl (ee.ria.xroad.common.message.SoapMessageImpl)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5