2013-08-02 1 views
10

KSOAP2 라이브러리의 HttpTransportSE 개체가 있습니다. 모트를 포함하고있을 가능성이있는 응답 파일을 덤프하고 싶습니다. 9697 문자. 현재 나는 수송을함으로써 그것을하고있다.KSOAP2에서 transport.dump 크기를 256 바이트에서 512 바이트 이상으로 늘리는 방법은 무엇입니까?

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

그러나 그것은 나에게 마침내 ... 반 응답을 제공합니다.

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; 
    } 
} 

당신은 유일한

INT의 RD 것으로 =된다

는 내부 코딩 구조에서 나는 아래처럼 작성하고 responseDump의 파괴에 대해 256 바이트를 사용하는 것으로 .read (buf, 0, 256);

그렇다면 responseDump 크기를 늘릴 수있는 옵션이 있습니까?

+0

대답은 : 만약 (transport.debug) { 바이트 [] = transport.responseDump.getBytes이다(); 문자열 경로 = "/ mnt/sdcard/appData /"; 파일 file = 새 파일 (경로 + "responseDump.xml"); if (! file.exists()) { file.createNewFile(); } BufferedOutputStream bos = 새 BufferedOutputStream (새 FileOutputStream (file)); bos.write (있음); bos.flush(); bos.close(); } 감사합니다. –

답변

1

ksoap에는 제한이 없지만 logcat에 있습니다. Logcat은 긴 문자열을 출력하지 않으므로 파일에 쓰거나 로그에 조각으로 글을 씁니다.

+0

이 내부 코드가 ksoap2 인 경우에만 256 바이트 만 사용합니다. 그래서 비록 내가 바이트로 바이트를 작성하려고한다면 그것은 완전한 responseDump가 아니다. 아직도 당신은 솔루션으로 가능한 친절한 대응을 생각합니다. 그리고 다시 감사드립니다. –

+0

첫 번째 256 바이트뿐만 아니라 256 바이트의 버퍼 크기로 한 사이클 씩 입력 스트림을 읽습니다. – esentsov

+0

[이것을 확인하십시오] (http://stackoverflow.com/questions/8888654/android-set-max-length-of-logcat-messages) – 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(); 
} 
관련 문제