SOAP via SSL

K

kubber

Hello,

I'm trying to write a programm, that will send SOAP requests ( from
request.xml file ) and put response
to response.xml file .

I managed to add few lines to a tip I found on the web :

http://www-128.ibm.com/developerworks/xml/library/x-jaxmsoap/

and I've got working programm, but .. everything runs fine via HTTP ,
but as I want
it to consume a web service via HTTPS it throws :

java.security.PrivilegedActionException:
com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send failed

I'm going to google further, I've even bougth a book , but I'm afraid I
won't make it on time ..

I don't have any access to a web server with SSL, ( I'm testing it in
home network with apache with SSL ),
so I could host a sample web service there ..

Maybe someone can help me ...

Thanks ;


Here's the code so far ( jre 1.6 )

<code>
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.net.URL;
import java.security.Security;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class BringSOAP {

public static void main(String args[]) {
if (args.length == 0)
{
System.out.println("Usage : BringSOAP <WebService - URL> ") ;
}
else
try {

System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider());

// System.setProperty("javax.net.debug", "all" );

//First create the connection
SOAPConnectionFactory soapConnFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection =
soapConnFactory.createConnection();

//Next, create the actual message
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();

// Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();

//Populate the Message
StreamSource preppedMsgSrc = new StreamSource(
new FileInputStream("request.xml"));
soapPart.setContent(preppedMsgSrc);

//Save the message
message.saveChanges();


// Check the input
System.out.println("\nREQUEST:\n");
message.writeTo(System.out);
System.out.println();

//Send the message and get a reply

//Set the destination
URL destination = new URL(args[0]);
// Send the message
SOAPMessage reply = connection.call(message, destination);

//Check the output
//Create the transformer
TransformerFactory transformerFactory =
TransformerFactory.newInstance();
Transformer transformer =
transformerFactory.newTransformer();
//Extract the content of the reply
Source sourceContent = reply.getSOAPPart().getContent();

//Set the output for the transformation
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object
// Create a new file output stream
out = new FileOutputStream("response.xml");
// Connect print stream to the output stream
p = new PrintStream( out );

StreamResult result = new StreamResult(p);
transformer.transform(sourceContent, result);

p.println();
p.close();
//Close the connection
connection.close();

}
catch(Exception e)
{
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object

try
{
System.out.println(e.getMessage());
out = new FileOutputStream("error.txt");
// Connect print stream to the output stream
p = new PrintStream( out );
p.println(e.getMessage());
p.close();
}
catch(Exception f)
{
System.out.println(f.getMessage());
}
}
}
}
</code>
 
W

wesley.hall

java.security.PrivilegedActionException:
com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send failed

This is not enough information.

At the beginning of your first catch block put...

e.printStackTrace();

and at the beginning of your second put...

f.printStackTrace();

Then paste the entire output here.
Here's the code so far ( jre 1.6 )

<code>
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.net.URL;
import java.security.Security;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class BringSOAP {

public static void main(String args[]) {
if (args.length == 0)
{
System.out.println("Usage : BringSOAP <WebService - URL> ") ;
}
else
try {

System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider());

// System.setProperty("javax.net.debug", "all" );

//First create the connection
SOAPConnectionFactory soapConnFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection =
soapConnFactory.createConnection();

//Next, create the actual message
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();

// Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();

//Populate the Message
StreamSource preppedMsgSrc = new StreamSource(
new FileInputStream("request.xml"));
soapPart.setContent(preppedMsgSrc);

//Save the message
message.saveChanges();


// Check the input
System.out.println("\nREQUEST:\n");
message.writeTo(System.out);
System.out.println();

//Send the message and get a reply

//Set the destination
URL destination = new URL(args[0]);
// Send the message
SOAPMessage reply = connection.call(message, destination);

//Check the output
//Create the transformer
TransformerFactory transformerFactory =
TransformerFactory.newInstance();
Transformer transformer =
transformerFactory.newTransformer();
//Extract the content of the reply
Source sourceContent = reply.getSOAPPart().getContent();

//Set the output for the transformation
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object
// Create a new file output stream
out = new FileOutputStream("response.xml");
// Connect print stream to the output stream
p = new PrintStream( out );

StreamResult result = new StreamResult(p);
transformer.transform(sourceContent, result);

p.println();
p.close();
//Close the connection
connection.close();

}
catch(Exception e)
{
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object

try
{
System.out.println(e.getMessage());
out = new FileOutputStream("error.txt");
// Connect print stream to the output stream
p = new PrintStream( out );
p.println(e.getMessage());
p.close();
}
catch(Exception f)
{
System.out.println(f.getMessage());
}
}
}
}
</code>
 
K

kubber

here it is :

2006-12-07 21:50:36
com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection pos
t
SEVERE: SAAJ0009: Message send failed
com.sun.xml.messaging.saaj.SOAPExceptionImpl:
java.security.PrivilegedActionExce
ption: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send
failed
at
com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown
Source)
at BringSOAP.main(BringSOAP.java:70)
Caused by: java.security.PrivilegedActionException:
com.sun.xml.messaging.saaj.S
OAPExceptionImpl: Message send failed
at java.security.AccessController.doPrivileged(Native Method)
... 2 more
Caused by: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send
failed
at
com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(Unknown
Source)
at
com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedP
ost.run(Unknown Source)
... 3 more
Caused by: javax.net.ssl.SSLHandshakeException:
sun.security.validator.Validator
Exception: PKIX path building failed:
sun.security.provider.certpath.SunCertPath
BuilderException: unable to find valid certification path to requested
target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown
Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown
Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown
Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown
Source)
at
com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unkno
wn Source)
at
com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown
Source)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown
Source)
at
com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source
)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)

at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Un
known Source)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Sou
rce)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Sou
rce)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown
Source)
at
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(Unknown Source)
at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown S
ource)
at
com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl
..getOutputStream(Unknown Source)
... 5 more
Caused by: sun.security.validator.ValidatorException: PKIX path
building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find vali
d certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
at sun.security.validator.PKIXValidator.engineValidate(Unknown
Source)
at sun.security.validator.Validator.validate(Unknown Source)
at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(Unknown So
urce)
at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(
Unknown Source)
at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(
Unknown Source)
... 17 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException:
unable to
find valid certification path to requested target
at
sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown
Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)
... 23 more

CAUSE:

java.security.PrivilegedActionException:
com.sun.xml.messaging.saaj.SOAPExceptio
nImpl: Message send failed
at java.security.AccessController.doPrivileged(Native Method)
at
com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown
Source)
at BringSOAP.main(BringSOAP.java:70)
Caused by: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send
failed
at
com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(Unknown
Source)
at
com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedP
ost.run(Unknown Source)
... 3 more
Caused by: javax.net.ssl.SSLHandshakeException:
sun.security.validator.Validator
Exception: PKIX path building failed:
sun.security.provider.certpath.SunCertPath
BuilderException: unable to find valid certification path to requested
target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown
Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown
Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown
Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown
Source)
at
com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unkno
wn Source)
at
com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown
Source)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown
Source)
at
com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source
)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)

at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Un
known Source)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Sou
rce)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Sou
rce)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown
Source)
at
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(Unknown Source)
at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown S
ource)
at
com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl
..getOutputStream(Unknown Source)
... 5 more
Caused by: sun.security.validator.ValidatorException: PKIX path
building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find vali
d certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
at sun.security.validator.PKIXValidator.engineValidate(Unknown
Source)
at sun.security.validator.Validator.validate(Unknown Source)
at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(Unknown So
urce)
at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(
Unknown Source)
at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(
Unknown Source)
... 17 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException:
unable to
find valid certification path to requested target
at
sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown
Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)
... 23 more

CAUSE:

java.security.PrivilegedActionException:
com.sun.xml.messaging.saaj.SOAPExceptio
nImpl: Message send failed
at java.security.AccessController.doPrivileged(Native Method)
at
com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown
Source)
at BringSOAP.main(BringSOAP.java:70)
Caused by: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send
failed
at
com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(Unknown
Source)
at
com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedP
ost.run(Unknown Source)
... 3 more
Caused by: javax.net.ssl.SSLHandshakeException:
sun.security.validator.Validator
Exception: PKIX path building failed:
sun.security.provider.certpath.SunCertPath
BuilderException: unable to find valid certification path to requested
target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown
Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown
Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown
Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown
Source)
at
com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unkno
wn Source)
at
com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown
Source)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown
Source)
at
com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source
)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)

at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Un
known Source)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Sou
rce)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Sou
rce)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown
Source)
at
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(Unknown Source)
at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown S
ource)
at
com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl
..getOutputStream(Unknown Source)
... 5 more
Caused by: sun.security.validator.ValidatorException: PKIX path
building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find vali
d certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
at sun.security.validator.PKIXValidator.engineValidate(Unknown
Source)
at sun.security.validator.Validator.validate(Unknown Source)
at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(Unknown So
urce)
at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(
Unknown Source)
at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(
Unknown Source)
... 17 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException:
unable to
find valid certification path to requested target
at
sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown
Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)
... 23 more
java.security.PrivilegedActionException:
com.sun.xml.messaging.saaj.SOAPExceptio
nImpl: Message send failed



java.security.PrivilegedActionException:
com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send failed

This is not enough information.

At the beginning of your first catch block put...

e.printStackTrace();

and at the beginning of your second put...

f.printStackTrace();

Then paste the entire output here.
Here's the code so far ( jre 1.6 )

<code>
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.net.URL;
import java.security.Security;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class BringSOAP {

public static void main(String args[]) {
if (args.length == 0)
{
System.out.println("Usage : BringSOAP <WebService - URL> ") ;
}
else
try {

System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider());

// System.setProperty("javax.net.debug", "all" );

//First create the connection
SOAPConnectionFactory soapConnFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection =
soapConnFactory.createConnection();

//Next, create the actual message
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();

// Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();

//Populate the Message
StreamSource preppedMsgSrc = new StreamSource(
new FileInputStream("request.xml"));
soapPart.setContent(preppedMsgSrc);

//Save the message
message.saveChanges();


// Check the input
System.out.println("\nREQUEST:\n");
message.writeTo(System.out);
System.out.println();

//Send the message and get a reply

//Set the destination
URL destination = new URL(args[0]);
// Send the message
SOAPMessage reply = connection.call(message, destination);

//Check the output
//Create the transformer
TransformerFactory transformerFactory =
TransformerFactory.newInstance();
Transformer transformer =
transformerFactory.newTransformer();
//Extract the content of the reply
Source sourceContent = reply.getSOAPPart().getContent();

//Set the output for the transformation
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object
// Create a new file output stream
out = new FileOutputStream("response.xml");
// Connect print stream to the output stream
p = new PrintStream( out );

StreamResult result = new StreamResult(p);
transformer.transform(sourceContent, result);

p.println();
p.close();
//Close the connection
connection.close();

}
catch(Exception e)
{
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object

try
{
System.out.println(e.getMessage());
out = new FileOutputStream("error.txt");
// Connect print stream to the output stream
p = new PrintStream( out );
p.println(e.getMessage());
p.close();
}
catch(Exception f)
{
System.out.println(f.getMessage());
}
}
}
}
</code>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,297
Latest member
EngineerD

Latest Threads

Top