Thanks for your help! You pointed me in the right direction but my
java client is still unable to reach the webservice. My proxy needs
authentication so I added 2 lines to your code:
System.getProperties().setProperty("http.proxyUser ", "myUserId");
System.getProperties().setProperty("http.proxyPass word", "myPwd");
When I execute the java client I get:
(405)Method Not Allowed
If I encode userId and password as I read in some articles as shown
here:
String userid = new sun.misc.BASE64Encoder().encode("myUserId".getByte s());
String password = new
sun.misc.BASE64Encoder().encode("myPwd".getBytes() );
System.getProperties().setProperty("http.proxyUser ", userid);
System.getProperties().setProperty("http.proxyPass word", password);
....then I get:
(407)Proxy Authentication Required
So, I read some more articles as (i.e.
http://www.doc.ic.ac.uk/~ca99/blogs/000157.html) and I even used the
Authenticator class as described there. The error I get then is:
(407)Proxy Authentication Required
Really strange is that the method "getPasswordAuthentication()" is
NEVER called! Why?
Ok, at least the first aproach seems to use my proxy correctly but why
I get an "(405)Method Not Allowed" error?
Thanks for your advice!
Here is the code of my java client:
public class TestClient{
public static void main(String [] args) {
TestClient tc = new TestClient();
//tc.callInternalWebservice();
tc.callExternalWebservice();
}
public void callExternalWebservice() {
try {
System.getProperties().setProperty("http.proxySet" , "true");
System.getProperties().setProperty("http.proxyHost ",
"proxy.com");
System.getProperties().setProperty("http.proxyPort ", "8080");
// NOW CREATE HTTP AUTHENTICATION
// ...either by setting system props
String userid = "myUserId";
String password = "myPwd";
//userid = new
sun.misc.BASE64Encoder().encode(userid.getBytes()) ;
//password = new
sun.misc.BASE64Encoder().encode(password.getBytes( ));
System.getProperties().setProperty("http.proxyUser ", userid);
System.getProperties().setProperty("http.proxyPass word",
password);
// ...or by using Authenticator class (Java2)
//Authenticator.setDefault(new MyAuthenticator());
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());
}
}
public class MyAuthenticator extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
System.out.println(">>>getPasswordAuthentication") ;//NEVER
called! Why?
return new PasswordAuthentication("myUserId",
"myPwd".toCharArray());
}
}
}