Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Making a SOAP call through a proxy! Please help!!!

843834Mar 31 2003 — edited Mar 5 2004
I'm behind a firewall. I've checked most of the posting in the forum and on the Internet. Most get by using the java.net.Authenticator class, and setting default properties such as https.proxyHost, https.proxyUserName, https.proxyPassword etc. I've tried all that!!! Still doesn't work.

Here's the error msg I get:
Required
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)
... 4 more
javax.xml.soap.SOAPException: java.security.PrivilegedActionException: javax.xml
.soap.SOAPException: Bad response: (407Proxy Authentication Required
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown
Source)
at GoogleJPClient.sendGoogJMsg(GoogleJPClient.java:103)
at GoogleJPClient.main(GoogleJPClient.java:149)
Caused by: java.security.PrivilegedActionException: javax.xml.soap.SOAPException
: Bad response: (407Proxy Authentication Required
at java.security.AccessController.doPrivileged(Native Method)
... 3 more
Caused by: javax.xml.soap.SOAPException: Bad response: (407Proxy Authentication
Required
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)
... 4 more

Attached is my code snippet:
========================================================================
public class GoogleJPClient
{
private static final String DEFAULT_HOST_URL =
"http://api.google.com/search/beta2";
private static final String URI = "urn:doGoogleSearch";

//Member variables
private String m_hostURL;

public GoogleJPClient(String hostURL) throws Exception
{
m_hostURL = hostURL;
}

public class pAuth extends Authenticator
{
protected PasswordAuthentication getPasswordAuthentication()
{
String uname = "apnt\\soolu01";
String pw = "boromir";

return new PasswordAuthentication(uname, pw.toCharArray());
}
}

public void sendGoogJMsg()
{
try
{
Properties props = new Properties();
props.setProperty("com.sun.xml.registry.https.proxyHost", "proxy_server");
props.setProperty("com.sun.xml.registry.https.proxyPort", "80");
props.setProperty("com.sun.xml.registry.https.proxyUserName", "a-user");
props.setProperty("com.sun.xml.registry.https.proxyPassword", "a-passwd");

javax.xml.soap.SOAPConnectionFactory scf =
javax.xml.soap.SOAPConnectionFactory.newInstance();


javax.xml.soap.SOAPConnection conn = scf.createConnection();

//conn.setProperties(props);

//Get instance of MessageFactory class
javax.xml.soap.MessageFactory mf =
javax.xml.soap.MessageFactory.newInstance();

//Create message from the message factory, already containing
//SOAP part
javax.xml.soap.SOAPMessage message = mf.createMessage();

//.Get the message's SOAP part
javax.xml.soap.SOAPPart soapPart = message.getSOAPPart();

//Populate msg with Google template
StreamSource prepMsg = new StreamSource(new FileInputStream("doGoogleSearchmod.xml"));
soapPart.setContent(prepMsg);

message.saveChanges(); //save changes

//fingers crossed
java.net.Authenticator.setDefault(new pAuth());


//Properties props = System.getProperties();
System.setProperty("https.proxyHost", "a-proxyserver");
System.setProperty("https.proxyPort", "80");
System.setProperty("https.proxyUserName", "a-username");
System.setProperty("https.proxyPassword", "a-passwd");
System.setProperty("https.proxySet", "true");

System.setProperty("http.proxyHost", "proxy_server");
System.setProperty("http.proxyPort", "80");
System.setProperty("http.proxyUserName", "a-username");
System.setProperty("http.proxyPassword", "a-passwd");
System.setProperty("http.proxySet", "true");

//System.setProperties(props);

URLEndpoint dest =
new URLEndpoint("http://api.google.com/search/beta2");
javax.xml.soap.SOAPMessage reply = conn.call(message, dest);

TransformerFactory tFact = TransformerFactory.newInstance();
Transformer t = tFact.newTransformer();

Source srcContent = reply.getSOAPPart().getContent();

StreamResult res = new StreamResult("doGoogleSearchresp.xml");
t.transform(srcContent, res);

System.out.println("Received reply from: " + m_hostURL);

//Display reply from endpoint
boolean dispRes = true;
if(dispRes)
{
//Dump onto screen
System.out.println("Result:");
reply.writeTo(System.out);
}
conn.close();

}catch(Throwable e){
e.printStackTrace();
}
}
public static void main(String args[])
{
//String hostURL = DEFAULT_HOST_NAME;

Properties sysprop= System.getProperties();
//sysprop.put("firewallHost", "proxy_server");
//sysprop.put("firewallPort", "80");
//sysprop.put("firewallSet", "true");
//sysprop.put("proxyHost", "proxy_server");
//sysprop.put("proxyPort", "80");
//sysprop.put("proxySet", "true");



try
{
GoogleJPClient gjc = new GoogleJPClient("http://api.google.com/search/beta2");
gjc.sendGoogJMsg();
}catch(Exception e){
e.printStackTrace();
}
}
}
========================================================================
As you can see it's pretty messy, and I've tried getting around the HTTPS proxy in a variety of methods, but with no results.

Please help.

Rgds,
frustrated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 2 2004
Added on Mar 31 2003
2 comments
3,556 views