2013-08-02 4 views
10

मेरे पास KSOAP2 लाइब्रेरी से HttpTransportSE ऑब्जेक्ट है। मैं प्रतिक्रिया फ़ाइल को डंप करना चाहता हूं जिसमें मोटे हो सकता है तो सरल 9 6 9 7 वर्ण। वर्तमान में मैं परिवहन करके इसे कर रहा हूं।केएसओएपी 2 में 256 बाइट्स से 512 या अधिक बाइट्स तक transport.dump आकार को कैसे बढ़ाया जाए?

transport.debug = true; 
System.out.println("Response ----------"+transport.responseDump); 

लेकिन यह मुझे ... पिछले पर साथ आधा प्रतिक्रिया देता है।

अपने आंतरिक कोडिंग संरचना में मैंने पाया है कि यह करते हैं और ऐसा responseDump है को नष्ट करने के लिए 256 बाइट्स उपयोग कर रहा है नीचे दिखाया गया है जैसे:

package org.ksoap2.transport; 

import java.io.ByteArrayInputStream; 
import java.io.ByteArrayOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.net.MalformedURLException; 
import java.net.Proxy; 
import java.net.URL; 
import java.util.List; 
import org.ksoap2.HeaderProperty; 
import org.ksoap2.SoapEnvelope; 
import org.xmlpull.v1.XmlPullParserException; 

public class HttpTransportSE extends Transport 
{ 
    private ServiceConnection connection; 

    public HttpTransportSE(String url) 
    { 
    super(null, url); 
    } 

    public HttpTransportSE(Proxy proxy, String url) 
    { 
    super(proxy, url); 
    } 

    public HttpTransportSE(String url, int timeout) 
    { 
    super(url, timeout); 
    } 

    public HttpTransportSE(Proxy proxy, String url, int timeout) { 
    super(proxy, url, timeout); 
    } 

    public void call(String soapAction, SoapEnvelope envelope) 
    throws IOException, XmlPullParserException 
    { 
    call(soapAction, envelope, null); 
    } 

    public List call(String soapAction, SoapEnvelope envelope, List headers) 
    throws IOException, XmlPullParserException 
    { 
    if (soapAction == null) { 
     soapAction = "\"\""; 
    } 
    byte[] requestData = createRequestData(envelope); 

    this.requestDump = (this.debug ? new String(requestData) : null); 
    this.responseDump = null; 

    this.connection = getServiceConnection(); 

    this.connection.setRequestProperty("User-Agent", "kSOAP/2.0"); 

    if (envelope.version != 120) { 
     this.connection.setRequestProperty("SOAPAction", soapAction); 
    } 
    this.connection.setRequestProperty("Content-Type", "text/xml"); 
    this.connection.setRequestProperty("Connection", "close"); 
    this.connection.setRequestProperty("Content-Length", "" + requestData.length); 

    if (headers != null) { 
     for (int i = 0; i < headers.size(); i++) { 
     HeaderProperty hp = (HeaderProperty)headers.get(i); 
     this.connection.setRequestProperty(hp.getKey(), hp.getValue()); } } 
this.connection.setRequestMethod("POST"); 
    this.connection.connect(); 

    OutputStream os = this.connection.openOutputStream(); 

    os.write(requestData, 0, requestData.length); 
    os.flush(); 
    os.close(); 
    requestData = null; 

    List retHeaders = null; 
    InputStream is; 
    try { this.connection.connect(); 
     is = this.connection.openInputStream(); 
     retHeaders = this.connection.getResponseProperties(); 
    } catch (IOException e) { 
     is = this.connection.getErrorStream(); 

     if (is == null) { 
     this.connection.disconnect(); 
     throw e; 
     } 
    } 

    if (this.debug) { 
     ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
     byte[] buf = new byte[256]; 
     while (true) 
     { 
     int rd = is.read(buf, 0, 256); 
     if (rd == -1) 
      break; 
     bos.write(buf, 0, rd); 
     } 

     bos.flush(); 
     buf = bos.toByteArray(); 
     this.responseDump = new String(buf); 
     is.close(); 
     is = new ByteArrayInputStream(buf); 
    } 

    parseResponse(envelope, is); 
    return retHeaders; 
    } 

    public ServiceConnection getConnection() { 
    return (ServiceConnectionSE)this.connection; 
    } 

    protected ServiceConnection getServiceConnection() throws IOException { 
    return new ServiceConnectionSE(this.proxy, this.url, this.timeout); 
    } 

    public String getHost() 
    { 
    String retVal = null; 
    try 
    { 
     retVal = new URL(this.url).getHost(); 
    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } 

    return retVal; 
    } 

    public int getPort() 
    { 
    int retVal = -1; 
    try 
    { 
     retVal = new URL(this.url).getPort(); 
    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } 

    return retVal; 
    } 

    public String getPath() 
    { 
    String retVal = null; 
    try 
    { 
     retVal = new URL(this.url).getPath(); 
    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } 

    return retVal; 
    } 
} 

आपको लगता है कि अपने ही

पूर्णांक वां पाया = है .read (buf, 0, 256);

तो क्या प्रतिक्रिया डंप आकार बढ़ाने के लिए कोई विकल्प है?

+0

जवाब है: अगर (transport.debug) { बाइट [] है = transport.responseDump.getBytes(); स्ट्रिंग पथ = "/ mnt/sdcard/appData /"; फ़ाइल फ़ाइल = नई फ़ाइल (पथ + "प्रतिक्रिया डंप.एक्सएमएल"); अगर (! File.exists()) { file.createNewFile(); } BufferedOutputStream बोस = नया BufferedOutputStream (नई फ़ाइलऑटपुटस्ट्रीम (फ़ाइल)); bos.write (है); बोस.फ्लश(); bos.close(); } धन्यवाद esentsov। –

उत्तर

1

ksoap में कोई सीमा नहीं है, लेकिन यह logcat में है। लॉगकैट लंबे तारों को प्रिंट नहीं करता है, इसलिए लॉग में टुकड़े से फ़ाइल में लिखें या टुकड़ा लिखें।

+0

यदि आप ksoap2 का यह आंतरिक कोड देखते हैं तो केवल 256 बाइट ही लेते हैं। तो अगर मैं बाइट द्वारा बाइट लिखने की कोशिश कर रहा हूं तो यह पूरी प्रतिक्रिया नहीं है डंप। फिर भी ii आपको लगता है कि समाधान के साथ इसकी संभावित प्रतिक्रिया है। और फिर धन्यवाद! –

+0

यह बफर आकार 256 बाइट्स के साथ टुकड़े द्वारा एक चक्र टुकड़े में एक इनपुट स्ट्रीम पढ़ता है, न केवल पहले 256 बाइट्स। – esentsov

+0

[इसे जांचें] (http://stackoverflow.com/questions/8888654/android-set-max-length-of-logcat- संदेश) – esentsov

0
if (transport.debug) 
{ 
byte[] is = transport.responseDump.getBytes(); 
String path="/mnt/sdcard/appData/"; 
File file = new File(path+"responseDump.xml"); 
if (!file.exists()) 
{ 
file.createNewFile(); 
} 
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); bos.write(is); bos.flush(); bos.close(); 
} 
संबंधित मुद्दे