~ubuntu-branches/ubuntu/maverick/eucalyptus/maverick

« back to all changes in this revision

Viewing changes to clc/modules/storage-controller/src/main/java/edu/ucsb/eucalyptus/cloud/ws/HttpReader.java

  • Committer: Bazaar Package Importer
  • Author(s): Dave Walker (Daviey)
  • Date: 2010-07-21 17:27:10 UTC
  • mfrom: (1.1.38 upstream)
  • Revision ID: james.westby@ubuntu.com-20100721172710-7xv07dmdqgivc3t9
Tags: 2.0~bzr1211-0ubuntu1
* New major upstream version merge, 2.0 (r1211).
* debian/patches/:
  - 01-wsdl-stubs.patch, debian/wsdl.md5sums: wsdl stubs updated.
  - 02-Makefile.patch: Updated to reflect new code layout.
  - 07-local_support_euca_conf-in.patch: Updated to reflect new code layout.
  - 08-ubuntu-default-networking.patch: Refreshed.
  - 09-small-128-192MB.patch: Updated to point to new location.
  - 10-disable-iscsi.patch: Refreshed.
  - 11-state-cleanup-memleakfix.patch: Removed, fixed upstream.
  - 15-fix-default-ramdisk.patch: Updated to point to new location.
  - 16-kvm_libvirt_xml_default_use_kvm.patch: Updated to reflect changes.
  - 17-fix_walrus_OOM_errors.patch: Removed, fixed upstream.
  - 18-priv_security.patch: Updated to reflect upstream changes.
  - 20-brute-force-webui.patch: Updated to reflect upstream changes. 
  - 21-eucalyptus-1.7-with-gwt-1.6.4.patch: New patch, allows 
    eucalyptus-1.7 to be built against gwt 1.6.4. Based on patch courtesy 
    of Dmitrii Zagorodnov, upstream. (LP: #597330)
* debian/eucalyptus-java-common.links: 
  - Changed symlink for groovy, point to groovy.all.jar, making compatiable 
    with groovy versions >1.7. (LP: #595421)
  - Added ant.jar & jetty-rewrite-handler.jar as they are now required.
* debian/control
  - & debian/build-jars: Added libjavassist-java and libjetty-extra-java as 
    build dependencies.
  - Added libjetty-extra-java as a dependency of eucalyptus-java-common
* The binary resulting jar's have been renamed from eucalyptus-*-1.6.2.jar
  to eucalyptus-*-main.jar:    
  - debian/eucalyptus-cc.upstart
  - debian/eucalyptus-cloud.install
  - debian/eucalyptus-common.eucalyptus.upstart
  - debian/eucalyptus-java-common.install
  - debian/eucalyptus-network.upstart
  - debian/eucalyptus-sc.install
  - debian/eucalyptus-walrus.install
* debian/eucalyptus-java-common.install: New upstream jars that have been
  installed:
  - eucalyptus-db-hsqldb-ext-main.jar
  - eucalyptus-component-main.jar
* debian/control:
  - Updated Standards Version to 3.8.4 (no change)
  - Updated the upstream Homepage to: http://open.eucalyptus.com/
  - Changed Vcs-Bzr to reflect new location of Ubuntu hosted development branch.
  - Made the Build Dependency of groovy and the binary eucalyptus-java-common
    package depend on version >=1.7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
import java.util.concurrent.LinkedBlockingQueue;
9
9
import java.util.zip.GZIPInputStream;
10
10
 
 
11
import org.apache.commons.httpclient.Header;
11
12
import org.apache.commons.httpclient.HttpClient;
12
13
import org.apache.commons.httpclient.HttpMethodBase;
13
14
import org.apache.log4j.Logger;
14
15
 
 
16
import com.eucalyptus.auth.util.Hashes;
15
17
import com.eucalyptus.util.StorageProperties;
16
18
 
 
19
import edu.ucsb.eucalyptus.util.StreamConsumer;
17
20
import edu.ucsb.eucalyptus.util.SystemUtil;
18
21
import edu.ucsb.eucalyptus.util.WalrusDataMessage;
19
22
 
27
30
        private HttpClient httpClient;
28
31
        private HttpMethodBase method;
29
32
        private File file;
 
33
        private String tempPath;
30
34
        private boolean compressed;
31
35
 
32
36
        public HttpReader(String path, LinkedBlockingQueue<WalrusDataMessage> getQueue, File file, String eucaOperation, String eucaHeader) {
40
44
                method = constructHttpMethod(httpVerb, addr, eucaOperation, eucaHeader);
41
45
        }
42
46
 
43
 
        public HttpReader(String path, LinkedBlockingQueue<WalrusDataMessage> getQueue, File file, String eucaOperation, String eucaHeader, boolean compressed) {
 
47
        public HttpReader(String path, LinkedBlockingQueue<WalrusDataMessage> getQueue, File file, String eucaOperation, String eucaHeader, boolean compressed, String tempPath) {
44
48
                this(path, getQueue, file, eucaOperation, eucaHeader);
45
49
                this.compressed = compressed;
 
50
                this.tempPath = tempPath;
46
51
        }
47
52
 
48
53
        public String getResponseAsString() {
74
79
                FileOutputStream fileOutputStream = null;
75
80
                BufferedOutputStream bufferedOut = null;
76
81
                try {
77
 
                        File compressedFile = new File(file.getAbsolutePath() + ".gz");                         
78
 
                        assert(method != null);
 
82
                        File outFile;
 
83
                        if(compressed)
 
84
                                outFile = new File(tempPath + File.separator + file.getName() + Hashes.getRandom(16) + ".gz");          
 
85
                        else
 
86
                                outFile = file;
79
87
                        httpClient.executeMethod(method);
80
88
                        InputStream httpIn;
81
89
                        httpIn = method.getResponseBodyAsStream();
82
90
                        int bytesRead;
83
 
                        fileOutputStream = new FileOutputStream(compressedFile);
 
91
                        fileOutputStream = new FileOutputStream(outFile);
84
92
                        bufferedOut = new BufferedOutputStream(fileOutputStream);
85
93
                        while((bytesRead = httpIn.read(bytes)) > 0) {
86
94
                                bufferedOut.write(bytes, 0, bytesRead);
87
95
                        }
88
 
 
 
96
                        bufferedOut.close();
89
97
                        if(compressed) {
90
 
                                SystemUtil.run(new String[]{"/bin/gunzip", compressedFile.getAbsolutePath()});
 
98
                                try
 
99
                                {
 
100
                                        Runtime rt = Runtime.getRuntime();
 
101
                                        Process proc = rt.exec(new String[]{ "/bin/gunzip", "-c", outFile.getAbsolutePath()});
 
102
                                        StreamConsumer error = new StreamConsumer(proc.getErrorStream());
 
103
                                        StreamConsumer output = new StreamConsumer(proc.getInputStream(), file);
 
104
                                        error.start();
 
105
                                        output.start();
 
106
                                        output.join();
 
107
                                        error.join();
 
108
                                } catch (Throwable t) {
 
109
                                        LOG.error(t);
 
110
                                }
 
111
                                if(!outFile.delete()) {
 
112
                                        LOG.error("Unable to delete temporary file: " + outFile.getAbsolutePath());
 
113
                                }
91
114
                        }
92
 
                        method.releaseConnection();
93
115
                } catch (Exception ex) {
94
116
                        LOG.error(ex, ex);
95
117
                } finally {
 
118
                        method.releaseConnection();
96
119
                        if(bufferedOut != null) {
97
120
                                try {
98
121
                                        bufferedOut.close();
135
158
                        getResponseToFile();
136
159
                }
137
160
        }
138
 
}
 
 
b'\\ No newline at end of file'
 
161
 
 
162
        public String getResponseHeader(String headerName) {
 
163
                try {
 
164
                        httpClient.executeMethod(method);
 
165
                        Header value = method.getResponseHeader(headerName);
 
166
                        method.releaseConnection();
 
167
                        if(value != null)
 
168
                            return value.getValue();
 
169
                } catch(Exception ex) {
 
170
                        LOG.error(ex, ex);
 
171
                }
 
172
                return null;
 
173
        }
 
174
}