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 na...@apache.org on 2008/07/21 16:17:56 UTC

svn commit: r678431 - in /webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2: deployment/util/Utils.java description/AxisEndpoint.java description/AxisService.java dispatchers/RequestURIBasedServiceDispatcher.java

Author: nandana
Date: Mon Jul 21 07:17:56 2008
New Revision: 678431

URL: http://svn.apache.org/viewvc?rev=678431&view=rev
Log:
AXIS2-3905 setting the binding correctly when messages come through old EPR

Modified:
    webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
    webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/description/AxisEndpoint.java
    webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/description/AxisService.java
    webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcher.java

Modified: webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java?rev=678431&r1=678430&r2=678431&view=diff
==============================================================================
--- webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java (original)
+++ webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java Mon Jul 21 07:17:56 2008
@@ -1584,4 +1584,65 @@
 			}
 		}
 	}
+	
+	public static void populateEPMap(AxisService service) {
+	    HashMap map = new HashMap();
+	    for (Iterator iterator = service.getEndpoints().values().iterator(); iterator
+	            .hasNext();) {
+	        AxisEndpoint endpoint = (AxisEndpoint) iterator.next();
+	        String transportInDescription = endpoint
+	                .getTransportInDescription();
+	        if (transportInDescription == null) {
+	            continue;
+	        }
+	        AxisBinding binding = endpoint.getBinding();
+	        if (binding != null) {
+	            if (isSoap11Binding(binding)) {
+	                map.put(transportInDescription + ":soap11", endpoint);
+	            } else if (isSoap12Binding(binding)) {
+	                map.put(transportInDescription + ":soap12", endpoint);
+	            } else if (isHttpBinding(binding)) {
+	                map.put(transportInDescription + ":http", endpoint);
+	            }
+	        }
+	    }
+	        service.setEpMap(map);
+	}
+	
+	public static boolean isSoap11Binding(AxisBinding binding) {
+	    String type = binding.getType();
+	    if (Java2WSDLConstants.TRANSPORT_URI.equals(type)
+	            || WSDL2Constants.URI_WSDL2_SOAP.equals(type)) {
+	        String v = (String) binding
+	                .getProperty(WSDL2Constants.ATTR_WSOAP_VERSION);
+	        if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(v)) {
+	            return true;
+	        }
+	    }
+	        
+	    return false;
+	}
+	        
+	public static boolean isSoap12Binding(AxisBinding binding) {
+	    String type = binding.getType();
+	    if (Java2WSDLConstants.TRANSPORT_URI.equals(type)
+	            || WSDL2Constants.URI_WSDL2_SOAP.equals(type)) {
+	        String v = (String) binding
+	            .getProperty(WSDL2Constants.ATTR_WSOAP_VERSION);
+	        if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(v)) {
+	            return true;
+	        }
+	    }
+	    
+	    return false;
+	}
+	        
+	public static boolean isHttpBinding(AxisBinding binding) {
+	    String type = binding.getType();
+	    if (WSDL2Constants.URI_WSDL2_HTTP.equals(type)) {
+	        return true;
+	    }
+	    
+	    return false;
+	}
 }

Modified: webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/description/AxisEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/description/AxisEndpoint.java?rev=678431&r1=678430&r2=678431&view=diff
==============================================================================
--- webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/description/AxisEndpoint.java (original)
+++ webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/description/AxisEndpoint.java Mon Jul 21 07:17:56 2008
@@ -172,6 +172,10 @@
 	public void setTransportInDescription(String transportInDescName) {
 		this.transportInDescName = transportInDescName;
 	}
+	
+	public String getTransportInDescription() {
+	    return transportInDescName;
+	}
 
 	private String calculateEndpointURL() {
 		if (transportInDescName != null && parent != null) {

Modified: webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/description/AxisService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/description/AxisService.java?rev=678431&r1=678430&r2=678431&view=diff
==============================================================================
--- webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/description/AxisService.java (original)
+++ webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/description/AxisService.java Mon Jul 21 07:17:56 2008
@@ -301,7 +301,9 @@
 	private boolean customWsdl = false;
 
 	private HashMap policyMap = new HashMap();
-
+	
+	private HashMap epMap = null; 
+	
 	public AxisEndpoint getEndpoint(String key) {
 		return (AxisEndpoint) endpointMap.get(key);
 	}
@@ -3067,4 +3069,15 @@
             }
         }
     }
+    
+    public HashMap getEpMap() {
+        if (epMap == null) {
+            Utils.populateEPMap(this);      
+        }
+            return epMap;
+    }
+      
+    public void setEpMap(HashMap epMap) {
+        this.epMap = epMap;
+    }
 }

Modified: webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcher.java?rev=678431&r1=678430&r2=678431&view=diff
==============================================================================
--- webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcher.java (original)
+++ webservices/axis2/branches/java/1_4/modules/kernel/src/org/apache/axis2/dispatchers/RequestURIBasedServiceDispatcher.java Mon Jul 21 07:17:56 2008
@@ -19,12 +19,18 @@
 
 package org.apache.axis2.dispatchers;
 
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisEndpoint;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.HandlerDescription;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.description.TransportOutDescription;
 import org.apache.axis2.description.WSDL2Constants;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.util.LoggingControl;
@@ -32,74 +38,131 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import java.util.HashMap;
 import java.util.Map;
 
 public class RequestURIBasedServiceDispatcher extends AbstractServiceDispatcher {
 
-    public static final String NAME = "RequestURIBasedServiceDispatcher";
-    private static final Log log = LogFactory.getLog(RequestURIBasedServiceDispatcher.class);
-
-    /*
-     *  (non-Javadoc)
-     * @see org.apache.axis2.engine.AbstractDispatcher#findService(org.apache.axis2.context.MessageContext)
-     */
-    public AxisService findService(MessageContext messageContext) throws AxisFault {
-        EndpointReference toEPR = messageContext.getTo();
-        if (toEPR != null) {
-            if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) {
-                log.debug(messageContext.getLogIDString() +
-                        " Checking for Service using target endpoint address : " +
-                        toEPR.getAddress());
-            }
-            String filePart = toEPR.getAddress();
-            //REVIEW: (nagy) Parsing the RequestURI will also give us the operationName if present, so we could conceivably store it in the MessageContext, but doing so and retrieving it is probably no faster than simply reparsing the URI
-            ConfigurationContext configurationContext = messageContext.getConfigurationContext();
-            String[] values = Utils.parseRequestURLForServiceAndOperation(filePart,
-                                                                          messageContext
-                                                                                  .getConfigurationContext().getServiceContextPath());
-
-            if ((values.length >= 1) && (values[0] != null)) {
-            	
-            	AxisConfiguration registry =
-            		configurationContext.getAxisConfiguration();
-
-            	AxisService axisService = registry.getService(values[0]);
-
-            	// If the axisService is not null we get the binding that the request came to add
-            	// add it as a property to the messageContext
-            	if (axisService != null) {
-            		Map endpoints = axisService.getEndpoints();
-            		if (endpoints != null) {
-            			if (endpoints.size() == 1) {
-            				messageContext.setProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME,
-            						endpoints.get(
-            								axisService.getEndpointName()));
-            			} else {
-            				String endpointName = values[0].substring(values[0].indexOf(".") + 1);
-            				messageContext.setProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME,
-            						endpoints.get(endpointName));
-            			}
-            		}
-            	}
-
-            	return axisService;
-            } else {
-                if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) {
-                    log.debug(messageContext.getLogIDString() +
-                            " Attempted to check for Service using target endpoint URI, but the service fragment was missing");
-                }
-                return null;
-            }
-        } else {
-            if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) {
-                log.debug(messageContext.getLogIDString() +
-                        " Attempted to check for Service using null target endpoint URI");
-            }
-            return null;
-        }
-    }
-
-    public void initDispatcher() {
-        init(new HandlerDescription(NAME));
-    }
+	public static final String NAME = "RequestURIBasedServiceDispatcher";
+	private static final Log log = LogFactory
+			.getLog(RequestURIBasedServiceDispatcher.class);
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.axis2.engine.AbstractDispatcher#findService(org.apache.axis2.context.MessageContext)
+	 */
+	public AxisService findService(MessageContext messageContext)
+			throws AxisFault {
+		EndpointReference toEPR = messageContext.getTo();
+		if (toEPR != null) {
+			if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) {
+				log
+						.debug(messageContext.getLogIDString()
+								+ " Checking for Service using target endpoint address : "
+								+ toEPR.getAddress());
+			}
+			String filePart = toEPR.getAddress();
+			// REVIEW: (nagy) Parsing the RequestURI will also give us the
+			// operationName if present, so we could conceivably store it in the
+			// MessageContext, but doing so and retrieving it is probably no
+			// faster than simply reparsing the URI
+			ConfigurationContext configurationContext = messageContext
+					.getConfigurationContext();
+			String[] values = Utils.parseRequestURLForServiceAndOperation(
+					filePart, messageContext.getConfigurationContext()
+							.getServiceContextPath());
+
+			if ((values.length >= 1) && (values[0] != null)) {
+
+				AxisConfiguration registry = configurationContext
+						.getAxisConfiguration();
+
+				AxisService axisService = registry.getService(values[0]);
+
+				// If the axisService is not null we get the binding that the
+				// request came to add
+				// add it as a property to the messageContext
+				if (axisService != null) {
+					Map endpoints = axisService.getEndpoints();
+					if (endpoints != null) {
+						if (endpoints.size() == 1) {
+							messageContext
+									.setProperty(
+											WSDL2Constants.ENDPOINT_LOCAL_NAME,
+											endpoints.get(axisService
+													.getEndpointName()));
+						} else {
+							String endpointName = values[0].substring(values[0]
+									.indexOf(".") + 1);
+							AxisEndpoint endpoint = (AxisEndpoint) endpoints.get(endpointName);
+							if (endpoint != null) {
+							messageContext.setProperty(
+									WSDL2Constants.ENDPOINT_LOCAL_NAME,
+									endpoint);
+							} else {
+								inferEndpoint(messageContext, axisService);
+							}
+						}
+					}
+				}
+				return axisService;
+				
+			} else {
+				if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) {
+					log
+							.debug(messageContext.getLogIDString()
+									+ " Attempted to check for Service using target endpoint URI, but the service fragment was missing");
+				}
+				return null;
+			}
+		} else {
+			if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) {
+				log
+						.debug(messageContext.getLogIDString()
+								+ " Attempted to check for Service using null target endpoint URI");
+			}
+			return null;
+		}
+	}
+
+	public void initDispatcher() {
+		init(new HandlerDescription(NAME));
+	}
+
+	private void inferEndpoint(MessageContext msgCtx, AxisService service) {
+		if (!msgCtx.isServerSide()) {
+			return;
+		}
+		String transport = null;
+		TransportInDescription transportIn = msgCtx.getTransportIn();
+		if (transportIn != null) {
+			transport = transportIn.getName();
+			if (transport == null) {
+				return;
+			}
+		}
+		AxisEndpoint endpoint = null;
+		HashMap endpointMapping = service.getEpMap();
+
+		if (msgCtx.isDoingREST()) {
+			endpoint = (AxisEndpoint) endpointMapping.get(transport + ":http");
+		} else {
+			SOAPEnvelope envelope = msgCtx.getEnvelope();
+			String namespaceURI = envelope.getNamespace().getNamespaceURI();
+			if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI
+					.equals(namespaceURI)) {
+				endpoint = (AxisEndpoint) endpointMapping.get(transport
+						+ ":soap11");
+			} else if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI
+					.equals(namespaceURI)) {
+				endpoint = (AxisEndpoint) endpointMapping.get(transport
+						+ ":soap12");
+			}
+		}
+
+		if (endpoint != null) {
+			msgCtx.setProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME, endpoint);
+		}
+	}
 }