001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.jaxws;
019:
020: import java.net.URL;
021: import java.util.List;
022:
023: import javax.xml.namespace.QName;
024:
025: import org.apache.cxf.binding.BindingFactoryManager;
026: import org.apache.cxf.binding.soap.SoapBindingFactory;
027: import org.apache.cxf.endpoint.Endpoint;
028: import org.apache.cxf.endpoint.EndpointImpl;
029: import org.apache.cxf.interceptor.Fault;
030: import org.apache.cxf.interceptor.URIMappingInterceptor;
031: import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
032: import org.apache.cxf.message.Exchange;
033: import org.apache.cxf.message.ExchangeImpl;
034: import org.apache.cxf.message.Message;
035: import org.apache.cxf.message.MessageImpl;
036: import org.apache.cxf.service.Service;
037: import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
038: import org.apache.cxf.service.invoker.BeanInvoker;
039: import org.apache.cxf.service.model.BindingOperationInfo;
040: import org.apache.cxf.service.model.EndpointInfo;
041: import org.apache.cxf.test.AbstractCXFTest;
042: import org.apache.hello_world_soap_http.RPCLitGreeterImpl;
043: import org.junit.Before;
044: import org.junit.Test;
045:
046: public class URIMappingInterceptorRPCTest extends AbstractCXFTest {
047:
048: Message message;
049: String ns = "http://apache.org/hello_world_rpclit";
050:
051: @Before
052: public void setUp() throws Exception {
053: super .setUpBus();
054: BindingFactoryManager bfm = getBus().getExtension(
055: BindingFactoryManager.class);
056: bfm.registerBindingFactory(
057: "http://schemas.xmlsoap.org/wsdl/soap/",
058: new SoapBindingFactory());
059: message = new MessageImpl();
060: message.put(Message.HTTP_REQUEST_METHOD, "GET");
061: message.put(Message.BASE_PATH, "/SOAPServiceRPCLit/SoapPort/");
062:
063: Exchange exchange = new ExchangeImpl();
064: message.setExchange(exchange);
065:
066: ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
067: URL resource = getClass().getResource(
068: "/wsdl/hello_world_rpc_lit.wsdl");
069: assertNotNull(resource);
070: bean.setWsdlURL(resource.toString());
071: bean.setBus(getBus());
072: bean.setServiceClass(RPCLitGreeterImpl.class);
073: RPCLitGreeterImpl greeter = new RPCLitGreeterImpl();
074: BeanInvoker invoker = new BeanInvoker(greeter);
075: bean.setInvoker(invoker);
076:
077: Service service = bean.create();
078:
079: EndpointInfo endpointInfo = service.getEndpointInfo(new QName(
080: ns, "SoapPortRPCLit"));
081: Endpoint endpoint = new EndpointImpl(getBus(), service,
082: endpointInfo);
083: exchange.put(Service.class, service);
084: exchange.put(Endpoint.class, endpoint);
085: }
086:
087: @Test
088: public void testGetSayHiFromPath() throws Exception {
089: message.put(Message.PATH_INFO,
090: "/SOAPServiceRPCLit/SoapPort/sayHi");
091:
092: URIMappingInterceptor interceptor = new URIMappingInterceptor();
093: interceptor.handleMessage(message);
094:
095: assertNull(message.getContent(Exception.class));
096:
097: Object parameters = message.getContent(List.class);
098: assertNotNull(parameters);
099: assertEquals(0, ((List) parameters).size());
100: BindingOperationInfo boi = message.getExchange().get(
101: BindingOperationInfo.class);
102: assertNotNull(boi);
103: assertEquals(new QName(ns, "sayHi"), boi.getName());
104: }
105:
106: @Test
107: public void testGetGreetMeFromPath() throws Exception {
108: message.put(Message.PATH_INFO,
109: "/SOAPServiceRPCLit/SoapPort/greetMe/in/king+author");
110:
111: URIMappingInterceptor interceptor = new URIMappingInterceptor();
112: interceptor.handleMessage(message);
113:
114: assertNull(message.getContent(Exception.class));
115:
116: Object parameters = message.getContent(List.class);
117: assertNotNull(parameters);
118: assertEquals(1, ((List) parameters).size());
119: String value = (String) ((List) parameters).get(0);
120: assertEquals("king author", value);
121: }
122:
123: @Test
124: public void testGetSayHiFromQueryFixedOrder() throws Exception {
125: message.put(Message.FIXED_PARAMETER_ORDER, Boolean.TRUE);
126: message.put(Message.PATH_INFO,
127: "/SOAPServiceRPCLit/SoapPort/greetMe");
128: message.put(Message.QUERY_STRING, "me=king");
129:
130: URIMappingInterceptor interceptor = new URIMappingInterceptor();
131: interceptor.handleMessage(message);
132:
133: assertNull(message.getContent(Exception.class));
134:
135: assertion();
136: }
137:
138: @Test
139: public void testGetSayHiFromQueryRandomOrder() throws Exception {
140: message.put(Message.PATH_INFO,
141: "/SOAPServiceRPCLit/SoapPort/greetMe");
142: message.put(Message.QUERY_STRING, "in=king");
143:
144: URIMappingInterceptor interceptor = new URIMappingInterceptor();
145: interceptor.handleMessage(message);
146:
147: assertNull(message.getContent(Exception.class));
148: assertion();
149: }
150:
151: @Test
152: public void testGetSayHiFromQueryRandomOrderFault()
153: throws Exception {
154: message.put(Message.PATH_INFO,
155: "/SOAPServiceRPCLit/SoapPort/greetMe");
156: message.put(Message.QUERY_STRING, "me=king");
157:
158: URIMappingInterceptor interceptor = new URIMappingInterceptor();
159: try {
160: interceptor.handleMessage(message);
161: } catch (Exception e) {
162: assertTrue(e instanceof Fault);
163: assertEquals(
164: "Parameter should be ordered in the following sequence: [in]",
165: e.getMessage());
166: }
167: Object parameters = message.getContent(List.class);
168: assertNull(parameters);
169: }
170:
171: private void assertion() throws Exception {
172: Object parameters = message.getContent(List.class);
173: assertNotNull(parameters);
174: assertEquals(1, ((List) parameters).size());
175: String value = (String) ((List) parameters).get(0);
176: assertEquals("king", value);
177: }
178:
179: @Test
180: public void testGetSayHiFromQueryEncoded() throws Exception {
181: message.put(Message.PATH_INFO,
182: "/SOAPServiceRPCLit/SoapPort/greetMe");
183: message.put(Message.QUERY_STRING, "in=king+author");
184:
185: URIMappingInterceptor interceptor = new URIMappingInterceptor();
186: interceptor.handleMessage(message);
187:
188: assertNull(message.getContent(Exception.class));
189:
190: Object parameters = message.getContent(List.class);
191: assertNotNull(parameters);
192: assertEquals(1, ((List) parameters).size());
193: String value = (String) ((List) parameters).get(0);
194: assertEquals("king author", value);
195: }
196: }
|