use of ee.ria.xroad.common.message.Soap 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;
}
use of ee.ria.xroad.common.message.Soap 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);
}
}
use of ee.ria.xroad.common.message.Soap 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);
}
}
use of ee.ria.xroad.common.message.Soap in project X-Road by nordic-institute.
the class AsicContainerVerifier method getSigner.
private static ClientId getSigner(String messageXml) {
final byte[] messageBytes = messageXml.getBytes(UTF_8);
try {
Soap soap = new SaxSoapParserImpl().parse(MimeTypes.TEXT_XML_UTF8, new ByteArrayInputStream(messageBytes));
if (!(soap instanceof SoapMessageImpl)) {
throw new RuntimeException("Unexpected SOAP: " + soap.getClass());
}
SoapMessageImpl msg = (SoapMessageImpl) soap;
return msg.isRequest() ? msg.getClient() : msg.getService().getClientId();
} catch (CodedException ce) {
if (X_INVALID_SOAP.equals(ce.getFaultCode())) {
try {
final RestMessage restMessage = RestMessage.of(messageBytes);
return restMessage.getSender();
} catch (Exception e) {
throw new RuntimeException("Invalid message", e);
}
}
}
return null;
}
use of ee.ria.xroad.common.message.Soap in project X-Road by nordic-institute.
the class ProxyMessageDecoder method parseFault.
private void parseFault(InputStream is) throws Exception {
Soap soap = new SaxSoapParserImpl().parse(MimeTypes.TEXT_XML_UTF8, is);
if (!(soap instanceof SoapFault)) {
throw new CodedException(X_INVALID_MESSAGE, "Expected fault message, but got reqular SOAP message");
}
callback.fault((SoapFault) soap);
}
Aggregations