I am working in a proxy based environment, where I am not able to consume SOAP web service through emulator. Does anyone know how to consume SOAP web service in a proxy based environment?
I have created this class:
import java.io.IOException;
import java.net.Proxy;
import org.kobjects.base64.Base64;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.transport.ServiceConnection;
//class to handle authentication in a proxy based environment
public class HttpTransportBasicAuth extends HttpTransportSE {
//username and password for accessing a proxy based network
private String username;
private String password;
public HttpTransportBasicAuth(String url, String username, String password) {
super(url);
this.username = username;
this.password = password;
}
@Override
public ServiceConnection getServiceConnection() throws IOException {
ServiceConnection serviceConnection = super.getServiceConnection();
addBasicAuthentication(serviceConnection);
return serviceConnection;
}
protected void addBasicAuthentication(ServiceConnection serviceConnection)
throws IOException {
if (username != null && password != null) {
StringBuffer buffer = new StringBuffer(username);
buffer.append(':').append(password);
byte[] bytes = buffer.toString().getBytes();
buffer.setLength(0);
buffer.append("Basic ");
Base64.encode(bytes, 0, bytes.length, buffer);
serviceConnection.setRequestProperty
("Authorization", buffer.toString());
}
}
}
and then I created its object like:
HttpTransportBasicAuth androidHttpTransportSE = new HttpTransportBasicAuth(url); androidHttpTransportSE.call(url);
but its returning null pointer exception, I am not able to findout what could be the solution to access webservice in a proxy based network..Please help
Thanks in advance