You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by is...@apache.org on 2016/05/31 18:27:39 UTC

svn commit: r1746312 - in /synapse/trunk/java/modules: core/src/main/java/org/apache/synapse/config/xml/ core/src/main/java/org/apache/synapse/mediators/builtin/ core/src/test/java/org/apache/synapse/config/xml/ integration/src/test/java/org/apache/syn...

Author: isudana
Date: Tue May 31 18:27:38 2016
New Revision: 1746312

URL: http://svn.apache.org/viewvc?rev=1746312&view=rev
Log:
applying patch to include Respond Mediator improvement SYNAPSE-997 together with integration test provided through SYNAPSE-1031

Added:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/RespondMediatorFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/RespondMediatorSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RespondMediator.java
    synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/RespondMediatorSerializationTest.java
    synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample161.java
    synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_161.xml
    synapse/trunk/java/modules/integration/src/test/resources/sample161.xml
Modified:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
    synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java?rev=1746312&r1=1746311&r2=1746312&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java Tue May 31 18:27:38 2016
@@ -84,7 +84,8 @@ public class MediatorFactoryFinder imple
         InvokeMediatorFactory.class,
         PayloadFactoryMediatorFactory.class,
         BeanMediatorFactory.class,
-        EJBMediatorFactory.class
+        EJBMediatorFactory.class,
+        RespondMediatorFactory.class
     };
 
     private final static MediatorFactoryFinder instance  = new MediatorFactoryFinder();

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java?rev=1746312&r1=1746311&r2=1746312&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java Tue May 31 18:27:38 2016
@@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.Mediator;
 import org.apache.synapse.config.xml.eventing.EventPublisherMediatorSerializer;
+import org.apache.synapse.mediators.builtin.RespondMediator;
 import sun.misc.Service;
 
 import java.util.HashMap;
@@ -70,7 +71,8 @@ public class MediatorSerializerFinder {
         URLRewriteMediatorSerializer.class,
         PayloadFactoryMediatorSerializer.class,
         BeanMediatorSerializer.class,
-        EJBMediatorSerializer.class
+        EJBMediatorSerializer.class,
+        RespondMediatorSerializer.class
     };
 
     private final static MediatorSerializerFinder instance = new MediatorSerializerFinder();

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/RespondMediatorFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/RespondMediatorFactory.java?rev=1746312&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/RespondMediatorFactory.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/RespondMediatorFactory.java Tue May 31 18:27:38 2016
@@ -0,0 +1,50 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.axiom.om.OMElement;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.mediators.builtin.RespondMediator;
+
+import javax.xml.namespace.QName;
+import java.util.Properties;
+
+/**
+ * Factory for {@link RespondMediator} instances.
+ * <p/>
+ * Configuration syntax:
+ * <pre>
+ * &lt;respond/&gt;
+ * </pre>
+ */
+public class RespondMediatorFactory extends AbstractMediatorFactory {
+    private static final QName Respond_Q = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "respond");
+
+    @Override
+    protected Mediator createSpecificMediator(OMElement omElement, Properties properties) {
+        Mediator responseMediator = new RespondMediator();
+        processAuditStatus(responseMediator, omElement);
+        return responseMediator;
+    }
+
+    public QName getTagQName() {
+        return Respond_Q;
+    }
+}

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/RespondMediatorSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/RespondMediatorSerializer.java?rev=1746312&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/RespondMediatorSerializer.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/RespondMediatorSerializer.java Tue May 31 18:27:38 2016
@@ -0,0 +1,46 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.axiom.om.OMElement;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.mediators.builtin.RespondMediator;
+
+/**
+ * Serializer for {@link RespondMediator} instances.
+ *
+ * @see RespondMediator
+ */
+public class RespondMediatorSerializer extends AbstractMediatorSerializer{
+
+    public OMElement serializeSpecificMediator(Mediator m) {
+        if (!(m instanceof RespondMediator)) {
+            handleException("Unsupported mediator passed in for serialization : " + m.getType());
+        }
+        RespondMediator mediator = (RespondMediator) m;
+        OMElement respond = fac.createOMElement("respond", synNS);
+        saveTracingState(respond, mediator);
+        return respond;
+    }
+
+    public String getMediatorClassName() {
+        return RespondMediator.class.getName();
+    }
+}
\ No newline at end of file

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RespondMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RespondMediator.java?rev=1746312&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RespondMediator.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RespondMediator.java Tue May 31 18:27:38 2016
@@ -0,0 +1,70 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.builtin;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseLog;
+import org.apache.synapse.core.axis2.Axis2Sender;
+import org.apache.synapse.mediators.AbstractMediator;
+
+/**
+ * Halts further processing/mediation of the current message and return the current message back to client
+ * This Mediator reduce the number of configuration element need to build an echo service from ESB.
+ */
+public class RespondMediator extends AbstractMediator {
+
+    /**
+     * Halts further processing/mediation of the current message and return the current message back to client.
+     *
+     * @param synCtx the current message for mediation
+     * @return false
+     */
+    public boolean mediate(MessageContext synCtx) {
+        SynapseLog synapseLog = getLog(synCtx);
+
+        boolean isTraceOrDebugEnabled = synapseLog.isTraceOrDebugEnabled();
+        if (isTraceOrDebugEnabled) {
+            synapseLog.traceOrDebug("Start : Respond mediator");
+
+            if (synapseLog.isTraceTraceEnabled()) {
+                synapseLog.traceOrDebug("Message : " + synCtx.getEnvelope());
+            }
+        }
+
+        synCtx.setTo(null);
+        synCtx.setResponse(true);
+        Axis2Sender.sendBack(synCtx);
+
+        if (isTraceOrDebugEnabled) {
+            synapseLog.traceOrDebug("End : Respond Mediator");
+        }
+        return false;
+    }
+
+    /**
+     * Since this Mediator does not touch the content of the message Content Aware property is set into False.
+     *
+     * @return false
+     */
+    @Override
+    public boolean isContentAware() {
+        return false;
+    }
+}

Added: synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/RespondMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/RespondMediatorSerializationTest.java?rev=1746312&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/RespondMediatorSerializationTest.java (added)
+++ synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/RespondMediatorSerializationTest.java Tue May 31 18:27:38 2016
@@ -0,0 +1,38 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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;
+
+public class RespondMediatorSerializationTest extends AbstractTestCase {
+
+    RespondMediatorFactory respondMediatorFactory;
+    RespondMediatorSerializer respondMediatorSerializer;
+
+    public RespondMediatorSerializationTest() {
+        super(RespondMediatorSerializationTest.class.getName());
+        respondMediatorFactory = new RespondMediatorFactory();
+        respondMediatorSerializer = new RespondMediatorSerializer();
+    }
+
+    public void testRespondMediatorSerializationSenarioOne() throws Exception {
+        String inputXml = "<respond xmlns=\"http://ws.apache.org/ns/synapse\" />";
+        assertTrue(serialization(inputXml, respondMediatorFactory, respondMediatorSerializer));
+        assertTrue(serialization(inputXml, respondMediatorSerializer));
+    }
+}

Modified: synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java?rev=1746312&r1=1746311&r2=1746312&view=diff
==============================================================================
--- synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java (original)
+++ synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java Tue May 31 18:27:38 2016
@@ -207,7 +207,7 @@ public class TestSamplesHandlerSuite ext
         sampleClassRepo.put("155", Sample155.class);
         sampleClassRepo.put("156", Sample156.class);
         sampleClassRepo.put("157", Sample157.class);
-
+        sampleClassRepo.put("161", Sample161.class);
         //Transport switching
         sampleClassRepo.put("250", Sample250.class);
         sampleClassRepo.put("251", Sample251.class);
@@ -250,4 +250,4 @@ public class TestSamplesHandlerSuite ext
 
         sampleClassRepo.put("10101", Sample10101.class);
     }
-}
\ No newline at end of file
+}

Added: synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample161.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample161.java?rev=1746312&view=auto
==============================================================================
--- synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample161.java (added)
+++ synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample161.java Tue May 31 18:27:38 2016
@@ -0,0 +1,44 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.samples.framework.tests.proxy;
+
+import org.apache.http.HttpStatus;
+import org.apache.synapse.samples.framework.SynapseTestCase;
+import org.apache.synapse.samples.framework.clients.BasicHttpClient;
+import org.apache.synapse.samples.framework.clients.HttpResponse;
+
+public class Sample161 extends SynapseTestCase {
+    private String requestXml = "<test>foo</test>";
+
+    public Sample161() {
+        super(161);
+    }
+
+    public void testRespondMediator() throws Exception {
+
+        String url = "http://localhost:8280/services/EchoService";
+        BasicHttpClient client = new BasicHttpClient();
+        HttpResponse response = client.doPost(url, requestXml.getBytes(), "application/xml");
+        assertEquals(HttpStatus.SC_OK, response.getStatus());
+        assertEquals("Request and Echo Service Response is not equal", requestXml, response.getBodyAsString());
+
+    }
+
+}

Added: synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_161.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_161.xml?rev=1746312&view=auto
==============================================================================
--- synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_161.xml (added)
+++ synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_161.xml Tue May 31 18:27:38 2016
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~  Licensed to the Apache Software Foundation (ASF) under one
+  ~  or more contributor license agreements.  See the NOTICE file
+  ~  distributed with this work for additional information
+  ~  regarding copyright ownership.  The ASF licenses this file
+  ~  to you 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.
+  -->
+
+<!-- Repond Mediator with proxy services -->
+<definitions xmlns="http://ws.apache.org/ns/synapse">
+    <proxy name="EchoService">
+        <target>
+            <inSequence>
+                <respond/>
+            </inSequence>
+        </target>
+    </proxy>
+</definitions>

Added: synapse/trunk/java/modules/integration/src/test/resources/sample161.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/resources/sample161.xml?rev=1746312&view=auto
==============================================================================
--- synapse/trunk/java/modules/integration/src/test/resources/sample161.xml (added)
+++ synapse/trunk/java/modules/integration/src/test/resources/sample161.xml Tue May 31 18:27:38 2016
@@ -0,0 +1,18 @@
+<synapseSample>
+    <sampleID>161</sampleID>
+    <sampleName>Proxy with respond mediator</sampleName>
+    <synapseConfig>
+        <axis2Repo>modules/integration/target/test_repos/synapse</axis2Repo>
+        <axis2Xml>modules/integration/target/test_repos/synapse/conf/axis2_def.xml</axis2Xml>
+        <synapseXml>modules/integration/src/test/resources/extras/synapse_sample_161.xml</synapseXml>
+    </synapseConfig>
+    <backEndServerConfig>
+        <axis2Server id='0'>
+            <axis2Repo>modules/integration/target/test_repos/axis2Server</axis2Repo>
+            <axis2Xml>modules/integration/target/test_repos/axis2Server/conf/axis2_def.xml</axis2Xml>
+        </axis2Server>
+    </backEndServerConfig>
+    <clientConfig>
+	<clientRepo>modules/integration/target/test_repos/axis2Client</clientRepo>
+    </clientConfig>
+</synapseSample>