Search in sources :

Example 1 with SoapParser

use of ee.ria.xroad.common.message.SoapParser 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)

Example 2 with SoapParser

use of ee.ria.xroad.common.message.SoapParser 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()));
}
Also used : SoapFault(ee.ria.xroad.common.message.SoapFault) Set(java.util.Set) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SoapParserImpl(ee.ria.xroad.common.message.SoapParserImpl) SecurityServerId(ee.ria.xroad.common.identifier.SecurityServerId) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SoapMessageDecoder(ee.ria.xroad.common.message.SoapMessageDecoder) FileInputStream(java.io.FileInputStream) SoapMessage(ee.ria.xroad.common.message.SoapMessage) SoapMessageImpl(ee.ria.xroad.common.message.SoapMessageImpl) ClientId(ee.ria.xroad.common.identifier.ClientId) SoapParser(ee.ria.xroad.common.message.SoapParser) Test(org.junit.Test)

Aggregations

SoapMessageImpl (ee.ria.xroad.common.message.SoapMessageImpl)2 SoapParser (ee.ria.xroad.common.message.SoapParser)2 SoapParserImpl (ee.ria.xroad.common.message.SoapParserImpl)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 ClientId (ee.ria.xroad.common.identifier.ClientId)1 SecurityServerId (ee.ria.xroad.common.identifier.SecurityServerId)1 SoapFault (ee.ria.xroad.common.message.SoapFault)1 SoapMessage (ee.ria.xroad.common.message.SoapMessage)1 SoapMessageDecoder (ee.ria.xroad.common.message.SoapMessageDecoder)1 GetSecurityServerHealthDataResponseType (ee.ria.xroad.opmonitordaemon.message.GetSecurityServerHealthDataResponseType)1 Set (java.util.Set)1