Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2006-11-14 21:41:01 -0500
committermkersten2006-11-14 21:41:01 -0500
commit12cb1b55a46017b65fe9ef6e3a9e1b88e37fe060 (patch)
treed514ab78b08b4e4ca07ffeee66610c9f7948d5f3 /org.eclipse.mylyn.trac.core/src
parent2834e3a2b8bb2b08ec5b1fef10d16159a02ead69 (diff)
downloadorg.eclipse.mylyn.tasks-12cb1b55a46017b65fe9ef6e3a9e1b88e37fe060.tar.gz
org.eclipse.mylyn.tasks-12cb1b55a46017b65fe9ef6e3a9e1b88e37fe060.tar.xz
org.eclipse.mylyn.tasks-12cb1b55a46017b65fe9ef6e3a9e1b88e37fe060.zip
RESOLVED - bug 164269: Update XML-RPC library
https://bugs.eclipse.org/bugs/show_bug.cgi?id=164269
Diffstat (limited to 'org.eclipse.mylyn.trac.core/src')
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java3
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java103
2 files changed, 22 insertions, 84 deletions
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java
index 206daf8c1..60b9de3f1 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java
@@ -63,7 +63,8 @@ public class TracXmlRpcClient extends AbstractTracClient {
config.setBasicPassword(password);
config.setServerURL(getXmlRpcUrl());
config.setTimeZone(TimeZone.getTimeZone(ITracClient.TIME_ZONE));
-
+ config.setContentLengthOptional(false);
+
xmlrpc = new XmlRpcClient();
xmlrpc.setConfig(config);
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 572760b0c..9d3e6b342 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
@@ -11,28 +11,22 @@
package org.eclipse.mylar.internal.trac.core.util;
-import java.io.BufferedOutputStream;
-import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.Proxy;
-import java.util.zip.GZIPInputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpVersion;
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.XmlRpcCommonsTransport;
import org.apache.xmlrpc.client.XmlRpcHttpClientConfig;
import org.apache.xmlrpc.client.XmlRpcTransport;
import org.apache.xmlrpc.client.XmlRpcTransportFactoryImpl;
-import org.apache.xmlrpc.util.XmlRpcIOException;
import org.eclipse.mylar.internal.tasks.core.WebClientUtil;
/**
@@ -58,13 +52,13 @@ public class TracHttpClientTransportFactory extends XmlRpcTransportFactoryImpl {
*/
public static class TracHttpClientTransport extends XmlRpcCommonsTransport {
- private int contentLength;
private Proxy proxy;
public TracHttpClientTransport(XmlRpcClient client) {
super(client);
XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) client.getConfig();
+
// this needs to be set to avoid exceptions
getHttpClient().getParams().setAuthenticationPreemptive(config.getBasicUserName() != null);
}
@@ -111,18 +105,30 @@ public class TracHttpClientTransportFactory extends XmlRpcTransportFactoryImpl {
}
}
- /**
- * Based on the implementation of XmlRpcCommonsTransport and its super classes.
- */
@Override
- public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
- XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pRequest.getConfig();
+ protected void initHttpHeaders(XmlRpcRequest request) throws XmlRpcClientException {
+ // super call needed to initialize private fields of XmlRpcCommonsTransport
+ super.initHttpHeaders(request);
+
+ // The super method sets a private field that contains the
+ // HttpClient Method object which is initialized using the wrong url.
+ // Since the URL can not be modified once the Method object has been
+ // constructed a new object is constructed here, initialized and
+ // assigned to the private field
+
+ XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) request.getConfig();
String url = config.getServerURL().toString();
WebClientUtil.setupHttpClient(getHttpClient(), proxy, url, null, null);
PostMethod method = new PostMethod(WebClientUtil.getRequestPath(url));
-
+ setMethod(method);
+
+ setRequestHeader("Content-Type", "text/xml");
+ setRequestHeader("User-Agent", getUserAgent());
+ setCredentials(config);
+ setCompressionHeaders(config);
+
if (config.getConnectionTimeout() != 0)
getHttpClient().getHttpConnectionManager().getParams().setConnectionTimeout(config.getConnectionTimeout());
@@ -130,75 +136,6 @@ public class TracHttpClientTransportFactory extends XmlRpcTransportFactoryImpl {
getHttpClient().getHttpConnectionManager().getParams().setSoTimeout(config.getConnectionTimeout());
method.getParams().setVersion(HttpVersion.HTTP_1_1);
-
- setMethod(method);
-
- initHttpHeaders(pRequest);
-
- boolean closed = false;
- try {
- RequestWriter writer = newRequestWriter(pRequest);
- writeRequest(writer);
- InputStream istream = getInputStream();
- if (isResponseGzipCompressed(config)) {
- istream = new GZIPInputStream(istream);
- }
- Object result = readResponse(config, istream);
- closed = true;
- close();
- return result;
- } catch (IOException e) {
- throw new XmlRpcException("Failed to read servers response: "
- + e.getMessage(), e);
- } finally {
- if (!closed) { try { close(); } catch (Throwable ignore) {} }
- }
- }
-
- @Override
- protected void writeRequest(final RequestWriter pWriter) throws XmlRpcException {
- getMethod().setRequestEntity(new RequestEntity(){
- public boolean isRepeatable() { return true; }
- public void writeRequest(OutputStream pOut) throws IOException {
- /* Make sure, that the socket is not closed by replacing it with our
- * own BufferedOutputStream.
- */
- BufferedOutputStream bos = new BufferedOutputStream(pOut){
- public void close() throws IOException {
- flush();
- }
- };
- try {
- Method m = RequestWriter.class.getDeclaredMethod("write", new Class[] { OutputStream.class });
- m.setAccessible(true);
- m.invoke(pWriter, bos);
- } catch (Exception e) {
- throw new XmlRpcIOException(e);
- }
- }
- public long getContentLength() { return contentLength; }
- public String getContentType() { return "text/xml"; }
- });
-
- try {
- getHttpClient().executeMethod(getMethod());
- } catch (XmlRpcIOException e) {
- Throwable t = e.getLinkedException();
- if (t instanceof XmlRpcException) {
- throw (XmlRpcException) t;
- } else {
- throw new XmlRpcException("Unexpected exception: " + t.getMessage(), t);
- }
- } catch (IOException e) {
- throw new XmlRpcException("I/O error while communicating with HTTP server: " + e.getMessage(), e);
- }
- }
-
- @Override
- protected void setContentLength(int pLength) {
- super.setContentLength(pLength);
-
- this.contentLength = pLength;
}
public void setProxy(Proxy proxy) {

Back to the top