This is an automated email from the ASF dual-hosted git repository. billblough pushed a commit to branch AXIS2-4318 in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git
commit 29806b4d82fd045a94d0285dcf25003713a65b16 Author: Sagara Gunathunga <sag...@apache.org> AuthorDate: Wed Apr 18 12:16:43 2012 +0000 Applied provided patch AXIS2-4318. --- .../axis2/transport/http/AxisRequestEntity.java | 6 ++ .../axis2/transport/http/RESTRequestEntity2.java | 8 +- .../impl/httpclient4/AxisRequestEntityImpl.java | 81 +++++++++++++++++++ .../impl/httpclient4/HTTPTransportHeaders.java | 44 ++++++++++ .../httpclient4/HttpTransportPropertiesImpl.java | 93 ++++++++++++++++++++++ .../impl/httpclient4/RESTRequestEntity2Impl.java | 65 +++++++++++++++ .../impl/httpclient4/RESTRequestEntityImpl.java | 68 ++++++++++++++++ 7 files changed, 364 insertions(+), 1 deletion(-) diff --git a/modules/transport/http/src/org/apache/axis2/transport/http/AxisRequestEntity.java b/modules/transport/http/src/org/apache/axis2/transport/http/AxisRequestEntity.java index 8834def..2fe3e2e 100644 --- a/modules/transport/http/src/org/apache/axis2/transport/http/AxisRequestEntity.java +++ b/modules/transport/http/src/org/apache/axis2/transport/http/AxisRequestEntity.java @@ -26,7 +26,9 @@ import org.apache.axis2.transport.MessageFormatter; import org.apache.axis2.util.JavaUtils; import javax.xml.stream.FactoryConfigurationError; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.util.zip.GZIPOutputStream; @@ -124,6 +126,10 @@ public abstract class AxisRequestEntity { public void setChunked(boolean chunked) { this.chunked = chunked; } + + public InputStream getRequestEntityContent() throws IOException { + return new ByteArrayInputStream(messageFormatter.getBytes(messageContext, format)); + } } diff --git a/modules/transport/http/src/org/apache/axis2/transport/http/RESTRequestEntity2.java b/modules/transport/http/src/org/apache/axis2/transport/http/RESTRequestEntity2.java index 434b127..1dfa528 100644 --- a/modules/transport/http/src/org/apache/axis2/transport/http/RESTRequestEntity2.java +++ b/modules/transport/http/src/org/apache/axis2/transport/http/RESTRequestEntity2.java @@ -19,7 +19,9 @@ package org.apache.axis2.transport.http; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; public abstract class RESTRequestEntity2 { @@ -59,5 +61,9 @@ public abstract class RESTRequestEntity2 { public void setPostRequestBody(String postRequestBody) { this.postRequestBody = postRequestBody; } - + + public InputStream getRequestEntityContent() { + return new ByteArrayInputStream(this.postRequestBody.getBytes()); + } + } diff --git a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/AxisRequestEntityImpl.java b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/AxisRequestEntityImpl.java new file mode 100644 index 0000000..5be5a33 --- /dev/null +++ b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/AxisRequestEntityImpl.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.transport.http.impl.httpclient4; + +import org.apache.axiom.om.OMOutputFormat; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.transport.MessageFormatter; +import org.apache.axis2.transport.http.AxisRequestEntity; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.http.Header; +import org.apache.http.HttpEntity; +import org.apache.http.message.BasicHeader; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * This Request Entity is used by the HttpComponentsTransportSender. This wraps the + * Axis2 message formatter object. + */ +public class AxisRequestEntityImpl extends AxisRequestEntity implements HttpEntity { + + /** + * Method calls to this request entity are delegated to the following Axis2 + * message formatter object. + * + * @param messageFormatter + * @param msgContext + * @param format + * @param soapAction + * @param chunked + * @param isAllowedRetry + */ + public AxisRequestEntityImpl(MessageFormatter messageFormatter, MessageContext msgContext, + OMOutputFormat format, String soapAction, boolean chunked, boolean isAllowedRetry) { + super(messageFormatter, msgContext, format, soapAction, chunked, isAllowedRetry); + } + + public Header getContentType() { + return new BasicHeader(HTTPConstants.HEADER_CONTENT_TYPE, getContentTypeAsString()); + } + + public Header getContentEncoding() { + return null; + } + + public InputStream getContent() throws IOException { + return getRequestEntityContent(); + } + + public void writeTo(OutputStream outputStream) throws IOException { + writeRequest(outputStream); + } + + public boolean isStreaming() { + return false; + } + + public void consumeContent() { + // TODO: Handle this correctly + } + +} diff --git a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPTransportHeaders.java b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPTransportHeaders.java new file mode 100644 index 0000000..ed6d058 --- /dev/null +++ b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPTransportHeaders.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.transport.http.impl.httpclient4; + +import org.apache.axis2.transport.http.CommonsTransportHeaders; +import org.apache.http.Header; + +import java.util.HashMap; + + +public class HTTPTransportHeaders extends CommonsTransportHeaders { + + private Header[] headers; + + public HTTPTransportHeaders(Header[] headers) { + this.headers = headers; + + } + + protected void init() { + setHeaderMap(new HashMap()); + for (int i = 0; i < headers.length; i++) { + getHeaderMap().put(headers[i].getName(), headers[i].getValue()); + } + } + +} diff --git a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HttpTransportPropertiesImpl.java b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HttpTransportPropertiesImpl.java new file mode 100644 index 0000000..dd34240 --- /dev/null +++ b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HttpTransportPropertiesImpl.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.transport.http.impl.httpclient4; + +import org.apache.axis2.transport.http.HTTPAuthenticator; +import org.apache.axis2.transport.http.HttpTransportProperties; +import org.apache.http.HttpVersion; +import org.apache.http.auth.AuthScope; +import org.apache.http.client.params.AuthPolicy; + +public class HttpTransportPropertiesImpl extends HttpTransportProperties { + + protected HttpVersion httpVersion; + + @Override + public void setHttpVersion(Object httpVerion) { + this.httpVersion = (HttpVersion) httpVerion; + } + + @Override + public Object getHttpVersion() { + return this.httpVersion; + } + + /* + * This class is responsible for holding all the necessary information + * needed for NTML, Digest, Basic and SPNEGO(Keberos) Authentication. + * Authentication itself is handled by httpclient. User doesn't need + * to worry about what authentication mechanism it uses. Axis2 uses + * httpclinet's default authentication patterns. + */ + public static class Authenticator extends HTTPAuthenticator { + + /* port of the host that needed to be authenticated with */ + private int port = AuthScope.ANY_PORT; + /* Realm for authentication scope */ + private String realm = AuthScope.ANY_REALM; + /* Default Auth Schems */ + public static final String NTLM = AuthPolicy.NTLM; + public static final String DIGEST = AuthPolicy.DIGEST; + public static final String BASIC = AuthPolicy.BASIC; + public static final String SPNEGO = AuthPolicy.SPNEGO; + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getRealm() { + return realm; + } + + public void setRealm(String realm) { + this.realm = realm; + } + + @Override + public Object getAuthPolicyPref(String scheme) { + if (BASIC.equals(scheme)) { + return AuthPolicy.BASIC; + } else if (NTLM.equals(scheme)) { + return AuthPolicy.NTLM; + } else if (DIGEST.equals(scheme)) { + return AuthPolicy.DIGEST; + } else if (SPNEGO.equals(scheme)) { + return AuthPolicy.SPNEGO; + } + return null; + } + + } + +} diff --git a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RESTRequestEntity2Impl.java b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RESTRequestEntity2Impl.java new file mode 100644 index 0000000..634fa8a --- /dev/null +++ b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RESTRequestEntity2Impl.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.transport.http.impl.httpclient4; + +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.transport.http.RESTRequestEntity2; +import org.apache.http.Header; +import org.apache.http.HttpEntity; +import org.apache.http.message.BasicHeader; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class RESTRequestEntity2Impl extends RESTRequestEntity2 implements HttpEntity{ + + public RESTRequestEntity2Impl(String postRequestBody, String contentType) { + super(postRequestBody, contentType); + } + + public boolean isChunked() { + return false; + } + + public Header getContentType() { + return new BasicHeader(HTTPConstants.HEADER_CONTENT_TYPE, getContentTypeAsString()); + } + + public Header getContentEncoding() { + return null; + } + + public InputStream getContent() throws IOException{ + return getRequestEntityContent(); + } + + public void writeTo(OutputStream outputStream) throws IOException { + writeRequest(outputStream); + } + + public boolean isStreaming() { + return false; + } + + public void consumeContent() { + //TODO : Handle this correctly + } +} diff --git a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RESTRequestEntityImpl.java b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RESTRequestEntityImpl.java new file mode 100644 index 0000000..1107ad8 --- /dev/null +++ b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RESTRequestEntityImpl.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.transport.http.impl.httpclient4; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMOutputFormat; +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.transport.http.RESTRequestEntity; +import org.apache.http.Header; +import org.apache.http.HttpEntity; +import org.apache.http.message.BasicHeader; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class RESTRequestEntityImpl extends RESTRequestEntity implements HttpEntity { + + public RESTRequestEntityImpl(OMElement element, boolean chunked, MessageContext msgCtxt, + String charSetEncoding, String soapActionString, OMOutputFormat format) { + super(element, chunked, msgCtxt, charSetEncoding, soapActionString, format); + } + + public Header getContentType() { + return new BasicHeader(HTTPConstants.HEADER_CONTENT_TYPE, getContentTypeAsString()); + } + + public Header getContentEncoding() { + return null; + } + + public InputStream getContent() throws AxisFault { + return new ByteArrayInputStream(writeBytes()); + } + + public void writeTo(OutputStream outputStream) throws IOException { + writeRequest(outputStream); + } + + public boolean isStreaming() { + return false; + } + + public void consumeContent() { + //TODO : Handle this correctly + } + +}