Please note that I've tested the following in SOAPUI and it appears to work as expected (i.e. returning a 200 status) using the same URL and Authorization credentials. The fact that it works OK in SOAPUI makes me think I should be doing something specific when building my request to handle the fact that it's https.
Attempting to POST to a URL using DefaultHttpClient (v4.2.3) using the following method:
String requestUrl = "https://test.host.name:9093/ws/simple/serviceName";
HttpPost httpPost = new HttpPost(requestUrl);
String username = "username@domainname";
String password = "pass-word-string";
String usernameAndPassword = username + ":" + password;
String encodedUserNameAndPassword = new sun.misc.BASE64Encoder().encode(usernameAndPassword.getBytes());
httpPost.setHeader("Authorization", encodedUserNameAndPassword);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(httpPost);
System.out.println(response.getStatusLine().toString());
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity, "UTF-8");
System.out.println(responseString);
EntityUtils.consume(entity);
The problem I'm having is that the server is responding with a 400 status and Bad Request message:
[DEBUG] wire - << "HTTP/1.1 400 Bad Request[\r][\n]"
[DEBUG] wire - << "Connection: close[\r][\n]"
[DEBUG] wire - << "Server: Jetty(6.1.26-boomi)[\r][\n]"
[DEBUG] wire - << "[\r][\n]"
If I remove the authentication part then I get a "401 Not Authorized" which at least indicates that the server is expecting my request:
[DEBUG] wire - << "HTTP/1.1 401 Unauthorized[\r][\n]"
[DEBUG] wire - << "WWW-Authenticate: Basic realm="BoomiBasicRealm"[\r][\n]"
[DEBUG] wire - << "Content-Type: text/html; charset=iso-8859-1[\r][\n]"
[DEBUG] wire - << "Cache-Control: must-revalidate,no-cache,no-store[\r][\n]"
[DEBUG] wire - << "Content-Length: 1396[\r][\n]"
[DEBUG] wire - << "Server: Jetty(6.1.26-boomi)[\r][\n]"
The server admin has said that he can see the following coming through to the server logs:
SSL renegotiate denied: java.nio.channels.SocketChannel[connected local=/192.168.20.86:9093 remote=/ip.ip.ip.ip:61356]”
The strange thing is that I've used the same code to post successfully to other URLs which are using https, albeit not using a different port in the address, and it works without an issue.
The server admin is looking at it from their end while I continue to investigate but the fact that it works in SOAPUI makes me think there is something I need to do differently.
I noticed that SOAPUI is using Apache-HttpClient v4.1.1 whereas I'm using 4.2.3 so I switched to 4.1.1 and it didn't make a difference. Therefore I'm guessing that SOAPUI is doing something different under the covers which I need to mimic.
Are there any SOAPUI devs out there who might be able to advise?