You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by as...@apache.org on 2006/08/04 12:50:29 UTC
svn commit: r428689 [2/2] - in /incubator/synapse/trunk/java:
modules/core/src/org/apache/synapse/config/
modules/core/src/org/apache/synapse/config/xml/
modules/core/src/org/apache/synapse/core/axis2/
modules/core/src/org/apache/synapse/mediators/buil...
Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/TryMediatorSerializer.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/TryMediatorSerializer.java?rev=428689&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/TryMediatorSerializer.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/TryMediatorSerializer.java Fri Aug 4 03:50:26 2006
@@ -0,0 +1,81 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.base.TryMediator;
+
+/**
+ * <pre>
+ * <try>
+ * <sequence>
+ * mediator+
+ * </sequence>
+ * <onError>
+ * mediator+
+ * </onError>
+ * <finally>
+ * mediator+
+ * </finally>?
+ * </try>
+ * </pre>
+ */
+public class TryMediatorSerializer extends AbstractListMediatorSerializer
+ implements MediatorSerializer {
+
+ private static final Log log = LogFactory.getLog(TryMediatorSerializer.class);
+
+ public OMElement serializeMediator(OMElement parent, Mediator m) {
+
+ if (!(m instanceof TryMediator)) {
+ handleException("Unsupported mediator passed in for serialization : " + m.getType());
+ }
+
+ TryMediator mediator = (TryMediator) m;
+ OMElement tryMed = fac.createOMElement("try", synNS);
+
+ OMElement sequence = fac.createOMElement("sequence", synNS);
+ super.serializeChildren(sequence, mediator.getList());
+ tryMed.addChild(sequence);
+
+ OMElement onError = fac.createOMElement("onError", synNS);
+ super.serializeChildren(onError, mediator.getErrorHandlerMediators());
+ tryMed.addChild(onError);
+
+ OMElement finallyMed = fac.createOMElement("finally", synNS);
+ super.serializeChildren(finallyMed, mediator.getFinallyMediators());
+ tryMed.addChild(finallyMed);
+
+ if (parent != null) {
+ parent.addChild(tryMed);
+ }
+ return tryMed;
+ }
+
+ public String getMediatorClassName() {
+ return TryMediator.class.getName();
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+}
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java Fri Aug 4 03:50:26 2006
@@ -45,7 +45,6 @@
public class XMLConfigurationBuilder {
private static Log log = LogFactory.getLog(XMLConfigurationBuilder.class);
- ExtensionFactoryFinder extensionFacFinder = ExtensionFactoryFinder.getInstance();
public SynapseConfiguration getConfiguration(InputStream is) {
@@ -75,7 +74,7 @@
} else if (Constants.PROPERTY_ELT.equals(elt.getQName())) {
defineProperty(config, elt);
} else {
- defineExtension(config, elt);
+ handleException("Unexpected element : " + elt);
}
}
}
@@ -239,32 +238,6 @@
Endpoint endpoint = EndpointFactory.createEndpoint(ele);
// add this endpoint to the configuration
config.addNamedEndpoint(endpoint.getName(), endpoint);
- }
- }
-
- /**
- * Digest extensions into Synapse configuration definitions
- *
- * An extension *must* have a unique 'name' attribute. The instance
- * created through the ExtensionFactoryFinder will be set as a
- * global property into the SynapseConfiguration with this name as
- * the key.
- *
- * e.g. The Spring configuration extension is as follows
- * <pre>
- * <configuration name="string" src="string"/>
- * </pre>
- *
- * @param elem the XML element defining the configuration
- */
- public void defineExtension(SynapseConfiguration config, OMElement elem) {
-
- OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
-
- if (name == null) {
- handleException("The 'name' attribute is required for an extension configuration definition");
- } else {
- config.addProperty(name.getAttributeValue(), extensionFacFinder.getExtension(elem));
}
}
Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationSerializer.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationSerializer.java?rev=428689&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationSerializer.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationSerializer.java Fri Aug 4 03:50:26 2006
@@ -0,0 +1,46 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.synapse.config.SynapseConfiguration;
+
+import java.io.FileInputStream;
+import java.util.Iterator;
+
+public class XMLConfigurationSerializer {
+
+ public void serializeConfiguration(SynapseConfiguration synCfg) {
+
+ Iterator iter = synCfg.getNamedSequences().keySet().iterator();
+ while (iter.hasNext()) {
+ String name = (String) iter.next();
+ System.out.println(MediatorSerializerFinder.getInstance().getSerializer(synCfg.getNamedSequence(name))
+ .serializeMediator(null, synCfg.getNamedSequence(name)));
+ }
+
+ System.out.println(MediatorSerializerFinder.getInstance().getSerializer(synCfg.getMainMediator())
+ .serializeMediator(null, synCfg.getMainMediator()));
+ }
+
+ public static void main(String[] args) throws Exception {
+ XMLConfigurationBuilder xmlBuilder = new XMLConfigurationBuilder();
+ SynapseConfiguration synCfg = xmlBuilder.getConfiguration(
+ new FileInputStream("C:\\Code\\Synapse\\repository\\conf\\sample\\synapse_sample_1.xml"));
+
+ XMLConfigurationSerializer xmlSer = new XMLConfigurationSerializer();
+ xmlSer.serializeConfiguration(synCfg);
+ }
+}
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/ProxyService.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/ProxyService.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/ProxyService.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/ProxyService.java Fri Aug 4 03:50:26 2006
@@ -22,6 +22,8 @@
import org.apache.axis2.transport.njms.JMSConstants;
import org.apache.synapse.SynapseException;
import org.apache.synapse.Constants;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.config.Util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.policy.util.PolicyReader;
@@ -32,6 +34,7 @@
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.stream.StreamSource;
import java.net.URL;
import java.io.IOException;
import java.util.*;
@@ -39,9 +42,9 @@
/**
* <proxy name="string" [description="string"] [transports="(http|https|jms)+|all"]>
* <target sequence="name" | endpoint="name"/>? // default is main sequence
- * <wsdl url="url">?
- * <schema url="url">*
- * <policy url="url">*
+ * <wsdl key="string">?
+ * <schema key="string">*
+ * <policy key="string">*
* <property name="string" value="string"/>*
* <enableRM/>+
* <enableSec/>+
@@ -65,11 +68,11 @@
/** A list properties */
private Map properties = new HashMap();
- /** The URL for the base WSDL, if specified */
- private URL wsdl;
- /** The URLs for any supplied schemas */
- private URL[] schemas;
- /** The URLs for any supplied policies that would apply at the service level */
+ /** The key for the base WSDL, if specified */
+ private String wsdlKey;
+ /** The keys for any supplied schemas */
+ private List schemaKeys = new ArrayList();
+ /** The keys for any supplied policies that would apply at the service level */
private List serviceLevelPolicies = new ArrayList();
/** Should WS RM (default configuration) be engaged on this service */
private boolean wsRMEnabled = false;
@@ -80,26 +83,29 @@
public ProxyService() {}
- public AxisService buildAxisService(AxisConfiguration axisCfg) {
+ public AxisService buildAxisService(SynapseConfiguration synCfg, AxisConfiguration axisCfg) {
AxisService proxyService = null;
- if (wsdl != null) {
+ if (wsdlKey != null) {
try {
+ StreamSource wsdlStreamSource = Util.getStreamSource(synCfg.getProperty(wsdlKey));
// detect version of the WSDL 1.1 or 2.0
- OMNamespace documentElementNS = new StAXOMBuilder(wsdl.openStream()).
+ OMNamespace documentElementNS = new StAXOMBuilder(wsdlStreamSource.getInputStream()).
getDocumentElement().getNamespace();
if (documentElementNS != null) {
WSDLToAxisServiceBuilder wsdlToAxisServiceBuilder = null;
if (WSDLConstants.WSDL20_2006Constants.DEFAULT_NAMESPACE_URI.
- equals(documentElementNS.getName())) {
+ equals(documentElementNS.getNamespaceURI())) {
wsdlToAxisServiceBuilder =
- new WSDL20ToAxisServiceBuilder(wsdl.openStream(), null, null);
+ new WSDL20ToAxisServiceBuilder(
+ wsdlStreamSource.getInputStream(), null, null);
} else if (org.apache.axis2.namespace.Constants.NS_URI_WSDL11.
- equals(documentElementNS.getName())) {
+ equals(documentElementNS.getNamespaceURI())) {
wsdlToAxisServiceBuilder =
- new WSDL11ToAxisServiceBuilder(wsdl.openStream(), null, null);
+ new WSDL11ToAxisServiceBuilder(
+ wsdlStreamSource.getInputStream(), null, null);
} else {
handleException("Unknown WSDL format.. not WSDL 1.1 or WSDL 2.0");
}
@@ -112,11 +118,11 @@
}
} catch (XMLStreamException e) {
- handleException("Error reading WSDL at URL : " + wsdl, e);
+ handleException("Error reading WSDL defined by registry key : " + wsdlKey, e);
} catch (AxisFault af) {
- handleException("Error building service from WSDL at : " + wsdl, af);
+ handleException("Error building service from WSDL defined by registry key : " + wsdlKey, af);
} catch (IOException ioe) {
- handleException("Error reading WSDL from URL : " + wsdl, ioe);
+ handleException("Error reading WSDL from WSDL defined by registry key : " + wsdlKey, ioe);
}
} else {
// this is for POX... create a dummy service and an operation for which
@@ -174,19 +180,17 @@
PolicyReader reader = PolicyFactory.getPolicyReader(PolicyFactory.OM_POLICY_READER);
Policy svcEffectivePolicy = null;
- URL policyUrl = null;
- try {
- iter = serviceLevelPolicies.iterator();
- while (iter.hasNext()) {
- policyUrl = (URL) iter.next();
- if (svcEffectivePolicy == null) {
- svcEffectivePolicy = reader.readPolicy(policyUrl.openStream());
- } else {
- svcEffectivePolicy.merge(reader.readPolicy(policyUrl.openStream()));
- }
+ String policyKey = null;
+ iter = serviceLevelPolicies.iterator();
+ while (iter.hasNext()) {
+ policyKey = (String) iter.next();
+ if (svcEffectivePolicy == null) {
+ svcEffectivePolicy = reader.readPolicy(
+ Util.getStreamSource(synCfg.getProperty(policyKey)).getInputStream());
+ } else {
+ svcEffectivePolicy.merge(reader.readPolicy(
+ Util.getStreamSource(synCfg.getProperty(policyKey)).getInputStream()));
}
- } catch (IOException ioe) {
- handleException("Error reading policy from URL : " + policyUrl, ioe);
}
PolicyInclude policyInclude = new PolicyInclude();
@@ -250,7 +254,7 @@
}
public String getTransports() {
- return transports;
+ return transports != null ? transports : ALL_TRANSPORTS;
}
public void addProperty(String name, String value) {
@@ -281,20 +285,20 @@
this.targetSequence = targetSequence;
}
- public URL getWsdl() {
- return wsdl;
+ public String getWSDLKey() {
+ return wsdlKey;
}
- public void setWsdl(URL wsdl) {
- this.wsdl = wsdl;
+ public void setWSDLKey(String wsdlKey) {
+ this.wsdlKey = wsdlKey;
}
- public URL[] getSchemas() {
- return schemas;
+ public List getSchemas() {
+ return schemaKeys;
}
- public void setSchemas(URL[] schemas) {
- this.schemas = schemas;
+ public void setSchemas(List schemas) {
+ this.schemaKeys = schemas;
}
public List getServiceLevelPolicies() {
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/SynapseModule.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/SynapseModule.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/SynapseModule.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/SynapseModule.java Fri Aug 4 03:50:26 2006
@@ -64,7 +64,7 @@
Iterator iter = synCfg.getProxyServices().iterator();
while (iter.hasNext()) {
ProxyService proxy = (ProxyService) iter.next();
- axisCfg.addService(proxy.buildAxisService(axisCfg));
+ axisCfg.addService(proxy.buildAxisService(synCfg, axisCfg));
}
}
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java Fri Aug 4 03:50:26 2006
@@ -43,9 +43,10 @@
public static final int SIMPLE = 1;
public static final int HEADERS = 2;
public static final int FULL = 3;
+ public static final String DEFAULT_SEP = ", ";
private int logLevel = SIMPLE;
- private String SEP = ", ";
+ private String separator = DEFAULT_SEP;
private List properties = new ArrayList();
/**
@@ -87,15 +88,15 @@
else
sb.append("To: ");
if (synCtx.getFrom() != null)
- sb.append(SEP + "From: " + synCtx.getFrom().getAddress());
+ sb.append(separator + "From: " + synCtx.getFrom().getAddress());
if (synCtx.getWSAAction() != null)
- sb.append(SEP + "WSAction: " + synCtx.getWSAAction());
+ sb.append(separator + "WSAction: " + synCtx.getWSAAction());
if (synCtx.getSoapAction() != null)
- sb.append(SEP + "SOAPAction: " + synCtx.getSoapAction());
+ sb.append(separator + "SOAPAction: " + synCtx.getSoapAction());
if (synCtx.getReplyTo() != null)
- sb.append(SEP + "ReplyTo: " + synCtx.getReplyTo().getAddress());
+ sb.append(separator + "ReplyTo: " + synCtx.getReplyTo().getAddress());
if (synCtx.getMessageID() != null)
- sb.append(SEP + "MessageID: " + synCtx.getMessageID());
+ sb.append(separator + "MessageID: " + synCtx.getMessageID());
setCustomProperties(sb, synCtx);
return sb.toString();
}
@@ -105,19 +106,19 @@
Iterator iter = synCtx.getEnvelope().getHeader().examineAllHeaderBlocks();
while (iter.hasNext()) {
SOAPHeader header = (SOAPHeader) iter.next();
- sb.append(SEP + header.getLocalName() + " : " + header.getText());
+ sb.append(separator + header.getLocalName() + " : " + header.getText());
}
setCustomProperties(sb, synCtx);
- return sb.toString();
+ return trimLeadingSeparator(sb);
}
private String getFullLogMessage(MessageContext synCtx) {
StringBuffer sb = new StringBuffer();
sb.append(getSimpleLogMessage(synCtx));
if (synCtx.getEnvelope() != null)
- sb.append(SEP + "Envelope: " + synCtx.getEnvelope());
+ sb.append(separator + "Envelope: " + synCtx.getEnvelope());
setCustomProperties(sb, synCtx);
- return sb.toString();
+ return trimLeadingSeparator(sb);
}
private void setCustomProperties(StringBuffer sb, MessageContext synCtx) {
@@ -125,7 +126,7 @@
Iterator iter = properties.iterator();
while (iter.hasNext()) {
MediatorProperty prop = (MediatorProperty) iter.next();
- sb.append(SEP + prop.getName() + " = " +
+ sb.append(separator + prop.getName() + " = " +
(prop.getValue() != null ? prop.getValue() : prop.getEvaluatedExpression(synCtx)));
}
}
@@ -140,11 +141,11 @@
}
public String getSeparator() {
- return SEP;
+ return separator;
}
- public void setSeparator(String SEP) {
- this.SEP = SEP;
+ public void setSeparator(String separator) {
+ this.separator = separator;
}
public void addProperty(MediatorProperty p) {
@@ -155,4 +156,16 @@
properties.addAll(list);
}
+ public List getProperties() {
+ return properties;
+ }
+
+ private String trimLeadingSeparator(StringBuffer sb) {
+ String retStr = sb.toString();
+ if (retStr.startsWith(separator)) {
+ return retStr.substring(separator.length());
+ } else {
+ return retStr;
+ }
+ }
}
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java Fri Aug 4 03:50:26 2006
@@ -134,4 +134,12 @@
public boolean addEndpoint(Endpoint e) {
return endpoints.add(e);
}
+
+ /**
+ * Get list of Endpoints to which the message should be sent
+ * @return the endpoints to which the message should be sent
+ */
+ public List getEndpoints() {
+ return endpoints;
+ }
}
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java Fri Aug 4 03:50:26 2006
@@ -111,4 +111,8 @@
properties.addAll(list);
}
+ public List getProperties() {
+ return properties;
+ }
+
}
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java Fri Aug 4 03:50:26 2006
@@ -80,6 +80,14 @@
}
/**
+ * Get the list of cases
+ * @return the cases list
+ */
+ public List getCases() {
+ return cases;
+ }
+
+ /**
* Return the source XPath expression set
* @return thje source XPath expression
*/
@@ -93,5 +101,13 @@
*/
public void setSource(AXIOMXPath source) {
this.source = source;
+ }
+
+ /**
+ * Get default case
+ * @return the default csae
+ */
+ public SwitchCaseMediator getDefaultCase() {
+ return defaultCase;
}
}
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/registry/AbstractRegistry.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/registry/AbstractRegistry.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/registry/AbstractRegistry.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/registry/AbstractRegistry.java Fri Aug 4 03:50:26 2006
@@ -21,8 +21,6 @@
import org.apache.synapse.config.XMLToObjectMapper;
import org.apache.synapse.config.DynamicProperty;
-import java.util.HashMap;
-import java.util.Map;
import java.net.URI;
/**
@@ -50,7 +48,7 @@
// if we have an unexpired cached copy, return the cached object
if (dp.isCached() && !dp.isExpired()) {
- return dp.getCache();
+ return dp.getValue();
// if we have not cached the referenced object, fetch it and its RegistryEntry
} else if (!dp.isCached()) {
@@ -75,7 +73,7 @@
log.debug("Renew cache lease for another " + re.getCachableDuration() / 1000 + "s");
// return cached object
- return dp.getCache();
+ return dp.getValue();
} else {
omNode = lookup(dp.getKey());
@@ -86,7 +84,7 @@
// registry and our previous copy (if we had one) has expired or is not valid
if (dp.getMapper() != null) {
- dp.setCache(
+ dp.setValue(
dp.getMapper().getObjectFromOMNode(omNode));
} else {
// if the type of the object is known to have a mapper, create the
@@ -97,10 +95,10 @@
XMLToObjectMapper mapper = getMapper(re.getType());
if (mapper != null) {
dp.setMapper(mapper);
- dp.setCache(mapper.getObjectFromOMNode(omNode));
+ dp.setValue(mapper.getObjectFromOMNode(omNode));
} else {
- dp.setCache(omNode);
+ dp.setValue(omNode);
}
}
}
@@ -110,7 +108,7 @@
System.currentTimeMillis() + re.getCachableDuration());
dp.setVersion(re.getVersion());
- return dp.getCache();
+ return dp.getValue();
}
private XMLToObjectMapper getMapper(URI type) {
Added: incubator/synapse/trunk/java/modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.MediatorSerializer
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.MediatorSerializer?rev=428689&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.MediatorSerializer (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.MediatorSerializer Fri Aug 4 03:50:26 2006
@@ -0,0 +1,5 @@
+org.apache.synapse.mediators.validate.ValidateMediatorSerializer
+org.apache.synapse.mediators.transform.XSLTMediatorSerializer
+org.apache.synapse.mediators.spring.SpringMediatorSerializer
+org.apache.synapse.mediators.json.JsonMediatorSerializer
+org.apache.synapse.mediators.javascript.JavaScriptMediatorSerializer
Modified: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/javascript/JavaScriptMediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/javascript/JavaScriptMediator.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/javascript/JavaScriptMediator.java (original)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/javascript/JavaScriptMediator.java Fri Aug 4 03:50:26 2006
@@ -29,6 +29,7 @@
public class JavaScriptMediator extends AbstractMediator {
private RhinoFunctionInvoker mediateFunction;
+ private String script;
public boolean mediate(MessageContext synCtx) {
Boolean b = (Boolean) mediateFunction.invoke(new Object[] { synCtx });
@@ -36,9 +37,14 @@
}
public void setScript(String script) {
+ this.script = script;
RhinoScript rhinoScript = new RhinoScript("JavaScriptMediator", script);
rhinoScript.setResponseClass("mediate", Boolean.class);
RhinoScriptInstance scriptInstance = rhinoScript.createRhinoScriptInstance();
this.mediateFunction = scriptInstance.createRhinoFunctionInvoker("mediate");
+ }
+
+ public String getScript() {
+ return script;
}
}
Modified: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/javascript/JavaScriptMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/javascript/JavaScriptMediatorFactory.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/javascript/JavaScriptMediatorFactory.java (original)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/javascript/JavaScriptMediatorFactory.java Fri Aug 4 03:50:26 2006
@@ -58,9 +58,4 @@
public QName getTagQName() {
return TAG_NAME;
}
-
- public QName getTagSchemaType() {
- return new QName(Constants.SYNAPSE_NAMESPACE,
- getTagQName().getLocalPart() + "_type", "js");
- }
}
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/javascript/JavaScriptMediatorSerializer.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/javascript/JavaScriptMediatorSerializer.java?rev=428689&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/javascript/JavaScriptMediatorSerializer.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/javascript/JavaScriptMediatorSerializer.java Fri Aug 4 03:50:26 2006
@@ -0,0 +1,67 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.mediators.javascript;
+
+import org.apache.synapse.config.xml.AbstractMediatorSerializer;
+import org.apache.synapse.config.xml.MediatorSerializer;
+import org.apache.synapse.config.xml.Constants;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+
+import javax.xml.stream.XMLStreamConstants;
+
+/**
+ * <javascript/>
+ * <![CDATA[ script here ]]>
+ * </javascript>
+ */
+public class JavaScriptMediatorSerializer extends AbstractMediatorSerializer
+ implements MediatorSerializer {
+
+ private static final OMNamespace jsNS = fac.createOMNamespace(Constants.SYNAPSE_NAMESPACE+"/js", "js");
+
+ private static final Log log = LogFactory.getLog(JavaScriptMediatorSerializer.class);
+
+ public OMElement serializeMediator(OMElement parent, Mediator m) {
+
+ if (!(m instanceof JavaScriptMediator)) {
+ handleException("Unsupported mediator passed in for serialization : " + m.getType());
+ }
+
+ JavaScriptMediator mediator = (JavaScriptMediator) m;
+ OMElement js = fac.createOMElement("javascript", jsNS);
+
+ js.addChild(fac.createOMText(mediator.getScript(), XMLStreamConstants.CDATA));
+
+ if (parent != null) {
+ parent.addChild(js);
+ }
+ return js;
+ }
+
+ public String getMediatorClassName() {
+ return JavaScriptMediator.class.getName();
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+}
Modified: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/json/JsonMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/json/JsonMediatorFactory.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/json/JsonMediatorFactory.java (original)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/json/JsonMediatorFactory.java Fri Aug 4 03:50:26 2006
@@ -33,7 +33,7 @@
* Creates an instance of JsonMediator.
* <x:json/> mediator belongs to the http://ws.apache.org/ns/synapse/json namespace.
* <p/>
- * <x:json (direction="JTX"|"XTJ)"/>
+ * <x:json direction="JTX"|"XTJ"/>
* JTX is Json to XML
* XTJ is XML to Json
*/
@@ -48,7 +48,7 @@
OMAttribute direction = elem.getAttribute(new QName("direction"));
if (direction == null) {
handleException("JSON element doesnot contain 'direction' attribute.");
- }else {
+ } else {
jsonMediator.setDirection(direction.getAttributeValue().trim());
}
return jsonMediator;
@@ -56,11 +56,6 @@
public QName getTagQName() {
return TAG_NAME;
- }
-
- public QName getTagSchemaType() {
- return new QName(Constants.SYNAPSE_NAMESPACE,
- getTagQName().getLocalPart() + "_type", "json");
}
private void handleException(String msg) {
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/json/JsonMediatorSerializer.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/json/JsonMediatorSerializer.java?rev=428689&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/json/JsonMediatorSerializer.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/json/JsonMediatorSerializer.java Fri Aug 4 03:50:26 2006
@@ -0,0 +1,72 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.mediators.json;
+
+import org.apache.synapse.config.xml.AbstractMediatorSerializer;
+import org.apache.synapse.config.xml.MediatorSerializer;
+import org.apache.synapse.config.xml.Constants;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+
+import javax.xml.stream.XMLStreamConstants;
+
+/**
+ * <x:json/> mediator belongs to the http://ws.apache.org/ns/synapse/json namespace.
+ * <p/>
+ * <x:json (direction="JTX"|"XTJ)"/>
+ */
+public class JsonMediatorSerializer extends AbstractMediatorSerializer
+ implements MediatorSerializer {
+
+ private static final OMNamespace jsonNS = fac.createOMNamespace(Constants.SYNAPSE_NAMESPACE+"/json", "json");
+
+ private static final Log log = LogFactory.getLog(JsonMediatorSerializer.class);
+
+ public OMElement serializeMediator(OMElement parent, Mediator m) {
+
+ if (!(m instanceof JsonMediator)) {
+ handleException("Unsupported mediator passed in for serialization : " + m.getType());
+ }
+
+ JsonMediator mediator = (JsonMediator) m;
+ OMElement json = fac.createOMElement("json", jsonNS);
+
+ if (mediator.getDirection() != null) {
+ json.addAttribute(fac.createOMAttribute(
+ "direction", nullNS, mediator.getDirection()));
+ } else {
+ handleException("Invalid mediator. Direction is required");
+ }
+
+ if (parent != null) {
+ parent.addChild(json);
+ }
+ return json;
+ }
+
+ public String getMediatorClassName() {
+ return JsonMediatorSerializer.class.getName();
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+}
Modified: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/json/SynapseJsonSender.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/json/SynapseJsonSender.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/json/SynapseJsonSender.java (original)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/json/SynapseJsonSender.java Fri Aug 4 03:50:26 2006
@@ -24,6 +24,7 @@
import org.apache.axis2.context.MessageContextConstants;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.addressing.AddressingConstants;
@@ -52,7 +53,7 @@
EndpointReference epr = null;
String transportURL =
(String) msgContext
- .getProperty(MessageContextConstants.TRANSPORT_URL);
+ .getProperty(Constants.Configuration.TRANSPORT_URL);
if (transportURL != null) {
epr = new EndpointReference(transportURL);
@@ -185,7 +186,7 @@
if (charsetEnc != null) {
if (opContext != null) {
opContext.setProperty(
- MessageContext.CHARACTER_SET_ENCODING,
+ Constants.Configuration.CHARACTER_SET_ENCODING,
charsetEnc.getValue());
}
}
Modified: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/spring/SpringMediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/spring/SpringMediator.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/spring/SpringMediator.java (original)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/spring/SpringMediator.java Fri Aug 4 03:50:26 2006
@@ -19,9 +19,13 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.DynamicProperty;
+import org.apache.synapse.config.Util;
import org.apache.synapse.api.Mediator;
-import org.apache.synapse.mediators.spring.SpringConfigExtension;
import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.core.io.InputStreamResource;
/**
* This mediator allows Spring beans implementing the org.apache.synapse.api.Mediator
@@ -40,9 +44,9 @@
*/
private String beanName = null;
/**
- * The named Spring configName to be used
+ * The named Spring config to be used
*/
- private String configName = null;
+ private String configKey = null;
/**
* The Spring ApplicationContext to be used
*/
@@ -50,53 +54,50 @@
public boolean mediate(MessageContext synCtx) {
- if (beanName == null) {
- handleException("The bean name for the Spring mediator has not been specified");
- }
+ DynamicProperty dp = synCtx.getConfiguration().getDynamicProperty(configKey);
- // if a named configuration is referenced, use it
- if (configName != null) {
- // get named Spring configuration
- Object cfg = synCtx.getConfiguration().getProperty(configName);
-
- if (cfg != null && cfg instanceof SpringConfigExtension) {
-
- ApplicationContext appContext = ((SpringConfigExtension) cfg).getAppContext();
- log.debug("Loading bean : " + beanName + " from Spring configuration named : " + configName);
- Object o = appContext.getBean(beanName);
-
- if (o != null && Mediator.class.isAssignableFrom(o.getClass())) {
- Mediator m = (Mediator) o;
- return m.mediate(synCtx);
-
- } else {
- handleException("Could not find the bean named : " + beanName +
- " from the Spring configuration named : " + configName);
- }
- } else {
- handleException("Could not get a reference to a valid Spring configuration named : " + configName);
+ // if the configKey refers to a dynamic property
+ if (dp != null) {
+ if (!dp.isCached() || dp.isExpired()) {
+ buildAppContext(synCtx);
}
+ // if the property is not a DynamicProperty, we will create an ApplicationContext only once
+ } else {
+ if (appContext == null) {
+ buildAppContext(synCtx);
+ }
+ }
- } else if (appContext != null) {
-
- log.debug("Loading bean : " + beanName + " from inline Spring configuration");
- Object o = appContext.getBean(beanName);
+ if (appContext != null) {
+ Object o = appContext.getBean(beanName);
if (o != null && Mediator.class.isAssignableFrom(o.getClass())) {
Mediator m = (Mediator) o;
return m.mediate(synCtx);
} else {
- handleException("Could not find the bean named : " + beanName +
- " from the inline Spring configuration");
+ handleException("Could not load bean named : " + beanName +
+ " from the Spring configuration with key : " + configKey);
}
-
} else {
- handleException("A named Spring configuration or an ApplicationContext has not been specified");
+ handleException("Cannot reference Spring application context with key : " + configKey);
}
+
return true;
}
+ private synchronized void buildAppContext(MessageContext synCtx) {
+ log.debug("Creating Spring ApplicationContext from property key : " + configKey);
+ GenericApplicationContext appContext = new GenericApplicationContext();
+ XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
+ xbdr.setValidating(false);
+ xbdr.loadBeanDefinitions(new InputStreamResource(
+ Util.getStreamSource(
+ synCtx.getConfiguration().getProperty(configKey)).getInputStream()));
+ appContext.refresh();
+ this.appContext = appContext;
+ }
+
private void handleException(String msg) {
log.error(msg);
throw new SynapseException(msg);
@@ -110,12 +111,12 @@
return beanName;
}
- public String getConfigName() {
- return configName;
+ public String getConfigKey() {
+ return configKey;
}
- public void setConfigName(String configName) {
- this.configName = configName;
+ public void setConfigKey(String configKey) {
+ this.configKey = configKey;
}
public ApplicationContext getAppContext() {
Modified: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/spring/SpringMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/spring/SpringMediatorFactory.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/spring/SpringMediatorFactory.java (original)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/spring/SpringMediatorFactory.java Fri Aug 4 03:50:26 2006
@@ -21,11 +21,8 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseException;
import org.apache.synapse.api.Mediator;
-import org.apache.synapse.mediators.spring.SpringConfigExtension;
import org.apache.synapse.config.xml.Constants;
import org.apache.synapse.config.xml.MediatorFactory;
-import org.apache.synapse.mediators.spring.SpringMediator;
-import org.apache.ws.commons.schema.XmlSchema;
import javax.xml.namespace.QName;
@@ -34,7 +31,7 @@
* configuration and bean. Optionally, one could specify an inlined Spring
* configuration as opposed to a globally defined Spring configuration
* <p/>
- * <spring bean="exampleBean1" (config="spring1" | src="spring.xml)"/>
+ * <spring bean="exampleBean1" key="string""/>
*/
public class SpringMediatorFactory implements MediatorFactory {
@@ -53,25 +50,15 @@
SpringMediator sm = new SpringMediator();
OMAttribute bean = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "bean"));
- OMAttribute cfg = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "config"));
- OMAttribute src = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "src"));
+ OMAttribute key = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "key"));
if (bean == null) {
handleException("The 'bean' attribute is required for a Spring mediator definition");
- } else if (cfg == null && src == null) {
- handleException("A 'config' or 'src' attribute is required for a Spring mediator definition");
-
+ } else if (key == null) {
+ handleException("A 'key' attribute is required for a Spring mediator definition");
} else {
sm.setBeanName(bean.getAttributeValue());
- if (cfg != null) {
- log.debug("Creating a Spring mediator using configuration named : " + cfg.getAttributeValue());
- sm.setConfigName(cfg.getAttributeValue());
-
- } else {
- log.debug("Creating an inline Spring configuration using source : " + src.getAttributeValue());
- SpringConfigExtension sce = new SpringConfigExtension("inline", src.getAttributeValue());
- sm.setAppContext(sce.getAppContext());
- }
+ sm.setConfigKey(key.getAttributeValue());
return sm;
}
return null;
@@ -84,10 +71,5 @@
public QName getTagQName() {
return TAG_NAME;
- }
-
- public QName getTagSchemaType() {
- return new QName(Constants.SYNAPSE_NAMESPACE,
- getTagQName().getLocalPart() + "_type", "spring");
}
}
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/spring/SpringMediatorSerializer.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/spring/SpringMediatorSerializer.java?rev=428689&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/spring/SpringMediatorSerializer.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/spring/SpringMediatorSerializer.java Fri Aug 4 03:50:26 2006
@@ -0,0 +1,75 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.mediators.spring;
+
+import org.apache.synapse.config.xml.AbstractMediatorSerializer;
+import org.apache.synapse.config.xml.MediatorSerializer;
+import org.apache.synapse.config.xml.Constants;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * <spring bean="exampleBean1" (config="spring1" | src="spring.xml)"/>
+ */
+public class SpringMediatorSerializer extends AbstractMediatorSerializer
+ implements MediatorSerializer {
+
+ private static final OMNamespace sprNS = fac.createOMNamespace(Constants.SYNAPSE_NAMESPACE+"/spring", "spring");
+
+ private static final Log log = LogFactory.getLog(SpringMediatorSerializer.class);
+
+ public OMElement serializeMediator(OMElement parent, Mediator m) {
+
+ if (!(m instanceof SpringMediator)) {
+ handleException("Unsupported mediator passed in for serialization : " + m.getType());
+ }
+
+ SpringMediator mediator = (SpringMediator) m;
+ OMElement spring = fac.createOMElement("spring", sprNS);
+
+ if (mediator.getBeanName() != null) {
+ spring.addAttribute(fac.createOMAttribute(
+ "bean", nullNS, mediator.getBeanName()));
+ } else {
+ handleException("Invalid mediator. Bean name required.");
+ }
+
+ if (mediator.getConfigKey() != null) {
+ spring.addAttribute(fac.createOMAttribute(
+ "config", nullNS, mediator.getConfigKey()));
+ }
+
+ // TODO add support for src attribute - or replace with a reg key!
+
+ if (parent != null) {
+ parent.addChild(spring);
+ }
+ return spring;
+ }
+
+ public String getMediatorClassName() {
+ return SpringMediator.class.getName();
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+}
Modified: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/transform/XSLTMediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/transform/XSLTMediator.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/transform/XSLTMediator.java (original)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/transform/XSLTMediator.java Fri Aug 4 03:50:26 2006
@@ -75,7 +75,7 @@
/** Lock used to ensure thread-safe creation and use of the above Transformer */
private final Object transformerLock = new Object();
- private static final String DEFAULT_XPATH = "//s11:Envelope/s11:Body/child::*[position()=1] | " +
+ public static final String DEFAULT_XPATH = "//s11:Envelope/s11:Body/child::*[position()=1] | " +
"//s12:Envelope/s12:Body/child::*[position()=1]";
public XSLTMediator() {
@@ -251,6 +251,9 @@
properties.addAll(list);
}
+ public List getProperties() {
+ return properties;
+ }
}
Modified: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/transform/XSLTMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/transform/XSLTMediatorFactory.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/transform/XSLTMediatorFactory.java (original)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/transform/XSLTMediatorFactory.java Fri Aug 4 03:50:26 2006
@@ -21,8 +21,8 @@
import org.apache.synapse.SynapseException;
import org.apache.synapse.Util;
import org.apache.synapse.config.xml.Constants;
-import org.apache.synapse.config.xml.AbstractMediatorFactory;
import org.apache.synapse.config.xml.MediatorPropertyFactory;
+import org.apache.synapse.config.xml.MediatorFactory;
import org.apache.synapse.mediators.transform.XSLTMediator;
import org.apache.synapse.api.Mediator;
import org.apache.commons.logging.Log;
@@ -43,7 +43,7 @@
* </transform>
* </pre>
*/
-public class XSLTMediatorFactory extends AbstractMediatorFactory {
+public class XSLTMediatorFactory implements MediatorFactory {
private static final Log log = LogFactory.getLog(XSLTMediatorFactory.class);
private static final QName TAG_NAME = new QName(Constants.SYNAPSE_NAMESPACE, "xslt");
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/transform/XSLTMediatorSerializer.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/transform/XSLTMediatorSerializer.java?rev=428689&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/transform/XSLTMediatorSerializer.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/transform/XSLTMediatorSerializer.java Fri Aug 4 03:50:26 2006
@@ -0,0 +1,77 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.mediators.transform;
+
+import org.apache.synapse.config.xml.AbstractMediatorSerializer;
+import org.apache.synapse.config.xml.MediatorSerializer;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+
+/**
+ * <pre>
+ * <xslt key="property-key" [source="xpath"]>
+ * <property name="string" (value="literal" | expression="xpath")/>*
+ * </transform>
+ * </pre>
+ */
+public class XSLTMediatorSerializer extends AbstractMediatorSerializer
+ implements MediatorSerializer {
+
+ private static final Log log = LogFactory.getLog(XSLTMediatorSerializer.class);
+
+ public OMElement serializeMediator(OMElement parent, Mediator m) {
+
+ if (!(m instanceof XSLTMediator)) {
+ handleException("Unsupported mediator passed in for serialization : " + m.getType());
+ }
+
+ XSLTMediator mediator = (XSLTMediator) m;
+ OMElement xslt = fac.createOMElement("xslt", synNS);
+
+ if (mediator.getXsltKey() != null) {
+ xslt.addAttribute(fac.createOMAttribute(
+ "key", nullNS, mediator.getXsltKey()));
+ } else {
+ handleException("Invalid XSLT mediator. XSLT registry key is required");
+ }
+
+ if (mediator.getSource() != null &&
+ !XSLTMediator.DEFAULT_XPATH.toString().equals(mediator.getSource().toString())) {
+ xslt.addAttribute(fac.createOMAttribute(
+ "source", nullNS, mediator.getSource().toString()));
+ super.serializeNamespaces(xslt, mediator.getSource());
+ }
+
+ super.serializeProperties(xslt, mediator.getProperties());
+
+ if (parent != null) {
+ parent.addChild(xslt);
+ }
+ return xslt;
+ }
+
+ public String getMediatorClassName() {
+ return XSLTMediator.class.getName();
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+}
Modified: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/validate/ValidateMediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/validate/ValidateMediator.java?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/validate/ValidateMediator.java (original)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/validate/ValidateMediator.java Fri Aug 4 03:50:26 2006
@@ -352,4 +352,27 @@
this.source = source;
}
+ /**
+ * Get the source XPath which yeilds the source element for validation
+ * @return the XPath which yeilds the source element for validation
+ */
+ public AXIOMXPath getSource() {
+ return source;
+ }
+
+ /**
+ * The keys for the schema resources used for validation
+ * @return schema registry keys
+ */
+ public List getSchemaKeys() {
+ return schemaKeys;
+ }
+
+ /**
+ * Properties for the actual Xerces validator
+ * @return properties to be passed to the Xerces validator
+ */
+ public Map getProperties() {
+ return properties;
+ }
}
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/validate/ValidateMediatorSerializer.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/validate/ValidateMediatorSerializer.java?rev=428689&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/validate/ValidateMediatorSerializer.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/validate/ValidateMediatorSerializer.java Fri Aug 4 03:50:26 2006
@@ -0,0 +1,83 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.mediators.validate;
+
+import org.apache.synapse.config.xml.AbstractListMediatorSerializer;
+import org.apache.synapse.config.xml.MediatorSerializer;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+
+import java.util.Iterator;
+
+/**
+ * <validate [source="xpath"]>
+ * <schema key="string">+
+ * <property name="<validation-feature-id>" value="true|false"/> *
+ * <on-fail>
+ * mediator+
+ * </on-fail>
+ * </validate>
+ */
+public class ValidateMediatorSerializer extends AbstractListMediatorSerializer
+ implements MediatorSerializer {
+
+ private static final Log log = LogFactory.getLog(ValidateMediatorSerializer.class);
+
+ public OMElement serializeMediator(OMElement parent, Mediator m) {
+
+ if (!(m instanceof ValidateMediator)) {
+ handleException("Unsupported mediator passed in for serialization : " + m.getType());
+ }
+
+ ValidateMediator mediator = (ValidateMediator) m;
+ OMElement validate = fac.createOMElement("validate", synNS);
+
+ if (mediator.getSource() != null) {
+ validate.addAttribute(fac.createOMAttribute(
+ "source", nullNS, mediator.getSource().toString()));
+ super.serializeNamespaces(validate, mediator.getSource());
+ }
+
+ Iterator iter = mediator.getSchemaKeys().iterator();
+ while (iter.hasNext()) {
+ String key = (String) iter.next();
+ OMElement schema = fac.createOMElement("schema", synNS, validate);
+ schema.addAttribute(fac.createOMAttribute("key", nullNS, key));
+ }
+
+ super.serializeProperties(validate, mediator.getProperties().entrySet());
+
+ OMElement onFail = fac.createOMElement("on-fail", synNS, validate);
+ super.serializeChildren(onFail, mediator.getList());
+
+ if (parent != null) {
+ parent.addChild(validate);
+ }
+ return validate;
+ }
+
+ public String getMediatorClassName() {
+ return ValidateMediator.class.getName();
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+}
Modified: incubator/synapse/trunk/java/repository/conf/sample/synapse_spring_unittest.xml
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/repository/conf/sample/synapse_spring_unittest.xml?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/repository/conf/sample/synapse_spring_unittest.xml (original)
+++ incubator/synapse/trunk/java/repository/conf/sample/synapse_spring_unittest.xml Fri Aug 4 03:50:26 2006
@@ -1,12 +1,13 @@
<synapse xmlns="http://ws.apache.org/ns/synapse" xmlns:spring="http://ws.apache.org/ns/synapse/spring">
<definitions>
- <spring:config name="springconfig" src="./../../repository/conf/sample/springsample.xml"/>
+ <set-property name="springconfig1" key="file:./../../repository/conf/sample/springsample.xml"/>
+ <set-property name="springconfig2" src="file:./../../repository/conf/sample/springsample.xml"/>
</definitions>
<rules>
- <spring:spring bean="springtest" config="springconfig"/>
- <spring:spring bean="springtest" src="./../../repository/conf/sample/springsample.xml"/>
+ <spring:spring bean="springtest" key="springconfig1"/>
+ <spring:spring bean="springtest" key="springconfig2"/>
</rules>
</synapse>
Modified: incubator/synapse/trunk/java/xdocs/Synapse_Configuration_Language.html
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/xdocs/Synapse_Configuration_Language.html?rev=428689&r1=428688&r2=428689&view=diff
==============================================================================
--- incubator/synapse/trunk/java/xdocs/Synapse_Configuration_Language.html (original)
+++ incubator/synapse/trunk/java/xdocs/Synapse_Configuration_Language.html Fri Aug 4 03:50:26 2006
@@ -18,7 +18,7 @@
<p>A Synapse configuration looks like the following at the top level: </p>
<pre> <synapse>
<definitions>
- (sequencedef | endpointdef | literalpropertydef | extensiondef)+
+ (sequencedef | endpointdef | literalpropertydef)+
<definitions>?
<proxies>
proxyservice+
@@ -42,11 +42,11 @@
switching etc. </p>
<p>A proxyservice token represents a <proxy> element which is
used to define a Synapse Proxy service. </p>
-<pre> <proxy name="string" [description="string"] [transports="(http|https|jms)+|all"]>
- <target sequence="name" | endpoint="name"/>? // default is main sequence
- <wsdl url="url">?
- <schema url="url">*
- <policy url="url">*
+<pre> <proxy name="string" [description="string"] [transports="(http |https |jms )+|all"]>
+ <target sequence="name" | endpoint="name"/>? // defaults to the synapse main sequence
+ <wsdl key="string">?
+ <schema key="string">* // not yet used
+ <policy key="string">*
<property name="string" value="string"/>*
</proxy>
@@ -104,42 +104,29 @@
"RMPolicy" describes the Apache Sandesha2 RM configuration (or any
overrides against the default) to be used for messages flowing to this
endpoint. Please see Sandesha2/Axis2 documentation for more details. </p>
-<h4>Extensions</h4>
-<p>An extensiondef token represents an extension element that extends
-the core Synapse configuration. An extension provider must create an
-ExtensionFactory
-implementation that defines the type of element that the factory
-handles. At runtime the configuration builder loads any extensions
-through the Java service provider model, and then passes any unknown
-elements to the extension factory finder which will return the
-registered factory, if any. Then the factory is requested to process
-the extension element and create the extension, and this could be set
-as a 'property' into the SynapseConfiguration
-object. The Spring configuration extension operates in this manner and
-creates the Spring application contexts and sets it to the
-configuration as a property. </p>
-<p>See 'Extensibility of Synapse' below for more details. </p>
-<p>Note: The supported extensions are loaded through the J2SE Service
-Provider model. (<a rel="nofollow"
- href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider"><img
- src="file:///wiki/modern/img/moin-www.png" alt="[WWW]" height="11"
- width="11">
-http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider</a>)
-</p>
<h4>Properties</h4>
<p>The token literalpropertydef refers to a <set-property>
element as follows: </p>
-<pre> <set-property name="string" value="string"/>
+<pre> <set-property name="string" [value="string"] [src="url"] [key="string"]>
+ <inline-xml/>?
+ <set-property/>
</pre>
-<p>which is used to set a global property with a constant value. </p>
<p>These properties are top level properties which are set globally for
the entire system. Values of these properties can be retrieved via the
extension XPath function called "synapse:get-property(prop-name)". </p>
+<p>A property can be static literal text (specified with the value
+attribute) or static XML specified as an inline XML fragment or
+specified as a URL (using the src attribute). A property can alternatively
+be a DynamicProperty which will reference a key on a Registry.
+If a property is a DynamicProperty, it will be fetched from the Registry
+and cached locally as per meta information provided by the Registry for
+caching. DynamicProperties are automatically refreshed when expired, and
+thus can be used to specify dynamic behaviour in Synapse.</p>
<h3>Mediators</h3>
<p>A mediator token refers to any of the following tokens: </p>
<pre>send | drop | log | makefault | transform | header | filter |
- switch | class | validate | setproperty | sequenceref | in | out
+ switch | class | validate | setproperty | sequenceref | in | out | rm | try
</pre>
<p>In addition to the above, Synapse will be able to load mediators via
the J2SE Service Provider model. Mediator extensions must implement the
@@ -212,25 +199,19 @@
<h4>Log</h4>
<p>The log token refers to a <log> element which may be used to
log messages being mediated: </p>
-<pre> <log [level="string"] [seperator="string"]>
+<pre> <log [level="string"] [separator="string"]>
<property name="string" (value="literal" | expression="xpath")/>*
</log>
</pre>
<p>The optional level attribute selects a pre-defined subset of
-properties to be logged. e.g. simple = To, From, WSAction, SOAPAction,
-ReplyTo,
-MessageID and any properties </p>
-<ul>
- <li style="list-style-type: none;">
- <p>headers = All SOAP header blocks
-and any properties full = all attributes included in log level 'simple'
-and the SOAP envelope and any properties custom = Only properties
-specified to the Log mediator </p>
- </li>
-</ul>
-<p>A seperator if defined will be used to seperate the attributes being
-logged. The default seperator is the ',' comma. </p>
+properties to be logged.
+<p>e.g. simple = To, From, WSAction, SOAPAction, ReplyTo, MessageID and any properties </p>
+<p>headers = All SOAP header blocks and any properties</p>
+<p>full = all attributes included in log level 'simple' and the SOAP envelope and any properties</p>
+<p>custom = Only properties specified to the Log mediator </p>
+<p>A separator if defined will be used to seperate the attributes being
+logged. The default separator is the ',' comma. </p>
<h4>Transforms</h4>
<h5>Faults</h5>
<pre> <makefault [version="soap11|soap12"]>
@@ -248,18 +229,17 @@
"to" header is set to the "faultTo" of the original message if such a
header existed on the original message, else it is set it to the
"replyTo" of the original message. </p>
-<h5>XSLT/XQuery</h5>
-<pre> <transform xslt|xquery="url" [source="xpath"]>
+<h5>XSLT</h5>
+<pre> <xslt key="string" [source="xpath"]>
<property name="string" (value="literal" | expression="xpath")/>*
</transform>
</pre>
-<p>The <transform> mediator applies the specified XSLT or XQuery
+<p>The <xslt> mediator applies the specified XSLT
transformation to the given element. If the source element is not
-specified, it defaults to the soap body content. Optionally parameters
-(XSLT) or variables (XQuery) could be passed into the transformations
+specified, it defaults to the first child of the soap body. Optionally parameters
+(XSLT) could be passed into the transformations
through the <property> elements. </p>
-<p>Note: Synapse does not currently support XQuery transformations </p>
<h5>Headers</h5>
<pre> <header name="qname" (value="literal" | expression="xpath") [action="set"]/>
<header name="qname" action="remove"/>
@@ -299,7 +279,7 @@
regular expressions. If the specified cases does not match and a
default case exists, it will be executed. </p>
<h4>Validation</h4>
-<pre> <validate schema="url" [source="xpath"]>
+<pre> <validate key="string" [source="xpath"]>
<on-fail>
mediator+
</on-fail>
@@ -344,32 +324,25 @@
<h3>Extensibility of Synapse</h3>
<p>The Synapse configuration language could be easily extended, with
configuration extensions as well as mediation extensions. The Spring
-mediator and Spring Configuration are such examples. </p>
+mediator is such an example. </p>
<h4>Spring Configuration</h4>
-<p>The <spring:config> element could be used to define a reusable
-Spring ApplicationContext (BeanFactory).
-This could be referred subsequently by Spring mediator instances which
-will use this context. </p>
-<pre> <spring:config name="string" src="file"/>
-
+<p>A Spring configuration could be created as a property or DynamicProperty
+providing a URL or a reference to a Registry. The configuration is then
+created on first use or as necessary (as per DynamicProperty semantics)
+by the mediators which reference this configuration.</p>
+<pre> <set-property name="string" key="string"/>
+ <set-property name="string" src="url"/>
</pre>
<p>The name attribute specifies a unique name for the configuration,
-and the src attribute specifies the Spring configuration file. </p>
-<p>Note: the <spring:config> element belongs to the <a
- rel="nofollow" href="http://ws.apache.org/ns/synapse/spring"><img
- src="file:///wiki/modern/img/moin-www.png" alt="[WWW]" height="11"
- width="11"> http://ws.apache.org/ns/synapse/spring</a> namespace. </p>
+and the src, key or inlined XML references to the Spring configuration</p>
<h4>Spring mediator</h4>
-<pre> <spring:spring bean="exampleBean1" (config="spring1" | src="spring.xml)"/>
+<pre> <spring:spring bean="exampleBean1" key="string"/>
</pre>
<p>The <spring> element creates an instance of a mediator, which
is managed by Spring. This Spring bean must implement the Mediator
-interface for it to act as a Mediator. If a config attribute is
-specified, the bean will refer to the Spring configuration with the
-given name as its bean factory. If a src attribute specifies the Spring
-configuration file, the required application context is created inline
-and will be used by the mediator instance. </p>
+interface for it to act as a Mediator. The key will reference the Spring
+ApplicationContext/Configuration used for the bean</p>
<h2>Examples</h2>
<p>The following illustrates the hypothetical example used to
illustrate the new Synapse configuration language syntax. However,
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org