Author: gawor
Date: Thu Apr 12 14:03:09 2007
New Revision: 528233
URL: http://svn.apache.org/viewvc?view=rev&rev=528233
Log:
throw WebServiceException from Service API and fill-in port list
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceFactory.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/Messages.properties
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/AbstractJaxWsTest.java
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ServiceImplTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceFactory.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceFactory.java?view=diff&rev=528233&r1=528232&r2=528233
==============================================================================
---
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceFactory.java
(original)
+++
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceFactory.java
Thu Apr 12 14:03:09 2007
@@ -36,6 +36,7 @@
import org.apache.cxf.service.factory.ServiceConstructionException;
import org.apache.cxf.service.model.ServiceInfo;
import org.apache.cxf.wsdl.WSDLManager;
+import org.apache.ws.commons.schema.XmlSchemaException;
public class WSDLServiceFactory extends AbstractServiceFactoryBean {
@@ -87,7 +88,12 @@
public Service create() {
ServiceInfo serviceInfo;
if (serviceName == null) {
- List<ServiceInfo> services = new
WSDLServiceBuilder(getBus()).buildServices(definition);
+ List<ServiceInfo> services = null;
+ try {
+ services = new
WSDLServiceBuilder(getBus()).buildServices(definition);
+ } catch (XmlSchemaException ex) {
+ throw new ServiceConstructionException(new
Message("SERVICE_CREATION_MSG", LOG), ex);
+ }
if (services.size() == 0) {
throw new ServiceConstructionException(new
Message("NO_SERVICE_EXC", LOG));
} else {
@@ -100,7 +106,11 @@
if (wsdlService == null) {
throw new ServiceConstructionException(new
Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
}
- serviceInfo = new
WSDLServiceBuilder(getBus()).buildServices(definition, wsdlService).get(0);
+ try {
+ serviceInfo = new
WSDLServiceBuilder(getBus()).buildServices(definition, wsdlService).get(0);
+ } catch (XmlSchemaException ex) {
+ throw new ServiceConstructionException(new
Message("SERVICE_CREATION_MSG", LOG), ex);
+ }
}
ServiceImpl service = new ServiceImpl(serviceInfo);
setService(service);
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/Messages.properties
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/Messages.properties?view=diff&rev=528233&r1=528232&r2=528233
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/Messages.properties
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/Messages.properties
Thu Apr 12 14:03:09 2007
@@ -41,6 +41,7 @@
PORT_NAME_NULL_EXC = Port name must not be null.
NO_OPERATION_INFO = Could not find operation info for web method {0}.
COULD_NOT_DETERMINE_PORT = Unable to determine port name.
+INVALID_PORT = Port {0} not found.
FAILED_TO_PUBLISH_ENDPOINT_EXC = Failed to publish endpoint.
FAILED_TO_INITIALIZE_JAXBCONTEXT = Failed to initialize JAXB context for types
used by {0}.
ASYNC_HANDLER_TIMEDOUT_EXC = AsynHandler did not complete time.
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java?view=diff&rev=528233&r1=528232&r2=528233
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
Thu Apr 12 14:03:09 2007
@@ -43,6 +43,7 @@
import org.apache.cxf.Bus;
import org.apache.cxf.BusException;
import org.apache.cxf.binding.BindingFactoryManager;
+import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.configuration.Configurer;
import org.apache.cxf.databinding.DataBinding;
@@ -60,6 +61,7 @@
import org.apache.cxf.service.Service;
import org.apache.cxf.service.factory.AbstractServiceFactoryBean;
import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
+import org.apache.cxf.service.factory.ServiceConstructionException;
import org.apache.cxf.service.model.BindingInfo;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.service.model.ServiceInfo;
@@ -89,7 +91,22 @@
clazz = cls;
handlerResolver = new HandlerResolverImpl(bus, name, clazz);
-
+ if (url != null) {
+ try {
+ initializePorts();
+ } catch (ServiceConstructionException e) {
+ throw new WebServiceException(e);
+ }
+ }
+ }
+
+ private void initializePorts() {
+ WSDLServiceFactory sf = new WSDLServiceFactory(bus, wsdlURL,
serviceName);
+ Service service = sf.create();
+ ServiceInfo si = service.getServiceInfo();
+ for (EndpointInfo ei : si.getEndpoints()) {
+ this.ports.add(ei.getName());
+ }
}
public void addPort(QName portName, String bindingId, String address) {
@@ -117,6 +134,11 @@
}
}
+ if (ei == null) {
+ Message msg = new Message("INVALID_PORT", BUNDLE, portName);
+ throw new WebServiceException(msg.toString());
+ }
+
try {
return new JaxWsClientEndpointImpl(bus, service, ei, this);
} catch (EndpointException e) {
@@ -149,9 +171,13 @@
}
public <T> Dispatch<T> createDispatch(QName portName, Class<T> type, Mode
mode) {
- AbstractServiceFactoryBean sf = createDispatchService(new
SourceDataBinding());
+ AbstractServiceFactoryBean sf = null;
+ try {
+ sf = createDispatchService(new SourceDataBinding());
+ } catch (ServiceConstructionException e) {
+ throw new WebServiceException(e);
+ }
Endpoint endpoint = getJaxwsEndpoint(portName, sf);
-
Dispatch<T> disp = new DispatchImpl<T>(bus, mode, type, getExecutor(),
endpoint);
configureObject(disp);
@@ -160,8 +186,12 @@
}
public Dispatch<Object> createDispatch(QName portName, JAXBContext
context, Mode mode) {
-
- AbstractServiceFactoryBean sf = createDispatchService(new
JAXBDataBinding(context));
+ AbstractServiceFactoryBean sf = null;
+ try {
+ sf = createDispatchService(new JAXBDataBinding(context));
+ } catch (ServiceConstructionException e) {
+ throw new WebServiceException(e);
+ }
Endpoint endpoint = getJaxwsEndpoint(portName, sf);
Dispatch<Object> disp = new DispatchImpl<Object>(bus, mode, context,
Object.class, getExecutor(),
endpoint);
@@ -180,14 +210,22 @@
}
public <T> T getPort(Class<T> type) {
- return createPort(null, type);
+ try {
+ return createPort(null, type);
+ } catch (ServiceConstructionException e) {
+ throw new WebServiceException(e);
+ }
}
public <T> T getPort(QName portName, Class<T> type) {
if (portName == null) {
throw new
WebServiceException(BUNDLE.getString("PORT_NAME_NULL_EXC"));
}
- return createPort(portName, type);
+ try {
+ return createPort(portName, type);
+ } catch (ServiceConstructionException e) {
+ throw new WebServiceException(e);
+ }
}
public Iterator<QName> getPorts() {
@@ -229,7 +267,7 @@
if (wsdlURL != null) {
proxyFac.setWsdlURL(wsdlURL.toString());
}
-
+
if (portName == null) {
clientFac.create();
portName = serviceFactory.getEndpointName();
@@ -259,19 +297,17 @@
}
});
configureObject(service);
-
+
// Configure the JaxWsEndpoitnImpl
JaxWsEndpointImpl jaxwsEndpoint = (JaxWsEndpointImpl)
clientFac.getClient().getEndpoint();
configureObject(jaxwsEndpoint);
-
- QName pn = portName;
-
+
List<Handler> hc = jaxwsEndpoint.getJaxwsBinding().getHandlerChain();
- hc.addAll(handlerResolver.getHandlerChain(portInfos.get(pn)));
+ hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
LOG.log(Level.FINE, "created proxy", obj);
- ports.add(pn);
+ ports.add(portName);
return serviceEndpointInterface.cast(obj);
}
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/AbstractJaxWsTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/AbstractJaxWsTest.java?view=diff&rev=528233&r1=528232&r2=528233
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/AbstractJaxWsTest.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/AbstractJaxWsTest.java
Thu Apr 12 14:03:09 2007
@@ -66,6 +66,8 @@
extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http",
localTransport);
extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/",
localTransport);
- bus.setExtension(new WSDLManagerImpl(), WSDLManager.class);
+ WSDLManagerImpl manager = new WSDLManagerImpl();
+ manager.setBus(bus);
+ bus.setExtension(manager, WSDLManager.class);
}
}
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java?view=diff&rev=528233&r1=528232&r2=528233
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
Thu Apr 12 14:03:09 2007
@@ -27,6 +27,7 @@
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceException;
import org.apache.cxf.endpoint.ClientImpl;
import org.apache.cxf.interceptor.Fault;
@@ -37,7 +38,6 @@
import org.apache.cxf.phase.Phase;
import org.apache.cxf.service.Service;
import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
-import org.apache.cxf.service.factory.ServiceConstructionException;
import org.apache.cxf.service.invoker.BeanInvoker;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.cxf.service.model.EndpointInfo;
@@ -77,7 +77,8 @@
try {
s = javax.xml.ws.Service.create(new
URL("file:/does/not/exist.wsdl"),
new
QName("http://apache.org/hello_world_soap_http", "SoapPort"));
- } catch (ServiceConstructionException sce) {
+ fail("did not throw exception");
+ } catch (WebServiceException sce) {
// ignore, this is expected
}
}
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ServiceImplTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ServiceImplTest.java?view=diff&rev=528233&r1=528232&r2=528233
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ServiceImplTest.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ServiceImplTest.java
Thu Apr 12 14:03:09 2007
@@ -18,16 +18,40 @@
*/
package org.apache.cxf.jaxws;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.HandlerResolver;
+import javax.xml.ws.handler.PortInfo;
+import javax.xml.ws.soap.SOAPBinding;
+
import org.apache.cxf.Bus;
import org.apache.cxf.BusException;
import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.calculator.CalculatorPortType;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.hello_world_soap_http.Greeter;
import org.apache.hello_world_soap_http.SOAPService;
+import org.junit.Ignore;
import org.junit.Test;
public class ServiceImplTest extends AbstractJaxWsTest {
+
+ private static final QName SERVICE_1 =
+ new QName("http://apache.org/cxf/calculator", "CalculatorService");
+
+ private static final QName PORT_1 =
+ new QName("http://apache.org/cxf/calculator", "CalculatorPort");
+
@Test
public void testServiceImpl() throws Exception {
SOAPService service = new SOAPService();
@@ -42,6 +66,143 @@
protected Bus createBus() throws BusException {
SpringBusFactory bf = new SpringBusFactory();
return bf.createBus("/org/apache/cxf/jaxws/soapServiceConfig.xml");
+ }
+
+ @Test
+ public void testBadServiceName() {
+ URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
+ assertNotNull(wsdl1);
+
+ QName badService =
+ new QName("http://apache.org/cxf/calculator", "DoesNotExist");
+
+ try {
+ new ServiceImpl(getBus(), wsdl1, badService, ServiceImpl.class);
+ fail("Did not throw exception");
+ } catch (WebServiceException e) {
+ // that's expected
+ }
+ }
+
+ @Test
+ public void testPorts() {
+ URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
+ assertNotNull(wsdl1);
+
+ ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1,
ServiceImpl.class);
+ Iterator iter = service.getPorts();
+ assertNotNull(iter);
+ assertTrue(iter.hasNext());
+ assertEquals(PORT_1, iter.next());
+ assertFalse(iter.hasNext());
+ }
+
+ @Test
+ @Ignore
+ public void testGetBadPort() {
+ URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
+ assertNotNull(wsdl1);
+
+ ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1,
ServiceImpl.class);
+
+ QName badPort =
+ new QName("http://apache.org/cxf/calculator", "PortDoesNotExist");
+ try {
+ service.getPort(badPort, CalculatorPortType.class);
+ fail("Did not throw expected exception");
+ } catch (WebServiceException e) {
+ // that's ok
+ }
+ }
+
+ @Test
+ public void testGetBadSEI() {
+ URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
+ assertNotNull(wsdl1);
+
+ ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1,
ServiceImpl.class);
+
+ try {
+ service.getPort(ServiceImpl.class);
+ fail("Did not throw expected exception");
+ } catch (WebServiceException e) {
+ // that's ok
+ }
+ }
+
+ @Test
+ public void testGetGoodPort() {
+ URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
+ assertNotNull(wsdl1);
+
+ ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1,
ServiceImpl.class);
+
+ CalculatorPortType cal = (CalculatorPortType)service.getPort(PORT_1,
CalculatorPortType.class);
+ assertNotNull(cal);
+ }
+
+ @Test
+ public void testCreateDispatchGoodPort() {
+ URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
+ assertNotNull(wsdl1);
+
+ ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1,
ServiceImpl.class);
+
+ Dispatch dispatch = service.createDispatch(PORT_1, Source.class,
Service.Mode.PAYLOAD);
+ assertNotNull(dispatch);
+ }
+
+ @Test
+ public void testCreateDispatchBadPort() {
+ URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
+ assertNotNull(wsdl1);
+
+ ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1,
ServiceImpl.class);
+
+ QName badPort =
+ new QName("http://apache.org/cxf/calculator", "PortDoesNotExist");
+ try {
+ service.createDispatch(badPort, Source.class,
Service.Mode.PAYLOAD);
+ } catch (WebServiceException e) {
+ // that's ok
+ }
+ }
+
+ @Test
+ @Ignore
+ public void testHandlerResolver() {
+ URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
+ assertNotNull(wsdl1);
+
+ ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1,
ServiceImpl.class);
+
+ TestHandlerResolver resolver = new TestHandlerResolver();
+ assertNull(resolver.getPortInfo());
+
+ service.setHandlerResolver(resolver);
+
+ CalculatorPortType cal = (CalculatorPortType)service.getPort(PORT_1,
CalculatorPortType.class);
+ assertNotNull(cal);
+
+ PortInfo info = resolver.getPortInfo();
+ assertNotNull(info);
+ assertEquals(SERVICE_1, info.getServiceName());
+ assertEquals(PORT_1, info.getPortName());
+ assertEquals(SOAPBinding.SOAP12HTTP_BINDING, info.getBindingID());
+ }
+
+ private static class TestHandlerResolver implements HandlerResolver {
+ private PortInfo info;
+
+ public PortInfo getPortInfo() {
+ return info;
+ }
+
+ public List<Handler> getHandlerChain(PortInfo portInfo) {
+ List<Handler> handlerList = new ArrayList<Handler>();
+ this.info = portInfo;
+ return handlerList;
+ }
}
}
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java?view=diff&rev=528233&r1=528232&r2=528233
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/OASISCatalogTest.java
Thu Apr 12 14:03:09 2007
@@ -25,6 +25,7 @@
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceException;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
@@ -70,13 +71,11 @@
OASISCatalogManager catalog = new OASISCatalogManager();
bus.setExtension(catalog.getCatalog(), Catalog.class);
- SOAPService service = new SOAPService(wsdl, serviceName);
- assertNotNull(service);
-
try {
+ SOAPService service = new SOAPService(wsdl, serviceName);
service.getPort(portName, Greeter.class);
fail("Test did not fail as expected");
- } catch (Exception e) {
+ } catch (WebServiceException e) {
// ignore
}
@@ -87,6 +86,7 @@
catalog.loadCatalog(jaxwscatalog);
+ SOAPService service = new SOAPService(wsdl, serviceName);
Greeter greeter = service.getPort(portName, Greeter.class);
assertNotNull(greeter);
}