diff options
author | fbecker | 2010-04-11 19:49:57 +0000 |
---|---|---|
committer | fbecker | 2010-04-11 19:49:57 +0000 |
commit | 91f5a311a05552b28fba0cb1f1a80c1383a2f743 (patch) | |
tree | 3acbb4d0928ebbe3871683d7eba82123a7d7ae14 | |
parent | 21b5fddc2d986a59d2c751b17fa632729def2637 (diff) | |
download | org.eclipse.mylyn.tasks-91f5a311a05552b28fba0cb1f1a80c1383a2f743.tar.gz org.eclipse.mylyn.tasks-91f5a311a05552b28fba0cb1f1a80c1383a2f743.tar.xz org.eclipse.mylyn.tasks-91f5a311a05552b28fba0cb1f1a80c1383a2f743.zip |
ASSIGNED - bug 282211: create Webservice API
https://bugs.eclipse.org/bugs/show_bug.cgi?id=282211
revert see comment#11
9 files changed, 3 insertions, 891 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF index 8fe6c9e25..c7fcbc447 100644 --- a/org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF @@ -8,8 +8,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.mylyn.tasks.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.core;bundle-version="[3.0.0,4.0.0)", - org.eclipse.core.net, - org.apache.xmlrpc;bundle-version="[3.0.0,4.0.0)" + org.eclipse.core.net Bundle-ActivationPolicy: lazy Bundle-Vendor: %Bundle-Vendor Bundle-ClassPath: . diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcClient.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcClient.java deleted file mode 100644 index d07752dd9..000000000 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcClient.java +++ /dev/null @@ -1,391 +0,0 @@ -/******************************************************************************* - * 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.internal.bugzilla.core.service; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Date; -import java.util.HashMap; - -import org.apache.commons.httpclient.Cookie; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.cookie.CookiePolicy; -import org.apache.xmlrpc.XmlRpcException; -import org.apache.xmlrpc.client.XmlRpcClient; -import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.mylyn.commons.net.AuthenticationCredentials; -import org.eclipse.mylyn.commons.net.AuthenticationType; -import org.eclipse.mylyn.commons.net.Policy; -import org.eclipse.mylyn.commons.net.WebUtil; -import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration; -import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryLocation; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.service.BaseHttpMethodInterceptor; -import org.eclipse.mylyn.tasks.core.service.BaseXMLRPCTransportFactory; -import org.eclipse.mylyn.tasks.core.service.BaseXmlRpcClient; -import org.eclipse.mylyn.tasks.core.service.BaseXmlRpcClientRequestImpl; - -@SuppressWarnings("restriction") -public class BugzillaXmlRpcClient extends BaseXmlRpcClient { - - private class XmlRpcRequest { - - private final String method; - - private final Object[] parameters; - - public XmlRpcRequest(String method, Object[] parameters) { - this.method = method; - this.parameters = parameters; - } - - public Object execute(IProgressMonitor monitor) throws XmlRpcException { - BaseXmlRpcClientRequestImpl request = new BaseXmlRpcClientRequestImpl(xmlrpc.getClientConfig(), method, - parameters, monitor); - return xmlrpc.execute(request); - } - } - - public static final String URL_XMLRPC = "/xmlrpc.cgi"; //$NON-NLS-1$ - - private int userID = -1; - - private RepositoryConfiguration repositoryConfiguration; - - public BugzillaXmlRpcClient(TaskRepository repository) { - super(repository); - } - - public void setRepositoryConfiguration(RepositoryConfiguration repositoryConfiguration) { - this.repositoryConfiguration = repositoryConfiguration; - } - - public RepositoryConfiguration getRepositoryConfiguration() { - return repositoryConfiguration; - } - - private synchronized XmlRpcClient getClient() throws MalformedURLException { - if (xmlrpc == null) { - xmlConfig = new XmlRpcClientConfigImpl(); - xmlConfig.setContentLengthOptional(false); - xmlConfig.setConnectionTimeout(WebUtil.getConnectionTimeout()); - xmlConfig.setReplyTimeout(WebUtil.getSocketTimeout()); - xmlConfig.setServerURL(new URL(repository.getUrl() + URL_XMLRPC)); - - xmlrpc = new XmlRpcClient(); - httpClient = new HttpClient(); - httpClient.setHttpConnectionManager(WebUtil.getConnectionManager()); - httpClient.getParams().setCookiePolicy(CookiePolicy.RFC_2109); - TaskRepositoryLocation location = new TaskRepositoryLocation(repository); - AuthenticationCredentials httpAuthCredentials = location.getCredentials(AuthenticationType.HTTP); - if (httpAuthCredentials != null && httpAuthCredentials.getUserName() != null - && httpAuthCredentials.getUserName().length() > 0) { - httpClient.getParams().setAuthenticationPreemptive(true); - } - - WebUtil.configureHttpClient(httpClient, "BugzillaClient"); //$NON-NLS-1$ - BaseXMLRPCTransportFactory factory = new BaseXMLRPCTransportFactory(xmlrpc, httpClient); - factory.setLocation(location); - int i = 0; - if (i == 1) { - factory.setInterceptor(new BaseHttpMethodInterceptor() { - @SuppressWarnings("unused") - public void processRequest(HttpMethod method) { - Cookie[] c = httpClient.getState().getCookies(); - int i = 9; - i++; - } - - @SuppressWarnings("unused") - public void processResponse(HttpMethod method) { - Cookie[] c = httpClient.getState().getCookies(); - int i = 9; - i++; - } - }); - } - xmlrpc.setTransportFactory(factory); - xmlrpc.setConfig(xmlConfig); - try { - login(); - } catch (Exception e) { - userID = -1; - } - } - return xmlrpc; - } - - private Object call(IProgressMonitor monitor, String method, Object... parameters) throws XmlRpcException, - MalformedURLException { - monitor = Policy.monitorFor(monitor); - getClient(); - XmlRpcRequest request = new XmlRpcRequest(method, parameters); - return request.execute(monitor); - } - - public int getUserID() { - return userID; - } - - /* - * Modul Webservice:User - */ - @SuppressWarnings("unchecked") - private void login() { - AuthenticationCredentials credentials = repository.getCredentials(AuthenticationType.REPOSITORY); - HashMap<String, String> loginpar = new HashMap<String, String>(); - Object[] paramslogin = new Object[] { loginpar }; - - loginpar.put("login", credentials.getUserName()); //$NON-NLS-1$ - loginpar.put("password", credentials.getPassword()); //$NON-NLS-1$ - loginpar.put("remember", "TRUE"); //$NON-NLS-1$//$NON-NLS-2$ - try { - Object result = call(null, "User.login", paramslogin); //$NON-NLS-1$ - if (result instanceof HashMap<?, ?>) { - HashMap<String, Integer> resultHash = (HashMap<String, Integer>) result; - Integer resultUser = resultHash.get("id"); //$NON-NLS-1$ - userID = resultUser; - } - } catch (XmlRpcException e) { - userID = -1; - } catch (MalformedURLException e) { - userID = -1; - } - } - - @SuppressWarnings("serial") - public Object[] getUserInfoFromIDs(final Integer[] ids) { - return getUserInfoInternal(new Object[] { new HashMap<String, Object[]>() { - { - put("ids", ids); //$NON-NLS-1$ - } - } }); - } - - @SuppressWarnings("serial") - public Object[] getUserInfoFromNames(final String[] names) { - return getUserInfoInternal(new Object[] { new HashMap<String, Object[]>() { - { - put("names", names); //$NON-NLS-1$ - } - } }); - } - - public Object[] getUserInfoWithMatch(String[] matchs) { - HashMap<String, Object[]> parmArray = new HashMap<String, Object[]>(); - Object[] callParm = new Object[] { parmArray }; - parmArray.put("match", matchs); //$NON-NLS-1$ - return getUserInfoInternal(callParm); - } - - @SuppressWarnings("unchecked") - private Object[] getUserInfoInternal(Object[] callParm) { - HashMap<String, Object[]> result; - try { - result = (HashMap<String, Object[]>) call(null, "User.get", callParm); //$NON-NLS-1$ - } catch (XmlRpcException e) { - result = null; - } catch (MalformedURLException e) { - result = null; - } - if (result != null) { - Object[] a = result.get("users"); //$NON-NLS-1$ - return a; - } - return null; - } - - /* - * Modul Webservice Bugzilla - */ - - public String getVersion() { - HashMap<?, ?> result; - try { - result = (HashMap<?, ?>) call(null, "Bugzilla.version", (Object[]) null); //$NON-NLS-1$ - } catch (XmlRpcException e) { - result = null; - } catch (MalformedURLException e) { - result = null; - } - if (result != null) { - return (String) result.get("version"); //$NON-NLS-1$ - } - return null; - } - - @SuppressWarnings("unchecked") - public HashMap<String, Date> getTime() { - HashMap<String, Date> result; - try { - result = (HashMap<String, Date>) call(null, "Bugzilla.time", (Object[]) null); //$NON-NLS-1$ - } catch (XmlRpcException e) { - result = null; - } catch (MalformedURLException e) { - result = null; - } - if (result != null) { - result.remove("tz_offset"); //$NON-NLS-1$ - result.remove("tz_short_name"); //$NON-NLS-1$ - result.remove("web_time_utc"); //$NON-NLS-1$ - result.remove("tz_name"); //$NON-NLS-1$ - } - return result; - } - - public Date getDBTime() { - HashMap<?, ?> result; - try { - result = (HashMap<?, ?>) call(null, "Bugzilla.time", (Object[]) null); //$NON-NLS-1$ - } catch (XmlRpcException e) { - result = null; - } catch (MalformedURLException e) { - result = null; - } - if (result != null) { - return (Date) result.get("db_time"); //$NON-NLS-1$ - } - return null; - } - - public Date getWebTime() { - HashMap<?, ?> result; - try { - result = (HashMap<?, ?>) call(null, "Bugzilla.time", (Object[]) null); //$NON-NLS-1$ - } catch (XmlRpcException e) { - result = null; - } catch (MalformedURLException e) { - result = null; - } - if (result != null) { - return (Date) result.get("web_time"); //$NON-NLS-1$ - } - return null; - } - - /* - * Modul Webservice Bug - */ - - public Object[] getAllFields() { - return getFieldsInternal(null); - } - - @SuppressWarnings("serial") - public Object[] getFieldsWithNames(final String[] names) { - return getFieldsInternal(new Object[] { new HashMap<String, Object[]>() { - { - put("names", names); //$NON-NLS-1$ - } - } }); - } - - @SuppressWarnings("serial") - public Object[] getFieldsWithIDs(final Integer[] ids) { - return getFieldsInternal(new Object[] { new HashMap<String, Object[]>() { - { - put("ids", ids); //$NON-NLS-1$ - } - } }); - } - - @SuppressWarnings("unchecked") - private Object[] getFieldsInternal(Object[] param) { - HashMap<String, Object[]> result; - try { - result = (HashMap<String, Object[]>) call(null, "Bug.fields", param); //$NON-NLS-1$ - } catch (XmlRpcException e) { - result = null; - } catch (MalformedURLException e) { - result = null; - } - if (result != null) { - return result.get("fields"); //$NON-NLS-1$ - } - return null; - - } - - /* - * Modul Webservice Bug - */ - public Object[] getSelectableProducts() { - HashMap<String, Object[]> result; - try { - result = (HashMap<String, Object[]>) call(null, "Product.get_selectable_products", (Object[]) null); //$NON-NLS-1$ - } catch (XmlRpcException e) { - result = null; - } catch (MalformedURLException e) { - result = null; - } - if (result != null) { - return result.get("ids"); //$NON-NLS-1$ - } - return null; - } - - @SuppressWarnings("unchecked") - public Object[] getEnterableProducts() { - HashMap<String, Object[]> result; - try { - result = (HashMap<String, Object[]>) call(null, "Product.get_enterable_products", (Object[]) null); //$NON-NLS-1$ - } catch (XmlRpcException e) { - result = null; - } catch (MalformedURLException e) { - result = null; - } - if (result != null) { - return result.get("ids"); //$NON-NLS-1$ - } - return null; - } - - @SuppressWarnings("unchecked") - public Object[] getAccessibleProducts() { - HashMap<String, Object[]> result; - try { - result = (HashMap<String, Object[]>) call(null, "Product.get_accessible_products", (Object[]) null); //$NON-NLS-1$ - } catch (XmlRpcException e) { - result = null; - } catch (MalformedURLException e) { - result = null; - } - if (result != null) { - return result.get("ids"); //$NON-NLS-1$ - } - return null; - } - - @SuppressWarnings({ "unchecked", "serial" }) - public Object[] getProducts(final Integer[] ids) { - HashMap<String, Object[]> result; - try { - result = (HashMap<String, Object[]>) call(null, - "Product.get", new Object[] { new HashMap<String, Object[]>() { //$NON-NLS-1$ - { - put("ids", ids); //$NON-NLS-1$ - } - } }); - } catch (XmlRpcException e) { - result = null; - } catch (MalformedURLException e) { - result = null; - } - if (result != null) { - return result.get("products"); //$NON-NLS-1$ - } - return null; - } - -} diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaXMLRPCTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaXMLRPCTest.java deleted file mode 100644 index de699bcf8..000000000 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaXMLRPCTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * 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.bugzilla.tests.core; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Date; -import java.util.HashMap; - -import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture; -import org.eclipse.mylyn.commons.net.AuthenticationCredentials; -import org.eclipse.mylyn.commons.net.AuthenticationType; -import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector; -import org.eclipse.mylyn.internal.bugzilla.core.service.BugzillaXmlRpcClient; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.junit.Before; -import org.junit.Test; - -public class BugzillaXMLRPCTest { - private TaskRepository repository; - - private BugzillaRepositoryConnector connector; - - private static String TEST_REPO = "http://macmainz.dyndns.org/Internet/BugzillaDevelop"; - - - public static BugzillaFixture BUGS_3_7 = new BugzillaFixture(TEST_REPO, "3.7", ""); - - @Before - public void setUp() throws Exception { - repository = BugzillaFixture.current(BUGS_3_7).repository(); - repository.setCredentials(AuthenticationType.REPOSITORY, new AuthenticationCredentials("YYYYYYYY", "XXXXXXXX"), - false); - repository.setCredentials(AuthenticationType.HTTP, new AuthenticationCredentials("YYYYYYYY", "XXXXXXXX"), false); - connector = BugzillaFixture.current(BUGS_3_7).connector(); - } - - @Test - @SuppressWarnings("unused") - public void testxmlrpc() throws Exception { - BugzillaXmlRpcClient ws = new BugzillaXmlRpcClient(repository); - int user = ws.getUserID(); - assertEquals(-1, user); - - // Services from Bugzilla::WebService::Bugzilla - String version = ws.getVersion(); - assertEquals("3.7", version); - user = ws.getUserID(); - assertTrue(user != -1); - Date dbtime = ws.getDBTime(); - Date webtime = ws.getWebTime(); - HashMap<String, Date> time = ws.getTime(); - // native Response - Object[] xx0 = ws.getUserInfoFromIDs(new Integer[] { 1, 2 }); - Object[] xx1 = ws.getUserInfoFromNames(new String[] { "test@Frank-Becker.de" }); - Object[] xx2 = ws.getUserInfoWithMatch(new String[] { "tes" }); - Object[] xx3 = ws.getAllFields(); - Object[] xx4 = ws.getFieldsWithNames(new String[] { "qa_contact" }); - Object[] xx5 = ws.getFieldsWithIDs(new Integer[] { 12, 18 }); - Object[] xx6 = ws.getSelectableProducts(); - Object[] xx7 = ws.getEnterableProducts(); - Object[] xx8 = ws.getAccessibleProducts(); - Object[] xx9 = ws.getProducts(new Integer[] { 1, 3 }); - - user++; - user--; - } -} diff --git a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF index 8083e94a6..b9018cbd8 100644 --- a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF @@ -9,8 +9,7 @@ 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.apache.xmlrpc;bundle-version="[3.0.0,4.0.0)" + org.eclipse.mylyn.commons.net;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", @@ -18,6 +17,5 @@ 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.service + org.eclipse.mylyn.tasks.core.sync 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 deleted file mode 100644 index ac0282547..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseHttpMethodInterceptor.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * 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 deleted file mode 100644 index 436865817..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXMLRPCTransportFactory.java +++ /dev/null @@ -1,284 +0,0 @@ -/******************************************************************************* - * 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 deleted file mode 100644 index 2ba50cce5..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXmlRpcClient.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * 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 deleted file mode 100644 index 332778554..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXmlRpcClientRequest.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * 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 deleted file mode 100644 index 6ae639a3c..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/service/BaseXmlRpcClientRequestImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * 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; - } -} |