use of ee.ria.xroad.common.message.SoapMessageDecoder in project X-Road by nordic-institute.
the class ManagementRequestHandler method readRequest.
/**
* Reads management requests from input stream.
*
* @param contentType expected content type of the stream
* @param inputStream the input stream
* @param clientRegRequestStatusWrapper helper for processing clientRegRequests
* @return management request SOAP message
* @throws Exception in case of any errors
*/
public static SoapMessageImpl readRequest(String contentType, InputStream inputStream, ClientRegRequestStatusWrapper clientRegRequestStatusWrapper) throws Exception {
log.info("readRequest(contentType={})", contentType);
DecoderCallback cb = new DecoderCallback();
SoapMessageDecoder decoder = new SoapMessageDecoder(contentType, cb);
decoder.parse(inputStream);
clientRegRequestStatusWrapper.setClientRegRequestSignedAndVerified(cb.getClientRegRequestSignedAndVerified());
return cb.getSoapMessage();
}
use of ee.ria.xroad.common.message.SoapMessageDecoder in project X-Road by nordic-institute.
the class QueryRequestProcessor method process.
/**
* Processes the incoming message.
* @throws Exception in case of any errors
*/
void process() throws Exception {
try (QueryRequestHandler handler = new QueryRequestHandler()) {
SoapMessageDecoder soapMessageDecoder = new SoapMessageDecoder(servletRequest.getContentType(), handler, new SoapParserImpl());
soapMessageDecoder.parse(servletRequest.getInputStream());
}
}
use of ee.ria.xroad.common.message.SoapMessageDecoder in project X-Road by nordic-institute.
the class ServerMessageProcessor method parseResponse.
private void parseResponse(ServiceHandler handler) throws Exception {
log.trace("parseResponse()");
preprocess();
// Preserve the original content type of the service response
servletResponse.addHeader(HEADER_ORIGINAL_CONTENT_TYPE, handler.getResponseContentType());
try (SoapMessageHandler messageHandler = new SoapMessageHandler()) {
SoapMessageDecoder soapMessageDecoder = new SoapMessageDecoder(handler.getResponseContentType(), messageHandler, new ResponseSoapParserImpl());
soapMessageDecoder.parse(handler.getResponseContent());
} catch (Exception ex) {
throw translateException(ex).withPrefix(X_SERVICE_FAILED_X);
}
// to the client.
if (responseFault != null) {
throw responseFault.toCodedException();
}
// from server?), it is an error instead.
if (responseSoap == null) {
throw new CodedException(X_INVALID_MESSAGE, "No response message received from service").withPrefix(X_SERVICE_FAILED_X);
}
updateOpMonitoringDataByResponse();
}
use of ee.ria.xroad.common.message.SoapMessageDecoder in project X-Road by nordic-institute.
the class ClientMessageProcessor method handleSoap.
public void handleSoap() {
try (SoapMessageHandler handler = new SoapMessageHandler()) {
SoapMessageDecoder soapMessageDecoder = new SoapMessageDecoder(servletRequest.getContentType(), handler, new RequestSoapParserImpl());
try {
originalSoapAction = validateSoapActionHeader(servletRequest.getHeader("SOAPAction"));
soapMessageDecoder.parse(servletRequest.getInputStream());
} catch (Exception ex) {
throw new ClientException(translateException(ex));
}
} catch (Throwable ex) {
setError(ex);
} finally {
continueProcessing();
continueReadingResponse();
}
}
use of ee.ria.xroad.common.message.SoapMessageDecoder in project X-Road by nordic-institute.
the class QueryRequestHandlerTest method handleOperationalDataRequest.
/**
* Ensure that an operational data response contains the required attachment
* that is correctly referenced from within the SOAP body.
*/
@Test
public void handleOperationalDataRequest() throws Exception {
InputStream is = new FileInputStream(OPERATIONAL_DATA_REQUEST);
SoapParser parser = new SoapParserImpl();
SoapMessageImpl request = (SoapMessageImpl) parser.parse(MimeTypes.TEXT_XML_UTF8, is);
QueryRequestHandler handler = new OperationalDataRequestHandler() {
@Override
protected OperationalDataRecords getOperationalDataRecords(ClientId filterByClient, long recordsFrom, long recordsTo, ClientId filterByServiceProvider, Set<String> outputFields) {
return new OperationalDataRecords(Collections.emptyList());
}
@Override
protected ClientId getClientForFilter(ClientId clientId, SecurityServerId serverId) throws Exception {
return null;
}
};
OutputStream out = new ByteArrayOutputStream();
handler.handle(request, out, ct -> testContentType = ct);
String baseContentType = MimeUtils.getBaseContentType(testContentType);
assertEquals(MimeTypes.MULTIPART_RELATED, baseContentType);
SoapMessageDecoder decoder = new SoapMessageDecoder(testContentType, new SoapMessageDecoder.Callback() {
@Override
public void soap(SoapMessage message, Map<String, String> headers) throws Exception {
assertEquals("cid:" + OperationalDataRequestHandler.CID, findRecordsContentId(message));
}
@Override
public void attachment(String contentType, InputStream content, Map<String, String> additionalHeaders) throws Exception {
String expectedCid = "<" + OperationalDataRequestHandler.CID + ">";
assertEquals(expectedCid, additionalHeaders.get("content-id"));
}
@Override
public void onCompleted() {
// Do nothing.
}
@Override
public void onError(Exception t) throws Exception {
throw t;
}
@Override
public void fault(SoapFault fault) throws Exception {
throw fault.toCodedException();
}
});
decoder.parse(IOUtils.toInputStream(out.toString()));
}
Aggregations