@Override public JAXRSClientFactoryBean load(Class<?> proxyType) throws Exception { JAXRSClientFactoryBean clientFactoryBean = new JAXRSClientFactoryBean(); clientFactoryBean.setResourceClass(proxyType); clientFactoryBean.setProvider(new JacksonJsonProvider(new ApiObjectMapper())); return clientFactoryBean; }
private WebClient getAccessTokenService() { final JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(oauth2TokenServiceURI.toASCIIString()); bean.setUsername("odatajclient"); bean.setPassword("odatajclient"); return bean.createWebClient() .type(MediaType.APPLICATION_FORM_URLENCODED_TYPE) .accept(MediaType.APPLICATION_JSON_TYPE); }
private void initTargetClientIfNeeded() { URI uri = uriBuilder.build(); if (targetClient == null) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(uri.toString()); targetClient = bean.createWebClient(); ClientImpl.this.baseClients.add(targetClient); } else if (!targetClient.getCurrentURI().equals(uri)) { targetClient.to(uri.toString(), false); } }
public void setProperties(Map<String, Object> properties) { if (this.getProperties() != null && properties != null) { this.getProperties().putAll(properties); } else { super.setProperties(properties); } }
@Before public void publish() { JAXRSServerFactoryBean serverFactoryBean = new JAXRSServerFactoryBean(); serverFactoryBean.setProvider(new JacksonJsonProvider()); serverFactoryBean.setResourceClasses(HelloService.class); ResourceProvider resourceProvider = new SingletonResourceProvider(helloServiceImplementation); serverFactoryBean.setResourceProvider(HelloService.class, resourceProvider); serverFactoryBean.setAddress("http://localhost:9000/"); BindingFactoryManager manager = serverFactoryBean.getBus().getExtension(BindingFactoryManager.class); JAXRSBindingFactory bindingFactory = new JAXRSBindingFactory(); bindingFactory.setBus(serverFactoryBean.getBus()); manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, bindingFactory); server = serverFactoryBean.create(); JAXRSClientFactoryBean clientFactoryBean = new JAXRSClientFactoryBean(); clientFactoryBean.setResourceClass(HelloService.class); clientFactoryBean.setAddress("http://localhost:9000/"); clientFactoryBean.setProvider(new JacksonJsonProvider()); client = clientFactoryBean.create(HelloService.class); }
@Scope(value = SCOPE_PROTOTYPE) public WebClient baseWebClient() { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(env.getRequiredProperty("nflow.url")); bean.getFeatures().add(new LoggingFeature()); bean.setProviders(asList(jsonProvider)); bean.setBus(cxf()); return bean.createWebClient() .type(APPLICATION_JSON) .accept(APPLICATION_JSON) .path("api") .path("v1"); }
// 调试用 @Test @Ignore public void rawTest() { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress("http://*****:*****@163.net","jiyi","lu")); // System.out.println(id); }
private WebClient createWebClient(String address, Map<String, Object> extraProperties) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSSamlAuthorizationTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); Map<String, Object> properties = new HashMap<String, Object>(); properties.put( "security.saml-callback-handler", "org.apache.cxf.systest.jaxrs.security.saml.SamlCallbackHandler"); if (extraProperties != null) { properties.putAll(extraProperties); } bean.setProperties(properties); bean.getOutInterceptors().add(new SamlEnvelopedOutInterceptor()); return bean.createWebClient(); }
/** * Build a client proxy, for a specific proxy type. * * @param proxyType proxy type class * @return client proxy stub */ protected <T> T build(Class<T> proxyType) { String address = generateAddress(); T rootResource; // Synchronized on the class to correlate with the scope of clientStaticResources // We want to ensure that the shared bean isn't set concurrently in multiple callers synchronized (ClouderaManagerClientBuilder.class) { JAXRSClientFactoryBean bean = cleanFactory(clientStaticResources.getUnchecked(proxyType)); bean.setAddress(address); if (username != null) { bean.setUsername(username); bean.setPassword(password); } if (enableLogging) { bean.setFeatures(Arrays.<AbstractFeature>asList(new LoggingFeature())); } rootResource = bean.create(proxyType); } boolean isTlsEnabled = address.startsWith("https://"); ClientConfiguration config = WebClient.getConfig(rootResource); HTTPConduit conduit = (HTTPConduit) config.getConduit(); if (isTlsEnabled) { TLSClientParameters tlsParams = new TLSClientParameters(); if (!validateCerts) { tlsParams.setTrustManagers(new TrustManager[] {new AcceptAllTrustManager()}); } else if (trustManagers != null) { tlsParams.setTrustManagers(trustManagers); } tlsParams.setDisableCNCheck(!validateCn); conduit.setTlsClientParameters(tlsParams); } HTTPClientPolicy policy = conduit.getClient(); policy.setConnectionTimeout(connectionTimeoutUnits.toMillis(connectionTimeout)); policy.setReceiveTimeout(receiveTimeoutUnits.toMillis(receiveTimeout)); return rootResource; }
private static JAXRSClientFactoryBean cleanFactory(JAXRSClientFactoryBean bean) { bean.setUsername(null); bean.setPassword(null); bean.setFeatures(Arrays.<AbstractFeature>asList()); return bean; }