Hi all,
I have a java client that tries to connect to our SOAP server through a proxy.
I have no problem with normal proxies but I do however when it's a secured proxy (with authentication).
I have tried several solutions:
1- The use of the system properties like for the normal proxies (+http.proxyHost+,
http.proxyPort,
http.proxyUser and
http.proxyPassword), but it did not work (Error 407: Proxy Authentication Required).
2- A simple class derived from the
java.net.Authenticator (code below) but still the same error.
3- Change the properties of the call directly but it might be used by axis only so again the same error.
The main problem comes from the fact that I am using SOAP (apache axis) to start the connection (see code below).
I would appreciate any inputs/remarks because I am really lost at this point.
I can try whatever you may advice me to do since the system is all mine.
Many thanks in advance and best regards.
Rob
The HttpAuthenticateProxy class
import java.net.Authenticator;
import java.net.PasswordAuthentication;
public class HttpAuthenticateProxy extends Authenticator {
private String username;
private String userpass;
public HttpAuthenticateProxy(String user, String pass) {
super();
username = user;
userpass = pass;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username,userpass.toCharArray());
}
}
The SOAP client class
[...]
/* SOAP classes */
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
[...]
public class SOAPClient {
public static Service service = null;
private static Call buildCall(String method) throws ServiceException {
if (service == null) {
if (GlobalProperties.getHttpProxyHost() != null && GlobalProperties.getHttpProxyHost().length() != 0 && !GlobalProperties.getHttpProxyHost().equalsIgnoreCase("null")) {
// Secured proxy.
if (GlobalProperties.getHttpProxyUser() != null && GlobalProperties.getHttpProxyUser().length() != 0 && !GlobalProperties.getHttpProxyUser().equalsIgnoreCase("null")) {
System.setProperty("http.proxyHost", GlobalProperties.getHttpProxyHost());
System.setProperty("http.proxyPort", GlobalProperties.getHttpProxyPort());
/* my first attempt */
System.setProperty("http.proxyUser", GlobalProperties.getHttpProxyUser());
System.setProperty("http.proxyPassword", GlobalProperties.getHttpProxyPass());
/* my second attempt */
Authenticator.setDefault(new HttpAuthenticateProxy(GlobalProperties.getHttpProxyUser(),GlobalProperties.getHttpProxyPass()));
} else { // Non secured proxy.
System.setProperty("http.proxyHost", GlobalProperties.getHttpProxyHost());
System.setProperty("http.proxyPort", GlobalProperties.getHttpProxyPort());
}
}
service = new Service();
}
Call call = (Call) service.createCall();
call.setOperationName(method);
call.setTimeout(new Integer(1800000));
return call;
}
private static Object invoke(Call call, Object[] objects) throws Exception,RemoteException,MalformedURLException {
for (String name : GlobalProperties.getSOAPServers()) {
call.setTargetEndpointAddress(new URL(name));
if (GlobalProperties.getHttpProxyUser() != null && GlobalProperties.getHttpProxyUser().length() != 0 && !GlobalProperties.getHttpProxyUser().equalsIgnoreCase("null")) {
/* my third attempt */
call.setProperty("javax.xml.rpc.security.auth.password",GlobalProperties.getHttpProxyPass());
call.setPassword(GlobalProperties.getHttpProxyPass());
call.setProperty("javax.xml.rpc.security.auth.username",GlobalProperties.getHttpProxyUser());
call.setUsername(GlobalProperties.getHttpProxyUser());
}
for (int j = 0; j < objects.length; j++) {
if (objects[j] == null)
objects[j] = "";
}
Object ret = call.invoke(objects);
return ret;
}
return null;
}
/* example of run */
public static String stressServerAnnot(String server, String nbRuns) throws Exception {
try {
Call call = buildCall("stressServerAnnot");
call.addParameter("server", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("nbRuns", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
String ret = (String) invoke(call, new Object[] {server, nbRuns});
return ret;
} catch (Exception e) {
System.out.println("[SOAPClient] Error in stressServerAnnot : " + e);
throw new Exception("[SOAPClient] Error in stressServerAnnot : " + e);
}
}
}
Edited by: RobR on Nov 29, 2007 1:25 AM
Edited by: RobR on Nov 29, 2007 1:26 AM