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;
}
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);
}
}
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);
}
}
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());
}
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());
}
Aggregations