starting GAE support

git-svn-id: http://google-refine.googlecode.com/svn/trunk@918 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Stefano Mazzocchi 2010-05-30 18:48:14 +00:00
parent f92ecfb715
commit 97842fabdd
9 changed files with 401 additions and 0 deletions

10
appengine/.classpath Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/gridworks"/>
<classpathentry kind="lib" path="/gridworks/webapp/WEB-INF/lib/httpcore-4.0.1.jar" sourcepath="/gridworks/webapp/WEB-INF/lib-src/httpcore-4.0.1-sources.jar"/>
<classpathentry kind="lib" path="/gridworks/webapp/WEB-INF/lib/httpclient-4.0.1.jar" sourcepath="/gridworks/webapp/WEB-INF/lib-src/httpclient-4.0.1-sources.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="com.google.appengine.eclipse.core.projectValidator"/>
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="com.google.gdt.eclipse.core.webAppProjectValidator"/>
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>

43
appengine/.project Normal file
View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>gridworks appengine</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/com.google.gdt.eclipse.core.webAppProjectValidator.launch</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>com.google.appengine.eclipse.core.enhancerbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/com.google.appengine.eclipse.core.projectValidator.launch</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>com.google.appengine.eclipse.core.gaeNature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,3 @@
#Wed May 26 15:13:15 PDT 2010
eclipse.preferences.version=1
validationExclusions=src/com/metaweb/gridworks/appengine/*ClientConnection*.java

View File

@ -0,0 +1,5 @@
#Wed May 26 15:11:38 PDT 2010
eclipse.preferences.version=1
jarsExcludedFromWebInfLib=
warSrcDir=
warSrcDirIsOutput=true

Binary file not shown.

View File

@ -0,0 +1,243 @@
package com.metaweb.gridworks.appengine;
import static com.google.appengine.api.urlfetch.FetchOptions.Builder.allowTruncate;
import java.io.ByteArrayOutputStream;
import java.net.InetAddress;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLSession;
import org.apache.http.Header;
import org.apache.http.HttpConnectionMetrics;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolVersion;
import org.apache.http.conn.ManagedClientConnection;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import com.google.appengine.api.urlfetch.HTTPHeader;
import com.google.appengine.api.urlfetch.HTTPMethod;
import com.google.appengine.api.urlfetch.HTTPRequest;
import com.google.appengine.api.urlfetch.HTTPResponse;
import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
class AppEngineClientConnection implements ManagedClientConnection {
// Managed is the composition of ConnectionReleaseTrigger,
// HttpClientConnection, HttpConnection, HttpInetConnection
private HttpRoute _route;
private Object _state;
private boolean _reuseable;
public AppEngineClientConnection(HttpRoute route, Object state) {
_route = route;
_state = state;
}
// ManagedClientConnection methods
public HttpRoute getRoute() {
return _route;
}
public Object getState() {
return _state;
}
public SSLSession getSSLSession() {
return null;
}
public boolean isSecure() {
// XXX maybe parse the url to see if it's https?
return false;
}
public boolean isMarkedReusable() {
return _reuseable;
}
public void markReusable() {
_reuseable = true;
}
public void layerProtocol(HttpContext context, HttpParams params) {
return;
}
public void open(HttpRoute route, HttpContext context, HttpParams params) {
return;
}
public void setIdleDuration(long duration, TimeUnit unit) {
return;
}
public void setState(Object state) {
_state = state;
}
public void tunnelProxy(HttpHost next, boolean secure, HttpParams params) {
return;
}
public void tunnelTarget(boolean secure, HttpParams params) {
return;
}
public void unmarkReusable() {
_reuseable = false;
}
// ConnectionReleaseTrigger methods
public void releaseConnection() {
return;
}
public void abortConnection() {
return;
}
// HttpClientConnection methods
private HTTPRequest _appengine_hrequest;
private HTTPResponse _appengine_hresponse;
public void flush() {
return;
}
public boolean isResponseAvailable(int timeout) {
// XXX possibly use Async fetcher
return true;
}
public void receiveResponseEntity(org.apache.http.HttpResponse apache_response) {
byte[] data = _appengine_hresponse.getContent();
if (data != null) {
apache_response.setEntity(new ByteArrayEntity(data));
}
}
public HttpResponse receiveResponseHeader() {
URLFetchService ufs = URLFetchServiceFactory.getURLFetchService();
try {
_appengine_hresponse = ufs.fetch(_appengine_hrequest);
} catch (java.io.IOException e) {
throw new RuntimeException(e);
}
org.apache.http.HttpResponse apache_response =
new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 0),
_appengine_hresponse.getResponseCode(),
null);
for (HTTPHeader h : _appengine_hresponse.getHeaders()) {
apache_response.addHeader(h.getName(), h.getValue());
}
return apache_response;
}
public void sendRequestEntity(org.apache.http.HttpEntityEnclosingRequest request) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
org.apache.http.HttpEntity ent = request.getEntity();
if (ent != null) {
try {
ent.writeTo(os);
} catch (java.io.IOException e) {
throw new RuntimeException(e);
}
}
_appengine_hrequest.setPayload(os.toByteArray());
}
public void sendRequestHeader(org.apache.http.HttpRequest apache_request) {
URL request_url;
HttpHost host = _route.getTargetHost();
String protocol = host.getSchemeName();
String addr = host.getHostName();
int port = host.getPort();
String path = apache_request.getRequestLine().getUri();
try {
request_url = new URL(protocol, addr, port, path);
} catch (java.net.MalformedURLException e) {
throw new RuntimeException(e);
}
HTTPMethod method = HTTPMethod.valueOf(apache_request.getRequestLine().getMethod());
_appengine_hrequest = new HTTPRequest(request_url, method, allowTruncate()
.doNotFollowRedirects());
Header[] apache_headers = apache_request.getAllHeaders();
for (int i = 0; i < apache_headers.length; i++) {
Header h = apache_headers[i];
_appengine_hrequest
.setHeader(new HTTPHeader(h.getName(), h.getValue()));
}
}
// HttpConnection methods
public void close() {
return;
}
public HttpConnectionMetrics getMetrics() {
return null;
}
public int getSocketTimeout() {
return -1;
}
public boolean isOpen() {
return true;
}
public boolean isStale() {
return false;
}
public void setSocketTimeout(int timeout) {
return;
}
public void shutdown() {
return;
}
// HttpInetConnection methods
public InetAddress getLocalAddress() {
return null;
}
public int getLocalPort() {
return -1;
}
public InetAddress getRemoteAddress() {
return null;
}
public int getRemotePort() {
return -1;
}
}

View File

@ -0,0 +1,83 @@
package com.metaweb.gridworks.appengine;
import java.net.InetAddress;
import java.net.Socket;
import java.util.concurrent.TimeUnit;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ManagedClientConnection;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.scheme.SocketFactory;
import org.apache.http.params.HttpParams;
public class AppEngineClientConnectionManager implements ClientConnectionManager {
private SchemeRegistry schemes;
class NoopSocketFactory implements SocketFactory {
public Socket connectSocket(Socket sock, String host, int port,
InetAddress addr, int lport,
HttpParams params) {
return null;
}
public Socket createSocket() {
return null;
}
public boolean isSecure(Socket sock) {
return false;
}
}
public AppEngineClientConnectionManager() {
SocketFactory noop_sf = new NoopSocketFactory();
schemes = new SchemeRegistry();
schemes.register(new Scheme("http", noop_sf, 80));
schemes.register(new Scheme("https", noop_sf, 443));
}
public void closeExpiredConnections() {
return;
}
public void closeIdleConnections(long idletime, TimeUnit tunit) {
return;
}
public ManagedClientConnection getConnection(HttpRoute route, Object state) {
return new AppEngineClientConnection(route, state);
}
public SchemeRegistry getSchemeRegistry() {
return schemes;
}
public void releaseConnection(ManagedClientConnection conn,
long valid, TimeUnit tuint) {
return;
}
public ClientConnectionRequest requestConnection(final HttpRoute route,
final Object state) {
return new ClientConnectionRequest() {
public void abortRequest() {
return;
}
public ManagedClientConnection getConnection(long idletime,
TimeUnit tunit) {
return AppEngineClientConnectionManager.this.getConnection(route, state);
}
};
}
public void shutdown() {
return;
}
}