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/04/30 00:59:32 UTC
svn commit: r652183 - in
/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse:
config/xml/CalloutMediatorFactory.java
config/xml/CalloutMediatorSerializer.java
mediators/builtin/CalloutMediator.java
Author: ruwan
Date: Tue Apr 29 15:59:32 2008
New Revision: 652183
URL: http://svn.apache.org/viewvc?rev=652183&view=rev
Log:
Fixing the issue, SYNAPSE-277. Now the client repo and the axis2.xml can be configured using the callout mediator configuration itself. You can add the following element to configure these properties;
<configuration axis2xml="string" repository="string"/>
but these are optional and if not provided, will be taken the values hardcoded earlier as defualt values. This keeps the backward compatibility as well
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CalloutMediatorFactory.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CalloutMediatorSerializer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CalloutMediator.java
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CalloutMediatorFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CalloutMediatorFactory.java?rev=652183&r1=652182&r2=652183&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CalloutMediatorFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CalloutMediatorFactory.java Tue Apr 29 15:59:32 2008
@@ -31,10 +31,11 @@
* Factory for {@link CalloutMediator} instances.
*
* <pre>
- * <callout serviceURL="string" [action="string"]>
- * <source xpath="expression" | key="string">
- * <target xpath="expression" | key="string"/>
- * </callout>
+ * <callout serviceURL="string" [action="string"]>
+ * <configuration [axis2xml="string"] [repository="string"]/>?
+ * <source xpath="expression" | key="string">
+ * <target xpath="expression" | key="string"/>
+ * </callout>
* </pre>
*/
public class CalloutMediatorFactory extends AbstractMediatorFactory {
@@ -43,8 +44,14 @@
= new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "callout");
private static final QName ATT_URL = new QName("serviceURL");
private static final QName ATT_ACTION = new QName("action");
- private static final QName Q_SOURCE = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "source");
- private static final QName Q_TARGET = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "target");
+ private static final QName ATT_AXIS2XML = new QName("axis2xml");
+ private static final QName ATT_REPOSITORY = new QName("repository");
+ private static final QName Q_CONFIG
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "configuration");
+ private static final QName Q_SOURCE
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "source");
+ private static final QName Q_TARGET
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "target");
public Mediator createMediator(OMElement elem) {
@@ -52,6 +59,7 @@
OMAttribute attServiceURL = elem.getAttribute(ATT_URL);
OMAttribute attAction = elem.getAttribute(ATT_ACTION);
+ OMElement configElt = elem.getFirstChildWithName(Q_CONFIG);
OMElement sourceElt = elem.getFirstChildWithName(Q_SOURCE);
OMElement targetElt = elem.getFirstChildWithName(Q_TARGET);
@@ -65,6 +73,20 @@
callout.setAction(attAction.getAttributeValue());
}
+ if (configElt != null) {
+
+ OMAttribute axis2xmlAttr = configElt.getAttribute(ATT_AXIS2XML);
+ OMAttribute repoAttr = configElt.getAttribute(ATT_REPOSITORY);
+
+ if (axis2xmlAttr != null && axis2xmlAttr.getAttributeValue() != null) {
+ callout.setAxis2xml(axis2xmlAttr.getAttributeValue());
+ }
+
+ if (repoAttr != null && repoAttr.getAttributeValue() != null) {
+ callout.setClientRepository(repoAttr.getAttributeValue());
+ }
+ }
+
if (sourceElt != null) {
if (sourceElt.getAttribute(ATT_XPATH) != null) {
try {
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CalloutMediatorSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CalloutMediatorSerializer.java?rev=652183&r1=652182&r2=652183&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CalloutMediatorSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CalloutMediatorSerializer.java Tue Apr 29 15:59:32 2008
@@ -24,10 +24,13 @@
import org.apache.synapse.mediators.builtin.CalloutMediator;
/**
- * <callout serviceURL="string" [action="string"]>
- * <source xpath="expression" | key="string">
- * <target xpath="expression" | key="string"/>
- * </callout>
+ * <pre>
+ * <callout serviceURL="string" [action="string"]>
+ * <configuration [axis2xml="string"] [repository="string"]/>?
+ * <source xpath="expression" | key="string">
+ * <target xpath="expression" | key="string"/>
+ * </callout>
+ * </pre>
*/
public class CalloutMediatorSerializer extends AbstractMediatorSerializer {
@@ -46,6 +49,19 @@
callout.addAttribute(fac.createOMAttribute("action", nullNS, mediator.getAction()));
}
+ if (mediator.getClientRepository() != null || mediator.getAxis2xml() != null) {
+ OMElement config = fac.createOMElement("configuration", synNS);
+ if (mediator.getClientRepository() != null) {
+ config.addAttribute(fac.createOMAttribute(
+ "repository", nullNS, mediator.getClientRepository()));
+ }
+ if (mediator.getAxis2xml() != null) {
+ config.addAttribute(fac.createOMAttribute(
+ "axis2xml", nullNS, mediator.getAxis2xml()));
+ }
+ callout.addChild(config);
+ }
+
OMElement source = fac.createOMElement("source", synNS, callout);
if (mediator.getRequestXPath() != null) {
SynapseXPathSerializer.serializeXPath(mediator.getRequestXPath(), source, "xpath");
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CalloutMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CalloutMediator.java?rev=652183&r1=652182&r2=652183&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CalloutMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CalloutMediator.java Tue Apr 29 15:59:32 2008
@@ -41,6 +41,7 @@
/**
* <callout serviceURL="string" [action="string"]>
+ * <configuration [axis2xml="string"] [repository="string"]/>?
* <source xpath="expression" | key="string"> <!-- key can be a MC property or entry key -->
* <target xpath="expression" | key="string"/>
* </callout>
@@ -54,6 +55,10 @@
private SynapseXPath requestXPath = null;
private SynapseXPath targetXPath = null;
private String targetKey = null;
+ private String clientRepository = null;
+ private String axis2xml = null;
+ public static String DEFAULT_CLIENT_REPO = "./samples/axis2Client/client_repo";
+ public static String DEFAULT_AXIS2_XML = "./samples/axis2Client/client_repo/conf/axis2.xml";
public boolean mediate(MessageContext synCtx) {
@@ -76,7 +81,8 @@
options.setAction(action);
}
- options.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.TRUE);
+ options.setProperty(
+ AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.TRUE);
sc.setOptions(options);
OMElement request = getRequestPayload(synCtx);
@@ -105,7 +111,8 @@
tgtNode.insertSiblingAfter(result);
tgtNode.detach();
} else if (o != null && o instanceof List && !((List) o).isEmpty()) {
- OMNode tgtNode = (OMElement) ((List) o).get(0); // Always fetches *only* the first
+ // Always fetches *only* the first
+ OMNode tgtNode = (OMElement) ((List) o).get(0);
tgtNode.insertSiblingAfter(result);
tgtNode.detach();
} else {
@@ -158,7 +165,8 @@
+ requestXPath.toString() + " did not result in an OMElement", synCtx);
}
} catch (JaxenException e) {
- handleException("Error evaluating XPath expression : " + requestXPath.toString(), e, synCtx);
+ handleException("Error evaluating XPath expression : "
+ + requestXPath.toString(), e, synCtx);
}
}
return null;
@@ -166,9 +174,10 @@
public void init(SynapseEnvironment synEnv) {
try {
- ConfigurationContext cfgCtx =
- ConfigurationContextFactory.createConfigurationContextFromFileSystem(
- "./samples/axis2Client/client_repo", "./samples/axis2Client/client_repo/conf/axis2.xml");
+ ConfigurationContext cfgCtx
+ = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
+ clientRepository != null ? clientRepository : DEFAULT_CLIENT_REPO,
+ axis2xml != null ? axis2xml : DEFAULT_AXIS2_XML);
sc = new ServiceClient(cfgCtx, null);
} catch (AxisFault e) {
String msg = "Error initializing callout mediator : " + e.getMessage();
@@ -230,4 +239,20 @@
public SynapseXPath getTargetXPath() {
return targetXPath;
}
+
+ public String getClientRepository() {
+ return clientRepository;
+ }
+
+ public void setClientRepository(String clientRepository) {
+ this.clientRepository = clientRepository;
+ }
+
+ public String getAxis2xml() {
+ return axis2xml;
+ }
+
+ public void setAxis2xml(String axis2xml) {
+ this.axis2xml = axis2xml;
+ }
}