Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2010-04-18 06:20:44 +0000
committerspingel2010-04-18 06:20:44 +0000
commit8461ca1436d01d992fdcc8f215e02d9178b5ddf3 (patch)
treedb4d73db1502a31226df395c7d108fde8a1405f7
parent67ec5c80e7ad24faa139af536ebe41d427404a57 (diff)
downloadorg.eclipse.mylyn.tasks-8461ca1436d01d992fdcc8f215e02d9178b5ddf3.tar.gz
org.eclipse.mylyn.tasks-8461ca1436d01d992fdcc8f215e02d9178b5ddf3.tar.xz
org.eclipse.mylyn.tasks-8461ca1436d01d992fdcc8f215e02d9178b5ddf3.zip
NEW - bug 308737: provide generic XML-RPC transport layer
https://bugs.eclipse.org/bugs/show_bug.cgi?id=308737
-rw-r--r--org.eclipse.mylyn.trac-feature/feature.xml7
-rw-r--r--org.eclipse.mylyn.trac.core/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcClient.java2
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcOperation.java161
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java2
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracUtil.java38
6 files changed, 170 insertions, 41 deletions
diff --git a/org.eclipse.mylyn.trac-feature/feature.xml b/org.eclipse.mylyn.trac-feature/feature.xml
index 710962111..49e9b9ed6 100644
--- a/org.eclipse.mylyn.trac-feature/feature.xml
+++ b/org.eclipse.mylyn.trac-feature/feature.xml
@@ -50,6 +50,13 @@
</requires>
<plugin
+ id="org.eclipse.mylyn.commons.xmlrpc"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
id="org.eclipse.mylyn.trac.ui"
download-size="0"
install-size="0"
diff --git a/org.eclipse.mylyn.trac.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.trac.core/META-INF/MANIFEST.MF
index 9389b5b7d..7653d0eb8 100644
--- a/org.eclipse.mylyn.trac.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.trac.core/META-INF/MANIFEST.MF
@@ -9,6 +9,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.mylyn.tasks.core;bundle-version="[3.0.0,4.0.0)",
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.xmlrpc;bundle-version="[3.0.0,4.0.0)",
org.apache.xmlrpc;bundle-version="[3.0.0,4.0.0)"
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.mylyn.internal.trac.core;x-friends:="org.eclipse.mylyn.trac.ui",
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcClient.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcClient.java
index 1955b1496..8f1d25a7e 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcClient.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcClient.java
@@ -158,7 +158,7 @@ public class TracXmlRpcClient extends AbstractTracClient implements ITracWikiCli
probeAuthenticationScheme(monitor);
}
if (DEBUG_XMLRPC) {
- System.err.println("Calling " + location.getUrl() + ": " + method + " " + TracUtil.toString(parameters)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ System.err.println("Calling " + location.getUrl() + ": " + method + " " + CoreUtil.toString(parameters)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
TracXmlRpcClientRequest request = new TracXmlRpcClientRequest(xmlrpc.getClientConfig(), method,
parameters, monitor);
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcOperation.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcOperation.java
new file mode 100644
index 000000000..ac6a80b8b
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcOperation.java
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Steffen Pingel 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:
+ * Steffen Pingel - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.trac.core.client;
+
+import java.util.regex.Pattern;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
+import org.eclipse.mylyn.commons.net.AuthenticationType;
+import org.eclipse.mylyn.internal.commons.xmlrpc.CommonXmlRpcClient;
+import org.eclipse.mylyn.internal.commons.xmlrpc.XmlRpcOperation;
+import org.eclipse.mylyn.internal.commons.xmlrpc.XmlRpcPermissionDeniedException;
+
+/**
+ * @author Steffen Pingel
+ */
+abstract class TracXmlRpcOperation<T> extends XmlRpcOperation<T> {
+
+ private static final Pattern RPC_METHOD_NOT_FOUND_PATTERN = Pattern.compile("RPC method \".*\" not found"); //$NON-NLS-1$
+
+ private boolean accountMangerAuthenticationFailed;
+
+ public TracXmlRpcOperation(CommonXmlRpcClient client) {
+ super(client);
+ }
+
+ @Override
+ protected Object executeCall(IProgressMonitor monitor, String method, Object... parameters) throws XmlRpcException {
+ try {
+ // first attempt
+ preCall();
+ return super.executeCall(monitor, method, parameters);
+ } catch (XmlRpcPermissionDeniedException e) {
+ if (accountMangerAuthenticationFailed) {
+ // do not try again if this has failed in the past since it
+ // is more likely that XML_RPC permissions have not been set
+ throw e;
+ }
+
+ AuthenticationCredentials credentials = getClient().getLocation().getCredentials(
+ AuthenticationType.REPOSITORY);
+ if (!credentialsValid(credentials)) {
+ throw e;
+ }
+
+ // try form-based authentication via AccountManagerPlugin as a
+ // fall-back
+// HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(getClient().getHttpClient(),
+// getClient().getLocation(), monitor);
+// try {
+// authenticateAccountManager(getClient().httpClient, hostConfiguration, credentials, monitor);
+// } catch (XmlRpcLoginException loginException) {
+// // caused by wrong user name or password
+// throw loginException;
+// } catch (IOException ignore) {
+// accountMangerAuthenticationFailed = true;
+// throw e;
+// }
+//
+// try {
+// validateAuthenticationState(getClient().httpClient);
+// } catch (XmlRpcLoginException ignore) {
+// // most likely form based authentication is not supported by
+// // repository
+// accountMangerAuthenticationFailed = true;
+// throw e;
+// }
+
+ // the authentication information is available through the shared state in httpClient
+ }
+
+ // second attempt
+ preCall();
+ return super.executeCall(monitor, method, parameters);
+ }
+
+ private void preCall() {
+// if (isTracd && digestScheme != null) {
+// probeAuthenticationScheme(monitor);
+// }
+ }
+
+// void probeAuthenticationScheme(IProgressMonitor monitor) throws XmlRpcException {
+// AuthenticationCredentials credentials = client.getLocation().getCredentials(AuthenticationType.REPOSITORY);
+// if (!credentialsValid(credentials)) {
+// return;
+// }
+//
+// if (CommonXmlRpcClient.DEBUG_AUTH) {
+// System.err.println(client.getLocation().getUrl() + ": Probing authentication"); //$NON-NLS-1$
+// }
+// HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor);
+// HeadMethod method = new HeadMethod(getXmlRpcUrl(credentials).toString());
+// try {
+// // execute without any credentials set
+// int result = WebUtil.execute(httpClient, hostConfiguration, method, new HttpState(), monitor);
+// if (CommonXmlRpcClient.DEBUG_AUTH) {
+// System.err.println(client.getLocation().getUrl()
+// + ": Received authentication response (" + result + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// if (result == HttpStatus.SC_UNAUTHORIZED || result == HttpStatus.SC_FORBIDDEN) {
+// AuthScheme authScheme = method.getHostAuthState().getAuthScheme();
+// if (authScheme instanceof DigestScheme) {
+// client.digestScheme = (DigestScheme) authScheme;
+// if (CommonXmlRpcClient.DEBUG_AUTH) {
+// System.err.println(client.getLocation().getUrl() + ": Received digest scheme"); //$NON-NLS-1$
+// }
+// } else if (authScheme instanceof BasicScheme) {
+// httpClient.getParams().setAuthenticationPreemptive(true);
+// if (CommonXmlRpcClient.DEBUG_AUTH) {
+// System.err.println(client.getLocation().getUrl() + ": Received basic scheme"); //$NON-NLS-1$
+// }
+// } else if (authScheme != null) {
+// if (CommonXmlRpcClient.DEBUG_AUTH) {
+// System.err.println(client.getLocation().getUrl()
+// + ": Received scheme (" + authScheme.getClass() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// } else {
+// if (CommonXmlRpcClient.DEBUG_AUTH) {
+// System.err.println(client.getLocation().getUrl() + ": No authentication scheme received"); //$NON-NLS-1$
+// }
+// }
+//
+// Header header = method.getResponseHeader("Server"); //$NON-NLS-1$
+// isTracd = (header != null && header.getValue().startsWith("tracd")); //$NON-NLS-1$
+// if (CommonXmlRpcClient.DEBUG_AUTH && isTracd) {
+// System.err.println(client.getLocation().getUrl() + ": Tracd detected"); //$NON-NLS-1$
+// }
+// }
+// } catch (IOException e) {
+// // ignore
+// } finally {
+// method.releaseConnection();
+// }
+//}
+
+ @Override
+ protected boolean isNoSuchMethodException(XmlRpcException e) {
+ // the fault code is used for various errors, therefore detection is based on the message
+ // message format by XML-RPC Plugin version:
+ // 1.0.1: XML-RPC method "ticket.ge1t" not found
+ // 1.0.6: RPC method "ticket.ge1t" not found
+ // 1.10: RPC method "ticket.ge1t" not found' while executing 'ticket.ge1t()
+ if (e.code == XML_FAULT_GENERAL_ERROR && e.getMessage() != null
+ && RPC_METHOD_NOT_FOUND_PATTERN.matcher(e.getMessage()).find()) {
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java
index 69ae72979..ae1163907 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java
@@ -251,8 +251,6 @@ public class TracHttpClientTransportFactory implements XmlRpcTransportFactory {
}
- protected static final String USER_AGENT = "TracConnector Apache XML-RPC/3.0"; //$NON-NLS-1$
-
private final XmlRpcClient xmlRpcClient;
private AbstractWebLocation location;
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracUtil.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracUtil.java
index 703b63d6b..0f1a8926c 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracUtil.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracUtil.java
@@ -15,7 +15,6 @@ package org.eclipse.mylyn.internal.trac.core.util;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
-import java.util.Map;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.mylyn.internal.trac.core.TracCorePlugin;
@@ -92,41 +91,4 @@ public class TracUtil {
}
}
- public static String toString(Object object) {
- StringBuilder sb = new StringBuilder();
- toString(sb, object);
- return sb.toString();
- }
-
- public static void toString(StringBuilder sb, Object object) {
- if (object instanceof Object[]) {
- sb.append("["); //$NON-NLS-1$
- Object[] entries = (Object[]) object;
- boolean prependSeparator = false;
- for (Object entry : entries) {
- if (prependSeparator) {
- sb.append(", "); //$NON-NLS-1$
- }
- toString(sb, entry);
- prependSeparator = true;
- }
- sb.append("]"); //$NON-NLS-1$
- } else if (object instanceof Map<?, ?>) {
- sb.append("{"); //$NON-NLS-1$
- boolean prependSeparator = false;
- for (Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
- if (prependSeparator) {
- sb.append(", "); //$NON-NLS-1$
- }
- toString(sb, entry.getKey());
- sb.append("="); //$NON-NLS-1$
- toString(sb, entry.getValue());
- prependSeparator = true;
- }
- sb.append("}"); //$NON-NLS-1$
- } else {
- sb.append(object);
- }
- }
-
}

Back to the top