| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 |
<!-- |
| 3 |
|
| 4 |
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 5 |
|
| 6 |
Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved. |
| 7 |
|
| 8 |
The contents of this file are subject to the terms of either the GNU |
| 9 |
General Public License Version 2 only ("GPL") or the Common Development |
| 10 |
and Distribution License("CDDL") (collectively, the "License"). You |
| 11 |
may not use this file except in compliance with the License. You can |
| 12 |
obtain a copy of the License at |
| 13 |
http://glassfish.java.net/public/CDDL+GPL_1_1.html |
| 14 |
or packager/legal/LICENSE.txt. See the License for the specific |
| 15 |
language governing permissions and limitations under the License. |
| 16 |
|
| 17 |
When distributing the software, include this License Header Notice in each |
| 18 |
file and include the License file at packager/legal/LICENSE.txt. |
| 19 |
|
| 20 |
GPL Classpath Exception: |
| 21 |
Oracle designates this particular file as subject to the "Classpath" |
| 22 |
exception as provided by Oracle in the GPL Version 2 section of the License |
| 23 |
file that accompanied this code. |
| 24 |
|
| 25 |
Modifications: |
| 26 |
If applicable, add the following below the License Header, with the fields |
| 27 |
enclosed by brackets [] replaced by your own identifying information: |
| 28 |
"Portions Copyright [year] [name of copyright owner]" |
| 29 |
|
| 30 |
Contributor(s): |
| 31 |
If you wish your version of this file to be governed by only the CDDL or |
| 32 |
only the GPL Version 2, indicate your decision by adding "[Contributor] |
| 33 |
elects to include this software in this distribution under the [CDDL or GPL |
| 34 |
Version 2] license." If you don't indicate a single choice of license, a |
| 35 |
recipient has the option to distribute your version of this file under |
| 36 |
either the CDDL, the GPL Version 2 or to extend the choice of license to |
| 37 |
its licensees as provided above. However, if you add GPL Version 2 code |
| 38 |
and therefore, elected the GPL Version 2 license, then the option applies |
| 39 |
only if the new code is made subject to such option by the copyright |
| 40 |
holder. |
| 41 |
|
| 42 |
--> |
| 43 |
<html> |
| 44 |
<head> |
| 45 |
<meta http-equiv="content-type" content="text/html;charset=utf-8"/> |
| 46 |
<title>OAuth Client Sample - Twitter Client</title> |
| 47 |
</head> |
| 48 |
<body style="width: 50em"> |
| 49 |
<h1>OAuth Client Sample - Twitter Client</h1> |
| 50 |
|
| 51 |
<p> |
| 52 |
This example demonstrates how to develop a simple web app client |
| 53 |
utilizing Jersey client API and Jersey OAuth support. |
| 54 |
</p> |
| 55 |
|
| 56 |
<h2>Contents</h2> |
| 57 |
|
| 58 |
<p> |
| 59 |
This example consists of the main class (<code>App</code>) and two JAXB beans |
| 60 |
used for unmarshaling the responses from Twitter (<code>Status</code> and <code>User</code>). |
| 61 |
</p> |
| 62 |
|
| 63 |
<h2>Running the Example</h2> |
| 64 |
|
| 65 |
<h3>Registering with Twitter</h3> |
| 66 |
|
| 67 |
<p> |
| 68 |
Before running the example, you have to register your own application |
| 69 |
with Twitter (to obtain consumer key and consumer secret you have to use |
| 70 |
to configure this client). You can do it as follows: |
| 71 |
</p> |
| 72 |
<ol> |
| 73 |
<li>Go to <a href="https://dev.twitter.com/apps">Twitter Developers Page</a>, sign in with your Twitter account and click <b>Create |
| 74 |
an app</b> link. If you are new to Twitter, you will need to Sign up. |
| 75 |
</li> |
| 76 |
<li>Fill out the "Create an application" form - you have to pick a unique application name (e.g. app12345678), put in |
| 77 |
some description, put in something for app website (e.g. http://jersey.java.net), |
| 78 |
Accept terms by selecting <b>Yes, I agree</b> in "Twitter Content" checkbox, enter captcha. |
| 79 |
</li> |
| 80 |
<li>Click <b>Create your twitter application</b> button.</li> |
| 81 |
<li>You will be presented with consumer key, consumer secret and other details for your registered application.</li> |
| 82 |
|
| 83 |
</ol> |
| 84 |
<h3>Running for the First Time</h3> |
| 85 |
|
| 86 |
<p>Enter the following on the command-line:</p> |
| 87 |
|
| 88 |
<pre> |
| 89 |
mvn clean compile exec:java -DforkMode=never -DconsumerKey=<consumer key assigned to your app> -DconsumerSecret=<consumer secret assigned to your app> |
| 90 |
</pre> |
| 91 |
<h3>Subsequent Runs</h3> |
| 92 |
|
| 93 |
<p>After you run the application for the first time, it stores the consumer key, secret and token and token secret |
| 94 |
in a property file for future use. So, for subsequent runs you don't have to specify these as system properties. |
| 95 |
The following command is good enough for running the application after it was built, run for the first time and |
| 96 |
the property file was created:</p> |
| 97 |
<pre> |
| 98 |
mvn exec:java |
| 99 |
</pre> |
| 100 |
<h2>Troubleshooting</h2> |
| 101 |
|
| 102 |
<h3>HTTP Proxy</h3> |
| 103 |
|
| 104 |
<p>Behind a HTTP proxy, you will need to setup the following system properties to communicate with the Twitter server: |
| 105 |
<ul> |
| 106 |
<li>http.proxyHost - the name of the proxy host.</li> |
| 107 |
<li>http.proxyPort - the port of the proxy host.</li> |
| 108 |
<li>http.proxyAuth - the user name and password to use when connecting to the proxy; this string should be the user name and |
| 109 |
password separated by a colon (e.g., rickhall:mypassword). |
| 110 |
</li> |
| 111 |
</ul> |
| 112 |
|
| 113 |
These system properties can be set directly on the command line when starting the JVM using the standard "-D<prop>=<value>" |
| 114 |
syntax.</p> |
| 115 |
|
| 116 |
</body> |
| 117 |
</html> |