diff options
author | fbecker | 2010-04-10 20:24:06 +0000 |
---|---|---|
committer | fbecker | 2010-04-10 20:24:06 +0000 |
commit | c2bfebf8d93832f3c1cc614dd4319f78c5da30ab (patch) | |
tree | 5f386953f3f77eeb539f11808d193d33d7e48858 /org.eclipse.mylyn.tasks.core | |
parent | eb74fdefa86061aa0344a02ce44563a05b46aee7 (diff) | |
download | org.eclipse.mylyn.tasks-c2bfebf8d93832f3c1cc614dd4319f78c5da30ab.tar.gz org.eclipse.mylyn.tasks-c2bfebf8d93832f3c1cc614dd4319f78c5da30ab.tar.xz org.eclipse.mylyn.tasks-c2bfebf8d93832f3c1cc614dd4319f78c5da30ab.zip |
ASSIGNED - bug 282211: create Webservice API
https://bugs.eclipse.org/bugs/show_bug.cgi?id=282211
Diffstat (limited to 'org.eclipse.mylyn.tasks.core')
6 files changed, 420 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF index b9018cbd8..8083e94a6 100644 --- a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF @@ -9,7 +9,8 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.net, org.eclipse.equinox.security, org.eclipse.mylyn.commons.core;bundle-version="[3.0.0,4.0.0)", - org.eclipse.mylyn.commons.net;bundle-version="[3.0.0,4.0.0)" + org.eclipse.mylyn.commons.net;bundle-version="[3.0.0,4.0.0)", + org.apache.xmlrpc;bundle-version="[3.0.0,4.0.0)" Export-Package: org.eclipse.mylyn.internal.provisional.tasks.core;x-internal:=true, org.eclipse.mylyn.internal.tasks.core;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs", org.eclipse.mylyn.internal.tasks.core.data;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs", @@ -17,5 +18,6 @@ Export-Package: org.eclipse.mylyn.internal.provisional.tasks.core;x-internal:=tr org.eclipse.mylyn.internal.tasks.core.sync;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs", org.eclipse.mylyn.tasks.core, org.eclipse.mylyn.tasks.core.data, - org.eclipse.mylyn.tasks.core.sync + org.eclipse.mylyn.tasks.core.sync, + org.eclipse.mylyn.tasks.core.service Bundle-Localization: plugin diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseHttpMethodInterceptor.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseHttpMethodInterceptor.java new file mode 100644 index 000000000..ac0282547 --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseHttpMethodInterceptor.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2010 Frank Becker and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.tasks.core.service; + +import org.apache.commons.httpclient.HttpMethod; + +/** + * @author Frank Becker + * @author Steffen Pingel + */ +public interface BaseHttpMethodInterceptor { + + public abstract void processRequest(HttpMethod method); + + public abstract void processResponse(HttpMethod method); + +} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXMLRPCTransportFactory.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXMLRPCTransportFactory.java new file mode 100644 index 000000000..436865817 --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXMLRPCTransportFactory.java @@ -0,0 +1,284 @@ +/******************************************************************************* + * Copyright (c) 2010 Frank Becker and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.tasks.core.service; + +import java.io.BufferedOutputStream; +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HostConfiguration; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.HttpVersion; +import org.apache.commons.httpclient.auth.AuthScheme; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.RequestEntity; +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.XmlRpcRequest; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.apache.xmlrpc.client.XmlRpcClientException; +import org.apache.xmlrpc.client.XmlRpcHttpClientConfig; +import org.apache.xmlrpc.client.XmlRpcHttpTransport; +import org.apache.xmlrpc.client.XmlRpcTransport; +import org.apache.xmlrpc.client.XmlRpcTransportFactory; +import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig; +import org.apache.xmlrpc.util.HttpUtil; +import org.apache.xmlrpc.util.XmlRpcIOException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.mylyn.commons.net.AbstractWebLocation; +import org.eclipse.mylyn.commons.net.WebUtil; +import org.xml.sax.SAXException; + +/** + * @author Frank Becker + * @author Steffen Pingel + */ +public class BaseXMLRPCTransportFactory implements XmlRpcTransportFactory { + /** + * A transport that uses the Apache HttpClient library. + */ + public static class BaseHttpClientTransport extends XmlRpcHttpTransport { + + private final HttpClient httpClient; + + private final AbstractWebLocation location; + + private PostMethod method; + + private int contentLength = -1; + + private XmlRpcHttpClientConfig config; + + private IProgressMonitor monitor; + + private HostConfiguration hostConfiguration; + + private final BaseHttpMethodInterceptor interceptor; + + public BaseHttpClientTransport(XmlRpcClient client, HttpClient httpClient, AbstractWebLocation location, + BaseHttpMethodInterceptor interceptor) { + super(client, ""); //$NON-NLS-1$ + this.httpClient = httpClient; + this.location = location; + this.interceptor = interceptor; + } + + @Override + protected void close() throws XmlRpcClientException { + method.releaseConnection(); + } + + public int getContentLength() { + return contentLength; + } + + @Override + protected InputStream getInputStream() throws XmlRpcException { + int responseCode = method.getStatusCode(); + if (responseCode != java.net.HttpURLConnection.HTTP_OK) { + BaseHttpException e = new BaseHttpException(responseCode); + if (responseCode == HttpStatus.SC_UNAUTHORIZED) { + e.setAuthScheme(method.getHostAuthState().getAuthScheme()); + } + throw e; + } + + try { + return method.getResponseBodyAsStream(); + } catch (HttpException e) { + throw new XmlRpcClientException("Error in HTTP transport: " + e.getMessage(), e); //$NON-NLS-1$ + } catch (IOException e) { + throw new XmlRpcClientException("I/O error in server communication: " + e.getMessage(), e); //$NON-NLS-1$ + } + } + + @Override + protected String getUserAgent() { + return WebUtil.getUserAgent(""); //$NON-NLS-1$ + } + + @Override + protected void initHttpHeaders(XmlRpcRequest request) throws XmlRpcClientException { + config = (XmlRpcHttpClientConfig) request.getConfig(); + + if (request instanceof BaseXmlRpcClientRequestImpl) { + BaseXmlRpcClientRequestImpl repositoryRequest = (BaseXmlRpcClientRequestImpl) request; + monitor = repositoryRequest.getProgressMonitor(); + } else { + monitor = null; + } + + String url = config.getServerURL().toString(); + hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor); + method = new PostMethod(WebUtil.getRequestPath(url)); + + super.initHttpHeaders(request); + + if (config.getConnectionTimeout() != 0) { + httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(config.getConnectionTimeout()); + } + + if (config.getReplyTimeout() != 0) { + httpClient.getHttpConnectionManager().getParams().setSoTimeout(config.getConnectionTimeout()); + } + + method.getParams().setVersion(HttpVersion.HTTP_1_1); + + if (interceptor != null) { + interceptor.processRequest(method); + } + } + + @Override + protected boolean isResponseGzipCompressed(XmlRpcStreamRequestConfig config) { + Header header = method.getResponseHeader("Content-Encoding"); //$NON-NLS-1$ + return header != null && HttpUtil.isUsingGzipEncoding(header.getValue()); + } + + @Override + protected void setContentLength(int contentLength) { + this.contentLength = contentLength; + } + + @Override + protected void setCredentials(XmlRpcHttpClientConfig config) throws XmlRpcClientException { + // handled by TracXmlRpcClient + } + + @Override + protected void setRequestHeader(String header, String value) { + method.setRequestHeader(new Header(header, value)); + } + + @Override + protected void writeRequest(final ReqWriter writer) throws XmlRpcException { + method.setRequestEntity(new RequestEntity() { + public long getContentLength() { + return BaseHttpClientTransport.this.getContentLength(); + } + + public String getContentType() { + return "text/xml"; //$NON-NLS-1$ + } + + public boolean isRepeatable() { + return getContentLength() != -1; + } + + public void writeRequest(OutputStream pOut) throws IOException { + try { + /* Make sure, that the socket is not closed by replacing it with our + * own BufferedOutputStream. + */ + OutputStream ostream; + if (isUsingByteArrayOutput(config)) { + // No need to buffer the output. + ostream = new FilterOutputStream(pOut) { + @Override + public void close() throws IOException { + flush(); + } + }; + } else { + ostream = new BufferedOutputStream(pOut) { + @Override + public void close() throws IOException { + flush(); + } + }; + } + writer.write(ostream); + } catch (XmlRpcException e) { + throw new XmlRpcIOException(e); + } catch (SAXException e) { + throw new XmlRpcIOException(e); + } + } + }); + + try { + WebUtil.execute(httpClient, hostConfiguration, method, monitor); + if (interceptor != null) { + interceptor.processResponse(method); + } + } catch (XmlRpcIOException e) { + Throwable t = e.getLinkedException(); + if (t instanceof XmlRpcException) { + throw (XmlRpcException) t; + } else { + throw new XmlRpcException("Unexpected exception: " + t.getMessage(), t); //$NON-NLS-1$ + } + } catch (IOException e) { + throw new XmlRpcException("I/O error while communicating with HTTP server: " + e.getMessage(), e); //$NON-NLS-1$ + } + } + + } + + public static class BaseHttpException extends XmlRpcException { + + private static final long serialVersionUID = -6088919818534852787L; + + private AuthScheme authScheme; + + public BaseHttpException(int responseCode) { + super(responseCode, "HTTP Error " + responseCode); //$NON-NLS-1$ + } + + public AuthScheme getAuthScheme() { + return authScheme; + } + + public void setAuthScheme(AuthScheme authScheme) { + this.authScheme = authScheme; + } + + } + + private final XmlRpcClient xmlRpcClient; + + private AbstractWebLocation location; + + private final HttpClient httpClient; + + private BaseHttpMethodInterceptor interceptor; + + public BaseXMLRPCTransportFactory(XmlRpcClient xmlRpcClient, HttpClient httpClient) { + this.xmlRpcClient = xmlRpcClient; + this.httpClient = httpClient; + } + + public AbstractWebLocation getLocation() { + return location; + } + + public XmlRpcTransport getTransport() { + return new BaseHttpClientTransport(xmlRpcClient, httpClient, location, interceptor); + } + + public void setLocation(AbstractWebLocation location) { + this.location = location; + } + + public BaseHttpMethodInterceptor getInterceptor() { + return interceptor; + } + + public void setInterceptor(BaseHttpMethodInterceptor interceptor) { + this.interceptor = interceptor; + } + +} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXmlRpcClient.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXmlRpcClient.java new file mode 100644 index 000000000..2ba50cce5 --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXmlRpcClient.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2010 Frank Becker and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.tasks.core.service; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; +import org.eclipse.mylyn.tasks.core.TaskRepository; + +/** + * @author Frank Becker + * @author Steffen Pingel + */ +public class BaseXmlRpcClient { + protected XmlRpcClientConfigImpl xmlConfig; + + protected XmlRpcClient xmlrpc; + + protected HttpClient httpClient; + + protected final TaskRepository repository; + + public BaseXmlRpcClient(TaskRepository repository) { + this.repository = repository; + } + +} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXmlRpcClientRequest.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXmlRpcClientRequest.java new file mode 100644 index 000000000..332778554 --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXmlRpcClientRequest.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2010 Frank Becker and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.tasks.core.service; + +import org.apache.xmlrpc.XmlRpcRequestConfig; +import org.apache.xmlrpc.client.XmlRpcClientRequestImpl; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * @author Frank Becker + * @author Steffen Pingel + */ +public class BaseXmlRpcClientRequest extends XmlRpcClientRequestImpl { + + private final IProgressMonitor progressMonitor; + + public BaseXmlRpcClientRequest(XmlRpcRequestConfig config, String methodName, Object[] params, + IProgressMonitor monitor) { + super(config, methodName, params); + this.progressMonitor = monitor; + } + + public IProgressMonitor getProgressMonitor() { + return progressMonitor; + } + +} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXmlRpcClientRequestImpl.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXmlRpcClientRequestImpl.java new file mode 100644 index 000000000..6ae639a3c --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXmlRpcClientRequestImpl.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010 Frank Becker and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.tasks.core.service; + +import org.apache.xmlrpc.XmlRpcRequestConfig; +import org.apache.xmlrpc.client.XmlRpcClientRequestImpl; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * @author Frank Becker + * @author Steffen Pingel + */ +public class BaseXmlRpcClientRequestImpl extends XmlRpcClientRequestImpl { + private final IProgressMonitor progressMonitor; + + public BaseXmlRpcClientRequestImpl(XmlRpcRequestConfig config, String methodName, Object[] params, + IProgressMonitor monitor) { + super(config, methodName, params); + this.progressMonitor = monitor; + } + + public IProgressMonitor getProgressMonitor() { + return progressMonitor; + } +} |