Source Code Cross Referenced for CookieDemoApp.java in  » Net » Apache-common-HttpClient » examples » 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 » Net » Apache common HttpClient » examples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/examples/CookieDemoApp.java,v 1.14 2004/02/22 18:08:45 olegk Exp $
003:         * $Revision: 480424 $
004:         * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005:         * ====================================================================
006:         *
007:         *  Licensed to the Apache Software Foundation (ASF) under one or more
008:         *  contributor license agreements.  See the NOTICE file distributed with
009:         *  this work for additional information regarding copyright ownership.
010:         *  The ASF licenses this file to You under the Apache License, Version 2.0
011:         *  (the "License"); you may not use this file except in compliance with
012:         *  the License.  You may obtain a copy of the License at
013:         *
014:         *      http://www.apache.org/licenses/LICENSE-2.0
015:         *
016:         *  Unless required by applicable law or agreed to in writing, software
017:         *  distributed under the License is distributed on an "AS IS" BASIS,
018:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019:         *  See the License for the specific language governing permissions and
020:         *  limitations under the License.
021:         * ====================================================================
022:         *
023:         * This software consists of voluntary contributions made by many
024:         * individuals on behalf of the Apache Software Foundation.  For more
025:         * information on the Apache Software Foundation, please see
026:         * <http://www.apache.org/>.
027:         *
028:         * [Additional notices, if required by prior licensing conditions]
029:         *
030:         */
031:
032:        import org.apache.commons.httpclient.Cookie;
033:        import org.apache.commons.httpclient.HttpClient;
034:        import org.apache.commons.httpclient.HttpState;
035:        import org.apache.commons.httpclient.cookie.CookiePolicy;
036:        import org.apache.commons.httpclient.methods.GetMethod;
037:
038:        /**
039:         *
040:         * This is a sample application that demonstrates
041:         * how to use the Jakarta HttpClient API.
042:         *
043:         * This application sets an HTTP cookie and
044:         * updates the cookie's value across multiple
045:         * HTTP GET requests.
046:         *
047:         * @author Sean C. Sullivan
048:         * @author Oleg Kalnichevski
049:         *
050:         */
051:        public class CookieDemoApp {
052:
053:            /**
054:             *
055:             * Usage:
056:             *          java CookieDemoApp http://mywebserver:80/
057:             *
058:             *  @param args command line arguments
059:             *                 Argument 0 is a URL to a web server
060:             *
061:             *
062:             */
063:            public static void main(String[] args) throws Exception {
064:                if (args.length != 1) {
065:                    System.err.println("Usage: java CookieDemoApp <url>");
066:                    System.err.println("<url> The url of a webpage");
067:                    System.exit(1);
068:                }
069:                // Get target URL
070:                String strURL = args[0];
071:                System.out.println("Target URL: " + strURL);
072:
073:                // Get initial state object
074:                HttpState initialState = new HttpState();
075:                // Initial set of cookies can be retrieved from persistent storage and 
076:                // re-created, using a persistence mechanism of choice,
077:                Cookie mycookie = new Cookie(".foobar.com", "mycookie",
078:                        "stuff", "/", null, false);
079:                // and then added to your HTTP state instance
080:                initialState.addCookie(mycookie);
081:
082:                // Get HTTP client instance
083:                HttpClient httpclient = new HttpClient();
084:                httpclient.getHttpConnectionManager().getParams()
085:                        .setConnectionTimeout(30000);
086:                httpclient.setState(initialState);
087:
088:                // RFC 2101 cookie management spec is used per default
089:                // to parse, validate, format & match cookies
090:                httpclient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
091:                // A different cookie management spec can be selected
092:                // when desired
093:
094:                //httpclient.getParams().setCookiePolicy(CookiePolicy.NETSCAPE);
095:                // Netscape Cookie Draft spec is provided for completeness
096:                // You would hardly want to use this spec in real life situations
097:                //httppclient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
098:                // Compatibility policy is provided in order to mimic cookie
099:                // management of popular web browsers that is in some areas 
100:                // not 100% standards compliant
101:
102:                // Get HTTP GET method
103:                GetMethod httpget = new GetMethod(strURL);
104:                // Execute HTTP GET
105:                int result = httpclient.executeMethod(httpget);
106:                // Display status code
107:                System.out.println("Response status code: " + result);
108:                // Get all the cookies
109:                Cookie[] cookies = httpclient.getState().getCookies();
110:                // Display the cookies
111:                System.out.println("Present cookies: ");
112:                for (int i = 0; i < cookies.length; i++) {
113:                    System.out.println(" - " + cookies[i].toExternalForm());
114:                }
115:                // Release current connection to the connection pool once you are done
116:                httpget.releaseConnection();
117:            }
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.