You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ru...@apache.org on 2008/05/06 03:24:48 UTC
svn commit: r653659 - in
/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints:
AddressEndpointFactory.java EndpointFactory.java WSDLEndpointFactory.java
Author: ruwan
Date: Mon May 5 18:24:47 2008
New Revision: 653659
URL: http://svn.apache.org/viewvc?rev=653659&view=rev
Log:
Initial refactoring to remove the duplicate code in WSDL/Address Endpoint factories
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java?rev=653659&r1=653658&r2=653659&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java Mon May 5 18:24:47 2008
@@ -23,7 +23,6 @@
import org.apache.synapse.endpoints.AddressEndpoint;
import org.apache.synapse.endpoints.utils.EndpointDefinition;
import org.apache.synapse.SynapseConstants;
-import org.apache.synapse.SynapseException;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMNode;
@@ -38,7 +37,8 @@
* Configuration syntax:
* <pre>
* <endpoint [name="<em>name</em>"] [trace="enable|disable"]>
- * <address uri="<em>url</em>" [format="soap11|soap12|pox|get"] [optimize="mtom|swa"] [encoding="<em>charset encoding</em>"] [statistics="enable|disable"]>
+ * <address uri="<em>url</em>" [format="soap11|soap12|pox|get"] [optimize="mtom|swa"]
+ * [encoding="<em>charset encoding</em>"] [statistics="enable|disable"]>
* .. extensibility ..
*
* <enableRM [policy="<em>key</em>"]/>?
@@ -50,12 +50,13 @@
* <action>discard|fault</action>
* </timeout>?
*
- * <suspendDurationOnFailure><em>suspend duration in seconds</em></suspendDurationOnFailure>?
+ * <suspendDurationOnFailure>
+ * <em>suspend duration in seconds</em></suspendDurationOnFailure>?
* </address>
* </endpoint>
* </pre>
*/
-public class AddressEndpointFactory implements EndpointFactory {
+public class AddressEndpointFactory extends EndpointFactory {
private static Log log = LogFactory.getLog(AddressEndpointFactory.class);
@@ -80,14 +81,12 @@
AddressEndpoint addressEndpoint = new AddressEndpoint();
-// if (!anonymousEndpoint) {
OMAttribute name = epConfig.getAttribute(new QName(
org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
addressEndpoint.setName(name.getAttributeValue());
}
-// }
OMElement addressElement = epConfig.getFirstChildWithName
(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "address"));
@@ -162,14 +161,13 @@
}
}
}
+
if (address != null) {
endpointDefinition.setAddress(address.getAttributeValue());
-// } else {
-// handleException("One of the 'address' or 'ref' attributes are required in an "
-// + "anonymous endpoint");
}
- if (format != null)
- {
+
+ if (format != null) {
+
String forceValue = format.getAttributeValue().trim().toLowerCase();
if (SynapseConstants.FORMAT_POX.equals(forceValue)) {
endpointDefinition.setForcePOX(true);
@@ -304,14 +302,4 @@
return endpointDefinition;
}
-
- private static void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- private static void handleException(String msg, Exception e) {
- log.error(msg, e);
- throw new SynapseException(msg, e);
- }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java?rev=653659&r1=653658&r2=653659&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java Mon May 5 18:24:47 2008
@@ -20,8 +20,16 @@
package org.apache.synapse.config.xml.endpoints;
import org.apache.synapse.endpoints.Endpoint;
+import org.apache.synapse.endpoints.utils.EndpointDefinition;
import org.apache.synapse.config.XMLToObjectMapper;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.SynapseException;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
/**
* All endpoint factories should implement this interface. Use EndpointAbstractFactory to obtain the
@@ -33,7 +41,9 @@
* If the endpoint type is not known use XMLToEndpointMapper as the generic XMLToObjectMapper for
* all endpoints.
*/
-public interface EndpointFactory extends XMLToObjectMapper {
+public abstract class EndpointFactory implements XMLToObjectMapper {
+
+ private static Log log = LogFactory.getLog(WSDLEndpointFactory.class);
/**
* Creates the Endpoint implementation for the given XML endpoint configuration. If the endpoint
@@ -44,5 +54,146 @@
* @param anonymousEndpoint false if the endpoint has a name. true otherwise.
* @return Endpoint implementation for the given configuration.
*/
- public Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint);
+ public abstract Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint);
+
+ protected void extractQOSInformation(EndpointDefinition endpointDefinition,
+ OMElement elem) {
+
+ OMAttribute format = elem.getAttribute(new QName(
+ org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "format"));
+ OMAttribute optimize = elem.getAttribute(new QName(
+ org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "optimize"));
+
+ if (format != null)
+ {
+ String forceValue = format.getAttributeValue().trim().toLowerCase();
+ if (SynapseConstants.FORMAT_POX.equals(forceValue)) {
+ endpointDefinition.setForcePOX(true);
+ endpointDefinition.setFormat(SynapseConstants.FORMAT_POX);
+
+ } else if (SynapseConstants.FORMAT_GET.equals(forceValue)) {
+ endpointDefinition.setForceGET(true);
+ endpointDefinition.setFormat(SynapseConstants.FORMAT_GET);
+
+ } else if (SynapseConstants.FORMAT_SOAP11.equals(forceValue)) {
+ endpointDefinition.setForceSOAP11(true);
+ endpointDefinition.setFormat(SynapseConstants.FORMAT_SOAP11);
+
+ } else if (SynapseConstants.FORMAT_SOAP12.equals(forceValue)) {
+ endpointDefinition.setForceSOAP12(true);
+ endpointDefinition.setFormat(SynapseConstants.FORMAT_SOAP12);
+
+ } else {
+ handleException("force value -\""+forceValue+"\" not yet implemented");
+ }
+ }
+
+ if (optimize != null && optimize.getAttributeValue().length() > 0) {
+ String method = optimize.getAttributeValue().trim();
+ if ("mtom".equalsIgnoreCase(method)) {
+ endpointDefinition.setUseMTOM(true);
+ } else if ("swa".equalsIgnoreCase(method)) {
+ endpointDefinition.setUseSwa(true);
+ }
+ }
+
+ OMElement wsAddr = elem.getFirstChildWithName(new QName(
+ org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE,
+ "enableAddressing"));
+
+ if (wsAddr != null) {
+ endpointDefinition.setAddressingOn(true);
+
+ OMAttribute version = wsAddr.getAttribute(new QName("version"));
+ if (version != null && version.getAttributeValue() != null) {
+ if (SynapseConstants.ADDRESSING_VERSION_FINAL.equals(version.getAttributeValue()) ||
+ SynapseConstants.ADDRESSING_VERSION_SUBMISSION.equals(
+ version.getAttributeValue())) {
+ endpointDefinition.setAddressingVersion(version.getAttributeValue());
+ } else {
+ handleException("Unknown value for the addressing version. Possible values " +
+ "for the addressing version are 'final' and 'submission' only.");
+ }
+ }
+
+ String useSepList = wsAddr.getAttributeValue(new QName("separateListener"));
+ if (useSepList != null) {
+ if (useSepList.trim().toLowerCase().startsWith("tr")
+ || useSepList.trim().startsWith("1")) {
+ endpointDefinition.setUseSeparateListener(true);
+ }
+ }
+ }
+
+ OMElement wsSec = elem.getFirstChildWithName(new QName(
+ org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "enableSec"));
+ if (wsSec != null) {
+ endpointDefinition.setSecurityOn(true);
+ OMAttribute policy = wsSec.getAttribute(new QName(
+ org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "policy"));
+ if (policy != null) {
+ endpointDefinition.setWsSecPolicyKey(policy.getAttributeValue());
+ }
+ }
+ OMElement wsRm = elem.getFirstChildWithName(new QName(
+ org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "enableRM"));
+ if (wsRm != null) {
+ endpointDefinition.setReliableMessagingOn(true);
+ OMAttribute policy = wsRm.getAttribute(new QName(
+ org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "policy"));
+ if (policy != null) {
+ endpointDefinition.setWsRMPolicyKey(policy.getAttributeValue());
+ }
+ }
+
+ // set the timeout configuration
+ OMElement timeout = elem.getFirstChildWithName(new QName(
+ org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "timeout"));
+ if (timeout != null) {
+ OMElement duration = timeout.getFirstChildWithName(new QName(
+ org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE,
+ "duration"));
+
+ if (duration != null) {
+ String d = duration.getText();
+ if (d != null) {
+ long timeoutSeconds = new Long(d.trim()).longValue();
+ endpointDefinition.setTimeoutDuration(timeoutSeconds * 1000);
+ }
+ }
+
+ OMElement action = timeout.getFirstChildWithName(new QName(
+ org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "action"));
+ if (action != null) {
+ String a = action.getText();
+ if (a != null) {
+ if ((a.trim()).equalsIgnoreCase("discard")) {
+ endpointDefinition.setTimeoutAction(SynapseConstants.DISCARD);
+
+ // set timeout duration to 30 seconds, if it is not set explicitly
+ if (endpointDefinition.getTimeoutDuration() == 0) {
+ endpointDefinition.setTimeoutDuration(30000);
+ }
+ } else if ((a.trim()).equalsIgnoreCase("fault")) {
+ endpointDefinition.setTimeoutAction(SynapseConstants.DISCARD_AND_FAULT);
+
+ // set timeout duration to 30 seconds, if it is not set explicitly
+ if (endpointDefinition.getTimeoutDuration() == 0) {
+ endpointDefinition.setTimeoutDuration(30000);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ protected static void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ protected static void handleException(String msg, Exception e) {
+ log.error(msg, e);
+ throw new SynapseException(msg, e);
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java?rev=653659&r1=653658&r2=653659&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java Mon May 5 18:24:47 2008
@@ -24,10 +24,7 @@
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
import org.apache.axis2.description.WSDL2Constants;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseConstants;
-import org.apache.synapse.SynapseException;
import org.apache.synapse.config.SynapseConfigUtils;
import org.apache.synapse.config.xml.endpoints.utils.WSDL11EndpointBuilder;
import org.apache.synapse.endpoints.Endpoint;
@@ -35,8 +32,8 @@
import org.apache.synapse.endpoints.utils.EndpointDefinition;
import javax.xml.namespace.QName;
-import java.net.URL;
import java.io.File;
+import java.net.URL;
/**
* Creates an WSDL based endpoint from a XML configuration.
@@ -54,9 +51,7 @@
* </timeout>?
* </wsdl>
*/
-public class WSDLEndpointFactory implements EndpointFactory {
-
- private static Log log = LogFactory.getLog(WSDLEndpointFactory.class);
+public class WSDLEndpointFactory extends EndpointFactory {
private static WSDLEndpointFactory instance = new WSDLEndpointFactory();
@@ -79,14 +74,12 @@
WSDLEndpoint wsdlEndpoint = new WSDLEndpoint();
-// if (!anonymousEndpoint) {
OMAttribute name = epConfig.getAttribute(new QName(
org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
wsdlEndpoint.setName(name.getAttributeValue());
}
-// }
OMElement wsdlElement = epConfig.getFirstChildWithName
(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "wsdl"));
@@ -212,145 +205,5 @@
return wsdlEndpoint;
}
-
- private static void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- private static void handleException(String msg, Exception e) {
- log.error(msg, e);
- throw new SynapseException(msg, e);
- }
-
- private void extractQOSInformation(EndpointDefinition endpointDefinition,
- OMElement elem) {
-
- OMAttribute format = elem.getAttribute(new QName(
- org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "format"));
- OMAttribute optimize = elem.getAttribute(new QName(
- org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "optimize"));
-
- if (format != null)
- {
- String forceValue = format.getAttributeValue().trim().toLowerCase();
- if (SynapseConstants.FORMAT_POX.equals(forceValue)) {
- endpointDefinition.setForcePOX(true);
- endpointDefinition.setFormat(SynapseConstants.FORMAT_POX);
-
- } else if (SynapseConstants.FORMAT_GET.equals(forceValue)) {
- endpointDefinition.setForceGET(true);
- endpointDefinition.setFormat(SynapseConstants.FORMAT_GET);
-
- } else if (SynapseConstants.FORMAT_SOAP11.equals(forceValue)) {
- endpointDefinition.setForceSOAP11(true);
- endpointDefinition.setFormat(SynapseConstants.FORMAT_SOAP11);
-
- } else if (SynapseConstants.FORMAT_SOAP12.equals(forceValue)) {
- endpointDefinition.setForceSOAP12(true);
- endpointDefinition.setFormat(SynapseConstants.FORMAT_SOAP12);
-
- } else {
- handleException("force value -\""+forceValue+"\" not yet implemented");
- }
- }
-
- if (optimize != null && optimize.getAttributeValue().length() > 0) {
- String method = optimize.getAttributeValue().trim();
- if ("mtom".equalsIgnoreCase(method)) {
- endpointDefinition.setUseMTOM(true);
- } else if ("swa".equalsIgnoreCase(method)) {
- endpointDefinition.setUseSwa(true);
- }
- }
-
- OMElement wsAddr = elem.getFirstChildWithName(new QName(
- org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE,
- "enableAddressing"));
-
- if (wsAddr != null) {
- endpointDefinition.setAddressingOn(true);
-
- OMAttribute version = wsAddr.getAttribute(new QName("version"));
- if (version != null && version.getAttributeValue() != null) {
- if (SynapseConstants.ADDRESSING_VERSION_FINAL.equals(version.getAttributeValue()) ||
- SynapseConstants.ADDRESSING_VERSION_SUBMISSION.equals(
- version.getAttributeValue())) {
- endpointDefinition.setAddressingVersion(version.getAttributeValue());
- } else {
- handleException("Unknown value for the addressing version. Possible values " +
- "for the addressing version are 'final' and 'submission' only.");
- }
- }
-
- String useSepList = wsAddr.getAttributeValue(new QName("separateListener"));
- if (useSepList != null) {
- if (useSepList.trim().toLowerCase().startsWith("tr")
- || useSepList.trim().startsWith("1")) {
- endpointDefinition.setUseSeparateListener(true);
- }
- }
- }
-
- OMElement wsSec = elem.getFirstChildWithName(new QName(
- org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "enableSec"));
- if (wsSec != null) {
- endpointDefinition.setSecurityOn(true);
- OMAttribute policy = wsSec.getAttribute(new QName(
- org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "policy"));
- if (policy != null) {
- endpointDefinition.setWsSecPolicyKey(policy.getAttributeValue());
- }
- }
- OMElement wsRm = elem.getFirstChildWithName(new QName(
- org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "enableRM"));
- if (wsRm != null) {
- endpointDefinition.setReliableMessagingOn(true);
- OMAttribute policy = wsRm.getAttribute(new QName(
- org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "policy"));
- if (policy != null) {
- endpointDefinition.setWsRMPolicyKey(policy.getAttributeValue());
- }
- }
-
- // set the timeout configuration
- OMElement timeout = elem.getFirstChildWithName(new QName(
- org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "timeout"));
- if (timeout != null) {
- OMElement duration = timeout.getFirstChildWithName(new QName(
- org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE,
- "duration"));
-
- if (duration != null) {
- String d = duration.getText();
- if (d != null) {
- long timeoutSeconds = new Long(d.trim()).longValue();
- endpointDefinition.setTimeoutDuration(timeoutSeconds * 1000);
- }
- }
-
- OMElement action = timeout.getFirstChildWithName(new QName(
- org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "action"));
- if (action != null) {
- String a = action.getText();
- if (a != null) {
- if ((a.trim()).equalsIgnoreCase("discard")) {
- endpointDefinition.setTimeoutAction(SynapseConstants.DISCARD);
-
- // set timeout duration to 30 seconds, if it is not set explicitly
- if (endpointDefinition.getTimeoutDuration() == 0) {
- endpointDefinition.setTimeoutDuration(30000);
- }
- } else if ((a.trim()).equalsIgnoreCase("fault")) {
- endpointDefinition.setTimeoutAction(SynapseConstants.DISCARD_AND_FAULT);
-
- // set timeout duration to 30 seconds, if it is not set explicitly
- if (endpointDefinition.getTimeoutDuration() == 0) {
- endpointDefinition.setTimeoutDuration(30000);
- }
- }
- }
- }
- }
- }
+
}