01: /*
02: * Copyright ? 2006 Sun Microsystems, Inc. All rights reserved.
03: *
04: * Sun Microsystems, Inc. has intellectual property rights relating to
05: * technology embodied in the product that is described in this document.
06: * In particular, and without limitation, these intellectual property
07: * rights may include one or more of the U.S. patents listed at
08: * http://www.sun.com/patents and one or more additional patents or
09: * pending patent applications in the U.S. and in other countries.
10: *
11: * U.S. Government Rights - Commercial software. Government users are subject
12: * to the Sun Microsystems, Inc. standard license agreement and applicable
13: * provisions of the FAR and its supplements. Use is subject to license terms.
14: * This distribution may include materials developed by third parties.
15: * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
16: * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
17: */
18: package com.sun.portal.app.blog.httpverb;
19:
20: import java.io.IOException;
21: import java.net.HttpURLConnection;
22: import java.net.URL;
23: import org.apache.commons.httpclient.HttpClient;
24: import org.apache.commons.httpclient.HttpMethod;
25: import org.apache.commons.httpclient.methods.GetMethod;
26:
27: public class Get extends HttpVerb {
28: public Get(URL url, String user, String password) {
29: super (url, user, password);
30: }
31:
32: protected int getSuccessStatus() {
33: return HttpURLConnection.HTTP_OK;
34: }
35:
36: public int execute() throws HttpVerbException {
37: try {
38: HttpClient httpClient = new HttpClient();
39: HttpMethod method = new GetMethod(getUrl().toString());
40: addAuthHeader(method);
41: int status = httpClient.executeMethod(method);
42: setStatus(status);
43: setResponseBody(method.getResponseBodyAsStream());
44: return status;
45: } catch (IOException ioe) {
46: setStatus(-1);
47: throw new HttpVerbException(ioe);
48: }
49: }
50: }
|