View Javadoc

1   /*
2    * Copyright 2000-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.jetspeed.services.webpage;
18  
19  // java.io
20  import java.io.IOException;
21  
22  // javax.servlet
23  import javax.servlet.http.*;
24  
25  // java.net
26  import java.net.URLConnection;
27  
28  /***
29   * Standard interface for all proxied sessions.
30   * Handles the communication and session state between the webpage service and a single site
31   *
32   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
33   * @version $Id: SiteSession.java,v 1.3 2004/02/23 03:46:26 jford Exp $ 
34   */
35  public interface SiteSession
36  {    
37  
38      /***
39       * Given a site URL, proxies the content of that site.  
40       * The actual rules on rewriting the proxied resource are dependent on implementation 
41       * and configuration parameters. For example, all HTTP hyperlinks(HREFs) could be
42       * rewritten as proxied hyperlinks back to this Proxy.
43       * Or all relative references to web resources (images, stylesheets, ...) could be
44       * rewritten as absolute references, but are not proxied.
45       *
46       * @param site the proxied resource address.
47       * @param data the request specific rundata.
48       *
49       * @exception IOException a servlet exception.
50       */    
51      public void proxy(String site, ProxyRunData data)
52                      throws IOException;
53  
54      /***
55       * Gets the HTML content from the URL Connection stream and returns it as a Stream
56       *
57       * @param con The URLConnection to read from.
58       * @param data the request specific rundata.
59       * @return The HTML Content from the stream.
60       *
61       * @deprecate
62       * @exception IOException a servlet exception.
63       */
64      public String getContentAsString(URLConnection con,
65                                       ProxyRunData data,
66                                       String url) 
67                      throws IOException;
68  
69      
70      /***
71       * Retrieves the content from the URL Connection stream and writes it to servlet response
72       *
73       * @param con The URLConnection to read from.
74       *
75       * @exception IOException a servlet exception.
76       */
77      public void drainContent(URLConnection con,
78                               HttpServletResponse response) throws IOException;
79  
80      /***
81        * Given a cookie, it first checks to see if that cookie is already
82        * managed in this session. If it is, it means that the session has
83        * timed out and that the network element has now created a new session.
84        * In that case, replace the cookie, and re-establish the session (logon)
85        * If its a new cookie, we will still need to logon, and and the cookie to
86        * the managed cookies collection for this session.
87        *
88        * @param cookie new cookie returned from target server.
89        * @return true when a new cookie added, false when updated.
90        *
91        */
92      public boolean addCookieToSession(Cookie cookie);
93  
94      /***
95       * Logs on to the target host
96       *
97       * @param data the request specific rundata.     
98       *
99       * @exception IOException a servlet exception.
100      */    
101     public boolean logon(ProxyRunData data)
102                       throws IOException;
103 
104 
105     /***
106      * Logs out of the target host
107      *
108      * @param data the request specific rundata.     
109      *
110      * @exception IOException a servlet exception.
111      */    
112     public boolean logout(ProxyRunData data)
113                       throws IOException;
114 
115 
116     /***
117      * Reads stream for proxied host, runs a rewriter against that stream,
118      * rewriting relevant links, and writes the parsed stream back to the client.
119      *
120      * @param request Servlet request.
121      * @param con the URLConnection with proxied host.
122      * @param contentType the contentType of the request.
123      *
124      * @exception IOException a servlet exception.
125      */    
126     public void rewriteContent(ProxyRunData data,
127                                URLConnection con,
128                                int contentType,
129                                String url) throws IOException;
130 
131     /***
132      * Gets the hitcount for this session.
133      *
134      * @return the hitcount for this session.
135      */
136     public int getHitCount();
137 
138     /***
139      * Increments the hitcount for this session.
140      *
141      */
142     public void incHitCount();
143 
144     /***
145      * Gets the cache count for this session.
146      *
147      * @return the cache count for this session.
148      */
149     public int getCacheCount();
150 
151     /***
152      * Increments the hitcount for this session.
153      *
154      */
155     public void incCacheCount();
156 
157 }
158