You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2006/09/14 16:42:28 UTC
svn commit: r443366 - in
/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http:
AbstractHTTPSender.java HTTPConstants.java HttpTransportProperties.java
RESTSender.java SOAPOverHTTPSender.java
Author: dims
Date: Thu Sep 14 07:42:27 2006
New Revision: 443366
URL: http://svn.apache.org/viewvc?view=rev&rev=443366
Log:
- New property (HTTPConstants.ALLOW_RETRY) for handling serialize/serializeWithConsume switch
- Move AxisRequestEntity to RESTSender (only place where it is used)
- Convert authenticationEnabled into a method (isAuthenticationEnabled)
- Allow the user to set the order and names of which Auth schemes to try
- Allow user to switch on/off the preemptive flag
- Allow user to specify BOTH proxy auth info *AND* endpoint authentication info for a web service at the same time.
Modified:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HttpTransportProperties.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java?view=diff&rev=443366&r1=443365&r2=443366
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java Thu Sep 14 07:42:27 2006
@@ -28,23 +28,30 @@
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.util.JavaUtils;
import org.apache.axis2.util.Utils;
-import org.apache.commons.httpclient.*;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HeaderElement;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.NTCredentials;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthPolicy;
import org.apache.commons.httpclient.auth.AuthScope;
-import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.xml.namespace.QName;
-import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLStreamException;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import java.util.zip.GZIPInputStream;
public abstract class AbstractHTTPSender {
@@ -56,8 +63,6 @@
private static final Log log = LogFactory.getLog(AbstractHTTPSender.class);
int soTimeout = HTTPConstants.DEFAULT_SO_TIMEOUT;
- protected boolean authenticationEnabled;
-
/**
* proxydiscription
*/
@@ -297,7 +302,8 @@
throws AxisFault {
boolean isHostProxy = isProxyListed(msgCtx); // list the proxy
- authenticationEnabled = serverPreemtiveAuthentication(msgCtx); // server authentication
+
+ boolean authenticationEnabled = isAuthenticationEnabled(msgCtx);
int port = targetURL.getPort();
if (port == -1) {
@@ -307,14 +313,15 @@
// to see the host is a proxy and in the proxy list - available in axis2.xml
HostConfiguration config = new HostConfiguration();
- if (!isHostProxy && !authenticationEnabled) {
- config.setHost(targetURL.getHost(), port, targetURL.getProtocol());
- } else if (authenticationEnabled) {
+ if (authenticationEnabled) {
// premtive authentication Basic or NTLM
- this.configServerPreemtiveAuthenticaiton(client, msgCtx, config, targetURL);
- } else {
+ this.setAuthenticationInfo(client, msgCtx, config, targetURL);
+ }
// proxy configuration
+ if (!isHostProxy) {
+ config.setHost(targetURL.getHost(), port, targetURL.getProtocol());
+ } else {
this.configProxyAuthentication(client, proxyOutSetting, config,
msgCtx);
}
@@ -322,18 +329,20 @@
return config;
}
+ protected boolean isAuthenticationEnabled(MessageContext msgCtx) {
+ return (msgCtx.getProperty(HTTPConstants.AUTHENTICATE) != null);
+ }
+
/*
This will handle server Authentication, It could be either NTLM, Digest or Basic Authentication
*/
- protected void configServerPreemtiveAuthenticaiton(HttpClient agent,
+ protected void setAuthenticationInfo(HttpClient agent,
MessageContext msgCtx,
HostConfiguration config,
URL targetURL) throws AxisFault {
config.setHost(targetURL.getHost(), targetURL.getPort(),
targetURL.getProtocol());
- agent.getParams().setAuthenticationPreemptive(true);
-
HttpTransportProperties.Authenticator authenticator;
Object obj = msgCtx.getProperty(HTTPConstants.AUTHENTICATE);
if (obj != null) {
@@ -350,6 +359,8 @@
Credentials creds;
+ agent.getParams().setAuthenticationPreemptive(authenticator.getPreemptiveAuthentication());
+
if (host != null) {
if (domain != null) {
/*Credentials for NTLM Authentication*/
@@ -364,6 +375,32 @@
creds = new UsernamePasswordCredentials(username, password);
agent.getState().setCredentials(new AuthScope(AuthScope.ANY), creds);
}
+
+ List schemes = authenticator.getAuthSchemes();
+ if (schemes != null && schemes.size() > 0) {
+ List authPrefs = new ArrayList(3);
+ for (int i = 0; i < schemes.size(); i++) {
+ if (schemes.get(i) instanceof AuthPolicy) {
+ authPrefs.add(schemes.get(i));
+ continue;
+ }
+ String scheme = (String) schemes.get(i);
+ if (HttpTransportProperties.Authenticator.BASIC.equals(scheme)) {
+ authPrefs.add(AuthPolicy.BASIC);
+ } else if (HttpTransportProperties.Authenticator.NTLM.equals(scheme)) {
+ authPrefs.add(AuthPolicy.NTLM);
+ } else if (HttpTransportProperties.Authenticator.DIGEST.equals(scheme)) {
+ authPrefs.add(AuthPolicy.DIGEST);
+ }
+ }
+ // If it is NTLM, then definitely switch on the RETRY flag.
+ if (authPrefs.indexOf(AuthPolicy.NTLM) != -1) {
+ msgCtx.setProperty(HTTPConstants.ALLOW_RETRY, Boolean.TRUE);
+ }
+ agent.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
+ authPrefs);
+ }
+
} else {
throw new AxisFault("HttpTransportProperties.Authenticator class cast exception");
}
@@ -403,13 +440,6 @@
}
}
- //Server Preemptive Authentication RUNTIME
-
- private boolean serverPreemtiveAuthentication(MessageContext msgContext) {
-
- return (msgContext.getProperty(HTTPConstants.AUTHENTICATE) != null);
- }
-
private boolean isProxyListed(MessageContext msgCtx) throws AxisFault {
boolean returnValue = false;
Parameter par = null;
@@ -455,123 +485,6 @@
public void setFormat(OMOutputFormat format) {
this.format = format;
- }
-
- public class AxisRequestEntity implements RequestEntity {
- private boolean doingMTOM = false;
- private byte[] bytes;
- private String charSetEnc;
- private boolean chunked;
- private OMElement element;
- private MessageContext msgCtxt;
- private String soapActionString;
-
- public AxisRequestEntity(OMElement element, boolean chunked,
- MessageContext msgCtxt,
- String charSetEncoding,
- String soapActionString) {
- this.element = element;
- this.chunked = chunked;
- this.msgCtxt = msgCtxt;
- this.doingMTOM = msgCtxt.isDoingMTOM();
- this.charSetEnc = charSetEncoding;
- this.soapActionString = soapActionString;
- }
-
- private void handleOMOutput(OutputStream out, boolean doingMTOM)
- throws XMLStreamException {
- format.setDoOptimize(doingMTOM);
- element.serializeAndConsume(out, format);
- }
-
- public byte[] writeBytes() throws AxisFault {
- try {
- ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
-
- if (!doingMTOM) {
- OMOutputFormat format2 = new OMOutputFormat();
-
- format2.setCharSetEncoding(charSetEnc);
- element.serializeAndConsume(bytesOut, format2);
-
- return bytesOut.toByteArray();
- } else {
- format.setCharSetEncoding(charSetEnc);
- format.setDoOptimize(true);
- element.serializeAndConsume(bytesOut, format);
-
- return bytesOut.toByteArray();
- }
- } catch (XMLStreamException e) {
- throw new AxisFault(e);
- } catch (FactoryConfigurationError e) {
- throw new AxisFault(e);
- }
- }
-
- public void writeRequest(OutputStream out) throws IOException {
- try {
- {
- if (chunked) {
- this.handleOMOutput(out, doingMTOM);
- } else {
- if (bytes == null) {
- bytes = writeBytes();
- }
-
- out.write(bytes);
- }
- }
-
- out.flush();
- } catch (XMLStreamException e) {
- throw new AxisFault(e);
- } catch (FactoryConfigurationError e) {
- throw new AxisFault(e);
- } catch (IOException e) {
- throw new AxisFault(e);
- }
- }
-
- public long getContentLength() {
- try {
- {
- if (chunked) {
- return -1;
- } else {
- if (bytes == null) {
- bytes = writeBytes();
- }
-
- return bytes.length;
- }
- }
- } catch (AxisFault e) {
- return -1;
- }
- }
-
- public String getContentType() {
- String encoding = format.getCharSetEncoding();
- String contentType = format.getContentType();
-
- if (encoding != null) {
- contentType += "; charset=" + encoding;
- }
-
- // action header is not mandated in SOAP 1.2. So putting it, if available
- if (!msgCtxt.isSOAP11() && (soapActionString != null)
- && !"".equals(soapActionString.trim())) {
- contentType =
- contentType + ";action=\"" + soapActionString + "\";";
- }
-
- return contentType;
- }
-
- public boolean isRepeatable() {
- return true;
- }
}
protected HttpClient getHttpClient(MessageContext msgContext) {
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java?view=diff&rev=443366&r1=443365&r2=443366
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java Thu Sep 14 07:42:27 2006
@@ -382,8 +382,9 @@
public static final String PROXY = "PROXY";
public static final String MAIL_SMTP = "_MAIL_SMTP_";
public static final String MAIL_POP3 = "_MAIL_POP3_";
- public static final String AUTHENTICATE = "_NTML_DIGEST_BASIC_AUTHENTICATION_";
+ public static final String AUTHENTICATE = "_NTLM_DIGEST_BASIC_AUTHENTICATION_";
public static final String MTOM_RECEIVED_CONTENT_TYPE = "MTOM_RECEIVED";
+ public static final String ALLOW_RETRY = "_ALLOW_RETRY_";
/**
* Field ISE[]
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HttpTransportProperties.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HttpTransportProperties.java?view=diff&rev=443366&r1=443365&r2=443366
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HttpTransportProperties.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HttpTransportProperties.java Thu Sep 14 07:42:27 2006
@@ -20,7 +20,7 @@
import org.apache.commons.httpclient.auth.AuthScope;
import java.util.Properties;
-
+import java.util.List;
/**
* Utility bean for setting transport properties in runtime.
*/
@@ -137,6 +137,12 @@
private String username;
/*Password of the user for authenticate*/
private String password;
+ private List authSchemes;
+ private boolean preempt = true;
+
+ public static final java.lang.String NTLM = "NTLM";
+ public static final java.lang.String DIGEST = "Digest";
+ public static final java.lang.String BASIC = "Basic";
public String getHost() {
return host;
@@ -176,6 +182,22 @@
public void setPassword(String password) {
this.password = password;
+ }
+
+ public void setAuthSchemes(List authSchemes) {
+ this.authSchemes = authSchemes;
+ }
+
+ public List getAuthSchemes() {
+ return this.authSchemes;
+ }
+
+ public void setPreemptiveAuthentication(boolean preempt) {
+ this.preempt = preempt;
+ }
+
+ public boolean getPreemptiveAuthentication() {
+ return this.preempt;
}
public String getDomain() {
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java?view=diff&rev=443366&r1=443365&r2=443366
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java Thu Sep 14 07:42:27 2006
@@ -18,6 +18,7 @@
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axis2.AxisFault;
@@ -34,8 +35,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.FactoryConfigurationError;
import java.io.IOException;
import java.io.OutputStream;
+import java.io.ByteArrayOutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@@ -144,7 +148,7 @@
throws MalformedURLException, AxisFault, IOException {
String param = getParam(msgContext);
GetMethod getMethod = new GetMethod();
- if (authenticationEnabled) {
+ if (isAuthenticationEnabled(msgContext)) {
getMethod.setDoAuthentication(true);
}
@@ -201,7 +205,7 @@
HttpClient httpClient = getHttpClient(msgContext);
PostMethod postMethod = new PostMethod(url.toString());
- if(authenticationEnabled) {
+ if(isAuthenticationEnabled(msgContext)) {
postMethod.setDoAuthentication(true);
}
String httpContentType;
@@ -321,6 +325,123 @@
}
return paraString;
+ }
+
+ public class AxisRequestEntity implements RequestEntity {
+ private boolean doingMTOM = false;
+ private byte[] bytes;
+ private String charSetEnc;
+ private boolean chunked;
+ private OMElement element;
+ private MessageContext msgCtxt;
+ private String soapActionString;
+
+ public AxisRequestEntity(OMElement element, boolean chunked,
+ MessageContext msgCtxt,
+ String charSetEncoding,
+ String soapActionString) {
+ this.element = element;
+ this.chunked = chunked;
+ this.msgCtxt = msgCtxt;
+ this.doingMTOM = msgCtxt.isDoingMTOM();
+ this.charSetEnc = charSetEncoding;
+ this.soapActionString = soapActionString;
+ }
+
+ private void handleOMOutput(OutputStream out, boolean doingMTOM)
+ throws XMLStreamException {
+ format.setDoOptimize(doingMTOM);
+ element.serializeAndConsume(out, format);
+ }
+
+ public byte[] writeBytes() throws AxisFault {
+ try {
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+
+ if (!doingMTOM) {
+ OMOutputFormat format2 = new OMOutputFormat();
+
+ format2.setCharSetEncoding(charSetEnc);
+ element.serializeAndConsume(bytesOut, format2);
+
+ return bytesOut.toByteArray();
+ } else {
+ format.setCharSetEncoding(charSetEnc);
+ format.setDoOptimize(true);
+ element.serializeAndConsume(bytesOut, format);
+
+ return bytesOut.toByteArray();
+ }
+ } catch (XMLStreamException e) {
+ throw new AxisFault(e);
+ } catch (FactoryConfigurationError e) {
+ throw new AxisFault(e);
+ }
+ }
+
+ public void writeRequest(OutputStream out) throws IOException {
+ try {
+ {
+ if (chunked) {
+ this.handleOMOutput(out, doingMTOM);
+ } else {
+ if (bytes == null) {
+ bytes = writeBytes();
+ }
+
+ out.write(bytes);
+ }
+ }
+
+ out.flush();
+ } catch (XMLStreamException e) {
+ throw new AxisFault(e);
+ } catch (FactoryConfigurationError e) {
+ throw new AxisFault(e);
+ } catch (IOException e) {
+ throw new AxisFault(e);
+ }
+ }
+
+ public long getContentLength() {
+ try {
+ {
+ if (chunked) {
+ return -1;
+ } else {
+ if (bytes == null) {
+ bytes = writeBytes();
+ }
+
+ return bytes.length;
+ }
+ }
+ } catch (AxisFault e) {
+ return -1;
+ }
+ }
+
+ public String getContentType() {
+ String encoding = format.getCharSetEncoding();
+ String contentType = format.getContentType();
+
+ if (encoding != null) {
+ contentType += "; charset=" + encoding;
+ }
+
+ // action header is not mandated in SOAP 1.2. So putting it, if available
+ if (!msgCtxt.isSOAP11() && (soapActionString != null)
+ && !"".equals(soapActionString.trim())) {
+ contentType =
+ contentType + ";action=\"" + soapActionString + "\";";
+ }
+
+ return contentType;
+ }
+
+ public boolean isRepeatable() {
+ return true;
+ }
}
public class AxisRESTRequestEntity implements RequestEntity {
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java?view=diff&rev=443366&r1=443365&r2=443366
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java Thu Sep 14 07:42:27 2006
@@ -54,7 +54,7 @@
// handle multiple
HttpClient httpClient = getHttpClient(msgContext);
PostMethod postMethod = new PostMethod(url.toString());
- if (authenticationEnabled) {
+ if (isAuthenticationEnabled(msgContext)) {
postMethod.setDoAuthentication(true);
}
@@ -174,18 +174,14 @@
if (!doingMTOM & doingSWA) {
StringWriter bufferedSOAPBody = new StringWriter();
- //To support NTLM Authentication the following check has been
- // done.
- if (msgCtxt.getProperty(HTTPConstants.AUTHENTICATE) != null) {
+ if (msgCtxt.getProperty(HTTPConstants.ALLOW_RETRY) != null) {
element.serialize(bufferedSOAPBody, format);
} else {
element.serializeAndConsume(bufferedSOAPBody, format);
}
MIMEOutputUtils.writeSOAPWithAttachmentsMessage(bufferedSOAPBody,out,msgCtxt.getAttachmentMap(), format);
} else {
- // To support NTLM Authentication the following check has been
- // done.
- if (msgCtxt.getProperty(HTTPConstants.AUTHENTICATE) != null) {
+ if (msgCtxt.getProperty(HTTPConstants.ALLOW_RETRY) != null) {
element.serialize(out, format);
} else {
element.serializeAndConsume(out, format);
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org