I am using axis2's ServiceClient to call to a webservice outside my company's network. However, I got an error that said that there was a NTLM challenge.
(SEVERE: Credentials cannot be used for NTLM authentication: org.apache.commons.httpclient.UsernamePasswordCredentials org.apache.commons.httpclient.auth.InvalidCredentialsException: Credentials cannot be used for NTLM authentication: org.apache.commons.httpclient.UsernamePasswordCredentials) Here is what I don't understand. 1. When I use the ServiceClient to call to a webservice that is inside the network, everything was fine. (Expected !) 2. When I use the ServiceClient to call to a webservice that is outside the network, I got NTLM challenge. (hmm, OK...) 3. When I use the plain Java client to call to the same webservice that is outside the network, everything was fine. (What ?) Below are the code of 2 and 3 respectively. Anyone know why and the solution to make 2 work ? ================================================================ public class Scenario1iClient { public static void main(String[] args) throws Exception { ServiceClient client = new ServiceClient(); Options opts = new Options(); opts.setTo(new EndpointReference("http://ws.cdyne.com/ip2geo/ip2geo.asmx")); opts.setAction("urn:ResolveIP"); client.setOptions(opts); OMElement res = client.sendReceive(createPayLoad()); } public static OMElement createPayLoad() { OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace("http://ws.cdyne.com/IP2Geo", "ns1"); OMElement method = fac.createOMElement("ResolveIP", omNs); OMElement value1 = fac.createOMElement("ipAddress", omNs); value1.setText("69.147.76.15"); method.addChild(value1); OMElement value2 = fac.createOMElement("licenseKey", omNs); value2.setText("0"); method.addChild(value2); System.out.println("method:"+method.toString()); return method; } } ======================================================================= public class HttpTest3 { public static void main(String[] args) throws Exception { String httpsURL = "http://ws.cdyne.com/ip2geo/ip2geo.asmx"; String urlParameters = "<soapenv:Envelope\n"+ "xmlns:q0=\"http://ws.cdyne.com/IP2Geo\ <http://ws.cdyne.com/IP2Geo/> "\n"+ "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\ <http://schemas.xmlsoap.org/soap/envelope/> "\n"+ "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\ <http://www.w3.org/2001/XMLSchema/> "\n"+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\ <http://www.w3.org/2001/XMLSchema-instance/> ">\n"+ "<soapenv:Header>\n"+ "</soapenv:Header>\n"+ "<soapenv:Body>\n"+ "<q0:ResolveIP>\n"+ "<q0:ipAddress>69.147.76.15</q0:ipAddress>\n"+ "<q0:licenseKey>0</q0:licenseKey>\n"+ "</q0:ResolveIP>\n"+ "</soapenv:Body>\n"+ "</soapenv:Envelope>\n"; URL myurl = new URL(httpsURL); HttpURLConnection con = (HttpURLConnection)myurl.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); con.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length)); con.setRequestProperty("Content-Language", "en-US"); con.setRequestProperty("SOAPAction", "\"http://ws.cdyne.com/IP2Geo/ResolveIP\ <http://ws.cdyne.com/IP2Geo/ResolveIP/> ""); con.setUseCaches (false); con.setDoInput(true); con.setDoOutput(true); //Send request DataOutputStream wr = new DataOutputStream (con.getOutputStream ()); wr.writeBytes (urlParameters); wr.flush (); wr.close (); InputStream ins = con.getInputStream(); InputStreamReader isr=new InputStreamReader(ins); BufferedReader in =new BufferedReader(isr); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } }