KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > io > HttpTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.io;
18
19 import java.io.BufferedReader JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.io.InputStreamReader JavaDoc;
23 import java.io.OutputStream JavaDoc;
24 import java.io.OutputStreamWriter JavaDoc;
25 import java.net.HttpURLConnection JavaDoc;
26 import java.net.MalformedURLException JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.net.URLConnection JavaDoc;
29
30 import javax.servlet.ServletContext JavaDoc;
31 import javax.servlet.jsp.JspException JavaDoc;
32 import javax.servlet.jsp.JspWriter JavaDoc;
33 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
34 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
35
36 /** A JSP Custom tag to make a HTTP request and output the response.
37   *
38   * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
39   * @version $Revision: 1.2 $
40   */

41 public class HttpTag extends URLTag {
42
43     /** HTTP request method */
44     private String JavaDoc action = "GET";
45     
46     public HttpTag() {
47     }
48     
49     // Tag interface
50
//-------------------------------------------------------------------------
51
public void release() {
52         super.release();
53         action = null;
54     }
55     
56     
57     // Properties
58
//-------------------------------------------------------------------------
59
public void setAction(String JavaDoc action) {
60         this.action = action;
61         setInput( isInputAction( action ) );
62     }
63
64     // Implementation methods
65
//-------------------------------------------------------------------------
66
protected void configureConnection( HttpURLConnection JavaDoc connection ) throws IOException JavaDoc {
67         super.configureConnection(connection);
68         
69         HttpURLConnection JavaDoc httpConnection = (HttpURLConnection JavaDoc) connection;
70         connection.setRequestMethod( action );
71     }
72
73     /** @return true if the given HTTP action should result in some
74       * information being sent as part of the request, such as the POST action
75       */

76     protected boolean isInputAction(String JavaDoc action) {
77         return "POST".equalsIgnoreCase( action ) || "PUT".equalsIgnoreCase( action );
78     }
79 }
80
Popular Tags