// 调试用 @Test @Ignore public void rawTest() { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress("http://*****:*****@163.net","jiyi","lu")); // System.out.println(id); }
@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); }
/** * 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; }