Search in sources :

Example 1 with SoapParserImpl

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) + ")");
    }
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) ByteArrayInputStream(java.io.ByteArrayInputStream) SoapParserImpl(ee.ria.xroad.common.message.SoapParserImpl) SoapMessageImpl(ee.ria.xroad.common.message.SoapMessageImpl)

Example 2 with SoapParserImpl

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;
}
Also used : SoapFault(ee.ria.xroad.common.message.SoapFault) CodedException(ee.ria.xroad.common.CodedException) SoapParserImpl(ee.ria.xroad.common.message.SoapParserImpl) SoapMessageImpl(ee.ria.xroad.common.message.SoapMessageImpl) Soap(ee.ria.xroad.common.message.Soap)

Example 3 with SoapParserImpl

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());
    }
}
Also used : SoapParserImpl(ee.ria.xroad.common.message.SoapParserImpl) SoapMessageDecoder(ee.ria.xroad.common.message.SoapMessageDecoder)

Example 4 with SoapParserImpl

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");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SoapParserImpl(ee.ria.xroad.common.message.SoapParserImpl) Node(org.w3c.dom.Node) SoapMessageImpl(ee.ria.xroad.common.message.SoapMessageImpl)

Example 5 with SoapParserImpl

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());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SoapParserImpl(ee.ria.xroad.common.message.SoapParserImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) SoapMessageImpl(ee.ria.xroad.common.message.SoapMessageImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SoapParser(ee.ria.xroad.common.message.SoapParser) FileInputStream(java.io.FileInputStream) GetSecurityServerHealthDataResponseType(ee.ria.xroad.opmonitordaemon.message.GetSecurityServerHealthDataResponseType) Test(org.junit.Test)

Aggregations

SoapParserImpl (ee.ria.xroad.common.message.SoapParserImpl)6 SoapMessageImpl (ee.ria.xroad.common.message.SoapMessageImpl)5 SoapFault (ee.ria.xroad.common.message.SoapFault)2 SoapMessageDecoder (ee.ria.xroad.common.message.SoapMessageDecoder)2 SoapParser (ee.ria.xroad.common.message.SoapParser)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Test (org.junit.Test)2 CodedException (ee.ria.xroad.common.CodedException)1 ClientId (ee.ria.xroad.common.identifier.ClientId)1 SecurityServerId (ee.ria.xroad.common.identifier.SecurityServerId)1 Soap (ee.ria.xroad.common.message.Soap)1 SoapMessage (ee.ria.xroad.common.message.SoapMessage)1 GetSecurityServerHealthDataResponseType (ee.ria.xroad.opmonitordaemon.message.GetSecurityServerHealthDataResponseType)1 Set (java.util.Set)1 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)1 Node (org.w3c.dom.Node)1