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.provider;
019:
020: import java.net.URL;
021:
022: import org.w3c.dom.Node;
023:
024: import org.apache.cxf.Bus;
025: import org.apache.cxf.binding.AbstractBindingFactory;
026: import org.apache.cxf.binding.Binding;
027: import org.apache.cxf.binding.soap.SoapBinding;
028: import org.apache.cxf.binding.soap.model.SoapBindingInfo;
029: import org.apache.cxf.binding.xml.XMLBinding;
030: import org.apache.cxf.endpoint.Endpoint;
031: import org.apache.cxf.endpoint.ServerImpl;
032: import org.apache.cxf.jaxws.AbstractJaxWsTest;
033: import org.apache.cxf.jaxws.JAXWSMethodInvoker;
034: import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
035: import org.apache.cxf.jaxws.support.JaxWsImplementorInfo;
036: import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
037: import org.apache.cxf.service.Service;
038: import org.apache.cxf.service.model.InterfaceInfo;
039: import org.apache.cxf.transport.local.LocalTransportFactory;
040: import org.apache.hello_world_soap_http.HWSoapMessageProvider;
041: import org.junit.Test;
042:
043: public class ProviderServiceFactoryTest extends AbstractJaxWsTest {
044: @Test
045: public void testFromWSDL() throws Exception {
046: URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
047: assertNotNull(resource);
048:
049: JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(
050: HWSoapMessageProvider.class);
051: JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean(
052: implInfo);
053: bean.setWsdlURL(resource.toString());
054:
055: Bus bus = getBus();
056: bean.setBus(bus);
057: bean.setServiceClass(HWSoapMessageProvider.class);
058:
059: Service service = bean.create();
060:
061: assertEquals("SOAPService", service.getName().getLocalPart());
062: assertEquals("http://apache.org/hello_world_soap_http", service
063: .getName().getNamespaceURI());
064:
065: InterfaceInfo intf = service.getServiceInfos().get(0)
066: .getInterface();
067: assertNotNull(intf);
068:
069: JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
070: svrFactory.setBus(bus);
071: svrFactory.setServiceFactory(bean);
072: svrFactory.setStart(false);
073:
074: ServerImpl server = (ServerImpl) svrFactory.create();
075:
076: Endpoint endpoint = server.getEndpoint();
077: Binding binding = endpoint.getBinding();
078: assertTrue(binding instanceof SoapBinding);
079: assertEquals(Boolean.TRUE, endpoint.getEndpointInfo()
080: .getBinding().getProperty(
081: AbstractBindingFactory.DATABINDING_DISABLED));
082: }
083:
084: @Test
085: public void testXMLBindingFromCode() throws Exception {
086: JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
087: bean.setServiceClass(DOMSourcePayloadProvider.class);
088: bean.setBus(getBus());
089: bean.setInvoker(new JAXWSMethodInvoker(
090: new DOMSourcePayloadProvider()));
091:
092: Service service = bean.create();
093:
094: assertEquals("DOMSourcePayloadProviderService", service
095: .getName().getLocalPart());
096:
097: InterfaceInfo intf = service.getServiceInfos().get(0)
098: .getInterface();
099: assertNotNull(intf);
100:
101: JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
102: svrFactory.setBus(getBus());
103: svrFactory.setServiceFactory(bean);
104: String address = "http://localhost:9000/test";
105: svrFactory.setAddress(address);
106: svrFactory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
107:
108: ServerImpl server = (ServerImpl) svrFactory.create();
109:
110: assertEquals(1, service.getServiceInfos().get(0).getEndpoints()
111: .size());
112:
113: Endpoint endpoint = server.getEndpoint();
114: Binding binding = endpoint.getBinding();
115: assertTrue(binding instanceof XMLBinding);
116:
117: Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID,
118: "/org/apache/cxf/jaxws/provider/sayHi.xml");
119:
120: addNamespace("j", "http://service.jaxws.cxf.apache.org/");
121: assertValid("/j:sayHi", res);
122: }
123:
124: @Test
125: public void testSOAPBindingFromCode() throws Exception {
126: JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
127: bean.setServiceClass(SOAPSourcePayloadProvider.class);
128: bean.setBus(getBus());
129: bean.setInvoker(new JAXWSMethodInvoker(
130: new SOAPSourcePayloadProvider()));
131:
132: Service service = bean.create();
133:
134: assertEquals("SOAPSourcePayloadProviderService", service
135: .getName().getLocalPart());
136:
137: InterfaceInfo intf = service.getServiceInfos().get(0)
138: .getInterface();
139: assertNotNull(intf);
140: assertEquals(1, intf.getOperations().size());
141:
142: JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
143: svrFactory.setBus(getBus());
144: svrFactory.setServiceFactory(bean);
145: String address = "http://localhost:9000/test";
146: svrFactory.setAddress(address);
147:
148: ServerImpl server = (ServerImpl) svrFactory.create();
149:
150: // See if our endpoint was created correctly
151: assertEquals(1, service.getServiceInfos().get(0).getEndpoints()
152: .size());
153:
154: Endpoint endpoint = server.getEndpoint();
155: Binding binding = endpoint.getBinding();
156: assertTrue(binding instanceof SoapBinding);
157:
158: SoapBindingInfo sb = (SoapBindingInfo) endpoint
159: .getEndpointInfo().getBinding();
160: assertEquals("document", sb.getStyle());
161: assertEquals(false, bean.isWrapped());
162: assertEquals(
163: Boolean.TRUE,
164: sb
165: .getProperty(AbstractBindingFactory.DATABINDING_DISABLED));
166:
167: assertEquals(1, sb.getOperations().size());
168: Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID,
169: "/org/apache/cxf/jaxws/sayHi.xml");
170:
171: addNamespace("j", "http://service.jaxws.cxf.apache.org/");
172: assertValid("/s:Envelope/s:Body/j:sayHi", res);
173: }
174:
175: @Test
176: public void testSAAJProviderCodeFirst() throws Exception {
177: JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
178: bean.setServiceClass(SAAJProvider.class);
179: bean.setBus(getBus());
180: bean.setInvoker(new JAXWSMethodInvoker(new SAAJProvider()));
181:
182: Service service = bean.create();
183:
184: assertEquals("SAAJProviderService", service.getName()
185: .getLocalPart());
186:
187: InterfaceInfo intf = service.getServiceInfos().get(0)
188: .getInterface();
189: assertNotNull(intf);
190: assertEquals(1, intf.getOperations().size());
191:
192: JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
193: svrFactory.setBus(getBus());
194: svrFactory.setServiceFactory(bean);
195: String address = "http://localhost:9000/test";
196: svrFactory.setAddress(address);
197:
198: ServerImpl server = (ServerImpl) svrFactory.create();
199:
200: Endpoint endpoint = server.getEndpoint();
201: Binding binding = endpoint.getBinding();
202: assertTrue(binding instanceof SoapBinding);
203:
204: SoapBindingInfo sb = (SoapBindingInfo) endpoint
205: .getEndpointInfo().getBinding();
206: assertEquals("document", sb.getStyle());
207: assertEquals(false, bean.isWrapped());
208: assertEquals(
209: Boolean.TRUE,
210: sb
211: .getProperty(AbstractBindingFactory.DATABINDING_DISABLED));
212:
213: assertEquals(1, sb.getOperations().size());
214: Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID,
215: "/org/apache/cxf/jaxws/sayHi.xml");
216:
217: addNamespace("j", "http://service.jaxws.cxf.apache.org/");
218: assertValid("/s:Envelope/s:Body/j:sayHi", res);
219: }
220:
221: @Test
222: public void testStreamSourceProviderCodeFirst() throws Exception {
223: JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
224: svrFactory.setServiceClass(StreamSourcePayloadProvider.class);
225: svrFactory.setBus(getBus());
226: svrFactory.setServiceBean(new StreamSourcePayloadProvider());
227: String address = "http://localhost:9000/test";
228: svrFactory.setAddress(address);
229: svrFactory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
230:
231: svrFactory.create();
232:
233: Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID,
234: "/org/apache/cxf/jaxws/sayHi.xml");
235:
236: addNamespace("j", "http://service.jaxws.cxf.apache.org/");
237: assertValid("/s:Envelope/s:Body/j:sayHi", res);
238: }
239:
240: @Test
241: public void testSourceMessageProviderCodeFirst() throws Exception {
242: JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
243: svrFactory.setServiceClass(SourceMessageProvider.class);
244: svrFactory.setBus(getBus());
245: svrFactory.setServiceBean(new SourceMessageProvider());
246: String address = "http://localhost:9000/test";
247: svrFactory.setAddress(address);
248:
249: svrFactory.create();
250:
251: Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID,
252: "/org/apache/cxf/jaxws/sayHi.xml");
253:
254: addNamespace("j", "http://service.jaxws.cxf.apache.org/");
255: assertValid("/s:Envelope/s:Body/j:sayHi", res);
256: }
257: }
|