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);
    }
  }
Esempio n. 3
0
  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;
  }
  @Override
  public void configure() {
    super.configure();

    HTTPClientPolicy httpClientPolicy = getHTTPClientPolicy();

    int timeout = getTimeoutFromConfig();
    httpClientPolicy.setReceiveTimeout(timeout);
    httpClientPolicy.setConnectionTimeout(timeout);
  }
  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());
  }
Esempio n. 6
0
  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());
        }
      }
    }
  }
 @Test
 public void testEqualClientPolicies() {
   ClientPolicyCalculator calc = new ClientPolicyCalculator();
   HTTPClientPolicy p1 = new HTTPClientPolicy();
   assertTrue(calc.equals(p1, p1));
   HTTPClientPolicy p2 = new HTTPClientPolicy();
   assertTrue(calc.equals(p1, p2));
   p1.setDecoupledEndpoint("http://localhost:8080/decoupled");
   assertTrue(!calc.equals(p1, p2));
   p2.setDecoupledEndpoint("http://localhost:8080/decoupled");
   assertTrue(calc.equals(p1, p2));
   p1.setReceiveTimeout(10000L);
   assertTrue(!calc.equals(p1, p2));
 }
  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;
  }
 @Test
 public void testCompatibleClientPolicies() {
   ClientPolicyCalculator calc = new ClientPolicyCalculator();
   HTTPClientPolicy p1 = new HTTPClientPolicy();
   assertTrue("Policy is not compatible with itself.", calc.compatible(p1, p1));
   HTTPClientPolicy p2 = new HTTPClientPolicy();
   assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
   p1.setBrowserType("browser");
   assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
   p1.setBrowserType(null);
   p1.setConnectionTimeout(10000);
   assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
   p1.setAllowChunking(false);
   assertTrue("Policies are compatible.", !calc.compatible(p1, p2));
   p2.setAllowChunking(false);
   assertTrue("Policies are compatible.", calc.compatible(p1, p2));
 }
  @Test
  public void testLongTimeouts() {
    ClientPolicyCalculator calc = new ClientPolicyCalculator();
    HTTPClientPolicy p1 = new HTTPClientPolicy();
    HTTPClientPolicy p2 = new HTTPClientPolicy();
    p2.setReceiveTimeout(120000);
    p2.setConnectionTimeout(60000);
    HTTPClientPolicy p = calc.intersect(p1, p2);
    assertEquals(120000, p.getReceiveTimeout());
    assertEquals(60000, p.getConnectionTimeout());

    p1 = new HTTPClientPolicy();
    p2 = new HTTPClientPolicy();
    p1.setReceiveTimeout(120000);
    p1.setConnectionTimeout(60000);
    p = calc.intersect(p1, p2);
    assertEquals(120000, p.getReceiveTimeout());
    assertEquals(60000, p.getConnectionTimeout());

    p2.setReceiveTimeout(50000);
    p2.setConnectionTimeout(20000);
    p = calc.intersect(p1, p2);
    // p1 should have priority
    assertEquals(120000, p.getReceiveTimeout());
    assertEquals(60000, p.getConnectionTimeout());

    // reverse intersect
    p = calc.intersect(p2, p1);
    // p2 should have priority
    assertEquals(50000, p.getReceiveTimeout());
    assertEquals(20000, p.getConnectionTimeout());
  }
  @Test
  public void testIntersectClientPolicies() {
    ClientPolicyCalculator calc = new ClientPolicyCalculator();
    HTTPClientPolicy p1 = new HTTPClientPolicy();
    HTTPClientPolicy p2 = new HTTPClientPolicy();
    HTTPClientPolicy p = null;

    p1.setBrowserType("browser");
    p = calc.intersect(p1, p2);
    assertEquals("browser", p.getBrowserType());
    p1.setBrowserType(null);
    p1.setConnectionTimeout(10000L);
    p = calc.intersect(p1, p2);
    assertEquals(10000L, p.getConnectionTimeout());
    p1.setAllowChunking(false);
    p2.setAllowChunking(false);
    p = calc.intersect(p1, p2);
    assertTrue(!p.isAllowChunking());
  }
Esempio n. 14
0
    @Override
    public DataSource invoke(DataSource msg) {
      try {
        final URL url = new URL(this.endpoint);
        final String httpMethod =
            (String) this.requestContext.get(MessageContext.HTTP_REQUEST_METHOD);

        Map<String, List<String>> header =
            (Map<String, List<String>>)
                this.requestContext.get(MessageContext.HTTP_REQUEST_HEADERS);
        for (Map.Entry<String, List<String>> entry : header.entrySet()) {
          this.client.header(entry.getKey(), entry.getValue().toArray());
        }
        String username = (String) this.requestContext.get(Dispatch.USERNAME_PROPERTY);
        String password = (String) this.requestContext.get(Dispatch.PASSWORD_PROPERTY);

        if (username != null) {
          this.client.header(
              AUTHORIZATION,
              "Basic " + Base64.encodeBytes((username + ':' + password).getBytes())); // $NON-NLS-1$
        } else if (this.requestContext.get(GSSCredential.class.getName()) != null) {
          WebClient.getConfig(this.client)
              .getRequestContext()
              .put(
                  GSSCredential.class.getName(),
                  this.requestContext.get(GSSCredential.class.getName()));
          WebClient.getConfig(this.client)
              .getRequestContext()
              .put("auth.spnego.requireCredDelegation", true); // $NON-NLS-1$
        } else if (this.requestContext.get(OAuthCredential.class.getName()) != null) {
          OAuthCredential credential =
              (OAuthCredential) this.requestContext.get(OAuthCredential.class.getName());
          this.client.header(
              AUTHORIZATION, credential.getAuthorizationHeader(this.endpoint, httpMethod));
        }

        InputStream payload = null;
        if (msg != null) {
          payload = msg.getInputStream();
        }

        HTTPClientPolicy clientPolicy =
            WebClient.getConfig(this.client).getHttpConduit().getClient();
        Long timeout = (Long) this.requestContext.get(RECEIVE_TIMEOUT);
        if (timeout != null) {
          clientPolicy.setReceiveTimeout(timeout);
        }
        timeout = (Long) this.requestContext.get(CONNECTION_TIMEOUT);
        if (timeout != null) {
          clientPolicy.setConnectionTimeout(timeout);
        }

        javax.ws.rs.core.Response response = this.client.invoke(httpMethod, payload);
        this.responseContext.put(WSConnection.STATUS_CODE, response.getStatus());
        this.responseContext.putAll(response.getMetadata());

        ArrayList contentTypes =
            (ArrayList) this.responseContext.get("content-type"); // $NON-NLS-1$
        String contentType =
            contentTypes != null
                ? (String) contentTypes.get(0)
                : "application/octet-stream"; //$NON-NLS-1$
        return new HttpDataSource(url, (InputStream) response.getEntity(), contentType);
      } catch (IOException e) {
        throw new WebServiceException(e);
      }
    }