C
contrex
I wrote a simple webservice client in java (Axis). When I call a
webservice localized in my local network all works fine but when I
call external webservices I get a java.net.UnknownHostException. I
think it's because I have to use a proxy when I want to connect to the
internet but I don't know how to tell it my java client.
Other java classes (not calling webservices) use the Socket class in
order to connect through a proxy to the internet which works very
well:
#### BEGIN code snippet
URL server = new URL("http://foo.bar");
Socket socket = new Socket("UrlProxy", 1234);
Writer writer = new OutputStreamWriter(socket.getOutputStream(),
"US-ASCII");
writer.write("GET " + server.toExternalForm() + " HTTP/1.0\r\n");
writer.write("Host: " + server.getHost() + "\r\n");
writer.write("Proxy-Authorization: Basic "
+ new sun.misc.BASE64Encoder().encode("someAuthenticationString".getBytes())
+ "\r\n\r\n");
writer.flush();
BufferedReader reader = new BufferedReader(new
InputStreamReader(socket.getInputStream(),"US-ASCII"));
#### END code snippet
But in the axis examples of the java client I didn't find a Socket
class or other things where I could specify my proxy.
Can you tell me please how the java client have to call a webservice
through a proxy server? THANKS!
Here is the code of my java client:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import javax.xml.namespace.QName;
public class TestClient
{
public static void main(String [] args) {
try {
String endpoint =
"http://www.vbnetexpert.com/vsm/timeservice";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName("GetLocal");
String ret = (String) call.invoke( new Object[] { "foo" } );
System.out.println("Sent 'foo', got '" + ret + "'");
}catch (Exception e) {
System.err.println(e.toString());
}
}
}
webservice localized in my local network all works fine but when I
call external webservices I get a java.net.UnknownHostException. I
think it's because I have to use a proxy when I want to connect to the
internet but I don't know how to tell it my java client.
Other java classes (not calling webservices) use the Socket class in
order to connect through a proxy to the internet which works very
well:
#### BEGIN code snippet
URL server = new URL("http://foo.bar");
Socket socket = new Socket("UrlProxy", 1234);
Writer writer = new OutputStreamWriter(socket.getOutputStream(),
"US-ASCII");
writer.write("GET " + server.toExternalForm() + " HTTP/1.0\r\n");
writer.write("Host: " + server.getHost() + "\r\n");
writer.write("Proxy-Authorization: Basic "
+ new sun.misc.BASE64Encoder().encode("someAuthenticationString".getBytes())
+ "\r\n\r\n");
writer.flush();
BufferedReader reader = new BufferedReader(new
InputStreamReader(socket.getInputStream(),"US-ASCII"));
#### END code snippet
But in the axis examples of the java client I didn't find a Socket
class or other things where I could specify my proxy.
Can you tell me please how the java client have to call a webservice
through a proxy server? THANKS!
Here is the code of my java client:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import javax.xml.namespace.QName;
public class TestClient
{
public static void main(String [] args) {
try {
String endpoint =
"http://www.vbnetexpert.com/vsm/timeservice";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName("GetLocal");
String ret = (String) call.invoke( new Object[] { "foo" } );
System.out.println("Sent 'foo', got '" + ret + "'");
}catch (Exception e) {
System.err.println(e.toString());
}
}
}