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.calculator.CalculatorImpl;
028: import org.apache.cxf.endpoint.Endpoint;
029: import org.apache.cxf.endpoint.EndpointImpl;
030: import org.apache.cxf.interceptor.Fault;
031: import org.apache.cxf.interceptor.URIMappingInterceptor;
032: import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
033: import org.apache.cxf.message.Exchange;
034: import org.apache.cxf.message.ExchangeImpl;
035: import org.apache.cxf.message.Message;
036: import org.apache.cxf.message.MessageImpl;
037: import org.apache.cxf.service.Service;
038: import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
039: import org.apache.cxf.service.invoker.BeanInvoker;
040: import org.apache.cxf.service.model.BindingOperationInfo;
041: import org.apache.cxf.service.model.EndpointInfo;
042: import org.apache.cxf.test.AbstractCXFTest;
043: import org.junit.Before;
044: import org.junit.Test;
045:
046: public class URIMappingInterceptorDocLitTest extends AbstractCXFTest {
047:
048: Message message;
049: String ns = "http://apache.org/cxf/calculator";
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:
060: message = new MessageImpl();
061: message.put(Message.HTTP_REQUEST_METHOD, "GET");
062: message.put(Message.BASE_PATH, "/CalculatorService/SoapPort");
063:
064: Exchange exchange = new ExchangeImpl();
065: message.setExchange(exchange);
066:
067: ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
068: URL resource = getClass().getResource("/wsdl/calculator.wsdl");
069: assertNotNull(resource);
070: bean.setWsdlURL(resource.toString());
071: bean.setBus(getBus());
072: bean.setServiceClass(CalculatorImpl.class);
073: CalculatorImpl calculator = new CalculatorImpl();
074: BeanInvoker invoker = new BeanInvoker(calculator);
075: bean.setInvoker(invoker);
076:
077: Service service = bean.create();
078:
079: EndpointInfo endpointInfo = service.getEndpointInfo(new QName(
080: ns, "CalculatorPort"));
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 testGetAddFromPath() throws Exception {
089: message.put(Message.FIXED_PARAMETER_ORDER, Boolean.TRUE);
090: message.put(Message.PATH_INFO,
091: "/CalculatorService/SoapPort/add/arg0/1/arg1/0");
092:
093: URIMappingInterceptor interceptor = new URIMappingInterceptor();
094: interceptor.handleMessage(message);
095:
096: assertNull(message.getContent(Exception.class));
097:
098: assertion();
099: }
100:
101: @Test
102: public void testGetAddFromQuery() throws Exception {
103: message.put(Message.FIXED_PARAMETER_ORDER, Boolean.TRUE);
104: message.put(Message.PATH_INFO,
105: "/CalculatorService/SoapPort/add");
106: message.put(Message.QUERY_STRING, "arg0=1&arg1=0");
107:
108: URIMappingInterceptor interceptor = new URIMappingInterceptor();
109: interceptor.handleMessage(message);
110:
111: assertNull(message.getContent(Exception.class));
112: assertion();
113: }
114:
115: @Test
116: public void testGetAddFromQueryOrdered() throws Exception {
117: message.put(Message.PATH_INFO,
118: "/CalculatorService/SoapPort/add");
119: message.put(Message.QUERY_STRING, "arg1=0&arg0=1");
120:
121: URIMappingInterceptor interceptor = new URIMappingInterceptor();
122: interceptor.handleMessage(message);
123:
124: assertNull(message.getContent(Exception.class));
125: assertion();
126: }
127:
128: @Test
129: public void testGetAddFromPathOrdered() throws Exception {
130: message.put(Message.PATH_INFO,
131: "/CalculatorService/SoapPort/add/arg1/0/arg0/1");
132:
133: URIMappingInterceptor interceptor = new URIMappingInterceptor();
134: interceptor.handleMessage(message);
135:
136: assertNull(message.getContent(Exception.class));
137: assertion();
138: }
139:
140: @Test
141: public void testGetAddFromQueryOrderedFault() throws Exception {
142: message.put(Message.PATH_INFO,
143: "/CalculatorService/SoapPort/add");
144: message.put(Message.QUERY_STRING, "one=1&two=2");
145:
146: URIMappingInterceptor interceptor = new URIMappingInterceptor();
147: try {
148: interceptor.handleMessage(message);
149: } catch (Exception e) {
150: assertTrue(e instanceof Fault);
151: assertEquals(
152: "Parameter should be ordered in the following sequence: [arg0, arg1]",
153: e.getMessage());
154: }
155:
156: Object parameters = message.getContent(List.class);
157: assertNull(parameters);
158: }
159:
160: private void assertion() throws Exception {
161: Object parameters = message.getContent(List.class);
162: assertNotNull(parameters);
163: assertEquals(2, ((List) parameters).size());
164:
165: Integer value = (Integer) ((List) parameters).get(0);
166: assertEquals(1, value.intValue());
167: value = (Integer) ((List) parameters).get(1);
168: assertEquals(0, value.intValue());
169: BindingOperationInfo boi = message.getExchange().get(
170: BindingOperationInfo.class);
171: assertNotNull(boi);
172: assertEquals(new QName(ns, "add"), boi.getName());
173: }
174: }
|