@Test public void shouldThrowWhenReceivingSoapFault() throws Exception { final String expectedMessage = "That was an invalid request, buddy!"; final String expectedErrorCode = X_INVALID_REQUEST; final CodedException generatedEx = new CodedException(expectedErrorCode, expectedMessage); mockServer.stubFor(WireMock.any(urlPathEqualTo(EXPECTED_WSDL_QUERY_PATH)) .willReturn(aResponse() .withBody(SoapFault.createFaultXml(generatedEx).getBytes(MimeUtils.UTF8)) .withHeader(HttpHeaders.CONTENT_TYPE, TEXT_XML_UTF8))); mockServer.start(); final SecurityServerId providedIdentifier = SecurityServerId.create(EXPECTED_XR_INSTANCE, "memberClassGov", "memberCode11", "serverCode_"); ServerConf.reload(new TestServerConf() { @Override public SecurityServerId getIdentifier() { return providedIdentifier; } }); final CentralServiceId expectedCentralServiceId = CentralServiceId.create(EXPECTED_XR_INSTANCE, "serviceCode3322"); when(mockRequest.getParameter(eq(WsdlRequestProcessor.PARAM_INSTANCE_IDENTIFIER))) .thenReturn(expectedCentralServiceId.getXRoadInstance()); when(mockRequest.getParameter(eq(WsdlRequestProcessor.PARAM_SERVICE_CODE))) .thenReturn(expectedCentralServiceId.getServiceCode()); WsdlRequestProcessor processorToTest = new WsdlRequestProcessor(mockRequest, mockResponse); thrown.expect(CodedException.class); thrown.expect(faultCodeEquals(expectedErrorCode)); thrown.expectMessage(allOf(containsString(expectedErrorCode), containsString(expectedMessage))); processorToTest.process(); }
void process() throws Exception { ClientId client = ServerConf.getIdentifier().getOwner(); ServiceId service = getServiceId(); log.trace("process({}, {})", client, service); SoapMessageImpl message = createMessage(client, service); if (log.isTraceEnabled()) { log.trace("message:\n{}", message.getXml()); } HttpURLConnection connection = createConnection(message); try (InputStream in = connection.getInputStream(); SoapDecoderCallback callback = new SoapDecoderCallback()) { SoapMessageDecoder decoder = new SoapMessageDecoder(connection.getContentType(), callback); decoder.parse(in); } }
WsdlRequestProcessor { void process() throws Exception { ClientId client = ServerConf.getIdentifier().getOwner(); ServiceId service = getServiceId(); log.trace("process({}, {})", client, service); SoapMessageImpl message = createMessage(client, service); if (log.isTraceEnabled()) { log.trace("message:\n{}", message.getXml()); } HttpURLConnection connection = createConnection(message); try (InputStream in = connection.getInputStream(); SoapDecoderCallback callback = new SoapDecoderCallback()) { SoapMessageDecoder decoder = new SoapMessageDecoder(connection.getContentType(), callback); decoder.parse(in); } } }
WsdlRequestProcessor { void process() throws Exception { ClientId client = ServerConf.getIdentifier().getOwner(); ServiceId service = getServiceId(); log.trace("process({}, {})", client, service); SoapMessageImpl message = createMessage(client, service); if (log.isTraceEnabled()) { log.trace("message:\n{}", message.getXml()); } HttpURLConnection connection = createConnection(message); try (InputStream in = connection.getInputStream(); SoapDecoderCallback callback = new SoapDecoderCallback()) { SoapMessageDecoder decoder = new SoapMessageDecoder(connection.getContentType(), callback); decoder.parse(in); } }  }
WsdlRequestProcessor { void process() throws Exception { ClientId client = ServerConf.getIdentifier().getOwner(); ServiceId service = getServiceId(); log.trace("process({}, {})", client, service); SoapMessageImpl message = createMessage(client, service); if (log.isTraceEnabled()) { log.trace("message:\n{}", message.getXml()); } HttpURLConnection connection = createConnection(message); try (InputStream in = connection.getInputStream(); SoapDecoderCallback callback = new SoapDecoderCallback()) { SoapMessageDecoder decoder = new SoapMessageDecoder(connection.getContentType(), callback); decoder.parse(in); } }   }
WsdlRequestProcessor { void process() throws Exception { ClientId client = ServerConf.getIdentifier().getOwner(); ServiceId service = getServiceId(); log.trace("process({}, {})", client, service); SoapMessageImpl message = createMessage(client, service); if (log.isTraceEnabled()) { log.trace("message:\n{}", message.getXml()); } HttpURLConnection connection = createConnection(message); try (InputStream in = connection.getInputStream(); SoapDecoderCallback callback = new SoapDecoderCallback()) { SoapMessageDecoder decoder = new SoapMessageDecoder(connection.getContentType(), callback); decoder.parse(in); } }   static final String PARAM_INSTANCE_IDENTIFIER; static final String PARAM_MEMBER_CLASS; static final String PARAM_MEMBER_CODE; static final String PARAM_SERVICE_CODE; }