@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());
  }
  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;
  }
Exemplo 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);
  }
  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 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 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());
  }
  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;
  }
Exemplo n.º 10
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);
      }
    }