Interview Questions

How can I make the SOAP call? And what do I do if the proxy requires authentication?

SOAP Interview Questions and Answers


(Continued from previous question...)

How can I make the SOAP call? And what do I do if the proxy requires authentication?

Q: I want to write a SOAP Client using Apache SOAP for Java but am behind a proxyserver. How can I make the SOAP call? And what do I do if the proxy requires authentication?

For SOAP clients, you can tell the soap connection object to use a proxy host and port. You can then set your call object to use this connection. Suppose your proxy server is called "proxy.foo.com" and it is on port 9999. Here is a snippet of code to do this:

1. SOAPHTTPConnection conn = new SOAPHTTPConnection();
2. conn.setProxyHost("proxy.foo.com"); // specifying the proxy server
3. conn.setProxyPort(9999); // specifying the port used by the proxy
4. Call call = new Call(); // getting a new call object
5. call.setSOAPTransport(conn); // use the proxy

If the proxy requires authentication use the code above but add the following lines:

3.1. conn.setProxyUserName("my proxy id");
3.2. conn.setProxyPassword("my secret password");

(Continued on next question...)

Other Interview Questions