Source Code Cross Referenced for LBSConnection.java in  » J2EE » Enhydra-Application-Framework » com » lutris » applet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Enhydra Application Framework » com.lutris.applet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         * 
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         * 
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         * 
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         * 
019:         * Contributor(s):
020:         * 
021:         * $Id: LBSConnection.java,v 1.2 2006-06-15 13:40:47 sinisa Exp $
022:         */
023:
024:        package com.lutris.applet;
025:
026:        import java.applet.Applet;
027:        import java.io.IOException;
028:        import java.net.MalformedURLException;
029:        import java.net.URL;
030:        import java.net.URLConnection;
031:
032:        //import java.util.*;
033:
034:        /**
035:         *   This file is the counterpart to 
036:         *   com.lutris.appserver.server.httpPresentation.AppletUtils. It is meant
037:         *   to be added to the applet's jar file or classes directory. The methods
038:         *   are split into two files so that the applet does not need to include
039:         *   any com.lutris.appserver.server.* classes. <P>
040:         *
041:         *   A dynamicly generated page contained the <APPLET...> tag that lead to
042:         *   the applet calling this function. That <APPLET...> tag was created by 
043:         *   com.lutris.appserver.server.httpPresentation.AppletUtils.createAppletTag.
044:         *   When the applet wants to establish a connection back to the 
045:         *   Multiserver, simply call the contactServer() and the extra 
046:         *   initialization parameters added by createAppletTag() will be used to
047:         *   contact the server. Specifically, the request will match the user's
048:         *   current session.
049:         *
050:         * @see com.lutris.appserver.server.httpPresentation.AppletUtils
051:         */
052:        public class LBSConnection {
053:
054:            public static final String nameParamName = "cookieName";
055:            public static final String valueParamName = "cookieValue";
056:            public static final String targetParamName = "targetURL";
057:
058:            /**
059:             *  Do not create instances; use the static method.
060:             */
061:            private LBSConnection() {
062:            }
063:
064:            /**
065:             *  Use the extra initialization parameters added to the APPLET tag
066:             *  by AppletUtils.createAppletTag() to open a connection back to
067:             *  the Multiserver, using the same session as the one used
068:             *  to get the HTML page that contained the APPLET tag. <P>
069:             *
070:             *  The resulting URLConnection is ready to have 
071:             *  <CODE>connect()</CODE> called on it. You may initialize more
072:             *  options if you wish, for example <CODE>setDoOutput()</CODE> or
073:             *  <CODE>setRequestMethod()</CODE> before calling <CODE>connect()</CODE>.
074:             *
075:             *  The resulting URLConnection may also be a HttpURLConnection, but
076:             *  this is not guarenteed. In the JDK on Windows and Solaris it is,
077:             *  but when running in Netscape Communicator as an applet, it is not.
078:             *  So to be safe, we return the more generic class. The main 
079:             *  functionality missing is the ability to set the request method.
080:             *  However, if you call <CODE>setDoOutput(true)</CODE> in Communicator,
081:             *  it will issue a POST request.
082:             *
083:             *  @param applet
084:             *   The applet that is calling this method.
085:             *  @return 
086:             *   A connection back to the server, or null if an error occured.
087:             */
088:            public static URLConnection contactServer(Applet applet) {
089:                /*
090:                 *  Get the extra parameters. Cookie is optional.
091:                 */
092:                String targetURL = applet.getParameter(targetParamName);
093:                System.out.println("target = " + targetURL);
094:                if (targetURL == null)
095:                    return null;
096:                String cookieName = applet.getParameter(nameParamName);
097:                System.out.println("name = " + cookieName);
098:                String cookieValue = applet.getParameter(valueParamName);
099:                System.out.println("value = " + cookieValue);
100:                /*
101:                 *  Get ready to contact the server.
102:                 */
103:                URL url = null;
104:                try {
105:                    url = new URL(targetURL);
106:                } catch (MalformedURLException e) {
107:                    System.out.println("bad url!");
108:                    return null;
109:                }
110:                URLConnection conn = null;
111:                try {
112:                    conn = url.openConnection();
113:                    System.out.println("conn = " + conn);
114:                } catch (IOException e) {
115:                    System.out.println("io err");
116:                    return null;
117:                } catch (ClassCastException e) {
118:                    System.out.println("class cast err");
119:                    return null;
120:                } catch (Throwable e) {
121:                    System.out.println("threw " + e);
122:                    return null;
123:                }
124:
125:                /*
126:                 * Optionally set a cookie.
127:                 * This is used to simulate the session cookie.,
128:                 */
129:                if ((cookieName != null) && (cookieValue != null))
130:                    conn.setRequestProperty("Cookie", cookieName + "="
131:                            + cookieValue);
132:                /*
133:                 * That's it. Don't initiate the connection, so the caller may set
134:                 * other parameters, for example method or more headers.
135:                 */
136:                return conn;
137:            }
138:
139:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.