Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java')
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java103
1 files changed, 20 insertions, 83 deletions
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