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: */
019: package org.apache.axis2.jaxws.provider;
020:
021: import org.apache.axis2.AxisFault;
022: import org.apache.axis2.context.MessageContext;
023: import org.apache.axis2.description.AxisOperation;
024: import org.apache.axis2.description.AxisService;
025: import org.apache.axis2.jaxws.description.DescriptionFactory;
026: import org.apache.axis2.jaxws.description.EndpointDescription;
027: import org.apache.axis2.jaxws.description.EndpointInterfaceDescription;
028: import org.apache.axis2.jaxws.description.OperationDescription;
029: import org.apache.axis2.jaxws.description.ServiceDescription;
030: import org.apache.axis2.jaxws.dispatchers.GenericProviderDispatcher;
031:
032: import javax.jws.WebService;
033: import javax.xml.ws.BindingType;
034: import javax.xml.ws.Provider;
035: import javax.xml.ws.ServiceMode;
036: import javax.xml.ws.WebServiceProvider;
037: import javax.xml.ws.http.HTTPBinding;
038:
039: import junit.framework.TestCase;
040:
041: /**
042: *
043: */
044: public class GenericOperationProviderTest extends TestCase {
045:
046: public void testGenericHTTPBindingOperation() {
047: // The HTTP binding supports a generic operation for WSDL-less endpoints.
048: ServiceDescription serviceDesc = DescriptionFactory
049: .createServiceDescription(HTTPBindingProviderImpl.class);
050: assertNotNull(serviceDesc);
051: EndpointDescription endpointDesc = serviceDesc
052: .getEndpointDescriptions_AsCollection().iterator()
053: .next();
054: assertNotNull(endpointDesc);
055: AxisService axisSvc = endpointDesc.getAxisService();
056: assertNotNull(axisSvc);
057:
058: EndpointInterfaceDescription interfaceDesc = endpointDesc
059: .getEndpointInterfaceDescription();
060: assertNotNull(interfaceDesc);
061:
062: // There should be a single OpDesc with a single AxisOperation with a specific name
063: OperationDescription opDescs[] = interfaceDesc.getOperations();
064: assertNotNull(opDescs);
065: assertEquals(1, opDescs.length);
066: AxisOperation axisOperation = opDescs[0].getAxisOperation();
067: assertNotNull(axisOperation);
068: assertEquals(
069: EndpointInterfaceDescription.JAXWS_NOWSDL_PROVIDER_OPERATION_NAME,
070: axisOperation.getName().getLocalPart());
071:
072: // Now verify that the special dispather can find this operation
073: GenericProviderDispatcher dispatcher = new GenericProviderDispatcher();
074: MessageContext messageContext = new MessageContext();
075: messageContext.setAxisService(axisSvc);
076:
077: try {
078: // The dispatcher will not try to resolve an AxisService
079: assertNull(dispatcher.findService(messageContext));
080:
081: // The dispatcher should find the special AxisOperation
082: assertEquals(axisOperation, dispatcher.findOperation(
083: axisSvc, messageContext));
084: } catch (AxisFault e) {
085: fail("Unexpected exception" + e);
086: }
087: }
088:
089: public void testGenericSOAPBindingOperation() {
090: // REVIEW: Currently generic operations are not supported for SOAP Bindings
091:
092: ServiceDescription serviceDesc = DescriptionFactory
093: .createServiceDescription(SOAPBindingProviderImpl.class);
094: assertNotNull(serviceDesc);
095: EndpointDescription endpointDesc = serviceDesc
096: .getEndpointDescriptions_AsCollection().iterator()
097: .next();
098: assertNotNull(endpointDesc);
099: AxisService axisSvc = endpointDesc.getAxisService();
100: assertNotNull(axisSvc);
101:
102: // Since there's no WSDL, there will be no operations and no EndpointInterfaceDescription
103: // because this is a SOAPBinding.
104: EndpointInterfaceDescription interfaceDesc = endpointDesc
105: .getEndpointInterfaceDescription();
106: assertNull(interfaceDesc);
107: }
108:
109: public void testSEIBasedEndpoint() {
110: ServiceDescription serviceDesc = DescriptionFactory
111: .createServiceDescription(SEIBasedEndpoint.class);
112: assertNotNull(serviceDesc);
113: EndpointDescription endpointDesc = serviceDesc
114: .getEndpointDescriptions_AsCollection().iterator()
115: .next();
116: assertNotNull(endpointDesc);
117: AxisService axisSvc = endpointDesc.getAxisService();
118: assertNotNull(axisSvc);
119:
120: EndpointInterfaceDescription interfaceDesc = endpointDesc
121: .getEndpointInterfaceDescription();
122: assertNotNull(interfaceDesc);
123:
124: // There should be a single OpDesc with a single AxisOperation based on the SEI below
125: // But it should not be the special named operation and the special dispatcher should not
126: // return null for operation dispatch
127: OperationDescription opDescs[] = interfaceDesc.getOperations();
128: assertNotNull(opDescs);
129: assertEquals(1, opDescs.length);
130: AxisOperation axisOperation = opDescs[0].getAxisOperation();
131: assertNotNull(axisOperation);
132: if (EndpointInterfaceDescription.JAXWS_NOWSDL_PROVIDER_OPERATION_NAME
133: .equals(axisOperation.getName().getLocalPart())) {
134: fail("Operation has the generic provider name");
135: }
136:
137: // Now verify that the special dispather doesn't find the special operation
138: GenericProviderDispatcher dispatcher = new GenericProviderDispatcher();
139: MessageContext messageContext = new MessageContext();
140: messageContext.setAxisService(axisSvc);
141:
142: try {
143: // The dispatcher will not try to resolve an AxisService
144: assertNull(dispatcher.findService(messageContext));
145:
146: // The dispatcher should find the special AxisOperation
147: assertNull(dispatcher
148: .findOperation(axisSvc, messageContext));
149: } catch (AxisFault e) {
150: fail("Unexpected exception" + e);
151: }
152:
153: }
154: }
155:
156: // Notice no WSDL is specified
157: @WebServiceProvider()
158: @BindingType(value=HTTPBinding.HTTP_BINDING)
159: @ServiceMode(value=javax.xml.ws.Service.Mode.MESSAGE)
160: class HTTPBindingProviderImpl implements Provider<String> {
161:
162: public String invoke(String obj) {
163: // TODO Auto-generated method stub
164: return null;
165: }
166:
167: }
168:
169: //Notice no WSDL is specified
170: @WebServiceProvider()
171: class SOAPBindingProviderImpl implements Provider<String> {
172:
173: public String invoke(String obj) {
174: // TODO Auto-generated method stub
175: return null;
176: }
177: }
178:
179: // SEI based endpoint to make sure it doesn't get get the special generic provider operation added
180: @WebService()
181: class SEIBasedEndpoint {
182: public String echo() {
183: return null;
184: }
185: }
|