Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AndroidHttpTransport extends Transport {
- /**
- * Creates instance of HttpTransport with set url
- *
- * @param url
- * the destination to POST SOAP data
- */
- public AndroidHttpTransport(String url) {
- super(url);
- }
- /**
- * set the desired soapAction header field
- *
- * @param soapAction
- * the desired soapAction
- * @param envelope
- * the envelope containing the information for the soap call.
- */
- @Override
- public void call(String soapAction, SoapEnvelope envelope) throws IOException, XmlPullParserException {
- if (soapAction == null)
- soapAction = "\"\"";
- byte[] requestData = createRequestData(envelope);
- requestDump = debug ? new String(requestData) : null;
- responseDump = null;
- ServiceConnection connection = getServiceConnection();
- connection.connect();
- try {
- connection.setRequestProperty("User-Agent", "kSOAP/1.0");
- connection.setRequestProperty("SOAPAction", soapAction);
- connection.setRequestProperty("Content-Type", "text/xml;charset=utf-8");
- connection.setRequestProperty("Connection", "close");
- connection.setRequestProperty("Content-Length", "" + requestData.length);
- connection.setRequestMethod("POST");
- OutputStream os = connection.openOutputStream();
- os.write(requestData, 0, requestData.length);
- os.flush();
- os.close();
- requestData = null;
- InputStream is;
- try {
- is = connection.openInputStream();
- } catch (IOException e) {
- is = connection.getErrorStream();
- if (is == null) {
- connection.disconnect();
- throw (e);
- }
- }
- //if (debug) {
- if (true) {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- byte[] buf = new byte[512];
- while (true) {
- int rd = is.read(buf, 0, 512);
- if (rd == -1)
- break;
- bos.write(buf, 0, rd);
- }
- bos.flush();
- buf = bos.toByteArray();
- responseDump = new String(buf);
- SoapExampleActivity.response = unescape(responseDump);
- SoapExampleActivity.response = responseDump;
- is.close();
- is = new ByteArrayInputStream(buf);
- }
- parseResponse(envelope, is);
- } finally {
- connection.disconnect();
- }
- }
- protected ServiceConnection getServiceConnection() throws IOException {
- return new AndroidServiceConnection(url);
- }
- public static String unescape (String s)
- {
- while (true)
- {
- int n=s.indexOf("&#");
- if (n<0) break;
- int m=s.indexOf(";",n+2);
- if (m<0) break;
- try
- {
- s=s.substring(0,n)+(char)(Integer.parseInt(s.substring(n+2,m)))+
- s.substring(m+1);
- }
- catch (Exception e)
- {
- return s;
- }
- }
- s=s.replace(""","\"");
- s=s.replace("<","<");
- s=s.replace(">",">");
- s=s.replace("&","&");
- return s;
- }
- @Override
- public List call(String arg0, SoapEnvelope arg1, List arg2)
- throws IOException, XmlPullParserException {
- return null;
- }
- @Override
- public String getHost() {
- return null;
- }
- @Override
- public String getPath() {
- return null;
- }
- @Override
- public int getPort() {
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement