summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-11-16 21:31:40 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-11-16 21:31:40 +0000
commit2db586f49d9d27ee249d3862189102b393b7846b (patch)
tree09186050ff94a96ae19a88422b63baa458e3f2dd /sca-java-2.x/trunk/modules
parent3b13b2066f00bdf9f1a65c5402cb7aa5e2fa5710 (diff)
Investigating migration to wink 1.2-SNAPSHOT
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1035822 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules')
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml4
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java54
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java30
-rw-r--r--sca-java-2.x/trunk/modules/wink/pom.xml5
4 files changed, 31 insertions, 62 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml b/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml
index a44303b6a8..451eb65cea 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml
@@ -107,7 +107,7 @@
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-server</artifactId>
- <version>1.1.1-incubating</version>
+ <version>1.1.2-incubating-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>com.sun.xml.bind</groupId>
@@ -119,7 +119,7 @@
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-client</artifactId>
- <version>1.1.1-incubating</version>
+ <version>1.1.2-incubating-SNAPSHOT</version>
</dependency>
<dependency>
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java
index fb9c245f75..14cf2ace7f 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/TuscanyRESTServlet.java
@@ -20,14 +20,10 @@
package org.apache.tuscany.sca.binding.rest.provider;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Calendar;
-import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.GregorianCalendar;
-import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -35,10 +31,8 @@ import java.util.logging.Logger;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.HttpMethod;
-import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import org.apache.tuscany.sca.assembly.Binding;
@@ -50,13 +44,10 @@ import org.apache.tuscany.sca.extensibility.ClassLoaderContext;
import org.apache.wink.common.internal.registry.ProvidersRegistry;
import org.apache.wink.common.internal.registry.metadata.MethodMetadata;
import org.apache.wink.server.handlers.HandlersChain;
-import org.apache.wink.server.handlers.HandlersFactory;
import org.apache.wink.server.handlers.MessageContext;
-import org.apache.wink.server.handlers.RequestHandler;
import org.apache.wink.server.handlers.ResponseHandler;
import org.apache.wink.server.internal.DeploymentConfiguration;
import org.apache.wink.server.internal.RequestProcessor;
-import org.apache.wink.server.internal.handlers.CheckLocationHeaderHandler;
import org.apache.wink.server.internal.registry.ResourceRecord;
import org.apache.wink.server.internal.servlet.RestServlet;
@@ -65,7 +56,7 @@ import org.apache.wink.server.internal.servlet.RestServlet;
*/
public class TuscanyRESTServlet extends RestServlet {
private static final Logger logger = Logger.getLogger(TuscanyRESTServlet.class.getName());
-
+
private static final long serialVersionUID = 89997233133964915L;
private ExtensionPointRegistry registry;
private RESTBinding binding;
@@ -78,7 +69,7 @@ public class TuscanyRESTServlet extends RestServlet {
this.binding = (RESTBinding) binding;
this.resourceClass = resourceClass;
}
-
+
public void init() throws ServletException {
ClassLoader cl =
ClassLoaderContext.setContextClassLoader(Thread.currentThread().getContextClassLoader(),
@@ -93,14 +84,6 @@ public class TuscanyRESTServlet extends RestServlet {
}
}
}
-
- /**
- * Create Tuscany own DeploymentConfiguration in order to be able to
- * add ResponseHandler to the Wink HandlerChain
- */
- public DeploymentConfiguration createDeploymentConfiguration() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
- return new TuscanyDeploymentConfiguration();
- }
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
@@ -149,7 +132,9 @@ public class TuscanyRESTServlet extends RestServlet {
ProvidersRegistry providers = config.getProvidersRegistry();
providers.addProvider(new DataBindingJAXRSReader(registry), 0.001, true);
providers.addProvider(new DataBindingJAXRSWriter(registry), 0.001, true);
-
+
+ config.getResponseUserHandlers().add(new TuscanyResponseHandler());
+
return config;
}
@@ -194,39 +179,24 @@ public class TuscanyRESTServlet extends RestServlet {
}
return processor;
}
-
- /**
- * TuscanyDeploymentConfiguration
- *
- * Required to inject TuscanyResponseHandler to the HandlerChain
- */
- class TuscanyDeploymentConfiguration extends DeploymentConfiguration {
-
- @Override
- protected List<ResponseHandler> initResponseUserHandlers() {
- List<ResponseHandler> list = super.initResponseUserHandlers();
- list.add(new TuscanyResponseHandler());
- return list;
- }
- }
-
+
/**
* TuscanyResponseHandler
- *
+ *
* Required to support declartive HTTP Headers
*/
class TuscanyResponseHandler implements ResponseHandler {
public void handleResponse(MessageContext context, HandlersChain chain) throws Throwable {
-
+
// assert response is not committed
final HttpServletResponse httpResponse = context.getAttribute(HttpServletResponse.class);
if (httpResponse.isCommitted()) {
logger.log(Level.FINE, "The response is already committed. Nothing to do.");
return;
}
-
+
//process declarative headers
- for(HTTPHeader header : binding.getHttpHeaders()) {
+ for(HTTPHeader header : binding.getHttpHeaders()) {
//treat special headers that need to be calculated
if(header.getName().equalsIgnoreCase("Expires")) {
GregorianCalendar calendar = new GregorianCalendar();
@@ -239,14 +209,14 @@ public class TuscanyRESTServlet extends RestServlet {
//default behaviour to pass the header value to HTTP response
httpResponse.setHeader(header.getName(), header.getValue());
}
- }
+ }
chain.doChain(context);
}
public void init(Properties props) {
- }
+ }
}
}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java
index c6e487596b..cd69cd0c41 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.binding.rest.wireformat.xml;
@@ -42,8 +42,8 @@ public class CustomerServiceTestCase {
private static final String GET_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Customer xmlns:ns2=\"http://tuscany.apache.org/xmlns/sca/databinding/jaxb/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@domain.com</email><id>John</id><name>John</name></Customer>";
private static final String UPDATED_ITEM = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Customer xmlns:ns2=\"http://customer.services/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@updated-domain.com</email><id>John</id><name>John</name></Customer>";
- private static final String GET_UPDATED_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Customer xmlns:ns2=\"http://tuscany.apache.org/xmlns/sca/databinding/jaxb/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@updated-domain.com</email><id>John</id><name>John</name></Customer>";
-
+ private static final String GET_UPDATED_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Customer xmlns:ns2=\"http://tuscany.apache.org/xmlns/sca/databinding/jaxb/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@updated-domain.com</email><id>John</id><name>John</name></Customer>";
+
private static Node node;
@BeforeClass
@@ -63,15 +63,15 @@ public class CustomerServiceTestCase {
node.stop();
}
}
-
+
@Test
public void testPing() throws Exception {
new Socket("127.0.0.1", 8085);
//System.in.read();
}
-
+
@Test
- public void testGetInvocation() throws Exception {
+ public void testGetInvocation() throws Exception {
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest(SERVICE_URL);
request.setHeaderField("Content-Type", "application/xml");
@@ -82,20 +82,20 @@ public class CustomerServiceTestCase {
//for(String headerField : response.getHeaderFieldNames()) {
// System.out.println(">>> Header:" + headerField + " - " + response.getHeaderField(headerField));
//}
-
+
//for debug purposes
- //System.out.println(">>>" + GET_RESPONSE);
- //System.out.println(">>>" + response.getText());
+ System.out.println(">>>" + GET_RESPONSE);
+ System.out.println(">>>" + response.getText());
Assert.assertEquals(200, response.getResponseCode());
Assert.assertEquals("no-cache", response.getHeaderField("Cache-Control"));
Assert.assertEquals("tuscany", response.getHeaderField("X-Tuscany"));
Assert.assertEquals(GET_RESPONSE, response.getText());
-
+
}
@Test
- public void testPutInvocation() throws Exception {
+ public void testPutInvocation() throws Exception {
//Add new item to catalog
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(UPDATED_ITEM.getBytes("UTF-8")),"application/xml");
@@ -103,12 +103,12 @@ public class CustomerServiceTestCase {
Assert.assertEquals(201, response.getResponseCode());
System.out.println(response.getHeaderField("Location"));
-
+
//read new results and expect to get new item back in the response
request = new GetMethodWebRequest(SERVICE_URL);
request.setHeaderField("Content-Type", "application/xml");
response = wc.getResource(request);
-
+
//for debug purposes
//System.out.println(">>>" + GET_UPDATED_RESPONSE);
//System.out.println(">>>" + response.getText());
diff --git a/sca-java-2.x/trunk/modules/wink/pom.xml b/sca-java-2.x/trunk/modules/wink/pom.xml
index 3aae6ac017..4ef4f22595 100644
--- a/sca-java-2.x/trunk/modules/wink/pom.xml
+++ b/sca-java-2.x/trunk/modules/wink/pom.xml
@@ -47,13 +47,13 @@
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-server</artifactId>
- <version>1.1.1-incubating</version>
+ <version>1.1.2-incubating-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-common</artifactId>
- <version>1.1.1-incubating</version>
+ <version>1.1.2-incubating-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
@@ -63,7 +63,6 @@
<version>2.5</version>
<scope>provided</scope>
</dependency>
-
</dependencies>
</project>