01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: * See the GNU Lesser General Public License for more details at gnu.org.
11: */
12:
13: package com.eviware.soapui.impl.wsdl.submit.transports.http;
14:
15: import java.io.ByteArrayInputStream;
16: import java.io.IOException;
17: import java.io.InputStream;
18: import java.io.OutputStream;
19:
20: import javax.activation.DataSource;
21:
22: import com.eviware.soapui.SoapUI;
23: import com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport;
24: import com.eviware.soapui.support.Tools;
25:
26: /**
27: * DataSource for a standard POST response
28: *
29: * @author ole.matzura
30: */
31:
32: public class PostResponseDataSource implements DataSource {
33: private final TimeablePostMethod postMethod;
34: private byte[] data;
35:
36: public PostResponseDataSource(TimeablePostMethod postMethod) {
37: this .postMethod = postMethod;
38:
39: try {
40: data = Tools.readAll(postMethod.getResponseBodyAsStream(),
41: 0).toByteArray();
42:
43: if (HttpClientSupport.isZippedResponse(postMethod)) {
44: data = HttpClientSupport.decompress(data);
45: }
46: } catch (Exception e) {
47: SoapUI.logError(e);
48: }
49: }
50:
51: public long getDataSize() {
52: return data == null ? -1 : data.length;
53: }
54:
55: public String getContentType() {
56: return postMethod.getResponseHeader("Content-Type").getValue();
57: }
58:
59: public InputStream getInputStream() throws IOException {
60: return new ByteArrayInputStream(data);
61: }
62:
63: public String getName() {
64: return postMethod.getName() + " response for "
65: + postMethod.getPath().toString();
66: }
67:
68: public OutputStream getOutputStream() throws IOException {
69: return null;
70: }
71:
72: }
|