• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with using HttpsURLConnection

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I'm new to Java but trying to make a client that will connect and send SOAP request to a Server.

The script I'm trying to send works well via soapUI.

When I'm trying to use "my" client I'm getting following error:

"java.io.IOException: Server returned HTTP response code: 500 for URL: https://xxxxx/path-to-location
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)"

Here is my code:

"// Set the HostnameVerifier to the HttpsURLConnection
HttpsURLConnection.setDefaultHostnameVerifier(verifier);

// Declare a new HttpsURLConnection
HttpsURLConnection connection = null;

// Try to connect and execute the request
try {
// Declare a SSLContext to use
SSLContext sslContext = SSLContext.getInstance("SSL");

// Call the TrustManager that is designed to accept all
TrustManager[] trustMgr = getTrustMgr();

// SSL Context.init(Key manager, Trust manager, random number generator)
sslContext.init(null, trustMgr, new SecureRandom());

// Set the socket of the HTTPS connection
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());

// Open the URL indicated by the reference End Point
URL url = new URL(this.refEndPoint);
connection = (HttpsURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Accept-Encoding", "gzip,deflate");
connection.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
connection.setRequestProperty("Host", this.xmlUrl);
connection.setRequestProperty("Content-Length", Integer.toString(command.length()));
connection.setRequestProperty("SOAPAction", "myAction");
connection.setRequestProperty("User-Agent", "Jakarta Commons-HttpClient/3.1");
connection.setRequestProperty("Authorization", "Basic");
setCredentials(connection, this.xmlUsername, this.xmlPassword);

// Connect
connection.connect();
System.out.println(connection.getCipherSuite());

// Send Request to the server
DataOutputStream outStr = new DataOutputStream(connection.getOutputStream ());
outStr.writeBytes(command);
outStr.flush();
outStr.close();

// Get Response from the server
InputStream inputStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while((line = reader.readLine()) != null) {
response.append(line);
response.append('\r');
logger.debug(line);
}
reader.close();

// Set the results
result = true;
rawXmlResult = new String(response);
}"


Here is my "command":
"<?xml version="1.0" encoding="UTF-8"?>
<ns2:myAction xmlns:cus="http://xxxxx/">
<buddy>
<name>John</name>
</buddy>
</ns2:myAction>
"

Any help are very much appreciated!

Thanks in advance!
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should start by using code tags. You can edit your post to add them.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A "5xx" status code indicates a server problem, so there should be something in the server log files about this.

You may also want to use an HTTP proxy such as tcpmon or SOAPUI to observe the traffic in transit.
 
lukas ka
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys. I found an error in the log file and figured out what I need to do. It seems to work now.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic