Skip to content

Commit 00f95e7

Browse files
committed
Update of the Amazon FPS library code to get the Co-Branded Service URL and to make a payment from the Java platform on Google App Engine
1 parent 66d2c7a commit 00f95e7

File tree

14 files changed

+644
-13
lines changed

14 files changed

+644
-13
lines changed

.classpath

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="lib" path="third-party/appengine-1.3.1/appengine-api-1.0-sdk-1.3.1.jar"/>
5+
<classpathentry kind="lib" path="third-party/commons-codec-1.3/commons-codec-1.3.jar"/>
6+
<classpathentry kind="lib" path="third-party/commons-httpclient-3.0.1/commons-httpclient-3.0.1.jar"/>
7+
<classpathentry kind="lib" path="third-party/commons-logging-1.1/commons-logging-1.1.jar"/>
8+
<classpathentry kind="lib" path="third-party/domderrien-1.0.6/domderrien-1.0.6.jar"/>
9+
<classpathentry kind="lib" path="third-party/jaxb-ri-2.1/activation.jar"/>
10+
<classpathentry kind="lib" path="third-party/jaxb-ri-2.1/jaxb-api.jar"/>
11+
<classpathentry kind="lib" path="third-party/jaxb-ri-2.1/jaxb-impl.jar"/>
12+
<classpathentry kind="lib" path="third-party/jaxb-ri-2.1/jaxb-xjc.jar"/>
13+
<classpathentry kind="lib" path="third-party/jaxb-ri-2.1/jsr173_1.0_api.jar"/>
14+
<classpathentry kind="lib" path="third-party/log4j-1.2.14/log4j-1.2.14.jar"/>
15+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
16+
<classpathentry kind="output" path="build/classes"/>
17+
</classpath>

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/*
2+
dist/*

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>amazon-fps-gaej</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

README

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
================================================================================
2+
Adaptation of the Amazon FPS library for the Java platform of Google App Engine
3+
Copyright 2010 Dom Derrien
4+
================================================================================
5+
6+
This derivative work is licensed under the Apache License, Version 2.0,
7+
as the original Amazon FPS library.
8+
9+
Follow indications from the README.html file to build the library. Don't forget
10+
to update the src/config.properties file with your own settings.
11+
12+
Deployment:
13+
- Among the third-party libraries, you only need to push the following ones in your
14+
Google App Engine environment (war/WEB-INF/lib):
15+
1. commons-codec-1.3.jar
16+
2. commons-httpclient-3.0.1.jar
17+
3. commons-logging-1.1.jar
18+
** have side-effects on traces generated by the data nucleus converter and
19+
on cobertura instrumentation tool
20+
4. domderrien-1.0.6.jar
21+
** just for the MockInputStream and MockOutputStream

build.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@
2020
*
2121
*/
2222
23+
/*******************************************************************************
24+
* Adapted by Dom Derrien for the Java platform of Google App Engine
25+
* Copyright 2010 Dom Derrien
26+
* *****************************************************************************
27+
* Change scope:
28+
* - Update the library name to mention the Google App Engine.
29+
*/
2330
2431
-->
2532
<project name="Amazon FPS Java Library" default="dist" basedir=".">
2633
<description>Auto generated ANT file for building AWS libraries</description>
27-
<property name="lib.name" value="amazon-fps-2008-09-17-java-library"/>
34+
<property name="lib.name" value="amazon-fps-2008-09-17-java-library-for-gae"/>
2835
<property name="java.src.dir" value="src"/>
2936
<property name="build.root" value="build"/>
3037
<property name="build.dir" value="build/classes"/>

src/com/amazonaws/fps/AmazonFPSClient.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919
*
2020
*/
2121

22-
22+
/*******************************************************************************
23+
* Adapted by Dom Derrien for the Java platform of Google App Engine
24+
* Copyright 2010 Dom Derrien
25+
* *****************************************************************************
26+
* Change scope:
27+
* - Replace the usage of a MultiThreadedHttpConnectionManager instance by
28+
* a wrapper over Google App Engine UrlFetch instance.
29+
*/
2330

2431
package com.amazonaws.fps;
2532

@@ -43,7 +50,10 @@
4350
import org.apache.commons.codec.binary.Base64;
4451
import org.apache.commons.httpclient.HttpClient;
4552
import org.apache.commons.httpclient.HttpStatus;
46-
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
53+
// Dom Derrien: refactor to accomodate the library to GAE Java environment
54+
// import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
55+
// import org.apache.commons.httpclient.SimpleHttpConnectionManager;
56+
import domderrien.wrapper.UrlFetch.UrlFetchConnectionManager;
4757
import org.apache.commons.httpclient.methods.PostMethod;
4858
import org.apache.commons.httpclient.HttpMethodRetryHandler;
4959
import org.apache.commons.httpclient.params.HttpMethodParams;
@@ -644,7 +654,10 @@ public boolean retryMethod(HttpMethod method, IOException exception, int executi
644654
connectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, config.getMaxConnections());
645655

646656
/* Set connection manager */
647-
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
657+
// Dom Derrien: refactor to accomodate the library to GAE Java environment
658+
// MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
659+
// SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager();
660+
UrlFetchConnectionManager connectionManager = new UrlFetchConnectionManager();
648661
connectionManager.setParams(connectionManagerParams);
649662

650663
/* Set http client */

src/com/amazonaws/ipnreturnurlvalidation/SignatureUtilsForOutbound.java

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
*
2020
*/
2121

22+
/*******************************************************************************
23+
* Adapted by Dom Derrien for the Java platform of Google App Engine
24+
* Copyright 2010 Dom Derrien
25+
* *****************************************************************************
26+
* Change scope:
27+
* - Replace the call to the static method HttpURLConnection.getFollowRedirects()
28+
* by an one related to a HttpURLConnection instance.
29+
*/
30+
2231
package com.amazonaws.ipnreturnurlvalidation;
2332

2433
import java.io.BufferedReader;
@@ -320,16 +329,31 @@ private String getPublicKeyCertificateAsString(String certificateUrl) throws Sig
320329
String certificate = keyStore.get(certificateUrl);
321330
if (certificate != null) return certificate;
322331

323-
//2. If not found in cache, fetch it
324-
boolean followRedirects = HttpURLConnection.getFollowRedirects();
325-
HttpURLConnection.setFollowRedirects(false);
332+
// Dom Derrien: update to not use the static function, forbidden in GAE Java environment
333+
// Cf. http://code.google.com/p/googleappengine/issues/detail?id=1556
334+
// Cf. http://code.google.com/appengine/docs/java/urlfetch/usingjavanet.html#Redirects
326335
try {
327-
certificate = URLReader.getUrlContents(certificateUrl);
328-
} catch (IOException e) {
329-
throw new SignatureException(e);
330-
} finally {
331-
HttpURLConnection.setFollowRedirects(followRedirects);
332-
}
336+
//2. If not found in cache, fetch it
337+
// boolean followRedirects = HttpURLConnection.getFollowRedirects();
338+
// HttpURLConnection.setFollowRedirects(false);
339+
URL url = new URL("http://aws.amazon.com/");
340+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
341+
boolean followRedirects = connection.getInstanceFollowRedirects();
342+
connection.setInstanceFollowRedirects(false);
343+
try {
344+
certificate = URLReader.getUrlContents(certificateUrl);
345+
} catch (IOException e) {
346+
throw new SignatureException(e);
347+
} finally {
348+
HttpURLConnection.setFollowRedirects(followRedirects);
349+
}
350+
}
351+
catch (MalformedURLException ex) {
352+
throw new SignatureException(ex);
353+
}
354+
catch (IOException ex) {
355+
throw new SignatureException(ex);
356+
}
333357

334358
//3. populate newly fetched certificate in cache.
335359
keyStore.put(certificateUrl, certificate);

src/domderrien/LICENSE

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Dom Derrien's code is available under the terms of the modified BSD license.
2+
The text of the BSD license is reproduced below.
3+
4+
-------------------------------------------------------------------------------
5+
The "New" BSD License:
6+
**********************
7+
8+
Copyright (c) 2006-2009, Dom Derrien
9+
All rights reserved.
10+
11+
Redistribution and use in source and binary forms, with or without
12+
modification, are permitted provided that the following conditions are met:
13+
14+
* Redistributions of source code must retain the above copyright notice, this
15+
list of conditions and the following disclaimer.
16+
* Redistributions in binary form must reproduce the above copyright notice,
17+
this list of conditions and the following disclaimer in the documentation
18+
and/or other materials provided with the distribution.
19+
* Neither the name of the Dom Derrien nor the names of other contributors
20+
may be used to endorse or promote products derived from this software
21+
without specific prior written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
27+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
-------------------------------------------------------------------------------
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*******************************************************************************
2+
* Adaptation for the Amazon FPS library to work on the Java platform of
3+
* Google App Engine.
4+
*
5+
* Copyright 2010 Dom Derrien
6+
* Licensed under the Apache License, Version 2.0
7+
*/
8+
9+
package domderrien.wrapper.UrlFetch;
10+
11+
import org.apache.commons.httpclient.ConnectionPoolTimeoutException;
12+
import org.apache.commons.httpclient.HostConfiguration;
13+
import org.apache.commons.httpclient.HttpConnection;
14+
import org.apache.commons.httpclient.HttpConnectionManager;
15+
import org.apache.commons.httpclient.HttpException;
16+
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
17+
18+
public class UrlFetchConnectionManager implements HttpConnectionManager {
19+
20+
private HttpConnectionManagerParams params;
21+
private HttpConnection connection;
22+
23+
public void closeIdleConnections(long timeout) {
24+
throw new RuntimeException("closeIdleConnections(long)");
25+
}
26+
27+
public HttpConnection getConnection(HostConfiguration hostConfiguration) {
28+
throw new RuntimeException("getConnection(HostConfiguration)");
29+
// return null;
30+
}
31+
32+
public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) throws HttpException {
33+
throw new RuntimeException("getConnection(HostConfiguration, long)");
34+
// return null;
35+
}
36+
37+
public HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration, long timeout) throws ConnectionPoolTimeoutException {
38+
// As reported in http://code.google.com/appengine/docs/java/urlfetch/usingjavanet.html#Java_Net_Features_Not_Supported
39+
// > The app cannot set explicit connection timeouts for the request.
40+
if (connection != null) {
41+
releaseConnection(connection);
42+
}
43+
connection = new UrlFetchHttpConnection(hostConfiguration);
44+
return connection;
45+
}
46+
47+
public HttpConnectionManagerParams getParams() {
48+
return params;
49+
}
50+
51+
public void releaseConnection(HttpConnection connection) {
52+
connection.releaseConnection();
53+
}
54+
55+
public void setParams(HttpConnectionManagerParams params) {
56+
// Parameters set in AmazonFPSClient#configureHttpClient:
57+
// - ConnectionTimeout: 50000 ms
58+
// - SoTimeout: 50000 ms
59+
// - StaleCheckingEnabled: true
60+
// - TcpNoDelay: true
61+
// - MaxTotalConnections: 100 (as proposed in the default config.properties file)
62+
// - MaxConnectionsPerHost: 100 (as proposed in the default config.properties file)
63+
64+
this.params = params;
65+
}
66+
67+
}

0 commit comments

Comments
 (0)