[teiid-commits] teiid SVN: r2138 - in trunk/connectors/connector-ws/src/main: rar/META-INF and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue May 18 12:05:11 EDT 2010


Author: shawkins
Date: 2010-05-18 12:05:10 -0400 (Tue, 18 May 2010)
New Revision: 2138

Modified:
   trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnection.java
   trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSManagedConnectionFactory.java
   trunk/connectors/connector-ws/src/main/rar/META-INF/ra.xml
Log:
TEIID-1077: adding the connector-ws module

Modified: trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnection.java
===================================================================
--- trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnection.java	2010-05-18 15:20:27 UTC (rev 2137)
+++ trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnection.java	2010-05-18 16:05:10 UTC (rev 2138)
@@ -1,6 +1,8 @@
 package org.teiid.resource.adapter.ws;
 
 import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -23,31 +25,31 @@
 import javax.xml.ws.soap.SOAPBinding;
 
 import org.jboss.ws.core.ConfigProvider;
-import org.teiid.resource.adapter.ws.WSManagedConnectionFactory.ParameterType;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.resource.adapter.ws.WSManagedConnectionFactory.InvocationType;
 import org.teiid.resource.spi.BasicConnection;
 
 public class WSConnection extends BasicConnection implements Dispatch<Source>{
 	private static QName svcQname = new QName("http://teiid.org", "teiid"); //$NON-NLS-1$ //$NON-NLS-2$
 	private static QName portQName = new QName("http://teiid.org", "teiid");//$NON-NLS-1$ //$NON-NLS-2$
 	
-	private Dispatch delegate;
+	private Dispatch<Source> delegate;
 	private WSManagedConnectionFactory mcf;
 
 	public WSConnection(WSManagedConnectionFactory mcf) {
-		if (mcf.getInvocationType() == WSManagedConnectionFactory.InvocationType.SOAP) {
-	        this.delegate = createSOAPDispatch(mcf);
+		this.mcf = mcf;
+		if (mcf.getInvocationType() == WSManagedConnectionFactory.InvocationType.HTTP_GET) {
+			this.delegate = createHTTPDispatch("GET"); //$NON-NLS-1$
 		}
-		else if (mcf.getInvocationType() == WSManagedConnectionFactory.InvocationType.HTTP_GET) {
-			this.delegate = createHTTPDispatch(mcf, "GET"); //$NON-NLS-1$
+		else if (mcf.getInvocationType() == WSManagedConnectionFactory.InvocationType.HTTP_POST) {
+			this.delegate = createHTTPDispatch("POST"); //$NON-NLS-1$
+		} else {
+			this.delegate = createSOAPDispatch();
 		}
-		else if (mcf.getInvocationType() == WSManagedConnectionFactory.InvocationType.HTTP_POST) {
-			this.delegate = createHTTPDispatch(mcf, "POST"); //$NON-NLS-1$
-		}		
-		this.mcf = mcf;
 	}
 
-	
-	private Dispatch createHTTPDispatch(WSManagedConnectionFactory mcf, String requestMethod){
+	private Dispatch<Source> createHTTPDispatch(String requestMethod){
 		Service svc = Service.create(svcQname);
 		svc.addPort(portQName, HTTPBinding.HTTP_BINDING, mcf.getEndPoint());
 
@@ -69,12 +71,12 @@
 		return dispatch;
 	}
 
-	private Dispatch createSOAPDispatch(WSManagedConnectionFactory mcf) {
+	private Dispatch<Source> createSOAPDispatch() {
 		Service svc = Service.create(svcQname);
 		
-		svc.addPort(portQName, SOAPBinding.SOAP11HTTP_BINDING, mcf.getEndPoint());
+		svc.addPort(portQName, mcf.getInvocationType() == InvocationType.SOAP11 ? SOAPBinding.SOAP11HTTP_BINDING : SOAPBinding.SOAP12HTTP_BINDING, mcf.getEndPoint());
 
-		Dispatch dispatch = svc.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
+		Dispatch<Source> dispatch = svc.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
 		if (mcf.getSecurityType() == WSManagedConnectionFactory.SecurityType.WSSecurity) {
 			//  JBoss WS-Security
 			((ConfigProvider) this.delegate).setSecurityConfig(mcf.getWsSecurityConfigURL());
@@ -118,36 +120,42 @@
         }
 
 		if (this.mcf.getInvocationType() == WSManagedConnectionFactory.InvocationType.HTTP_GET) {
-			if (isXMLInput() && xmlPayload != null) {
-				getRequestContext().put(MessageContext.QUERY_STRING, this.mcf.getXMLParamName()+"="+xmlPayload); //$NON-NLS-1$
+			if (this.mcf.getXMLParamName() != null) {
+				if (xmlPayload != null) {
+					try {
+						getRequestContext().put(MessageContext.QUERY_STRING, this.mcf.getXMLParamName()+"="+URLEncoder.encode(xmlPayload, "UTF-8")); //$NON-NLS-1$ //$NON-NLS-2$
+					} catch (UnsupportedEncodingException e) {
+						throw new RuntimeException(e);
+					} 
+				} else {
+					LogManager.logDetail(LogConstants.CTX_CONNECTOR, "XML Param specified, but no request document was generated."); //$NON-NLS-1$
+				}
 			}
-			else {
-				if (getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY) == null) {
+			else if (getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY) == null) {
 					
-					String path = (String)getRequestContext().get(MessageContext.PATH_INFO);
-					String queryString = (String)getRequestContext().get(MessageContext.QUERY_STRING);
-					String url = this.mcf.getEndPoint();
-					if (path != null) {
-						url = url + "/" + path; //$NON-NLS-1$
-					}
-					if (queryString != null) {
-						url = url + "?" + queryString; //$NON-NLS-1$
-					}
-					getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
+				String path = (String)getRequestContext().get(MessageContext.PATH_INFO);
+				String queryString = (String)getRequestContext().get(MessageContext.QUERY_STRING);
+				String url = this.mcf.getEndPoint();
+				if (path != null) {
+					url = url + "/" + path; //$NON-NLS-1$
 				}
+				if (queryString != null) {
+					url = url + "?" + queryString; //$NON-NLS-1$
+				}
+				getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
 			}
     		msg = null;
 		}
 		else if (this.mcf.getInvocationType() == WSManagedConnectionFactory.InvocationType.HTTP_POST) {
 			getRequestContext().put(MessageContext.QUERY_STRING, ""); //$NON-NLS-1$
-			if (isXMLInput() && xmlPayload != null) {
+			if (xmlPayload != null) {
 				msg = new StreamSource(new StringReader(xmlPayload));
 			}
 			else {
 				msg = null;
 			}
 		}
-		else if (this.mcf.getInvocationType() == WSManagedConnectionFactory.InvocationType.SOAP) {
+		else {
 			// JBossWS native adds the null based address property somewhere and results in error if this 
 			// is corrected
 			if (getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY) == null) {
@@ -157,22 +165,18 @@
 	
 		if (msg == null) {
 			// JBoss Native DispatchImpl throws exception when the source is null
-			msg = new StreamSource(new StringReader("<none/>"));
+			msg = new StreamSource(new StringReader("<none/>")); //$NON-NLS-1$
 		}
-		return (Source)delegate.invoke(msg);
+		return delegate.invoke(msg);
 	}
 	
-	private boolean isXMLInput() {
-		return (this.mcf.getParameterMethod() == ParameterType.XMLInQueryString || this.mcf.getParameterMethod() == ParameterType.XMLRequest);
-	}
-
 	@Override
-	public Future invokeAsync(Source msg, AsyncHandler handler) {
+	public Future invokeAsync(Source msg, AsyncHandler<Source> handler) {
 		return delegate.invokeAsync(msg, handler);
 	}
 
 	@Override
-	public Response invokeAsync(Source msg) {
+	public Response<Source> invokeAsync(Source msg) {
 		return delegate.invokeAsync(msg);
 	}
 

Modified: trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSManagedConnectionFactory.java
===================================================================
--- trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSManagedConnectionFactory.java	2010-05-18 15:20:27 UTC (rev 2137)
+++ trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSManagedConnectionFactory.java	2010-05-18 16:05:10 UTC (rev 2138)
@@ -22,7 +22,6 @@
 package org.teiid.resource.adapter.ws;
 
 import javax.resource.ResourceException;
-import javax.resource.cci.ConnectionSpec;
 
 import org.teiid.resource.spi.BasicConnection;
 import org.teiid.resource.spi.BasicConnectionFactory;
@@ -32,21 +31,18 @@
 
 	private static final long serialVersionUID = -2998163922934555003L;
 
-	enum InvocationType {HTTP_GET, HTTP_POST, SOAP};
-	enum SecurityType {None,HTTPBasic,WSSecurity}
-	enum ParameterType{None,Name_Value,XMLRequest,XMLInQueryString};
+	public enum InvocationType {HTTP_GET, HTTP_POST, SOAP11, SOAP12};
+	public enum SecurityType {None,HTTPBasic,WSSecurity}
 	
-	private String invocationType;
+	private String invocationType = InvocationType.SOAP12.name();
 	private String endPoint;
 	
-	private String securityType; // None, HTTPBasic, WS-Security
+	private String securityType = SecurityType.None.name(); // None, HTTPBasic, WS-Security
 	private String wsSecurityConfigURL; // path to the "jboss-wsse-client.xml" file
 	private String wsSecurityConfigName; // ws-security config name in the above file
 	private String authPassword; // httpbasic - password
 	private String authUserName; // httpbasic - username
-	private String parameterMethod;
-	private String xMLParamName;
-	
+	private String xmlParamName;
 
 	@Override
 	public Object createConnectionFactory() throws ResourceException {
@@ -58,12 +54,10 @@
 		};
 	}
 	
-	
 	public InvocationType getInvocationType() {
 		return InvocationType.valueOf(invocationType);
 	}
 
-
 	public void setInvocationType(String invocationType) {
 		this.invocationType = invocationType;
 	}
@@ -116,19 +110,11 @@
 		this.wsSecurityConfigName = wsSecurityConfigName;
 	}
 	
-	public ParameterType getParameterMethod() {
-		return ParameterType.valueOf(parameterMethod);
-	}
-
-	public void setParameterMethod(String parameterMethod) {
-		this.parameterMethod = parameterMethod;
-	}
-	
 	public String getXMLParamName() {
-		return xMLParamName;
+		return xmlParamName;
 	}
 
 	public void setXMLParamName(String xMLParamName) {
-		this.xMLParamName = xMLParamName;
+		this.xmlParamName = xMLParamName;
 	}
 }

Modified: trunk/connectors/connector-ws/src/main/rar/META-INF/ra.xml
===================================================================
--- trunk/connectors/connector-ws/src/main/rar/META-INF/ra.xml	2010-05-18 15:20:27 UTC (rev 2137)
+++ trunk/connectors/connector-ws/src/main/rar/META-INF/ra.xml	2010-05-18 16:05:10 UTC (rev 2138)
@@ -41,10 +41,10 @@
             <managedconnectionfactory-class>org.teiid.resource.adapter.ws.WSManagedConnectionFactory</managedconnectionfactory-class>
 
             <config-property>
-                <description>{$display:"Invocation Type",$description:"Service Invocation type (HTTP or SOAP)", $allowed="HTTP_GET, HTTP_POST,SOAP", $required="true", $defaultValue="SOAP"}</description>
+                <description>{$display:"Invocation Type",$description:"Service Invocation type (HTTP or SOAP)", $allowed="HTTP_GET, HTTP_POST, SOAP11, SOAP12", $required="true", $defaultValue="SOAP12"}</description>
                 <config-property-name>InvocationType</config-property-name>
                 <config-property-type>java.lang.String</config-property-type>
-                <config-property-value>SOAP</config-property-value>
+                <config-property-value>SOAP12</config-property-value>
             </config-property>
             
             <config-property>
@@ -85,18 +85,11 @@
             </config-property>
                                 
             <config-property>
-                <description>{$display:"XML Parameter Name", $description="only required for the HTTP with XML based request"}</description>
+                <description>{$display:"XML Parameter Name", $description="only required for HTTP_GET with an XML based request"}</description>
                 <config-property-name>XMLParamName</config-property-name>
                 <config-property-type>java.lang.String</config-property-type>
             </config-property>
                          
-            <config-property>
-                <description>{$display:"Parameter Method (None, Name_Value, XMLRequest, XMLInQueryString)",$description:"",$allowed:["None","Name_Value","XMLRequest","XMLInQueryString"], $editable:"false", defaultValue="Name_Value"}</description>
-                <config-property-name>ParameterMethod</config-property-name>
-                <config-property-type>java.lang.String</config-property-type>
-                <config-property-value>Name_Value</config-property-value>
-            </config-property>
-             
             <connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
             <connectionfactory-impl-class>org.teiid.resource.spi.WrappedConnectionFactory</connectionfactory-impl-class>
             <connection-interface>javax.resource.cci.Connection</connection-interface>



More information about the teiid-commits mailing list