KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > remote > hessian > HessianProxyFactory


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

19
20 package org.apache.cayenne.remote.hessian;
21
22 import java.io.IOException JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.net.URLConnection JavaDoc;
25
26 import org.apache.cayenne.remote.RemoteSession;
27
28 /**
29  * A proxy factory that handles HTTP sessions.
30  *
31  * @author Andrus Adamchik
32  * @since 1.2
33  */

34 class HessianProxyFactory extends com.caucho.hessian.client.HessianProxyFactory {
35
36     static final String JavaDoc SESSION_COOKIE_NAME = "JSESSIONID";
37
38     private HessianConnection clientConnection;
39
40     HessianProxyFactory(HessianConnection clientConnection) {
41         this.clientConnection = clientConnection;
42     }
43
44     protected URLConnection JavaDoc openConnection(URL JavaDoc url) throws IOException JavaDoc {
45         URLConnection JavaDoc connection = super.openConnection(url);
46
47         // unfortunately we can't read response cookies without completely reimplementing
48
// 'HessianProxy.invoke()'. Currently (3.0.13) it doesn't allow to cleanly
49
// intercept response... so extract session id from the RemoteSession....
50

51         // add session cookie
52
RemoteSession session = clientConnection.getSession();
53         if (session != null && session.getSessionId() != null) {
54             connection.setRequestProperty("Cookie", SESSION_COOKIE_NAME
55                     + "="
56                     + session.getSessionId());
57         }
58
59         return connection;
60     }
61 }
62
Popular Tags