You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by hi...@apache.org on 2014/09/21 00:09:12 UTC
svn commit: r1626502 - in /synapse/trunk/java/modules:
integration/src/test/java/org/apache/synapse/samples/framework/
integration/src/test/java/org/apache/synapse/samples/framework/clients/
integration/src/test/java/org/apache/synapse/samples/framewor...
Author: hiranya
Date: Sat Sep 20 22:09:11 2014
New Revision: 1626502
URL: http://svn.apache.org/r1626502
Log:
Fixing SYNAPSE-926 OPTIONS support in the PT transport -- Added integration test 10003 to cover the scenario
Added:
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/rest/Sample10003.java
synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_10003.xml
synapse/trunk/java/modules/integration/src/test/resources/sample10003.xml
Modified:
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/clients/BasicHttpClient.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughHttpSender.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetRequest.java
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=1626502&r1=1626501&r2=1626502&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 Sat Sep 20 22:09:11 2014
@@ -23,6 +23,7 @@ import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.samples.framework.tests.rest.Sample10002;
+import org.apache.synapse.samples.framework.tests.rest.Sample10003;
import org.apache.synapse.samples.framework.tests.tasks.*;
import org.apache.synapse.samples.framework.tests.transport.Sample250;
import org.apache.synapse.samples.framework.tests.advanced.*;
@@ -244,5 +245,6 @@ public class TestSamplesHandlerSuite ext
sampleClassRepo.put("800", Sample800.class);
sampleClassRepo.put("10001", Sample10001.class);
sampleClassRepo.put("10002", Sample10002.class);
+ sampleClassRepo.put("10003", Sample10003.class);
}
}
\ No newline at end of file
Modified: synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/clients/BasicHttpClient.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/clients/BasicHttpClient.java?rev=1626502&r1=1626501&r2=1626502&view=diff
==============================================================================
--- synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/clients/BasicHttpClient.java (original)
+++ synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/clients/BasicHttpClient.java Sat Sep 20 22:09:11 2014
@@ -20,6 +20,7 @@
package org.apache.synapse.samples.framework.clients;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpOptions;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -52,6 +53,23 @@ public class BasicHttpClient {
}
/**
+ * Make a HTTP OPTIONS request on the specified URL.
+ *
+ * @param url A valid HTTP URL
+ * @return A HttpResponse object
+ * @throws Exception If an error occurs while making the HTTP call
+ */
+ public HttpResponse doOptions(String url) throws Exception {
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ try {
+ HttpOptions options = new HttpOptions(url);
+ return new HttpResponse(client.execute(options));
+ } finally {
+ client.close();
+ }
+ }
+
+ /**
* Make a HTTP POST request on the specified URL.
*
* @param url A valid HTTP URL
Added: synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/rest/Sample10003.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/rest/Sample10003.java?rev=1626502&view=auto
==============================================================================
--- synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/rest/Sample10003.java (added)
+++ synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/rest/Sample10003.java Sat Sep 20 22:09:11 2014
@@ -0,0 +1,40 @@
+/*
+ * 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.rest;
+
+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 Sample10003 extends SynapseTestCase {
+
+ public Sample10003() {
+ super(10003);
+ }
+
+ public void testOptionsMethod() throws Exception {
+ BasicHttpClient client = new BasicHttpClient();
+ HttpResponse response = client.doOptions("http://127.0.0.1:8280/test");
+ // The echo server considers OPTIONS request to be entity non-enclosing,
+ // and hence will reply with a 204
+ assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatus());
+ }
+}
Added: synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_10003.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_10003.xml?rev=1626502&view=auto
==============================================================================
--- synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_10003.xml (added)
+++ synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_10003.xml Sat Sep 20 22:09:11 2014
@@ -0,0 +1,16 @@
+<syn:definitions xmlns:syn="http://ws.apache.org/ns/synapse">
+ <syn:api name="TestAPI" context="/test">
+ <syn:resource methods="OPTIONS">
+ <syn:inSequence>
+ <syn:send>
+ <syn:endpoint>
+ <syn:address uri="http://localhost:9000/services/EchoService"/>
+ </syn:endpoint>
+ </syn:send>
+ </syn:inSequence>
+ <syn:outSequence>
+ <syn:send/>
+ </syn:outSequence>
+ </syn:resource>
+ </syn:api>
+</syn:definitions>
\ No newline at end of file
Added: synapse/trunk/java/modules/integration/src/test/resources/sample10003.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/resources/sample10003.xml?rev=1626502&view=auto
==============================================================================
--- synapse/trunk/java/modules/integration/src/test/resources/sample10003.xml (added)
+++ synapse/trunk/java/modules/integration/src/test/resources/sample10003.xml Sat Sep 20 22:09:11 2014
@@ -0,0 +1,18 @@
+<synapseSample>
+ <sampleID>10003</sampleID>
+ <sampleName>Pass Through Transport OPTIONS Method Support</sampleName>
+ <synapseConfig>
+ <!--if we don't specify the optional values, framework will use defaults-->
+ <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_10003.xml</synapseXml>
+ </synapseConfig>
+ <backEndServerConfig>
+ <echoServer id="0">
+ <httpPort>9000</httpPort>
+ </echoServer>
+ </backEndServerConfig>
+ <clientConfig>
+ <clientRepo>modules/integration/target/test_repos/axis2Client</clientRepo>
+ </clientConfig>
+</synapseSample>
\ No newline at end of file
Modified: synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughHttpSender.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughHttpSender.java?rev=1626502&r1=1626501&r2=1626502&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughHttpSender.java (original)
+++ synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughHttpSender.java Sat Sep 20 22:09:11 2014
@@ -408,10 +408,7 @@ public class PassThroughHttpSender exten
formatter.writeTo(msgContext, format, out, false);
}
- if ((msgContext.getProperty(
- PassThroughConstants.REST_GET_DELETE_INVOKE) != null &&
- (Boolean) msgContext.getProperty(
- PassThroughConstants.REST_GET_DELETE_INVOKE))) {
+ if (isCompleteWithoutData(msgContext)) {
pipe.setSerializationCompleteWithoutData(true);
} else {
pipe.setSerializationComplete(true);
@@ -421,6 +418,15 @@ public class PassThroughHttpSender exten
}
}
+ private boolean isCompleteWithoutData(MessageContext msgContext) {
+ if (Boolean.TRUE.equals(msgContext.getProperty(
+ PassThroughConstants.REST_GET_DELETE_INVOKE))) {
+ return true;
+ }
+
+ return Boolean.TRUE.equals(msgContext.getProperty(PassThroughConstants.NO_ENTITY_BODY));
+ }
+
/**
* Return the IOEventDispatch implementation to be used. This is overridden by the
* SSL sender
Modified: synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetRequest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetRequest.java?rev=1626502&r1=1626501&r2=1626502&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetRequest.java (original)
+++ synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetRequest.java Sat Sep 20 22:09:11 2014
@@ -120,8 +120,8 @@ public class TargetRequest {
TargetContext.get(conn).setWriter(pipe);
}
- String path = fullUrl ?
- url.toString() : url.getPath() +
+ String path = fullUrl ? url.toString() :
+ ("".equals(url.getPath()) ? "/" : url.getPath()) +
(url.getQuery() != null ? "?" + url.getQuery() : "");
long contentLength = -1;