@Test public void shouldCreateConnection() throws Exception { SoapMessageImpl mockSoapMessage = mock(SoapMessageImpl.class); mockServer.stubFor(WireMock.any(urlPathEqualTo(EXPECTED_WSDL_QUERY_PATH)) .willReturn(aResponse())); mockServer.start(); final String expectedMessage = "expectedMessage135122"; when(mockSoapMessage.getBytes()).thenReturn(expectedMessage.getBytes()); WsdlRequestProcessor processorToTest = new WsdlRequestProcessor(mockRequest, mockResponse); processorToTest.createConnection(mockSoapMessage); mockServer.verify(postRequestedFor(urlEqualTo(EXPECTED_WSDL_QUERY_PATH)) .withHeader(HttpHeaders.CONTENT_TYPE, equalTo(TEXT_XML_UTF8)) .withRequestBody(equalTo(expectedMessage))); }
HttpURLConnection createConnection(SoapMessageImpl message) throws Exception { final HttpURLConnection urlConnection; if (request.isSecure()) { HttpsURLConnection tmp = (HttpsURLConnection) new URL(PROXY_LOCAL_HTTPS_ENDPOINT).openConnection(); tmp.setSSLSocketFactory(InternalSslSocketFactory.getInstance()); tmp.setHostnameVerifier(NoopHostnameVerifier.INSTANCE); urlConnection = tmp; } else { urlConnection = (HttpURLConnection) new URL(PROXY_LOCAL_HTTP_ENDPOINT).openConnection(); } urlConnection.setDoInput(true); urlConnection.setDoOutput(true); urlConnection.setConnectTimeout(SystemProperties.getClientProxyTimeout()); urlConnection.setReadTimeout(SystemProperties.getClientProxyHttpClientTimeout()); urlConnection.setRequestMethod("POST"); urlConnection.setRequestProperty( HttpHeaders.CONTENT_TYPE, MimeUtils.contentTypeWithCharset(MimeTypes.TEXT_XML, StandardCharsets.UTF_8.name())); IOUtils.write(message.getBytes(), urlConnection.getOutputStream()); if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) { urlConnection.disconnect(); throw new RuntimeException("Received HTTP error: " + urlConnection.getResponseCode() + " - " + urlConnection.getResponseMessage()); } return urlConnection; }
WsdlRequestProcessor { HttpURLConnection createConnection(SoapMessageImpl message) throws Exception { final HttpURLConnection urlConnection; if (request.isSecure()) { HttpsURLConnection tmp = (HttpsURLConnection) new URL(PROXY_LOCAL_HTTPS_ENDPOINT).openConnection(); tmp.setSSLSocketFactory(InternalSslSocketFactory.getInstance()); tmp.setHostnameVerifier(NoopHostnameVerifier.INSTANCE); urlConnection = tmp; } else { urlConnection = (HttpURLConnection) new URL(PROXY_LOCAL_HTTP_ENDPOINT).openConnection(); } urlConnection.setDoInput(true); urlConnection.setDoOutput(true); urlConnection.setConnectTimeout(SystemProperties.getClientProxyTimeout()); urlConnection.setReadTimeout(SystemProperties.getClientProxyHttpClientTimeout()); urlConnection.setRequestMethod("POST"); urlConnection.setRequestProperty( HttpHeaders.CONTENT_TYPE, MimeUtils.contentTypeWithCharset(MimeTypes.TEXT_XML, StandardCharsets.UTF_8.name())); IOUtils.write(message.getBytes(), urlConnection.getOutputStream()); if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) { urlConnection.disconnect(); throw new RuntimeException("Received HTTP error: " + urlConnection.getResponseCode() + " - " + urlConnection.getResponseMessage()); } return urlConnection; } }
WsdlRequestProcessor { HttpURLConnection createConnection(SoapMessageImpl message) throws Exception { final HttpURLConnection urlConnection; if (request.isSecure()) { HttpsURLConnection tmp = (HttpsURLConnection) new URL(PROXY_LOCAL_HTTPS_ENDPOINT).openConnection(); tmp.setSSLSocketFactory(InternalSslSocketFactory.getInstance()); tmp.setHostnameVerifier(NoopHostnameVerifier.INSTANCE); urlConnection = tmp; } else { urlConnection = (HttpURLConnection) new URL(PROXY_LOCAL_HTTP_ENDPOINT).openConnection(); } urlConnection.setDoInput(true); urlConnection.setDoOutput(true); urlConnection.setConnectTimeout(SystemProperties.getClientProxyTimeout()); urlConnection.setReadTimeout(SystemProperties.getClientProxyHttpClientTimeout()); urlConnection.setRequestMethod("POST"); urlConnection.setRequestProperty( HttpHeaders.CONTENT_TYPE, MimeUtils.contentTypeWithCharset(MimeTypes.TEXT_XML, StandardCharsets.UTF_8.name())); IOUtils.write(message.getBytes(), urlConnection.getOutputStream()); if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) { urlConnection.disconnect(); throw new RuntimeException("Received HTTP error: " + urlConnection.getResponseCode() + " - " + urlConnection.getResponseMessage()); } return urlConnection; }  }
WsdlRequestProcessor { HttpURLConnection createConnection(SoapMessageImpl message) throws Exception { final HttpURLConnection urlConnection; if (request.isSecure()) { HttpsURLConnection tmp = (HttpsURLConnection) new URL(PROXY_LOCAL_HTTPS_ENDPOINT).openConnection(); tmp.setSSLSocketFactory(InternalSslSocketFactory.getInstance()); tmp.setHostnameVerifier(NoopHostnameVerifier.INSTANCE); urlConnection = tmp; } else { urlConnection = (HttpURLConnection) new URL(PROXY_LOCAL_HTTP_ENDPOINT).openConnection(); } urlConnection.setDoInput(true); urlConnection.setDoOutput(true); urlConnection.setConnectTimeout(SystemProperties.getClientProxyTimeout()); urlConnection.setReadTimeout(SystemProperties.getClientProxyHttpClientTimeout()); urlConnection.setRequestMethod("POST"); urlConnection.setRequestProperty( HttpHeaders.CONTENT_TYPE, MimeUtils.contentTypeWithCharset(MimeTypes.TEXT_XML, StandardCharsets.UTF_8.name())); IOUtils.write(message.getBytes(), urlConnection.getOutputStream()); if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) { urlConnection.disconnect(); throw new RuntimeException("Received HTTP error: " + urlConnection.getResponseCode() + " - " + urlConnection.getResponseMessage()); } return urlConnection; }   }
WsdlRequestProcessor { HttpURLConnection createConnection(SoapMessageImpl message) throws Exception { final HttpURLConnection urlConnection; if (request.isSecure()) { HttpsURLConnection tmp = (HttpsURLConnection) new URL(PROXY_LOCAL_HTTPS_ENDPOINT).openConnection(); tmp.setSSLSocketFactory(InternalSslSocketFactory.getInstance()); tmp.setHostnameVerifier(NoopHostnameVerifier.INSTANCE); urlConnection = tmp; } else { urlConnection = (HttpURLConnection) new URL(PROXY_LOCAL_HTTP_ENDPOINT).openConnection(); } urlConnection.setDoInput(true); urlConnection.setDoOutput(true); urlConnection.setConnectTimeout(SystemProperties.getClientProxyTimeout()); urlConnection.setReadTimeout(SystemProperties.getClientProxyHttpClientTimeout()); urlConnection.setRequestMethod("POST"); urlConnection.setRequestProperty( HttpHeaders.CONTENT_TYPE, MimeUtils.contentTypeWithCharset(MimeTypes.TEXT_XML, StandardCharsets.UTF_8.name())); IOUtils.write(message.getBytes(), urlConnection.getOutputStream()); if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) { urlConnection.disconnect(); throw new RuntimeException("Received HTTP error: " + urlConnection.getResponseCode() + " - " + urlConnection.getResponseMessage()); } return urlConnection; }   static final String PARAM_INSTANCE_IDENTIFIER; static final String PARAM_MEMBER_CLASS; static final String PARAM_MEMBER_CODE; static final String PARAM_SERVICE_CODE; }