I'm using the current SOAP implementation as provided by sun/java. I cannot seem to authenticate through our proxy. When I run my program from home, where I don't have a proxy server, the program successfully connects to a webservice... I've tried using the -Dhttp parameters to pass in- but to no avail. I'm using the System.properties to store the http proxy stuff- but it doesn't seem to work. Please let me know if you see anything in my code....
(Please note that I've perused the forums looking for an answer already to my question, and although I have found and tried many of the solutions, none have worked. So just to let you know, I've done some upfront work on this.....Here goes.......)
import javax.xml.soap.*;
import javax.activation.*;
import javax.naming.*;
import java.net.*;
import java.io.*;
import java.util.*;
import javax.xml.*;
import javax.xml.messaging.*;
import javax.xml.soap.*;
import javax.xml.parsers.*;
import org.w3c.dom.Document;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import com.xxx.xxx.xxxx.databeans.*;
import com.sun.xml.messaging.jaxm.soaprp.*;
import java.net.*;
import java.io.*;
import com.xxx.xxx.xxxx.utilities.*;
import java.util.*;
public class WebServiceSendCmd {
private ProviderConnectionFactory pcf;
private ProviderConnection pc;
private MessageFactory mf = null;
private String from ="";
private String to = "";
private String data = "";
MessageFactory messageFactory;
public void Execute() {
}
public java.lang.String GetXml(java.lang.String argFileName) {
return null;
}
ArrayList SendMessage(AsnDto dto, EndPointConfiguration configEnd) { ArrayList list = new ArrayList();
try{
System.out.println("SENDING MESSAGE");
SOAPConnection con;
System.out.println(System.getProperty("java.class.path"));
Thread.currentThread().setContextClassLoader
(this.getClass().getClassLoader());
//get parser factory (uses contextclassloader)
this.messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
String soapAction = "http://www.regom.de/Soup";
soapMessage.getMimeHeaders().addHeader("SoapAction",soapAction);
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
soapBody.addDocument(dto.getXmlDocument());
SOAPConnectionFactory soapFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapFactory.createConnection();
URLEndpoint pt = new URLEndpoint(configEnd.getUrl());
String host = "myproxy.host";
String userid = new sun.misc.BASE64Encoder().encode("UserName".getBytes());
String password = new sun.misc.BASE64Encoder().encode("password".getBytes());
java.util.Properties props = new Properties();
props.setProperty("http.proxySet","true");
props.setProperty("http.proxyHost",host);
props.setProperty("http.proxyPort","8080");
props.setProperty("http.proxyUser",userid);
props.setProperty("http.proxyPassword",password);
Properties systemProps = System.getProperties();
Enumeration iter = props.propertyNames();
while (iter.hasMoreElements()) {
String s = (String) iter.nextElement();
systemProps.put(s, props.getProperty(s));
System.out.println(s+" "+props.getProperty(s));
}
System.setProperties(systemProps);
Enumeration iter2 = System.getProperties().propertyNames();
while (iter2.hasMoreElements()) {
System.out.println((String) iter2.nextElement());
}
SOAPMessage replyMsg = soapConnection.call(soapMessage,pt);
Iterator i = replyMsg.getSOAPBody().getAllAttributes();
SOAPBody returnBody = replyMsg.getSOAPBody();
System.out.println(returnBody.toString());
while(i.hasNext()){
String xmlNode = i.next().toString();
System.out.println("NODES"+xmlNode);
}
MimeHeaders mimeHeaders = replyMsg.getMimeHeaders();
Iterator mimeList = mimeHeaders.getAllHeaders();
while(mimeList.hasNext())
System.out.println(mimeList.next().toString());
soapConnection.close();
list.add(returnBody);
}catch(Exception e){
e.printStackTrace();
}
return list;
}