Hi I am trying to access the soap web services which are provided by another machine in my LAN from the android emulator in my machine.
This is the following code I have to access the web service...
public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
String SOAP_ACTION = "http://xxx.xxx.xx.xx:7001/yantrawebservices/yantrawebservice";
String URL = "http://xxx.xxx.xx.xx:7001/yantrawebservices/yantrawebservice?WSDL";
String response = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
HttpPost httpPost = new HttpPost(URL);
String bodyOut ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yan=\"http://yantra.com/yantrawebservices\">\n"
+ "<soapenv:Header/>\n"
+ "<soapenv:Body>\n"
+"<yan:getOrderDetails>\n"
+"<yan:env><![CDATA[<YFSEnvironment userId=\"admin\" Password=\"password\"/>]]></yan:env>\n"
+"<yan:document1><![CDATA[<Order EnterpriseCode=\"DEFAULT\" DocumentType=\"0001\" OrderNo=\"Y100000000\"/>]]></yan:document1>"
+"</yan:getOrderDetails>\n"
+"</soapenv:Body>\n"
+"</soapenv:Envelope>";
StringEntity se = new StringEntity(bodyOut, HTTP.UTF_8);
se.setContentType("text/xml");
httpPost.addHeader("SOAPAction", SOAP_ACTION);
httpPost.setEntity(se);
HttpResponse httpResponse = httpClient.execute(httpPost);
System.out.println("status"+httpResponse.getStatusLine().getStatusCode());
HttpEntity resEntity = httpResponse.getEntity();
response = EntityUtils.toString(resEntity);
System.out.println("status 2 this is sample status "+response);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
StringReader sr = new StringReader(response);
InputSource is = new InputSource(sr);
Document XMLResponse = builder.parse(is);
NodeList elements = XMLResponse.getElementsByTagName("ERRORS");
Boolean error = Boolean.valueOf(elements.item(0)
.getAttributes().item(0).getNodeValue());
System.out.println("the boolean"+error);
HashMap<String, String> Data = new HashMap<String, String>();
if (error) { // case of no error, value of error is returned
// true in case of no error.
elements = XMLResponse
.getElementsByTagName(
"AUTH_OUTPUT").item(0)
.getChildNodes();
System.out.println("response" +response);
System.out.println("DAta"+Data.get(0).charAt(0));
} else {// In case of error
String eCode = elements.item(0).getChildNodes().item(0)
.getAttributes().item(0).getNodeValue();
String eDesc = elements.item(0).getChildNodes().item(0)
.getAttributes().item(1).getNodeValue();
Exception e = new Exception("Server Response: Error Code- "
+ eCode + " -" + eDesc);
System.out.println("Baradwaj Exception"+e);
throw e;
}
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
} finally {
Log.v(LOG_TAG + " Response value", response);
}
return true;
}
But I am getting an exception saying "Authentication required". Here I am pasting my logcat.
01-05 02:29:47.377: V/TruitonMainActivity Response value(2653): <HEAD><TITLE>Proxy Authorization Required</TITLE></HEAD>
01-05 02:29:47.377: V/TruitonMainActivity Response value(2653): <BODY BGCOLOR="white" FGCOLOR="black"><H1>Proxy Authorization Required</H1><HR>
01-05 02:29:47.377: V/TruitonMainActivity Response value(2653): <FONT FACE="Helvetica,Arial"><B>
01-05 02:29:47.377: V/TruitonMainActivity Response value(2653): Description: Authorization is required for access to this proxy<BR><BR>
01-05 02:29:47.377: V/TruitonMainActivity Response value(2653): </B>Error Code: <BR>HTTP POST Body Is Drained!<BR><BR>
01-05 02:29:47.377: V/TruitonMainActivity Response value(2653): User Agent: <BR>Apache-HttpClient/UNAVAILABLE (java 1.4)<BR><BR>
01-05 02:29:47.377: V/TruitonMainActivity Response value(2653): Error Detail: <BR><PRE>(None).</PRE><BR><BR></B></FONT>
01-05 02:29:47.377: V/TruitonMainActivity Response value(2653): <HR>
01-05 02:29:47.377: V/TruitonMainActivity Response value(2653): <!-- default "Proxy Authorization Required" response (407) -->
01-05 02:29:47.377: V/TruitonMainActivity Response value(2653): </BODY>
01-05 02:29:47.377: V/TruitonMainActivity Response value(2653): ��
01-05 02:29:47.407: V/TruitonMainActivity AsyncTask(2653): Success
But I am able to access the URL "http://xxx.xxx.xx.xx:7001/yantrawebservices/yantrawebservice?WSDL" from the browser in the emulator. Please tell me where I am going wrong.