Skip to content

Commit

Permalink
[RESTEASY-1361] Copying examples to dedicated repository
Browse files Browse the repository at this point in the history
  • Loading branch information
asoldano committed May 24, 2016
1 parent 9b30e22 commit d64e516
Show file tree
Hide file tree
Showing 1,097 changed files with 55,237 additions and 7 deletions.
40 changes: 34 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
*.class
# Intellij
###################
.idea
*.iml

# Eclipse
###################
**/.settings
**/.project
**/.classpath
**/.checkstyle

# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Package Files #
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.war
*.ear
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# examples
RESTEasy examples
48 changes: 48 additions & 0 deletions api-clients/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

Client example with Flickr and Twitter
======================================
This project is a simple example showing usage of @Path, @GET, PUT, POST, and @PathParam. It uses pure streaming
output as well.

System Requirements:
--------------------
* Maven 2.0.9 or higher

Building the project:
--------------------
In root directoy

mvn clean compile

****Flickr Client:
1. apply for an API key from Flickr - http://www.flickr.com/services/api/keys/apply
2. mvn exec:java -Dexec.mainClass="org.jboss.resteasy.examples.flickr.FlickrClient" -Dexec.args="<apiKey>"

****Twitter Client
From August 31, 2010, Basic Auth has been deprecated by Twitter, and all applications must now use OAuth.
So the Twitter Client now uses OAuth to do the authentication. In this example you can see how to inject
OAuth Authentication Header via RESTEasy Proxy Client.

Be sure to run the example *in following step!*:
1. request token from twitter:
mvn exec:java -Dexec.mainClass="org.jboss.resteasy.examples.twitter.TwitterClient" -Dexec.args=request

2. authorize token by twitter:
mvn exec:java -Dexec.mainClass="org.jboss.resteasy.examples.twitter.TwitterClient" -Dexec.args=authorize
In this step you will be provided a link for authentication. Paste it to web browser and grant access to this example.

3. request access token for our example:
mvn exec:java -Dexec.mainClass="org.jboss.resteasy.examples.twitter.TwitterClient" -Dexec.args=access
Now we can play with twitter:

4. tweet:
mvn exec:java -Dexec.mainClass="org.jboss.resteasy.examples.twitter.TwitterClient" -Dexec.args=update

5. query the status:
mvn exec:java -Dexec.mainClass="org.jboss.resteasy.examples.twitter.TwitterClient" -Dexec.args=query

If you meet a '401 Authorization Problem' in the last two steps, it's most probably your token has expired.
Redo the first three steps may solve the problem. Have fun!



104 changes: 104 additions & 0 deletions api-clients/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.jboss.resteasy</groupId>
<artifactId>testable-examples-pom</artifactId>
<version>3.1.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.resteasy.examples</groupId>
<artifactId>examples-api-clients</artifactId>
<version>3.1.0-SNAPSHOT</version>
<description/>

<repositories>
<repository>
<id>jboss</id>
<name>jboss repo</name>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.1.0-SNAPSHOT</version>
<!-- filter out unwanted jars -->
<exclusions>
<exclusion>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>net.oauth.core</groupId>
<artifactId>oauth-provider</artifactId>
</dependency>
<dependency>
<groupId>net.oauth.core</groupId>
<artifactId>oauth-httpclient4</artifactId>
<version>20100601</version>
</dependency>
</dependencies>

<!--
this distributionManagement is only here for RESTEasy automated
testing of examples build. You can remove if you are copying this
pom.xml as a template
-->
<distributionManagement>
<repository>
<id>jboss-releases-repository</id>
<name>JBoss Releases Repository</name>
<url>https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.jboss.resteasy.examples.flickr;

import javax.swing.*;
import java.lang.reflect.Method;

public class BareBonesBrowserLaunch {

private static final String errMsg = "Error attempting to launch web browser";

public static void openURL(String url) {
String osName = System.getProperty("os.name");
try {
if (osName.startsWith("Mac OS")) {
Class fileMgr = Class.forName("com.apple.eio.FileManager");
Method openURL = fileMgr.getDeclaredMethod("openURL",
new Class[] { String.class });
openURL.invoke(null, new Object[] { url });
} else if (osName.startsWith("Windows"))
Runtime.getRuntime().exec(
"rundll32 url.dll,FileProtocolHandler " + url);
else { // assume Unix or Linux
String[] browsers = { "firefox", "opera", "konqueror",
"epiphany", "mozilla", "netscape" };
String browser = null;
for (int count = 0; count < browsers.length && browser == null; count++)
if (Runtime.getRuntime().exec(
new String[] { "which", browsers[count] })
.waitFor() == 0)
browser = browsers[count];
if (browser == null)
throw new Exception("Could not find web browser");
else
Runtime.getRuntime().exec(new String[] { browser, url });
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, errMsg + ":\n"
+ e.getLocalizedMessage());
}
}
}
Loading

0 comments on commit d64e516

Please sign in to comment.