private static <T> T createClient( String port, Class<T> serviceClass, SchemaValidationType type, Feature... features) { JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean(); clientFactory.setServiceClass(serviceClass); clientFactory.setAddress(getAddress(port, serviceClass)); if (features != null) { clientFactory.getFeatures().addAll(Arrays.asList(features)); } @SuppressWarnings("unchecked") T newClient = (T) clientFactory.create(); Client proxy = ClientProxy.getClient(newClient); if (type != null) { proxy.getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, type); } HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); // give me longer debug times HTTPClientPolicy clientPolicy = new HTTPClientPolicy(); clientPolicy.setConnectionTimeout(1000000); clientPolicy.setReceiveTimeout(1000000); conduit.setClient(clientPolicy); return newClient; }
private JobPositionClient() { URL wsdl = JobPositionWS_Service.WSDL_LOCATION; try { wsdl = new URL("file:" + System.getProperty("wsdl.location") + "jobposition.wsdl"); } catch (MalformedURLException e) { log.error( "Errore URL JobPositionClient, using default url " + JobPositionWS_Service.WSDL_LOCATION.toString(), e); } log.info("USING: " + wsdl.toString()); JobPositionWS_Service client = new JobPositionWS_Service(wsdl, JobPositionWS_Service.SERVICE); this.port = client.getJobPositionWSSOAP(); String proxyServer = System.getProperty("jobposition.proxy.server"); if ((proxyServer != null) && (!("".equals(proxyServer)))) { Client cxf = ClientProxy.getClient(this.port); HTTPConduit http = (HTTPConduit) cxf.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setProxyServer(proxyServer); httpClientPolicy.setProxyServerPort(8080); String proxyPort = System.getProperty("jobposition.proxy.port"); if ((proxyPort != null) && (!("".equals(proxyPort)))) { try { int portnum = Integer.parseInt(proxyPort); if (portnum > 0) httpClientPolicy.setProxyServerPort(portnum); } catch (RuntimeException re) { log.error("Error parsing ProxyPort: " + proxyPort); } } http.setClient(httpClientPolicy); } }
public void connect(TokenHolder tokenHolder) { for (Class<? extends PublicInterface> interface1 : interfaces) { JaxWsProxyFactoryBean cpfb = new JaxWsProxyFactoryBean(); cpfb.setServiceClass(interface1); cpfb.setAddress(address + "/" + interface1.getSimpleName()); Map<String, Object> properties = new HashMap<String, Object>(); properties.put("mtom-enabled", Boolean.TRUE); cpfb.setProperties(properties); PublicInterface serviceInterface = (PublicInterface) cpfb.create(); client = ClientProxy.getClient(serviceInterface); HTTPConduit http = (HTTPConduit) client.getConduit(); http.getClient().setConnectionTimeout(360000); http.getClient().setAllowChunking(false); http.getClient().setReceiveTimeout(320000); if (!useSoapHeaderSessions) { ((BindingProvider) serviceInterface) .getRequestContext() .put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE); } add(interface1.getName(), serviceInterface); } tokenHolder.registerTokenChangeListener(this); notifyOfConnect(); }
public static Webservices getProxy() { final JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); proxyFactory.setServiceClass(Webservices.class); SettingsDataProvider settings = BeanProvider.getContextualReference(SettingsDataProvider.class); proxyFactory.setAddress(settings.getSetting("cmdbuild_url")); Object proxy = proxyFactory.create(); final Map<String, Object> outProps = new HashMap<String, Object>(); outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST); outProps.put(WSHandlerConstants.USER, settings.getSetting("cmdbuild_login")); outProps.put( WSHandlerConstants.PW_CALLBACK_REF, new ClientPasswordCallback(settings.getSetting("cmdbuild_pwd"))); final Client client = ClientProxy.getClient(proxy); final Endpoint cxfEndpoint = client.getEndpoint(); long timeout = 9000000000L; if (client != null) { HTTPConduit conduit = (HTTPConduit) client.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(timeout); policy.setReceiveTimeout(timeout); conduit.setClient(policy); } cxfEndpoint.getOutInterceptors().add(new WSS4JOutInterceptorWOExpire(outProps)); return (Webservices) proxy; }
/** * Closes the transport level conduit in the client. Reopening a new connection, requires creating * a new client object using the build() method in this builder. * * @param root The resource returned by the build() method of this builder class */ public static void closeClient(ApiRootResource root) { ClientConfiguration config = WebClient.getConfig(root); HTTPConduit conduit = config.getHttpConduit(); if (conduit == null) { throw new IllegalArgumentException("Client is not using the HTTP transport"); } conduit.close(); }
@PostConstruct public void init() { studyService = getService().getPort(StudyService.class); Client cl = ClientProxy.getClient(studyService); HTTPConduit httpConduit = (HTTPConduit) cl.getConduit(); httpConduit.getClient().setReceiveTimeout(getConfigurationService().getWebServiceTimeout()); httpConduit.getClient().setConnectionTimeout(0); httpConduit.getClient().setConnection(ConnectionType.CLOSE); }
private void setupGreeter(String cfgResource, boolean useDecoupledEndpoint) throws NumberFormatException, MalformedURLException { SpringBusFactory bf = new SpringBusFactory(); controlBus = bf.createBus(); BusFactory.setDefaultBus(controlBus); ControlService cs = new ControlService(); control = cs.getControlPort(); updateAddressPort(control, PORT); assertTrue("Failed to start greeter", control.startGreeter(cfgResource)); greeterBus = bf.createBus(cfgResource); BusFactory.setDefaultBus(greeterBus); LOG.fine("Initialised greeter bus with configuration: " + cfgResource); if (null == comparator) { comparator = new PhaseComparator(); } if (null == inPhases) { inPhases = new ArrayList<Phase>(); inPhases.addAll(greeterBus.getExtension(PhaseManager.class).getInPhases()); Collections.sort(inPhases, comparator); } if (null == preLogicalPhase) { preLogicalPhase = getPhase(Phase.PRE_LOGICAL); } GreeterService gs = new GreeterService(); greeter = gs.getGreeterPort(); updateAddressPort(greeter, PORT); LOG.fine("Created greeter client."); if (!useDecoupledEndpoint) { return; } // programatically configure decoupled endpoint that is guaranteed to // be unique across all test cases decoupledEndpointPort++; decoupledEndpoint = "http://localhost:" + allocatePort("decoupled-" + decoupledEndpointPort) + "/decoupled_endpoint"; Client c = ClientProxy.getClient(greeter); HTTPConduit hc = (HTTPConduit) (c.getConduit()); HTTPClientPolicy cp = hc.getClient(); cp.setDecoupledEndpoint(decoupledEndpoint); LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint()); }
private TLSClientParameters getOrCreateAndSetTLSClientParameters(final HTTPConduit httpConduit) { TLSClientParameters tlsClientParameters = httpConduit.getTlsClientParameters(); if (tlsClientParameters == null) { tlsClientParameters = new TLSClientParameters(); httpConduit.setTlsClientParameters(tlsClientParameters); } return tlsClientParameters; }
private Client getClient() throws BusException, EndpointException { if (client == null) { client = clientFactory.create(); if (null != authorizationPolicy) { HTTPConduit conduit = (HTTPConduit) client.getConduit(); conduit.setAuthorization(authorizationPolicy); } } return client; }
public void configureService( String address, String pksFilename, String pksPassword, String trustPksFilename, String trustPksPassword) throws Exception { if (pksFilename != null && pksPassword != null && trustPksFilename != null && trustPksPassword != null) { System.setProperty("javax.net.ssl.keyStore", pksFilename); System.setProperty("javax.net.ssl.keyStorePassword", pksPassword); System.setProperty("javax.net.ssl.trustStore", trustPksFilename); System.setProperty("javax.net.ssl.trustStorePassword", trustPksPassword); } URL wsdlUrl = new URL(address + "?wsdl"); IoTaService service = new IoTaService(wsdlUrl); port = service.getPort(IoTaServicePortType.class); // turn off chunked transfer encoding Client client = ClientProxy.getClient(port); HTTPConduit httpConduit = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setAllowChunking(false); httpConduit.setClient(httpClientPolicy); if (pksFilename != null) { log.debug("Authenticating with certificate in file: " + pksFilename); if (!wsdlUrl.getProtocol().equalsIgnoreCase("https")) { throw new Exception("Authentication method requires the use of HTTPS"); } KeyStore keyStore = KeyStore.getInstance(pksFilename.endsWith(".p12") ? "PKCS12" : "JKS"); keyStore.load(new FileInputStream(new File(pksFilename)), pksPassword.toCharArray()); KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); keyManagerFactory.init(keyStore, pksPassword.toCharArray()); KeyStore trustStore = KeyStore.getInstance(trustPksFilename.endsWith(".p12") ? "PKCS12" : "JKS"); trustStore.load( new FileInputStream(new File(trustPksFilename)), trustPksPassword.toCharArray()); TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509"); trustManagerFactory.init(trustStore); TLSClientParameters tlscp = new TLSClientParameters(); tlscp.setSecureRandom(new SecureRandom()); tlscp.setKeyManagers(keyManagerFactory.getKeyManagers()); tlscp.setTrustManagers(trustManagerFactory.getTrustManagers()); httpConduit.setTlsClientParameters(tlscp); } }
public void excute() { URL wsdlURL = SBFIFATDImportAssetRetirmentSrv.WSDL_LOCATION; SBFIFATDImportAssetRetirmentSrv ss = new SBFIFATDImportAssetRetirmentSrv(wsdlURL, SERVICE_NAME); SBFIFAImportAssetRetirmentSrv port = ss.getSBFIFAImportAssetRetirmentSrvPort(); Client client = ClientProxy.getClient(port); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnectionTimeout(1000000000); // 连接时间 httpClientPolicy.setReceiveTimeout(1000000000); // 接收时间 httpClientPolicy.setAllowChunking(false); http.setClient(httpClientPolicy); { System.out.println("Invoking process..."); ImportAssetRetirmentSrvRequest _process_payload = null; _process_payload = new ImportAssetRetirmentSrvRequest(); MsgHeader msgHeader = new MsgHeader(); _process_payload.setMsgHeader(msgHeader); ImportAssetRetirmentSrvInputCollection collection = new ImportAssetRetirmentSrvInputCollection(); if (srvInputItems != null) { for (int i = 0; i < srvInputItems.size(); i++) { ImportAssetRetirmentSrvInputItem inputItem = srvInputItems.get(i); collection.getImportAssetRetirmentSrvInputItem().add(inputItem); } } // 传递数据集到request中 _process_payload.setImportAssetRetirmentSrvInputCollection(collection); ImportAssetRetirmentSrvResponse _process__return = port.process(_process_payload); System.out.println( "process.result=" + _process__return.getErrorFlag() + "||" + _process__return.getErrorMessage()); returnMessage.setErrorFlag(StrUtil.nullToString(_process__return.getErrorFlag())); returnMessage.setErrorMessage(_process__return.getErrorMessage()); if (_process__return.getErrorFlag().equals("Y")) { responseItemList = _process__return.getResponseCollecion().getResponseItem(); System.out.println("结果Y: " + responseItemList); } else { errorItemList = _process__return.getErrorCollection().getErrorItem(); int s1 = errorItemList.size(); for (int i = 0; i < s1; i++) { System.out.println("结果N: " + errorItemList.get(0).getERRORMESSAGE()); } } } }
public void excute() { URL wsdlURL = SBFIFATransAssetDeprecationSrv_Service.WSDL_LOCATION; SBFIFATransAssetDeprecationSrv_Service ss = new SBFIFATransAssetDeprecationSrv_Service(wsdlURL, SERVICE_NAME); com.sino.soa.mis.eip.fi.fa.sb_fi_fa_transassetdeprecationsrv.SBFIFATransAssetDeprecationSrv port = ss.getSBFIFATransAssetDeprecationSrvPort(); Client client = ClientProxy.getClient(port); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnectionTimeout(5400000); // 连接时间 httpClientPolicy.setReceiveTimeout(5400000); // 接收时间 httpClientPolicy.setAllowChunking(false); http.setClient(httpClientPolicy); { System.out.println("SB_FI_FA_TransAssetDeprecationSrv Invoking process..."); SBFIFATransAssetDeprecationSrvProcessRequest _process_payload = null; _process_payload = new SBFIFATransAssetDeprecationSrvProcessRequest(); _process_payload.setENVCODE(envCode); _process_payload.setPERIODNAME(periodName); long s = System.currentTimeMillis(); com.sino.soa.mis.eip.fi.fa.sb_fi_fa_transassetdeprecationsrv .SBFIFATransAssetDeprecationSrvProcessResponse _process__return = port.process(_process_payload); srvMessage.setErrorFlag(StrUtil.nullToString(_process__return.getERRORFLAG())); srvMessage.setErrorMessage(_process__return.getERRORMESSAGE()); System.out.println( "process.result=" + _process__return.getINSTANCEID() + "||" + _process__return.getERRORFLAG() + "||" + _process__return.getERRORMESSAGE()); System.out.println("耗时" + (System.currentTimeMillis() - s) + "毫秒"); } }
/** * 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; }
protected void setupHttpConduit(HTTPConduit httpConduit) { TLSClientParameters tlsClientParameters = tryToGetTLSClientParametersFromConduit(httpConduit); tlsClientParameters.setSSLSocketFactory(tryToGetSSLSocketFactory()); httpConduit.setTlsClientParameters(tlsClientParameters); }