You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2006/11/03 07:37:54 UTC
svn commit: r470687 - in /incubator/cxf/trunk:
rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/
rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/
rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/
rt/frontend/jaxws/src/test/...
Author: ningjiang
Date: Thu Nov 2 22:37:53 2006
New Revision: 470687
URL: http://svn.apache.org/viewvc?view=rev&rev=470687
Log:
[JIRA CXF-197] Got MessageContext.HTTP_REQUEST_HEADERS and HTTP_RESPONSE_HEADERS to work, Pulled out HandlerServer for test
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerServer.java (with props)
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ProviderInvoker.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestSourcePayloadProvider.java
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java?view=diff&rev=470687&r1=470686&r2=470687
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java Thu Nov 2 22:37:53 2006
@@ -116,7 +116,7 @@
Map<String, Object> responseContext = this.getResponseContext();
message.putAll(requestContext);
//need to do context mapping from jax-ws to cxf message
- ContextPropertiesMapping.mapJaxws2Cxf(message);
+ ContextPropertiesMapping.mapRequestfromJaxws2Cxf(message);
Exchange exchange = new ExchangeImpl();
exchange.put(Service.Mode.class, mode);
@@ -156,7 +156,7 @@
Message inMsg = waitResponse(exchange);
responseContext.putAll(inMsg);
//need to do context mapping from cxf message to jax-ws
- ContextPropertiesMapping.mapJaxws2Cxf(responseContext);
+ ContextPropertiesMapping.mapResponsefromCxf2Jaxws(responseContext);
return cl.cast(inMsg.getContent(Object.class));
}
}
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java?view=diff&rev=470687&r1=470686&r2=470687
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java Thu Nov 2 22:37:53 2006
@@ -98,7 +98,7 @@
Map<String, Object> context = new HashMap<String, Object>();
//need to do context mapping from jax-ws to cxf message
- ContextPropertiesMapping.mapJaxws2Cxf(requestContext);
+ ContextPropertiesMapping.mapRequestfromJaxws2Cxf(requestContext);
context.put(Client.REQUEST_CONTEXT, requestContext);
context.put(Client.RESPONSE_CONTEXT, responseContext);
@@ -114,7 +114,7 @@
result = invokeSync(method, oi, params, paramsWithOutHolder, context);
}
// need to do context mapping from cxf message to jax-ws
- ContextPropertiesMapping.mapJaxws2Cxf(responseContext);
+ ContextPropertiesMapping.mapResponsefromCxf2Jaxws(responseContext);
return result;
}
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java?view=diff&rev=470687&r1=470686&r2=470687
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java Thu Nov 2 22:37:53 2006
@@ -27,7 +27,10 @@
import java.util.List;
import javax.xml.ws.Holder;
+import javax.xml.ws.handler.MessageContext;
+import org.apache.cxf.jaxws.context.WebServiceContextImpl;
+import org.apache.cxf.jaxws.support.ContextPropertiesMapping;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.service.invoker.BeanInvoker;
@@ -40,13 +43,19 @@
@SuppressWarnings("unchecked")
protected Object invoke(Exchange exchange, final Object serviceObject, Method m, List<Object> params) {
checkHolder(m, params, exchange);
-
+ //set up the webservcie request context
+ MessageContext ctx =
+ ContextPropertiesMapping.createWebServiceContext(exchange);
+ WebServiceContextImpl.setMessageContext(ctx);
+
List<Object> res = (List<Object>) super.invoke(exchange, serviceObject, m, params);
for (Object o : params) {
if (o instanceof Holder) {
res.add(((Holder) o).value);
}
}
+ //update the webservice response context
+ ContextPropertiesMapping.updateWebServiceContext(exchange, ctx);
return res;
}
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ProviderInvoker.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ProviderInvoker.java?view=diff&rev=470687&r1=470686&r2=470687
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ProviderInvoker.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ProviderInvoker.java Thu Nov 2 22:37:53 2006
@@ -23,7 +23,7 @@
import javax.xml.ws.handler.MessageContext;
import org.apache.cxf.jaxws.context.WebServiceContextImpl;
-import org.apache.cxf.jaxws.context.WrappedMessageContext;
+import org.apache.cxf.jaxws.support.ContextPropertiesMapping;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.service.invoker.Invoker;
@@ -38,14 +38,21 @@
@SuppressWarnings("unchecked")
public Object invoke(Exchange exchange, Object o) {
- MessageContext ctx = new WrappedMessageContext(exchange.getInMessage());
+ Object result = null;
+ //set up the webservcie request context
+ MessageContext ctx =
+ ContextPropertiesMapping.createWebServiceContext(exchange);
WebServiceContextImpl.setMessageContext(ctx);
if (provider != null) {
- return (T)provider.invoke((T)o);
+ result = (T)provider.invoke((T)o);
+ //update the webservice response context
+ ContextPropertiesMapping.updateWebServiceContext(exchange, ctx);
} else {
- System.err.println("TODO: Should return fault instead of null");
- return null;
+ System.err.println("TODO: Should return fault instead of null");
}
+ return result;
+
+
}
}
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java?view=diff&rev=470687&r1=470686&r2=470687
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java Thu Nov 2 22:37:53 2006
@@ -24,8 +24,6 @@
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
-import org.apache.cxf.jaxws.support.ContextPropertiesMapping;
-
public class WebServiceContextImpl implements WebServiceContext {
@@ -53,7 +51,7 @@
}
public static void setMessageContext(MessageContext ctx) {
- ContextPropertiesMapping.mapCxf2Jaxws(ctx);
+ //ContextPropertiesMapping.mapCxf2Jaxws(ctx);
context.set(ctx);
}
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java?view=diff&rev=470687&r1=470686&r2=470687
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java Thu Nov 2 22:37:53 2006
@@ -19,12 +19,15 @@
package org.apache.cxf.jaxws.support;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.MessageContext;
+import org.apache.cxf.jaxws.context.WrappedMessageContext;
+import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
// Do some context mapping work from rt-core to jaxws stander
@@ -58,6 +61,7 @@
Message.USERNAME);
jaxws2cxfMap.put(BindingProvider.PASSWORD_PROPERTY,
Message.PASSWORD);
+
jaxws2cxfMap.put(MessageContext.HTTP_REQUEST_METHOD,
Message.HTTP_REQUEST_METHOD);
jaxws2cxfMap.put(MessageContext.HTTP_RESPONSE_CODE,
@@ -86,14 +90,61 @@
}
}
}
+
+ public static void mapRequestfromJaxws2Cxf(Map<String, Object> context) {
+ //deal with PROTOCOL_HEADERS mapping
+ Object requestHeaders =
+ context.get(MessageContext.HTTP_REQUEST_HEADERS);
+ if (null != requestHeaders) {
+ context.put(Message.PROTOCOL_HEADERS, requestHeaders);
+ }
+ mapJaxws2Cxf(context);
+ }
+ public static void mapResponsefromCxf2Jaxws(Map<String, Object> context) {
+ //deal with PROTOCOL_HEADERS mapping
+ Object responseHeaders =
+ context.get(Message.PROTOCOL_HEADERS);
+ if (null != responseHeaders) {
+ context.put(MessageContext.HTTP_RESPONSE_HEADERS, responseHeaders);
+ }
+ mapCxf2Jaxws(context);
+ }
- public static void mapJaxws2Cxf(Map<String, Object> context) {
+ private static void mapJaxws2Cxf(Map<String, Object> context) {
mapContext(context, jaxws2cxfMap);
}
-
- public static void mapCxf2Jaxws(Map<String, Object> context) {
+
+ private static void mapCxf2Jaxws(Map<String, Object> context) {
mapContext(context, cxf2jaxwsMap);
+ }
+
+
+ public static MessageContext createWebServiceContext(Exchange exchange) {
+ MessageContext ctx = new WrappedMessageContext(exchange.getInMessage());
+ mapCxf2Jaxws(ctx);
+ Object requestHeaders =
+ exchange.getInMessage().get(Message.PROTOCOL_HEADERS);
+ if (null != requestHeaders) {
+ ctx.put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);
+ }
+
+ Message outMessage = exchange.getOutMessage();
+ if (null != outMessage) {
+ Object responseHeaders =
+ outMessage.get(Message.PROTOCOL_HEADERS);
+ if (responseHeaders == null) {
+ responseHeaders = new HashMap<String, List<String>>();
+ outMessage.put(Message.PROTOCOL_HEADERS, responseHeaders);
+ }
+ ctx.put(MessageContext.HTTP_RESPONSE_HEADERS, responseHeaders);
+ }
+ return ctx;
+ }
+
+ public static void updateWebServiceContext(Exchange exchange, MessageContext ctx) {
+ //get the context response code and setback to out message
+
}
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java?view=diff&rev=470687&r1=470686&r2=470687
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java Thu Nov 2 22:37:53 2006
@@ -26,11 +26,15 @@
import junit.framework.TestCase;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
public class ContextPropertiesMappingTest extends TestCase {
private static final String ADDRESS = "test address";
private static final String REQUEST_METHOD = "GET";
+ private static final String HEADER = "header";
private Map<String, Object> message = new HashMap<String, Object>();
private Map<String, Object> requestContext = new HashMap<String, Object>();
private Map<String, Object> responseContext = new HashMap<String, Object>();
@@ -40,33 +44,61 @@
message.clear();
message.put(Message.ENDPOINT_ADDRESS, ADDRESS);
message.put(Message.HTTP_REQUEST_METHOD, REQUEST_METHOD);
+ message.put(Message.PROTOCOL_HEADERS, HEADER);
requestContext.clear();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESS + "jaxws");
+ requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, HEADER + "jaxws");
responseContext.clear();
}
- public void testJaxws2Cxf() {
+ public void testMapRequestfromJaxws2Cxf() {
Object address = requestContext.get(Message.ENDPOINT_ADDRESS);
- assertTrue("address should be null", address == null);
- ContextPropertiesMapping.mapJaxws2Cxf(requestContext);
+ assertNull("address should be null", address);
+ ContextPropertiesMapping.mapRequestfromJaxws2Cxf(requestContext);
address = requestContext.get(Message.ENDPOINT_ADDRESS);
- assertTrue("address should not be null", address != null);
+ assertNotNull("address should not be null", address);
assertEquals("address should get from requestContext", address, ADDRESS + "jaxws");
message.putAll(requestContext);
- address = message.get(Message.ENDPOINT_ADDRESS);
- address = requestContext.get(Message.ENDPOINT_ADDRESS);
- assertTrue("address should not be null", address != null);
- assertEquals("address should get from requestContext", address, ADDRESS + "jaxws");
+ address = message.get(Message.ENDPOINT_ADDRESS);
+ assertNotNull("address should not be null", address);
+ assertEquals("address should get from requestContext", address, ADDRESS + "jaxws");
+ Object header = message.get(Message.PROTOCOL_HEADERS);
+ assertEquals("the message PROTOCOL_HEADERS should be updated", header, HEADER + "jaxws");
}
- public void testCxf2Jaxws() {
+ public void testMapResponseCxf2Jaxws() {
responseContext.putAll(message);
Object requestMethod = responseContext.get(MessageContext.HTTP_REQUEST_METHOD);
- assertTrue("requestMethod should be null", requestMethod == null);
- ContextPropertiesMapping.mapCxf2Jaxws(responseContext);
+ assertNull("requestMethod should be null", requestMethod);
+ ContextPropertiesMapping.mapResponsefromCxf2Jaxws(responseContext);
requestMethod = responseContext.get(MessageContext.HTTP_REQUEST_METHOD);
- assertTrue("requestMethod should not be null", requestMethod != null);
+ assertNotNull("requestMethod should not be null", requestMethod);
assertEquals(requestMethod, REQUEST_METHOD);
+ Object header = responseContext.get(MessageContext.HTTP_RESPONSE_HEADERS);
+ assertNotNull("the HTTP_RESPONSE_HEADERS should not be null ", header);
+ assertEquals("the HTTP_RESPONSE_HEADERS should be updated", header, HEADER);
+ }
+
+ public void testCreateWebServiceContext() {
+ Exchange exchange = new ExchangeImpl();
+ Message inMessage = new MessageImpl();
+ Message outMessage = new MessageImpl();
+
+ inMessage.putAll(message);
+
+ exchange.setInMessage(inMessage);
+ exchange.setOutMessage(outMessage);
+
+ MessageContext ctx = ContextPropertiesMapping.createWebServiceContext(exchange);
+
+ Object requestHeader = ctx.get(MessageContext.HTTP_REQUEST_HEADERS);
+ assertNotNull("the request header should not be null", requestHeader);
+ assertEquals("we should get the request header", requestHeader, HEADER);
+ Object responseHeader = ctx.get(MessageContext.HTTP_RESPONSE_HEADERS);
+ assertNotNull("the response header should not be null", responseHeader);
+ Object outMessageHeader = outMessage.get(Message.PROTOCOL_HEADERS);
+ assertEquals("the outMessage PROTOCOL_HEADERS should be update", responseHeader, outMessageHeader);
+
}
Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java?view=diff&rev=470687&r1=470686&r2=470687
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java Thu Nov 2 22:37:53 2006
@@ -25,9 +25,7 @@
import javax.xml.namespace.QName;
-//import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.BindingProvider;
-import javax.xml.ws.Endpoint;
import javax.xml.ws.handler.Handler;
import junit.framework.Test;
@@ -35,7 +33,6 @@
import org.apache.cxf.systest.common.ClientServerSetupBase;
import org.apache.cxf.systest.common.ClientServerTestBase;
-import org.apache.cxf.systest.common.TestServerBase;
import org.apache.handlers.AddNumbers;
import org.apache.handlers.AddNumbersService;
@@ -44,33 +41,12 @@
static QName serviceName = new QName("http://apache.org/handlers", "AddNumbersService");
static QName portName = new QName("http://apache.org/handlers", "AddNumbersPort");
-
- public static class Server extends TestServerBase {
-
- protected void run() {
- Object implementor = new AddNumbersImpl();
- String address = "http://localhost:9025/handlers/AddNumbersService/AddNumbersPort";
- Endpoint.publish(address, implementor);
- }
-
- public static void main(String[] args) {
- try {
- Server s = new Server();
- s.start();
- } catch (Exception ex) {
- ex.printStackTrace();
- System.exit(-1);
- } finally {
- System.out.println("done!");
- }
- }
- }
-
+
public static Test suite() throws Exception {
TestSuite suite = new TestSuite(HandlerClientServerTest.class);
return new ClientServerSetupBase(suite) {
public void startServers() throws Exception {
- assertTrue("server did not launch correctly", launchServer(Server.class));
+ assertTrue("server did not launch correctly", launchServer(HandlerServer.class));
}
};
}
Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerServer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerServer.java?view=auto&rev=470687
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerServer.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerServer.java Thu Nov 2 22:37:53 2006
@@ -0,0 +1,45 @@
+/**
+ * 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.cxf.systest.handlers;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.systest.common.TestServerBase;
+
+public class HandlerServer extends TestServerBase {
+
+ protected void run() {
+ Object implementor = new AddNumbersImpl();
+ String address = "http://localhost:9025/handlers/AddNumbersService/AddNumbersPort";
+ Endpoint.publish(address, implementor);
+ }
+
+ public static void main(String[] args) {
+ try {
+ HandlerServer s = new HandlerServer();
+ s.start();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ System.exit(-1);
+ } finally {
+ System.out.println("done!");
+ }
+ }
+
+}
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerServer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerTest.java?view=diff&rev=470687&r1=470686&r2=470687
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerTest.java Thu Nov 2 22:37:53 2006
@@ -23,6 +23,7 @@
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -97,6 +98,7 @@
}
+ @SuppressWarnings("unchecked")
public void testHttpGETDispatcher() throws Exception {
String endpointAddress =
"http://localhost:9023/XMLService/RestProviderPort/Customer";
@@ -111,11 +113,22 @@
service.addPort(portName, HTTPBinding.HTTP_BINDING, endpointAddress.toString());
Dispatch<Source> d = service.createDispatch(portName, Source.class, Service.Mode.PAYLOAD);
Map<String, Object> requestContext = d.getRequestContext();
+ Map<String, Object> responseContext = d.getResponseContext();
+
requestContext.put(MessageContext.HTTP_REQUEST_METHOD, new String("GET"));
requestContext.put(MessageContext.QUERY_STRING, "id=1");
//this is the original path part of uri
requestContext.put(MessageContext.PATH_INFO, path);
Source result = d.invoke(null);
+
+ // varify the responseContext;
+ Map<String, List<String>> responseHeader =
+ (Map<String, List<String>>)responseContext.get(MessageContext.HTTP_RESPONSE_HEADERS);
+ assertNotNull("the response header should not be null", responseHeader);
+
+ List<String> values = responseHeader.get("REST");
+ assertNotNull("the response rest header should not be null", values);
+ assertEquals("the list size wrong", 2, values.size());
assertNotNull("result shoud not be null", result);
String tempstring = source2String(result);
assertTrue("Result should start with Customer", tempstring.startsWith("<ns4:Customer"));
Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestSourcePayloadProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestSourcePayloadProvider.java?view=diff&rev=470687&r1=470686&r2=470687
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestSourcePayloadProvider.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestSourcePayloadProvider.java Thu Nov 2 22:37:53 2006
@@ -20,6 +20,9 @@
package org.apache.cxf.systest.rest;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import javax.annotation.Resource;
import javax.xml.parsers.DocumentBuilder;
@@ -47,13 +50,23 @@
public RestSourcePayloadProvider() {
}
+ @SuppressWarnings("unchecked")
public DOMSource invoke(DOMSource request) {
MessageContext mc = wsContext.getMessageContext();
String path = (String)mc.get(MessageContext.PATH_INFO);
String query = (String)mc.get(MessageContext.QUERY_STRING);
String httpMethod = (String)mc.get(MessageContext.HTTP_REQUEST_METHOD);
-
+
+ /*Map<String, List<String>> requestHeader =
+ (Map<String, List<String>>)mc.get(MessageContext.HTTP_REQUEST_HEADERS);*/
+
+ Map<String, List<String>> responseHeader =
+ (Map<String, List<String>>)mc.get(MessageContext.HTTP_RESPONSE_HEADERS);
+ List<String> values = new ArrayList<String>();
+ values.add("hello1");
+ values.add("hello2");
+ responseHeader.put("REST", values);
// System.out.println("--path--- " + path);
// System.out.println("--query--- " + query);
// System.out.println("--httpMethod--- " + httpMethod);
@@ -68,6 +81,7 @@
return getAllCustomers();
} else if ("/XMLService/RestProviderPort/Customer".equals(path) && query != null) {
// System.out.println("--GET:getCustomer--- ");
+ // setup return context
return getCustomer(query);
}
}