use of ee.ria.xroad.common.message.SoapParserImpl in project X-Road by nordic-institute.
the class SplitHeaderMessage method validateFieldValue.
@SuppressWarnings("unchecked")
private static void validateFieldValue(Message message) throws Exception {
SoapMessageImpl msg = (SoapMessageImpl) new SoapParserImpl().parse(message.getContentType(), new ByteArrayInputStream(((SoapMessageImpl) message.getSoap()).getBytes()));
String value = null;
Iterator<SOAPHeaderElement> h = msg.getSoap().getSOAPHeader().examineAllHeaderElements();
while (h.hasNext()) {
SOAPHeaderElement header = h.next();
if (header.getElementName().getLocalName().equals("issue")) {
value = header.getValue();
}
}
if (!StringUtils.equals(EXPECTED_VALUE, value)) {
String diff = StringUtils.difference(EXPECTED_VALUE, value);
throw new Exception("Unexpected field value (difference starting at" + " index : " + value.indexOf(diff) + ")");
}
}
use of ee.ria.xroad.common.message.SoapParserImpl 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.SoapParserImpl 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.SoapParserImpl in project X-Road by nordic-institute.
the class CommentMessage method validateNormalResponse.
@Override
protected void validateNormalResponse(Message receivedResponse) throws Exception {
SoapMessageImpl msg = (SoapMessageImpl) new SoapParserImpl().parse(receivedResponse.getContentType(), new ByteArrayInputStream(((SoapMessageImpl) receivedResponse.getSoap()).getBytes()));
Node firstChild = msg.getSoap().getSOAPHeader().getFirstChild().getNextSibling();
short nodeType = firstChild.getNodeType();
if (nodeType != Node.COMMENT_NODE) {
throw new Exception("Expected comment not found!");
}
if (!firstChild.getTextContent().equals(EXPECTED_COMMENT)) {
throw new Exception("Comment '" + firstChild.getTextContent() + "' did not match expected value");
}
}
use of ee.ria.xroad.common.message.SoapParserImpl in project X-Road by nordic-institute.
the class QueryRequestHandlerTest method handleHealthDataRequest.
/**
* Ensure that an health data response data is filtered and body is
* constructed correctly.
*/
@Test
public void handleHealthDataRequest() throws Exception {
InputStream is = new FileInputStream(HEALTH_DATA_REQUEST);
SoapParser parser = new SoapParserImpl();
SoapMessageImpl request = (SoapMessageImpl) parser.parse(MimeTypes.TEXT_XML_UTF8, is);
QueryRequestHandler handler = new HealthDataRequestHandler(new TestMetricsRegistry());
OutputStream out = new ByteArrayOutputStream();
handler.handle(request, out, ct -> testContentType = ct);
String baseContentType = MimeUtils.getBaseContentType(testContentType);
assertEquals(MimeTypes.TEXT_XML, baseContentType);
SoapMessageImpl response = (SoapMessageImpl) parser.parse(MimeTypes.TEXT_XML, IOUtils.toInputStream(out.toString()));
GetSecurityServerHealthDataResponseType responseData = JaxbUtils.createUnmarshaller(GetSecurityServerHealthDataResponseType.class).unmarshal(SoapUtils.getFirstChild(response.getSoap().getSOAPBody()), GetSecurityServerHealthDataResponseType.class).getValue();
assertEquals(TEST_TIMESTAMP, responseData.getMonitoringStartupTimestamp());
assertEquals(2, responseData.getServicesEvents().getServiceEvents().size());
assertEquals(ServiceId.create("XTEE-CI-XM", "GOV", "00000001", "System1", "xroad/GetRandom", "v2"), responseData.getServicesEvents().getServiceEvents().get(0).getService());
assertEquals(5, responseData.getServicesEvents().getServiceEvents().get(0).getLastPeriodStatistics().getSuccessfulRequestCount());
assertEquals(5, responseData.getServicesEvents().getServiceEvents().get(0).getLastPeriodStatistics().getUnsuccessfulRequestCount());
}
Aggregations