private static WinRm doCreateServiceWithReflectivelySetDelegate() { WinRmService service = doCreateService_1_CreateMinimalServiceInstance(); try { Field delegateField = javax.xml.ws.Service.class.getDeclaredField("delegate"); //ALLOW CXF SPECIFIC SERVICE DELEGATE ONLY! delegateField.setAccessible(true); ServiceDelegate previousDelegate = (ServiceDelegate) delegateField.get(service); if (!previousDelegate.getClass().getName().contains("cxf")) { ServiceDelegate serviceDelegate = ((Provider) Class.forName("org.apache.cxf.jaxws.spi.ProviderImpl").newInstance()) .createServiceDelegate(WinRmService.WSDL_LOCATION, WinRmService.SERVICE, service.getClass()); delegateField.set(service, serviceDelegate); } } catch (Exception e) { throw new RuntimeException("Error reflectively setting CXF WS service delegate", e); } return doCreateService_2_GetClient(service); }
private void runJBossModulesClient(String clientJar) throws Exception { File javaFile = new File (System.getProperty("java.home") + FS + "bin" + FS + "java"); String javaCmd = javaFile.exists() ? javaFile.getCanonicalPath() : "java"; final String jbh = System.getProperty("jboss.home"); final String jbm = jbh + FS + "modules"; final String jbmjar = jbh + FS + "jboss-modules.jar"; final File f = new File(JBossWSTestHelper.getTestArchiveDir(), clientJar); //java -jar $JBOSS_HOME/jboss-modules.jar -mp $JBOSS_HOME/modules -jar client.jar String additionalJVMArgs = System.getProperty("additionalJvmArgs", ""); additionalJVMArgs = additionalJVMArgs.replace('\n', ' '); String props = " " + additionalJVMArgs + " -Dlog4j.output.dir=" + System.getProperty("log4j.output.dir") + " -jar " + jbmjar + " -mp " + jbm; final String command = javaCmd + props + " -jar " + f.getAbsolutePath() + " " + getServerHost() + " " + getServerPort(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); executeCommand(command, bout); //check result (includes check on Provider impl, which might be affected by missing javax.xml.ws.api module dependency assertEquals(Provider.provider().getClass().getName() + ", " + TestClient.REQ_STR, readFirstLine(bout)); }
/** * AS7 check on client TCCL * * @param cl */ private void checkImplementationClassesAreNotVisible(ClassLoader cl) { //retrieve the stack specific Provider impl class name through the JAXWS API //classloading mechanism (JBEE-75), which is able to "see" implementation classes String providerImplClassName = Provider.provider().getClass().getName(); if (!providerImplClassName.contains("jboss")) { throw new RuntimeException("Expected a JBoss(WS) specific implementation for javax.xml.ws.spi.Provider: " + providerImplClassName); } //then try loading the same class using the provided classloader try { cl.loadClass(providerImplClassName); throw new RuntimeException("ClassLoader " + cl + " should not be able to load " + providerImplClassName); } catch (ClassNotFoundException e) { //this is expected, just check the class that can't be found is our impl if (!(e.getMessage().contains(providerImplClassName))) { throw new RuntimeException("Unexpected Provider implementation being looked up: " + e.getMessage()); } } }
public void test() throws Exception { System.setProperty(Provider.class.getName(), MockProvider.class.getName()); Provider provider = Provider.provider(); assertNotNull("provider is null", provider); assertFalse("provider should not be an instance of ProviderWrapper", provider instanceof JaxWsProviderWrapper); JaxWsProviderWrapper.beforeCreate(null); try { provider = Provider.provider(); assertNotNull("provider is null", provider); assertTrue("provider should be an instance of ProviderWrapper", provider instanceof JaxWsProviderWrapper); final JaxWsProviderWrapper providerWrapper = (JaxWsProviderWrapper) provider; // check delegate final Provider delegate = providerWrapper.getDelegate(); assertNotNull("providerWrapper delegate is null", delegate); assertFalse("providerWrapper delegate should not be an instance of ProviderWrapper", delegate instanceof JaxWsProviderWrapper); } finally { JaxWsProviderWrapper.afterCreate(); } }
public void test() throws Exception { System.setProperty(Provider.class.getName(), MockProvider.class.getName()); Provider provider = Provider.provider(); assertNotNull("provider is null", provider); assertFalse("provider should not be an instance of ProviderWrapper", provider instanceof ProviderWrapper); ProviderWrapper.beforeCreate(null, null, null); try { provider = Provider.provider(); assertNotNull("provider is null", provider); assertTrue("provider should be an instance of ProviderWrapper", provider instanceof ProviderWrapper); final ProviderWrapper providerWrapper = (ProviderWrapper) provider; // check delegate final Provider delegate = providerWrapper.getDelegate(); assertNotNull("providerWrapper delegate is null", delegate); assertFalse("providerWrapper delegate should not be an instance of ProviderWrapper", delegate instanceof ProviderWrapper); } finally { ProviderWrapper.afterCreate(); } }
public static void verifyJaxWsSpiProvider(String expectedProviderClass) { Provider provider = Provider.provider(); String clazz = provider.getClass().getName(); if (!clazz.equals(expectedProviderClass)) { throw new RuntimeException("Expected " + expectedProviderClass + " but got " + clazz); } }
public static void main(String[] args) throws Exception { String serverHost = args[0]; String serverPort = args[1]; String resStr = testPortAccess(serverHost, Integer.valueOf(serverPort)); System.out.println(Provider.provider().getClass().getName() + ", " + resStr); //wait a bit before returning as the log processing can be aysnch, the test client //relies on the log contents and the log streams are closed by the system when the //process terminates Thread.sleep(1000); }
@Test public void testGetProvider() { //just check we get the jbossws-cxf provider impl when the default maven tccl is set Provider providerImpl = Provider.provider(); assertTrue(providerImpl instanceof ProviderImpl); }
@Test public void testGetProviderWithCustomClassLoaderIsBackwardCompatibility() { ClassLoader tccl = Thread.currentThread().getContextClassLoader(); try { //overwrite the TCCL so that no Provider configuration is specified, //hence the JAXWS RI default is tried (given this test is run //out of container); this verifies the additions due to JBEE-75 and //JBWS-3223 are backward compatible. TestClassLoader cl = new TestClassLoader(); Thread.currentThread().setContextClassLoader(cl); try { Provider.provider(); fail("Exception due to class not found expected!"); } catch (Exception e) { //check the default ProviderImpl was being looked up given no configuration was provided List<String> list = cl.getLoadClassRequests(); assertTrue(list.contains("com.sun.xml.internal.ws.spi.ProviderImpl")); assertEquals(1, list.size()); } } finally { Thread.currentThread().setContextClassLoader(tccl); } }
@Override public void start(final Deployment dep) { if (BusFactory.getDefaultBus(false) == null) { //Make sure the default bus is created and set for client side usage //(i.e. no server side integration contribution in it) JBossWSBusFactory.getDefaultBus(Provider.provider().getClass().getClassLoader()); } startDeploymentBus(dep); }
@Test public void testProvider() { Provider provider = Provider.provider(); LOG.debug("provider class: " + provider.getClass().getName()); assertEquals("org.apache.cxf.jaxws22.spi.ProviderImpl", provider .getClass().getName()); }
private static Provider createProviderInstance(final String providerClass, final ClassLoader classLoader) { if (providerClass != null && providerClass.length() > 0 && !providerClass.equals(JaxWsProviderWrapper.class.getName())) { try { final Class<? extends Provider> clazz = classLoader.loadClass(providerClass).asSubclass(Provider.class); return clazz.newInstance(); } catch (Throwable e) { logger.log(Level.WARNING, "Unable to construct provider implementation " + providerClass, e); } } return null; }
private static Provider createProviderInstance(final String providerClass, final ClassLoader classLoader) { if (providerClass != null && providerClass.length() > 0 && !providerClass.equals(ProviderWrapper.class.getName())) { try { final Class<? extends Provider> clazz = classLoader.loadClass(providerClass).asSubclass(Provider.class); return clazz.newInstance(); } catch (final Throwable e) { logger.warning("Unable to construct provider implementation " + providerClass, e); } } return null; }
protected Service(java.net.URL wsdlDocumentLocation, QName serviceName) { delegate = Provider.provider().createServiceDelegate(wsdlDocumentLocation, serviceName, this.getClass()); }
protected Service(java.net.URL wsdlDocumentLocation, QName serviceName, WebServiceFeature ... features) { delegate = Provider.provider().createServiceDelegate(wsdlDocumentLocation, serviceName, this.getClass(), features); }
private Service createServiceWithRetry(Class serviceInterface, ApiEnvironment env) throws Exception { final QName qName = getServiceQname(serviceInterface); final boolean isCxf = Provider.provider().getClass().getName().contains("org.apache.cxf"); final URL url = (isCxf ? null : new URL(getServiceUrl(serviceInterface, env) + "?wsdl")); int retryLeft = WS_CREATE_RETRY_TIMES; int timeout = 0; ExecutorService pool = Executors.newSingleThreadExecutor(); try { while (retryLeft > 0) { retryLeft--; timeout = prolongTimeout(timeout); Future<Service> future = pool.submit(new Callable<Service>() { public Service call() throws Exception { if (isCxf) { // CXF doesn't require WSDL url to be passed return Service.create(qName); } else { return Service.create(url, qName); } } }); try { return future.get(timeout, TimeUnit.SECONDS); } catch (TimeoutException e) { System.out.println(String.format("Timeout. Failed to create web service %s in %d seconds for %s. retry left %d", serviceInterface.getName(), timeout, env.value(), retryLeft)); future.cancel(true); try { if (retryLeft > 0) { Thread.sleep(WS_CREATE_RETRY_INTERVAL_IN_SECOND * 1000); } } catch (InterruptedException e1) { e1.printStackTrace(); } } } } finally { pool.shutdown(); } throw new Exception(String.format("Failed to create Service %s for %s!", serviceInterface.getName(), env.value())); }
public Provider getDelegate() { return delegate; }
/** * Builds a <code>W3CEndpointReference</code> from the accumulated * properties set on this <code>W3CEndpointReferenceBuilder</code> * instance. * <p> * This method can be used to create a <code>W3CEndpointReference</code> * for any endpoint by specifying the <code>address</code> property along * with any other desired properties. This method * can also be used to create a <code>W3CEndpointReference</code> for * an endpoint that is published by the same Java EE application. * This method can automatically determine the <code>address</code> of * an endpoint published by the same Java EE application that is identified by the * <code>serviceName</code> and * <code>endpointName</code> properties. If the <code>address</code> is * <code>null</code> and the <code>serviceName</code> and * <code>endpointName</code> * do not identify an endpoint published by the same Java EE application, a * <code>java.lang.IllegalStateException</code> MUST be thrown. * * * @return <code>W3CEndpointReference</code> from the accumulated * properties set on this <code>W3CEndpointReferenceBuilder</code> * instance. This method never returns <code>null</code>. * * @throws IllegalStateException * <ul> * <li>If the <code>address</code>, <code>serviceName</code> and * <code>endpointName</code> are all <code>null</code>. * <li>If the <code>serviceName</code> service is <code>null</code> and the * <code>endpointName</code> is NOT <code>null</code>. * <li>If the <code>address</code> property is <code>null</code> and * the <code>serviceName</code> and <code>endpointName</code> do not * specify a valid endpoint published by the same Java EE * application. * <li>If the <code>serviceName</code> is NOT <code>null</code> * and is not present in the specified WSDL. * <li>If the <code>endpointName</code> port is not <code>null</code> and it * is not present in <code>serviceName</code> service in the WSDL. * <li>If the <code>wsdlDocumentLocation</code> is NOT <code>null</code> * and does not represent a valid WSDL. * </ul> * @throws WebServiceException If an error occurs while creating the * <code>W3CEndpointReference</code>. * */ public W3CEndpointReference build() { if (elements.isEmpty() && attributes.isEmpty() && interfaceName == null) { // 2.1 API return Provider.provider().createW3CEndpointReference(address, serviceName, endpointName, metadata, wsdlDocumentLocation, referenceParameters); } return Provider.provider().createW3CEndpointReference(address, interfaceName, serviceName, endpointName, metadata, wsdlDocumentLocation, referenceParameters, elements, attributes); }
/** * Builds a {@code W3CEndpointReference} from the accumulated * properties set on this {@code W3CEndpointReferenceBuilder} * instance. * <p> * This method can be used to create a {@code W3CEndpointReference} * for any endpoint by specifying the {@code address} property along * with any other desired properties. This method * can also be used to create a {@code W3CEndpointReference} for * an endpoint that is published by the same Java EE application. * This method can automatically determine the {@code address} of * an endpoint published by the same Java EE application that is identified by the * {@code serviceName} and * {@code endpointName} properties. If the {@code address} is * {@code null} and the {@code serviceName} and * {@code endpointName} * do not identify an endpoint published by the same Java EE application, a * {@code java.lang.IllegalStateException} MUST be thrown. * * * @return {@code W3CEndpointReference} from the accumulated * properties set on this {@code W3CEndpointReferenceBuilder} * instance. This method never returns {@code null}. * * @throws IllegalStateException * <ul> * <li>If the {@code address}, {@code serviceName} and * {@code endpointName} are all {@code null}. * <li>If the {@code serviceName} service is {@code null} and the * {@code endpointName} is NOT {@code null}. * <li>If the {@code address} property is {@code null} and * the {@code serviceName} and {@code endpointName} do not * specify a valid endpoint published by the same Java EE * application. * <li>If the {@code serviceName} is NOT {@code null} * and is not present in the specified WSDL. * <li>If the {@code endpointName} port is not {@code null} and it * is not present in {@code serviceName} service in the WSDL. * <li>If the {@code wsdlDocumentLocation} is NOT {@code null} * and does not represent a valid WSDL. * </ul> * @throws WebServiceException If an error occurs while creating the * {@code W3CEndpointReference}. * */ public W3CEndpointReference build() { if (elements.isEmpty() && attributes.isEmpty() && interfaceName == null) { // 2.1 API return Provider.provider().createW3CEndpointReference(address, serviceName, endpointName, metadata, wsdlDocumentLocation, referenceParameters); } return Provider.provider().createW3CEndpointReference(address, interfaceName, serviceName, endpointName, metadata, wsdlDocumentLocation, referenceParameters, elements, attributes); }