public JaxWsWebServicePublisherBeanPostProcessor() throws SecurityException, NoSuchMethodException, ClassNotFoundException { try { servletClass = ClassLoaderUtils.loadClass(CXF_SERVLET_CLASS_NAME, getClass()); } catch (ClassNotFoundException e) { Message message = new Message("SERVLET_CLASS_MISSING", LOG, CXF_SERVLET_CLASS_NAME); LOG.severe(message.toString()); throw e; } servletGetBusMethod = servletClass.getMethod("getBus"); }
try { if (bus != null) { ClassLoader newLoader = bus.getExtension(ClassLoader.class); if (newLoader != null) { loader = ClassLoaderUtils.setThreadContextClassloader(newLoader); endpoint.getInInterceptors().addAll(in); endpoint.getOutInterceptors().addAll(out); endpoint.getInFaultInterceptors().addAll(inFault); loader.reset();
public DefaultInMemoryTokenStore() { super("STS", BusFactory.getDefaultBus(), ClassLoaderUtils.getResource("cxf-ehcache.xml", DefaultInMemoryTokenStore.class)); }
@org.junit.Test public void testSSLv3ServerAllowed() throws Exception { // Doesn't work with IBM JDK if ("IBM Corporation".equals(System.getProperty("java.vendor"))) { return; } SpringBusFactory bf = new SpringBusFactory(); URL busFile = SSLv3Test.class.getResource("sslv3-client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); System.setProperty("https.protocols", "SSLv3"); URL service = new URL("https://localhost:" + PORT2); HttpsURLConnection connection = (HttpsURLConnection) service.openConnection(); connection.setHostnameVerifier(new DisableCNCheckVerifier()); SSLContext sslContext = SSLContext.getInstance("SSL"); KeyStore trustedCertStore = KeyStore.getInstance("jks"); try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", SSLv3Test.class)) { trustedCertStore.load(keystore, null); } TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(trustedCertStore); TrustManager[] trustManagers = tmf.getTrustManagers(); sslContext.init(null, trustManagers, new java.security.SecureRandom()); connection.setSSLSocketFactory(sslContext.getSocketFactory()); connection.connect(); connection.disconnect(); System.clearProperty("https.protocols"); bus.shutdown(true); }
protected List<InputSource> getDefaultSchemas() throws IOException { List<InputSource> xsdList = new ArrayList<>(); URL url = ClassLoaderUtils.getResource("/schemas/configuration/parameterized-types.xsd", this.getClass()); if (url != null) { InputSource is = new InputSource(url.openStream()); is.setSystemId(url.toString()); xsdList.add(is); } addDefaultSchemas(ToolConstants.CXF_SCHEMAS_DIR_INJAR, xsdList); return xsdList; } private void addDefaultSchemas(String location, List<InputSource> xsdList) throws IOException {
private TokenStore configureTokenStore() throws MalformedURLException { if (TokenStoreFactory.isEhCacheInstalled()) { String cfg = "cxf-ehcache.xml"; URL url = null; if (url == null) { url = ClassLoaderUtils.getResource(cfg, STSLoginModule.class); } if (url == null) { url = new URL(cfg); } if (url != null) { return new EHCacheTokenStore(TOKEN_STORE_KEY, BusFactory.getDefaultBus(), url); } } return null; }
/** * This is a convenience method to load a resource as a stream. <p/> The * algorithm used to find the resource is given in getResource() * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static InputStream getResourceAsStream(String resourceName, Class<?> callingClass) { URL url = getResource(resourceName, callingClass); try { return (url != null) ? url.openStream() : null; } catch (IOException e) { return null; } }
public final void setScript(String scriptLocation) throws IOException { URL resource = ClassLoaderUtils.getResource(scriptLocation, this.getClass()); if (resource != null) { scriptLocation = resource.getPath(); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Script found within Classpath: " + scriptLocation); } } File scriptFile = new File(scriptLocation); if (scriptFile.exists()) { this.script = jexlEngine.createScript(scriptFile); } else { throw new IllegalArgumentException("Script resource not found!"); } }
@Test public void testChangedSignatureMethod() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); ClientTestFilter signatureFilter = new ClientTestFilter(); signatureFilter.setChangeSignatureAlgorithm(true); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray()); PrivateKey privateKey = (PrivateKey)keyStore.getKey("alice", "password".toCharArray()); assertNotNull(privateKey); MessageSigner messageSigner = new MessageSigner(privateKey, "custom_key_id"); signatureFilter.setMessageSigner(messageSigner); String address = "https://localhost:" + PORT + "/httpsig/bookstore/books"; WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString()); client.type("application/xml").accept("application/xml"); Response response = client.post(new Book("CXF", 126L)); assertEquals(response.getStatus(), 400); }
public void onMessage(Message m) { Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus); ClassLoaderHolder origLoader = null; try { if (loader != null) { origLoader = ClassLoaderUtils.setThreadContextClassloader(loader); if (m.getInterceptorChain() != null) { phaseChain = m.getInterceptorChain(); Exchange exchange = message.getExchange(); if (exchange == null) { exchange = new ExchangeImpl(); m.setExchange(exchange); exchange.setInMessage(message); setExchangeProperties(exchange, message); if (endpoint.getService().getDataBinding() instanceof InterceptorProvider) { dbp = (InterceptorProvider)endpoint.getService().getDataBinding(); BusFactory.setThreadDefaultBus(origBus); origLoader.reset();
public void onMessage(Message message) { Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus); ClassLoaderHolder origLoader = null; try { if (loader != null) { origLoader = ClassLoaderUtils.setThreadContextClassloader(loader); message.setExchange(exchange); exchange.setInMessage(message); setExchangeProperties(exchange, message); message.setInterceptorChain(chain); chain.add(bus.getInInterceptors()); if (bindingInterceptors != null) { chain.add(bindingInterceptors); exchange.put(ENDPOINTS, endpoints); } finally { if (origBus != bus) { BusFactory.setThreadDefaultBus(origBus); origLoader.reset();
public void onMessage(Message m) { Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus); ClassLoaderHolder origLoader = null; try { if (loader != null) { origLoader = ClassLoaderUtils.setThreadContextClassloader(loader); setExchangeProperties(ex, m); Message inMsg = endpoint.getBinding().createMessage(); MessageImpl.copyContent(m, inMsg); inMsg.putAll(m); ex.setInMessage(inMsg); inMsg.setExchange(ex); SortedSet<Phase> phases = new TreeSet<>(bus.getExtension(PhaseManager.class).getInPhases()); ColocUtil.setPhases(phases, Phase.USER_LOGICAL, Phase.INVOKE); InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, phases); BindingOperationInfo bop = m.getExchange().getBindingOperationInfo(); OperationInfo soi = bop != null ? bop.getOperationInfo() : null; if (soi != null && oi != null) { origLoader.reset();
public void onMessage(Message m) { Message message = cfg.getConduitSelector().getEndpoint().getBinding().createMessage(m); message.put(Message.REQUESTOR_ROLE, Boolean.TRUE); message.put(Message.INBOUND_MESSAGE, Boolean.TRUE); PhaseInterceptorChain chain = AbstractClient.setupInInterceptorChain(cfg); message.setInterceptorChain(chain); message.getExchange().setInMessage(message); Bus bus = cfg.getBus(); Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus); ClassLoaderHolder origLoader = null; try { if (loader != null) { origLoader = ClassLoaderUtils.setThreadContextClassloader(loader); } // execute chain chain.doIntercept(message); } finally { if (origBus != bus) { BusFactory.setThreadDefaultBus(origBus); } if (origLoader != null) { origLoader.reset(); } synchronized (message.getExchange()) { message.getExchange().notifyAll(); } } }
public EndpointReference getEndpointReference(Element... referenceParameters) { WrappedMessageContext ctx = (WrappedMessageContext)getMessageContext(); org.apache.cxf.message.Message msg = ctx.getWrappedMessage(); Endpoint ep = msg.getExchange().getEndpoint(); builder.address(ep.getEndpointInfo().getAddress()); builder.serviceName(ep.getService().getName()); builder.endpointName(ep.getEndpointInfo().getName()); URI wsdlDescription = ep.getEndpointInfo().getProperty("URI", URI.class); if (wsdlDescription == null) { orig = ClassLoaderUtils.setThreadContextClassloader(EndpointReferenceBuilder.class.getClassLoader()); return builder.build(); } finally { if (orig != null) { orig.reset();
private static InputStream getResourceAsStream(String resource) { InputStream is = ClassLoaderUtils.getResourceAsStream(resource, SSLUtils.class); if (is == null) { Bus bus = BusFactory.getThreadDefaultBus(true); ResourceManager rm = bus.getExtension(ResourceManager.class); if (rm != null) { is = rm.getResourceAsStream(resource); } } return is; }
try { if (bus != null) { ClassLoader newLoader = bus.getExtension(ClassLoader.class); if (newLoader != null) { loader = ClassLoaderUtils.setThreadContextClassloader(newLoader); EndpointInfo endpointInfo = serv.getEndpoint().getEndpointInfo(); if (endpointInfo.getAddress() == null || !endpointInfo.getAddress().contains(addr)) { endpointInfo.setAddress(addr); .getProperty(WSDLServiceBuilder.WSDL_DEFINITION, Definition.class); if (def == null) { def = bus.getExtension(WSDLManager.class).getDefinition(wsdlLocation); } finally { if (loader != null) { loader.reset();
Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus); ClassLoaderHolder origLoader = null; try { ClassLoader loader = configuredBus.getExtension(ClassLoader.class); if (loader != null) { origLoader = ClassLoaderUtils.setThreadContextClassloader(loader); } finally { if (origLoader != null) { origLoader.reset(); BusFactory.setThreadDefaultBus(origBus);
public Server create() { ClassLoaderHolder orig = null; try { if (bus != null) { ClassLoader loader = bus.getExtension(ClassLoader.class); if (loader != null) { orig = ClassLoaderUtils.setThreadContextClassloader(loader); } } Server server = super.create(); initializeResourcesAndHandlerChain(server); checkPrivateEndpoint(server.getEndpoint()); return server; } finally { if (orig != null) { orig.reset(); } } }
/** * This is factored out to permit use in a unit test. * * @param bus * @return */ public static ApplicationContext getApplicationContext(List<String> additionalFilePathnames) { BusApplicationContext busApplicationContext = BusFactory.getDefaultBus() .getExtension(BusApplicationContext.class); GenericApplicationContext appContext = new GenericApplicationContext(busApplicationContext); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext); List<URL> urls = ClassLoaderUtils.getResources("META-INF/cxf/java2wsbeans.xml", SpringServiceBuilderFactory.class); for (URL url : urls) { reader.loadBeanDefinitions(new UrlResource(url)); } for (String pathname : additionalFilePathnames) { try { reader.loadBeanDefinitions(new FileSystemResource(pathname)); } catch (BeanDefinitionStoreException bdse) { throw new ToolException("Unable to open bean definition file " + pathname, bdse.getCause()); } } appContext.refresh(); return appContext; }
protected InputStream getResourceAsStream(String path) { InputStream is = ClassLoaderUtils.getResourceAsStream(path, AbstractHTTPServlet.class); if (is == null && getBus() != null) { ResourceManager rm = getBus().getExtension(ResourceManager.class); if (rm != null) { is = rm.resolveResource(path, InputStream.class); } } return is; }