private URL getWsdlURL(final UnifiedServiceRefMetaData serviceRefMD, final Class<?> serviceClass) { if (serviceRefMD.getWsdlLocation() == null) { final WebServiceClient webServiceClientAnnotation = serviceClass.getAnnotation(WebServiceClient.class); if (webServiceClientAnnotation != null) { // use the @WebServiceClien(wsdlLocation=...) if the service ref wsdl location returned at this time would be null if (webServiceClientAnnotation.wsdlLocation().length() > 0) { return serviceRefMD.getWsdlLocation(webServiceClientAnnotation.wsdlLocation()); } } } return serviceRefMD.getWsdlLocation(); }
/** * Returns the remote service interface. * @return service interface */ public I getService() throws Exception { try { if (remoteService == null) { WebServiceClient ann = serviceType.getAnnotation(WebServiceClient.class); URL remoteWsdl = new URL( getRemoteWSDLURL()); service = serviceType.getConstructor(URL.class, QName.class).newInstance(remoteWsdl, new QName(ann.targetNamespace(), ann.name())); remoteService = service.getPort(interfaceType); if (handlers.size() > 0 ) { BindingProvider bindProv = (BindingProvider) remoteService; bindProv.getBinding().setHandlerChain(handlers); } } } catch (WebServiceException ex) { throw new Exception ("Service connection fails."); } catch (NullPointerException e) { throw new Exception ("Review JaxWSClient configuration."); } return remoteService; }
/** * Test the getPort functionality without any composite specified. */ public void testOriginalGetPort() { QName serviceQName = new QName(namespaceURI, svcLocalPart); URL wsdlUrl = ClientMetadataTest.getWsdlURL(otherWsdl); Service service = Service.create(wsdlUrl, serviceQName); assertNotNull(service); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertNotNull(dbcInServiceDesc); assertEquals(Service.class, dbcInServiceDesc.getCorrespondingClass()); // Since this is a generic Service with no overrides, there will be no WebServiceClient annotation WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNull(wsClient); // WSDL was specified on the create, so make sure the right one was used by checking the ports assertTrue("Wrong WSDL used", ClientMetadataTest.validatePort(service, otherWsdl_portLocalPart)); QName portQN = new QName(namespaceURI, otherWsdl_portLocalPart); ClientMetadataPortSEI port = service.getPort(portQN, ClientMetadataPortSEI.class); assertNotNull(port); }
/** * Test Service.create(QName) with no composite specified */ public void test1ArgServiceWithoutComposite() { QName serviceQName = new QName(namespaceURI, svcLocalPart); Service service = Service.create(serviceQName); assertNotNull(service); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertNotNull(dbcInServiceDesc); assertEquals(Service.class, dbcInServiceDesc.getCorrespondingClass()); // Since this is a generic Service with no overrides, there will be no WebServiceClient annotation WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNull(wsClient); // No WSDL should have been used, so no Ports should be found assertTrue("Wrong WSDL used", validatePort(service, null)); }
/** * Service.create(URL, QName) with no composite specified */ public void test2ArgServiceWithoutComposite() { QName serviceQName = new QName(namespaceURI, svcLocalPart); URL wsdlUrl = getWsdlURL(otherWsdl); Service service = Service.create(wsdlUrl, serviceQName); assertNotNull(service); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertNotNull(dbcInServiceDesc); assertEquals(Service.class, dbcInServiceDesc.getCorrespondingClass()); // Since this is a generic Service with no overrides, there will be no WebServiceClient annotation WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNull(wsClient); // WSDL was specified on the create, so make sure the right one was used by checking the ports assertTrue("Wrong WSDL used", validatePort(service, otherWsdl_portLocalPart)); }
/** * Service.create(URL, QName) with a composite specified but no override in the composite */ public void test2ArgServiceWithComposite() { QName serviceQName = new QName(namespaceURI, svcLocalPart); DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); URL wsdlUrl = getWsdlURL(otherWsdl); // Use the proprietary SPI to create a service with additional metadata specified ServiceDelegate.setServiceMetadata(composite); Service service = Service.create(wsdlUrl, serviceQName); assertNotNull(service); // Verify that the composite has been reset so that it would not affect the next Service assertNull(ServiceDelegate.getServiceMetadata()); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertSame(composite, dbcInServiceDesc.getSparseComposite(serviceDelegate)); assertEquals(Service.class, dbcInServiceDesc.getCorrespondingClass()); // Since this is a generic Service with no overrides, there will be no WebServiceClient annotation WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNull(wsClient); // WSDL was specified on the create, so make sure the right one was used by checking the ports assertTrue("Wrong WSDL used", validatePort(service, otherWsdl_portLocalPart)); }
/** * Generated service constructor() with no composite specified */ public void testNoArgGeneratedService() { Service service = new ClientMetadataGeneratedService(); assertNotNull(service); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertEquals(ClientMetadataGeneratedService.class, dbcInServiceDesc.getCorrespondingClass()); // There is WebServiceClient on the generated Service WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNotNull(wsClient); assertEquals(originalWsdl, wsClient.wsdlLocation()); assertEquals("originalTNS", wsClient.targetNamespace()); assertEquals("", wsClient.name()); // WSDL not specified, so generated Service should use the annotation value assertTrue("Wrong WSDL Used", validatePort(service, originalWsdl_portLocalPart)); }
/** * Generated service constructor(URL, QName) with no composite specified */ public void test2ArgGeneratedService() { Service service = new ClientMetadataGeneratedService(getWsdlURL(otherWsdl), new QName(namespaceURI, svcLocalPart)); assertNotNull(service); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertEquals(ClientMetadataGeneratedService.class, dbcInServiceDesc.getCorrespondingClass()); // There is WebServiceClient on the generated Service WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNotNull(wsClient); assertEquals(originalWsdl, wsClient.wsdlLocation()); assertEquals("originalTNS", wsClient.targetNamespace()); assertEquals("", wsClient.name()); // WSDL was specified on the generated Service constructor, // so make sure the right one was used by checking the ports assertTrue("Wrong WSDL used", validatePort(service, otherWsdl_portLocalPart)); }
/** * Create a ServiceDescription with a composite. Nothing in the composite is overriden; validate * the values from the annotions in the Service class. */ public void testClientServiceClassComposite() { QName serviceQName = new QName(namespaceURI, svcLocalPart); DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); Object compositeKey = "CompositeKey"; ServiceDescription svcDesc = new ServiceDescriptionImpl(null, serviceQName, ClientDBCSupportServiceSubclass.class, composite, compositeKey); assertNotNull(svcDesc); ServiceDescriptionImpl svcDescImpl = (ServiceDescriptionImpl) svcDesc; DescriptionBuilderComposite svcDescComposite = svcDescImpl.getDescriptionBuilderComposite(); assertNotNull(svcDescComposite); assertNotSame(composite, svcDescComposite); assertSame(composite, svcDescComposite.getSparseComposite(compositeKey)); WebServiceClient wsClient = svcDescComposite.getWebServiceClientAnnot(); assertNotNull(wsClient); assertEquals("originalWsdlLocation", wsClient.wsdlLocation()); assertEquals("originalTNS", wsClient.targetNamespace()); // We're testing the composite, not the metadata layer, so none of the defaulting logic // is exercised. assertEquals("", wsClient.name()); }
public void testAssociatedClass() { QName serviceQName = new QName(namespaceURI, svcLocalPart); // Create a composite with a WebServiceClient override of the WSDL location. DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); String overridenWsdlLocation = DescriptionTestUtils.getWSDLLocation("ClientEndpointMetadata.wsdl"); WebServiceClientAnnot wsClientAnno = WebServiceClientAnnot.createWebServiceClientAnnotImpl(null, null, overridenWsdlLocation); composite.setWebServiceClientAnnot(wsClientAnno); Object compositeKey = "CompositeKey"; ServiceDescription svcDesc = DescriptionFactory.createServiceDescription(null, serviceQName, SparseAnnotServiceSubclass.class, composite, compositeKey); assertNotNull(svcDesc); DescriptionBuilderComposite svcDescComposite = DescriptionTestUtils.getServiceDescriptionComposite(svcDesc); assertNotNull(svcDescComposite); assertNotSame(composite, svcDescComposite); assertSame(SparseAnnotServiceSubclass.class, svcDescComposite.getCorrespondingClass()); assertSame(composite, svcDescComposite.getSparseComposite(compositeKey)); WebServiceClient wsClient = svcDescComposite.getWebServiceClientAnnot(); assertTrue(wsClient instanceof WebServiceClientAnnot); }
/** * Gets a client service instance of the given name. * The name must be one of the names returned by {@link #getSupportedServices()}. The use of this method is * strongly encouraged, as it uses the WSDLs and XML schemas bundled with this class. This leads to lower load * times.<br/> * The service client is initialized with the values from the WSDL. In order to set other endpoints, use the other * {@code getClientService} functions. * * @param serviceName Name of the service. Must be one of the names returned by {@link #getSupportedServices()}. * @return Webservice client initialized with the settings from the WSDL. * @throws NoSuchMethodException In case there is no suitable constructor or {@code getPort()} method in the service * class. * @throws InstantiationException In case the constructor call failed. * @throws IllegalAccessException In case the constructor call or the {@code getPort()} method failed. * @throws InvocationTargetException In case the constructor call or the {@code getPort()} method failed. * @throws ClassNotFoundException In case no such service is registered in this loader. * @see #getClientService(java.lang.String, java.lang.String) * @see #getClientService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ public static Object getClientService(@Nonnull String serviceName) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { // the relevant information to create a service is extracted from the service instance // get serviceloader instance Class<Service> loaderClass = loadClass(serviceName); WebServiceClient clientAnnotation = getClientAnnotation(loaderClass); Constructor<Service> constructor = loaderClass.getConstructor(URL.class, QName.class); QName serviceQname = new QName(clientAnnotation.targetNamespace(), clientAnnotation.name()); Service serviceLoaderInst = constructor.newInstance(getWSDL(), serviceQname); //Constructor constructor = loaderClass.getConstructor(); //Service serviceLoaderInst = (Service) constructor.newInstance(); // get portmethod and call it to get actual service String portName = servicePorts.get(serviceName); Method portMethod = serviceLoaderInst.getClass().getMethod("get" + portName, WebServiceFeature[].class); //WebServiceFeature validator = (WebServiceFeature) inst.loadClass("com.sun.xml.internal.ws.developer.SchemaValidationFeature").getConstructor().newInstance(); //Object serviceInst = portMethod.invoke(serviceLoaderInst, new Object[]{ new WebServiceFeature[] {validator} }); Object serviceInst = portMethod.invoke(serviceLoaderInst, new Object[]{ new WebServiceFeature[] {} }); return serviceInst; }
SCAnnotations(final Class<?> sc) { AccessController.doPrivileged(new PrivilegedAction<Void>() { @Override public Void run() { WebServiceClient wsc =sc.getAnnotation(WebServiceClient.class); if(wsc==null) { throw new WebServiceException("Service Interface Annotations required, exiting..."); } String tns = wsc.targetNamespace(); try { JAXWSUtils.getFileOrURL(wsc.wsdlLocation()); } catch (IOException e) { // TODO: report a reasonable error message throw new WebServiceException(e); } for (Method method : sc.getDeclaredMethods()) { WebEndpoint webEndpoint = method.getAnnotation(WebEndpoint.class); if (webEndpoint != null) { String endpointName = webEndpoint.name(); QName portQName = new QName(tns, endpointName); portQNames.add(portQName); } Class<?> seiClazz = method.getReturnType(); if (seiClazz!=void.class) { classes.add(seiClazz); } } return null; } }); }
private QName getServiceQName(final UnifiedServiceRefMetaData serviceRefMD, final Class<?> serviceClass) { QName retVal = serviceRefMD.getServiceQName(); if (retVal == null) { final WebServiceClient webServiceClientAnnotation = serviceClass.getAnnotation(WebServiceClient.class); if (webServiceClientAnnotation != null) { retVal = new QName(webServiceClientAnnotation.targetNamespace(), webServiceClientAnnotation.name()); } } return retVal; }
/** * Service.create(QName) with a composite specified but no override in the composite */ public void test1ArgServiceWithComposite() { QName serviceQName = new QName(namespaceURI, svcLocalPart); DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); assertNull(ServiceDelegate.getServiceMetadata()); // Use the proprietary SPI to create a service with additional metadata specified ServiceDelegate.setServiceMetadata(composite); Service service = Service.create(serviceQName); assertNotNull(service); // Verify that the composite has been reset so that it would not affect the next Service assertNull(ServiceDelegate.getServiceMetadata()); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertSame(composite, dbcInServiceDesc.getSparseComposite(serviceDelegate)); assertEquals(Service.class, dbcInServiceDesc.getCorrespondingClass()); // Since this is a generic Service with no overrides, there will be no WebServiceClient annotation WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNull(wsClient); // No WSDL should have been used, so no Ports should be found assertTrue("Wrong WSDL used", validatePort(service, null)); }
/** * Generated service constructor() with composite specified but no override in composite */ public void testNoArgGeneratedServiceWithComposite() { DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); ServiceDelegate.setServiceMetadata(composite); Service service = new ClientMetadataGeneratedService(); assertNotNull(service); assertNull(ServiceDelegate.getServiceMetadata()); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertSame(composite, dbcInServiceDesc.getSparseComposite(serviceDelegate)); assertEquals(ClientMetadataGeneratedService.class, dbcInServiceDesc.getCorrespondingClass()); // There is WebServiceClient on the generated Service and it wasn't overriden in the composite WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNotNull(wsClient); assertEquals(originalWsdl, wsClient.wsdlLocation()); assertEquals("originalTNS", wsClient.targetNamespace()); assertEquals("", wsClient.name()); // No WSDL override specified in the composite, so generated Service should use the annotation value assertTrue("Wrong WSDL Used", validatePort(service, originalWsdl_portLocalPart)); }
/** * Generated service constructor(URL, QName) with composite specified but no override in composite */ public void test2ArgGeneratedServiceWithComposite() { DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); ServiceDelegate.setServiceMetadata(composite); Service service = new ClientMetadataGeneratedService(getWsdlURL(otherWsdl), new QName(namespaceURI, svcLocalPart)); assertNotNull(service); assertNull(ServiceDelegate.getServiceMetadata()); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertSame(composite, dbcInServiceDesc.getSparseComposite(serviceDelegate)); assertEquals(ClientMetadataGeneratedService.class, dbcInServiceDesc.getCorrespondingClass()); // There is WebServiceClient on the generated Service and it wasn't overriden in the composite WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNotNull(wsClient); assertEquals(originalWsdl, wsClient.wsdlLocation()); assertEquals("originalTNS", wsClient.targetNamespace()); assertEquals("", wsClient.name()); // WSDL was specified on the generated Service constructor, and none in the composite // so should get the WSDL specified on the constructor assertTrue("Wrong WSDL used", validatePort(service, otherWsdl_portLocalPart)); }
/** * Service.create(QName) with a composite that specifies a wsdlLocation override */ public void test1ArgServiceOverrideWsdlLocation() { QName serviceQName = new QName(namespaceURI, svcLocalPart); DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); WebServiceClientAnnot wsClientAnno = WebServiceClientAnnot.createWebServiceClientAnnotImpl(null, null, getWsdlLocation(overridenWsdl)); composite.setWebServiceClientAnnot(wsClientAnno); // Use the proprietary SPI to create a service with additional metadata specified ServiceDelegate.setServiceMetadata(composite); Service service = Service.create(serviceQName); assertNotNull(service); // Verify that the composite has been reset so that it would not affect the next Service assertNull(ServiceDelegate.getServiceMetadata()); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertSame(composite, dbcInServiceDesc.getSparseComposite(serviceDelegate)); assertEquals(Service.class, dbcInServiceDesc.getCorrespondingClass()); // This is a generic Service with overrides, there will be WebServiceClient annotation WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNull(wsClient); wsClient = dbcInServiceDesc.getWebServiceClientAnnot(serviceDelegate); assertNotNull(wsClient); assertEquals(getWsdlLocation(overridenWsdl), wsClient.wsdlLocation()); assertNull(wsClient.targetNamespace()); assertNull(wsClient.name()); // WSDL override specified in the composite assertTrue("Wrong WSDL used", validatePort(service, overridenWsdl_portLocalPart)); }
/** * Service.create(QName) with a composite that overrides the TargetNamespace. Most of the * other tests override the WSDL Location since that is what a JSR-109 DD can specify. This * test makes sure other values can be overridden as well */ public void test1ArgServiceOverrideTNS() { QName serviceQName = new QName(namespaceURI, svcLocalPart); DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); WebServiceClientAnnot wsClientAnno = WebServiceClientAnnot.createWebServiceClientAnnotImpl(null, "overrideTNS", null); composite.setWebServiceClientAnnot(wsClientAnno); // Use the proprietary SPI to create a service with additional metadata specified ServiceDelegate.setServiceMetadata(composite); Service service = Service.create(serviceQName); assertNotNull(service); // Verify that the composite has been reset so that it would not affect the next Service assertNull(ServiceDelegate.getServiceMetadata()); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertSame(composite, dbcInServiceDesc.getSparseComposite(serviceDelegate)); assertEquals(Service.class, dbcInServiceDesc.getCorrespondingClass()); // The target namespace for the key should be overriden; it should not be overriden for // no key. WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNull(wsClient); WebServiceClient wsClientKeyed = dbcInServiceDesc.getWebServiceClientAnnot(serviceDelegate); assertNotNull(wsClientKeyed); assertNull(wsClientKeyed.wsdlLocation()); assertEquals("overrideTNS", wsClientKeyed.targetNamespace()); assertNull(wsClientKeyed.name()); }
/** * Service.create(URL, QName) with a composite that specifies a wsdlLocation override */ public void test2ArgServiceOverrideWsdlLocation() { QName serviceQName = new QName(namespaceURI, svcLocalPart); URL wsdlUrl = getWsdlURL(otherWsdl); DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); WebServiceClientAnnot wsClientAnno = WebServiceClientAnnot.createWebServiceClientAnnotImpl(null, null, getWsdlLocation(overridenWsdl)); composite.setWebServiceClientAnnot(wsClientAnno); // Use the proprietary SPI to create a service with additional metadata specified ServiceDelegate.setServiceMetadata(composite); Service service = Service.create(wsdlUrl, serviceQName); assertNotNull(service); // Verify that the composite has been reset so that it would not affect the next Service assertNull(ServiceDelegate.getServiceMetadata()); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertSame(composite, dbcInServiceDesc.getSparseComposite(serviceDelegate)); assertEquals(Service.class, dbcInServiceDesc.getCorrespondingClass()); // Since this is a generic Service with overrides, there will be a WebServiceClient annotation WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNull(wsClient); wsClient = dbcInServiceDesc.getWebServiceClientAnnot(serviceDelegate); assertNotNull(wsClient); assertEquals(getWsdlLocation(overridenWsdl), wsClient.wsdlLocation()); assertNull(wsClient.targetNamespace()); assertNull(wsClient.name()); // WSDL override specified in the composite assertTrue("Wrong WSDL used", validatePort(service, overridenWsdl_portLocalPart)); }
/** * Generated service constructor() with a composite that specifies a wsdlLocation override */ public void testNoArgGeneratedServiceOverrideWsdlLocation() { DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); WebServiceClientAnnot wsClientAnno = WebServiceClientAnnot.createWebServiceClientAnnotImpl(null, null, getWsdlLocation(overridenWsdl)); composite.setWebServiceClientAnnot(wsClientAnno); ServiceDelegate.setServiceMetadata(composite); Service service = new ClientMetadataGeneratedService(); assertNotNull(service); assertNull(ServiceDelegate.getServiceMetadata()); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertSame(composite, dbcInServiceDesc.getSparseComposite(serviceDelegate)); assertEquals(ClientMetadataGeneratedService.class, dbcInServiceDesc.getCorrespondingClass()); // There is WebServiceClient on the generated Service and it was overriden in the composite // for this key, however the keyless composite should not have any overrides. WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNotNull(wsClient); assertEquals(originalWsdl, wsClient.wsdlLocation()); assertEquals("originalTNS", wsClient.targetNamespace()); assertEquals("", wsClient.name()); WebServiceClient wsClientKeyed = dbcInServiceDesc.getWebServiceClientAnnot(serviceDelegate); assertNotSame(wsClient, wsClientKeyed); assertEquals(getWsdlLocation(overridenWsdl), wsClientKeyed.wsdlLocation()); assertEquals("originalTNS", wsClientKeyed.targetNamespace()); assertEquals("", wsClientKeyed.name()); // WSDL override specified in the composite assertTrue("Wrong WSDL used", validatePort(service, overridenWsdl_portLocalPart)); }
/** * Generated service constructor(URL, QName) with a composite that specifies a wsdlLocation override */ public void test2ArgGeneratedServiceOverrideWsdlLocation() { DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); WebServiceClientAnnot wsClientAnno = WebServiceClientAnnot.createWebServiceClientAnnotImpl(null, null, getWsdlLocation(overridenWsdl)); composite.setWebServiceClientAnnot(wsClientAnno); ServiceDelegate.setServiceMetadata(composite); Service service = new ClientMetadataGeneratedService(getWsdlURL(otherWsdl), new QName(namespaceURI, svcLocalPart)); assertNotNull(service); assertNull(ServiceDelegate.getServiceMetadata()); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertSame(composite, dbcInServiceDesc.getSparseComposite(serviceDelegate)); assertEquals(ClientMetadataGeneratedService.class, dbcInServiceDesc.getCorrespondingClass()); // There is WebServiceClient on the generated Service and it was overriden in the composite // for this key, however the keyless composite should not have any overrides. WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNotNull(wsClient); assertEquals(originalWsdl, wsClient.wsdlLocation()); assertEquals("originalTNS", wsClient.targetNamespace()); assertEquals("", wsClient.name()); WebServiceClient wsClientKeyed = dbcInServiceDesc.getWebServiceClientAnnot(serviceDelegate); assertNotSame(wsClient, wsClientKeyed); assertEquals(getWsdlLocation(overridenWsdl), wsClientKeyed.wsdlLocation()); assertEquals("originalTNS", wsClientKeyed.targetNamespace()); assertEquals("", wsClientKeyed.name()); // WSDL override specified in the composite assertTrue("Wrong WSDL used", validatePort(service, overridenWsdl_portLocalPart)); }
/** * Generated service constructor(URL, QName) with a composite that specifies a * target Namespace override. Most of the other tests are based on wsdlLocation since * that is what JSR-109 DDs override. This test verifies that other members can also * be override. */ public void test2ArgGeneratedServiceOverrideTNS() { DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); WebServiceClientAnnot wsClientAnno = WebServiceClientAnnot.createWebServiceClientAnnotImpl(null, "overrideTNS", getWsdlLocation(overridenWsdl)); composite.setWebServiceClientAnnot(wsClientAnno); ServiceDelegate.setServiceMetadata(composite); Service service = new ClientMetadataGeneratedService(getWsdlURL(otherWsdl), new QName(namespaceURI, svcLocalPart)); assertNotNull(service); assertNull(ServiceDelegate.getServiceMetadata()); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertSame(composite, dbcInServiceDesc.getSparseComposite(serviceDelegate)); assertEquals(ClientMetadataGeneratedService.class, dbcInServiceDesc.getCorrespondingClass()); // There is WebServiceClient on the generated Service and it was overriden in the composite // for this key, however the keyless composite should not have any overrides. WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNotNull(wsClient); assertEquals(originalWsdl, wsClient.wsdlLocation()); assertEquals("originalTNS", wsClient.targetNamespace()); assertEquals("", wsClient.name()); WebServiceClient wsClientKeyed = dbcInServiceDesc.getWebServiceClientAnnot(serviceDelegate); assertNotSame(wsClient, wsClientKeyed); assertEquals(getWsdlLocation(overridenWsdl), wsClientKeyed.wsdlLocation()); assertEquals("overrideTNS", wsClientKeyed.targetNamespace()); assertEquals("", wsClientKeyed.name()); // WSDL override specified in the composite assertTrue("Wrong WSDL used", validatePort(service, overridenWsdl_portLocalPart)); }
/** * This method will be used to attach @WebServiceClient annotation data to the * <code>DescriptionBuildercomposite</code> * * @param composite - <code>DescriptionBuilderComposite</code> */ private void attachWebServiceClientAnnotation(DescriptionBuilderComposite composite) { WebServiceClient webServiceClient = (WebServiceClient)ConverterUtils. getAnnotation(WebServiceClient.class, serviceClass); if (webServiceClient != null) { } }
/** * Create a ServiceDescription using a sparse composite that overrides the wsdlLocation on the * WebServiceClient annotation. Validate the override only affects the wsdlLocation and not * the other annotations members. */ public void testServiceClientWSDLLocationOverride() { QName serviceQName = new QName(namespaceURI, svcLocalPart); // Create a composite with a WebServiceClient override of the WSDL location. DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); String overridenWsdlLocation = DescriptionTestUtils.getWSDLLocation("ClientEndpointMetadata.wsdl"); WebServiceClientAnnot wsClientAnno = WebServiceClientAnnot.createWebServiceClientAnnotImpl(null, null, overridenWsdlLocation); composite.setWebServiceClientAnnot(wsClientAnno); Object compositeKey = "CompositeKey"; ServiceDescription svcDesc = new ServiceDescriptionImpl(null, serviceQName, ClientDBCSupportServiceSubclass.class, composite, compositeKey); assertNotNull(svcDesc); ServiceDescriptionImpl svcDescImpl = (ServiceDescriptionImpl) svcDesc; DescriptionBuilderComposite svcDescComposite = svcDescImpl.getDescriptionBuilderComposite(); assertNotNull(svcDescComposite); assertNotSame(composite, svcDescComposite); assertSame(composite, svcDescComposite.getSparseComposite(compositeKey)); // The client annot we set as a sparse composite should be the same. assertSame(wsClientAnno, svcDescComposite.getSparseComposite(compositeKey).getWebServiceClientAnnot()); // The WebServiceClient annot on the service desc should represent the wsdl override from the // sparse composite WebServiceClient wsClient = svcDescComposite.getWebServiceClientAnnot(compositeKey); assertEquals(overridenWsdlLocation, wsClient.wsdlLocation()); // Make sure the non-overridden values still come from the service class annotation assertEquals("originalTNS", wsClient.targetNamespace()); assertEquals("", wsClient.name()); }
public void testNoSparseAnnot() { QName serviceQName = new QName(namespaceURI, svcLocalPart); ServiceDescription svcDesc = DescriptionFactory.createServiceDescription(null, serviceQName, SparseAnnotServiceSubclass.class); assertNotNull(svcDesc); // A DBC will be created for us DescriptionBuilderComposite svcDescComposite = DescriptionTestUtils.getServiceDescriptionComposite(svcDesc); assertNotNull(svcDescComposite); WebServiceClient wsClient = svcDescComposite.getWebServiceClientAnnot(); // There is no DBC Annot in this case; it is the class annotation but it should be // returned as an instance of a WebServiceClientAnnot assertTrue(wsClient instanceof WebServiceClientAnnot); }
SCAnnotations(final Class<?> sc) { AccessController.doPrivileged(new PrivilegedAction<Void>() { public Void run() { WebServiceClient wsc =sc.getAnnotation(WebServiceClient.class); if(wsc==null) throw new WebServiceException("Service Interface Annotations required, exiting..."); String name = wsc.name(); String tns = wsc.targetNamespace(); serviceQName = new QName(tns, name); try { wsdlLocation = JAXWSUtils.getFileOrURL(wsc.wsdlLocation()); } catch (IOException e) { // TODO: report a reasonable error message throw new WebServiceException(e); } for (Method method : sc.getDeclaredMethods()) { WebEndpoint webEndpoint = method.getAnnotation(WebEndpoint.class); if (webEndpoint != null) { String endpointName = webEndpoint.name(); QName portQName = new QName(tns, endpointName); portQNames.add(portQName); } Class<?> seiClazz = method.getReturnType(); if (seiClazz!=void.class) { classes.add(seiClazz); } } return null; } }); }
public static QName getServiceQName(final Class<?> clazz) { final WebService webService = clazz.getAnnotation(WebService.class); if (webService != null) { return getServiceQName(clazz, webService.targetNamespace(), webService.serviceName()); } final WebServiceProvider webServiceProvider = clazz.getAnnotation(WebServiceProvider.class); if (webServiceProvider != null) { return getServiceQName(clazz, webServiceProvider.targetNamespace(), webServiceProvider.serviceName()); } final WebServiceClient webServiceClient = clazz.getAnnotation(WebServiceClient.class); if (webServiceClient != null) { return getServiceQName(clazz, webServiceClient.targetNamespace(), webServiceClient.name()); } throw new IllegalArgumentException("The " + clazz.getName() + " is not annotated"); }
private String findWsdlLocation(Class<? extends Service> serviceClass) { return serviceClass.getAnnotation(WebServiceClient.class).wsdlLocation(); }
/** * @param cls * @return true if this is a JAX-WS or JAX-WS generated class */ public static final boolean isJAXWSClass(Class cls) { // TODO Processing all of these annotations is very expensive. We need to cache the // result in a static WeakHashMap<Class, Boolean> // Kinds of generated classes: Service, Provider, Impl, Exception, Holder // Or the class is in the jaxws.xml.ws package // Check for Impl WebService wsAnn = (WebService)getAnnotation(cls,WebService.class); if (wsAnn != null) { return true; } // Check for service WebServiceClient wscAnn = (WebServiceClient)getAnnotation(cls,WebServiceClient.class); if (wscAnn != null) { return true; } // Check for provider WebServiceProvider wspAnn = (WebServiceProvider) getAnnotation(cls,WebServiceProvider.class); if (wspAnn != null) { return true; } // Check for Exception WebFault wfAnn = (WebFault)getAnnotation(cls,WebFault.class); if (wfAnn != null) { return true; } // Check for Holder if (Holder.class.isAssignableFrom(cls)) { return true; } // Check for a javax.xml.ws.Service class instance if (Service.class.isAssignableFrom(cls)) { return true; } String className = cls.getPackage() == null ? null : cls.getPackage().getName(); if (className != null && className.startsWith("javax.xml.ws") && !className.startsWith("javax.xml.ws.wsaddressing")) { return true; } return false; }
/** * Generated service constructor(URL, QName) with a composite that specifies a wsdlLocation override * where the override is a fully specifed URL to a file. */ public void test2ArgGeneratedServiceOverrideWsdlLocationWithProtocol() { DescriptionBuilderComposite composite = new DescriptionBuilderComposite(); // If the wsdlLocation in the composite specifies a protocol (like file: or http:) then // it should be used as-is. Otherwise (as shown by the other tests), it is treated as // a path on the local filesystem. String wsdlLocation = getWsdlLocation(overridenWsdl); // This check is necessary because Unix/Linux file paths begin // with a '/'. When adding the prefix 'jar:file:/' we may end // up with '//' after the 'file:' part. This causes the URL // object to treat this like a remote resource if(wsdlLocation.indexOf("/") == 0) { wsdlLocation = wsdlLocation.substring(1, wsdlLocation.length()); } String fullWsdlLocation = "file:/" + wsdlLocation; WebServiceClientAnnot wsClientAnno = WebServiceClientAnnot.createWebServiceClientAnnotImpl(null, null, fullWsdlLocation); composite.setWebServiceClientAnnot(wsClientAnno); ServiceDelegate.setServiceMetadata(composite); Service service = new ClientMetadataGeneratedService(getWsdlURL(otherWsdl), new QName(namespaceURI, svcLocalPart)); assertNotNull(service); assertNull(ServiceDelegate.getServiceMetadata()); ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service); assertNotNull(serviceDelegate); ServiceDescription serviceDesc = serviceDelegate.getServiceDescription(); assertNotNull(serviceDesc); DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc); assertSame(composite, dbcInServiceDesc.getSparseComposite(serviceDelegate)); assertEquals(ClientMetadataGeneratedService.class, dbcInServiceDesc.getCorrespondingClass()); // There is WebServiceClient on the generated Service and it was overriden in the composite // for the key. The annotation with no key should be unchanged. WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot(); assertNotNull(wsClient); assertEquals(originalWsdl, wsClient.wsdlLocation()); assertEquals("originalTNS", wsClient.targetNamespace()); assertEquals("", wsClient.name()); WebServiceClient wsClientKeyed = dbcInServiceDesc.getWebServiceClientAnnot(serviceDelegate); assertNotSame(wsClient, wsClientKeyed); assertEquals(fullWsdlLocation, wsClientKeyed.wsdlLocation()); assertEquals("originalTNS", wsClientKeyed.targetNamespace()); assertEquals("", wsClientKeyed.name()); // WSDL override specified in the composite assertTrue("Wrong WSDL used", validatePort(service, overridenWsdl_portLocalPart)); }
private static WebServiceClient getClientAnnotation(Class<Service> clazz) { return clazz.getAnnotation(WebServiceClient.class); }