/**
   * This test ensures that the interceptor count is the same no matter how many times the decorator
   * is called on the constructor.
   */
  @Test
  public void ensureInterceptorCountIsConstant() {
    CONNECTClient<TestServicePortType> client = createClient();

    Client cxfClient = ClientProxy.getClient(client.getPort());
    int numOutInterceptors = cxfClient.getOutInterceptors().size();

    createClient();
    createClient();
    CONNECTClient<TestServicePortType> client2 = createClient();

    Client cxfClient2 = ClientProxy.getClient(client2.getPort());
    assertEquals(numOutInterceptors, cxfClient2.getOutInterceptors().size());
  }
示例#2
0
  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();
  }
示例#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;
  }
示例#4
0
  @Test
  public void testSaml1() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    inProperties.setValidateSamlSubjectConfirmation(false);
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(WSHandlerConstants.ACTION, WSHandlerConstants.SAML_TOKEN_UNSIGNED);
    properties.put(WSHandlerConstants.SAML_CALLBACK_REF, new SAML1CallbackHandler());

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
  }
  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;
  }
示例#6
0
  @Test
  public void testServerFactoryBean() throws Exception {
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello");
    svrBean.setTransportId("http://schemas.xmlsoap.org/soap/http");
    svrBean.setServiceBean(new HelloServiceImpl());
    svrBean.setServiceClass(HelloService.class);
    svrBean.setBus(getBus());

    svrBean.create();

    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress("http://localhost/Hello");
    clientBean.setTransportId("http://schemas.xmlsoap.org/soap/http");
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(getBus());
    clientBean.getInInterceptors().add(new LoggingInInterceptor());

    HelloService client = (HelloService) proxyFactory.create();

    ClientImpl c = (ClientImpl) ClientProxy.getClient(client);
    c.getOutInterceptors().add(new LoggingOutInterceptor());
    c.getInInterceptors().add(new LoggingInInterceptor());

    assertEquals("hello", client.sayHello());
    assertEquals("hello", client.echo("hello"));
  }
示例#7
0
  @Test
  public void testSaml1SignedSenderVouches() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    Properties cryptoProperties =
        CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
    inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(WSHandlerConstants.ACTION, WSHandlerConstants.SAML_TOKEN_SIGNED);
    properties.put(WSHandlerConstants.SAML_CALLBACK_REF, new SAML1CallbackHandler());

    properties.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
    properties.put(WSHandlerConstants.USER, "alice");
    properties.put(WSHandlerConstants.PW_CALLBACK_REF, new PasswordCallbackHandler());
    properties.put(WSHandlerConstants.SIG_PROP_FILE, "alice.properties");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
  }
  public void init() {
    Bus oldbus = BusFactory.getThreadDefaultBus();
    BusFactory.setThreadDefaultBus(bus);
    try {
      GreeterService service =
          new GreeterService(GreeterTargetBean.class.getResource("/wsdl/hello_world.wsdl"));
      greeter = service.getGreeterPort();
      if (address != null) {
        ((BindingProvider) greeter)
            .getRequestContext()
            .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
      }
      client = ClientProxy.getClient(greeter);
      System.out.println("Greeter endpoint: " + client.getEndpoint().getEndpointInfo());

    } catch (RuntimeException e) {
      e.printStackTrace();
      throw e;
    } catch (Error e) {
      e.printStackTrace();
      throw e;
    } finally {
      BusFactory.setThreadDefaultBus(oldbus);
    }
  }
  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);
    }
  }
示例#10
0
  // In this test, the service is using the UsernameTokenInterceptor, but the
  // client is using the WSS4JOutInterceptor
  @org.junit.Test
  public void testPasswordHashedNoBindingReplay() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = UsernameTokenTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    SpringBusFactory.setDefaultBus(bus);
    SpringBusFactory.setThreadDefaultBus(bus);

    URL wsdl = UsernameTokenTest.class.getResource("DoubleItUt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);

    QName portQName = new QName(NAMESPACE, "DoubleItDigestNoBindingPort");
    DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

    if (!test.isStreaming() && PORT.equals(test.getPort())) {
      Client cxfClient = ClientProxy.getClient(utPort);
      SecurityHeaderCacheInterceptor cacheInterceptor = new SecurityHeaderCacheInterceptor();
      cxfClient.getOutInterceptors().add(cacheInterceptor);

      // Make two invocations with the same UsernameToken
      utPort.doubleIt(25);
      try {
        utPort.doubleIt(25);
        fail("Failure expected on a replayed UsernameToken");
      } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        assertTrue(ex.getMessage().equals(WSSecurityException.UNIFIED_SECURITY_ERR));
      }
    }

    ((java.io.Closeable) utPort).close();
    bus.shutdown(true);
  }
  private void setWSS4JOutInterceptor(Object service) {
    Client client = ClientProxy.getClient(service);
    Endpoint cxfEP = client.getEndpoint();

    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);

    cxfEP.getOutInterceptors().add(wssOut);
  }
示例#12
0
  @Test
  public void testSaml2TokenHOK() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    Properties cryptoProperties =
        CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
    inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);

    CustomStaxSamlValidator validator = new CustomStaxSamlValidator();
    inProperties.addValidator(WSConstants.SAML_TOKEN, validator);
    inProperties.addValidator(WSConstants.SAML2_TOKEN, validator);

    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(WSHandlerConstants.ACTION, WSHandlerConstants.SAML_TOKEN_SIGNED);
    SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
    callbackHandler.setSignAssertion(true);
    properties.put(WSHandlerConstants.SAML_CALLBACK_REF, callbackHandler);

    properties.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
    properties.put(WSHandlerConstants.USER, "alice");
    properties.put(WSHandlerConstants.PW_CALLBACK_REF, new PasswordCallbackHandler());
    properties.put(WSHandlerConstants.SIG_PROP_FILE, "alice.properties");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    try {
      echo.echo("test");
      fail("Failure expected on receiving sender vouches instead of HOK");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
      // expected
    }
    validator.setRequireSenderVouches(false);

    try {
      echo.echo("test");
      fail("Failure expected on receiving a SAML 1.1 Token instead of SAML 2.0");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
      // expected
    }
    validator.setRequireSAML1Assertion(false);

    assertEquals("test", echo.echo("test"));
  }
示例#13
0
 @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);
 }
示例#14
0
  private MetadataModelServicePortType getMMSSoapClient()
      throws GeneralSecurityException, IOException {

    MetadataModelServicePortType mmsPort = MMSSoapClientFactory.createSoapClient(MMS_URL);
    Client client = ClientProxy.getClient(mmsPort);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    return mmsPort;
  }
  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());
  }
示例#16
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);
    }
  }
示例#17
0
  void prepareRequest(
      String actionURI, String shellId, String messageId, HashMap<String, String> options) {
    // add SOAP headers
    List<Header> soapHeaders =
        getSOAPHeaders(actionURI, URI_RESOURCE_SHELL_CMD, shellId, messageId, options);

    Client proxy = ClientProxy.getClient(wsmanService);
    proxy.getRequestContext().put(Header.HEADER_LIST, soapHeaders);
    proxy.getRequestContext().put("SOAPAction", actionURI);

    transport.setupAuth(proxy);
  }
  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());
        }
      }
    }
  }
示例#19
0
  @Test
  public void testClientProxyFactory() {

    JaxWsProxyFactoryBean cf = new JaxWsProxyFactoryBean();
    cf.setAddress("http://localhost:" + PORT + "/test");
    cf.setServiceClass(Greeter.class);
    cf.setBus(getBus());
    Configurer c = getBus().getExtension(Configurer.class);
    c.configureBean("client.proxyFactory", cf);
    Greeter greeter = (Greeter) cf.create();
    Client client = ClientProxy.getClient(greeter);
    checkAddressInterceptors(client.getInInterceptors());
  }
示例#20
0
  /**
   * Returns a client stub for the web-service.
   *
   * <p>This method reuses the last stub created by the current thread.
   *
   * @return the client stub.
   */
  public synchronized Object getClient() {
    if (threadLocalPort.get() == null) {
      URL wsdlURL =
          getClass().getClassLoader().getResource(wsTransactionConfiguration.getWsdlLocation());
      Service service = Service.create(wsdlURL, wsTransactionConfiguration.getServiceName());
      Object port = service.getPort(wsTransactionConfiguration.getSei());
      Client client = ClientProxy.getClient(port);
      configureBinding(port);
      configureInterceptors(client);

      threadLocalPort.set(port);
      LOG.debug("Created client adapter for: {}", wsTransactionConfiguration.getServiceName());
    }
    return threadLocalPort.get();
  }
  /**
   * This method verifies that the passed in client is configured for Ws-Security properly.
   *
   * @param client
   */
  public void verifyWsSecurityProperties(CONNECTClient<?> client) {
    Client clientProxy = ClientProxy.getClient(client.getPort());

    WSS4JOutInterceptor wss4jInterceptor = null;
    for (Interceptor<? extends Message> interceptor : clientProxy.getOutInterceptors()) {
      if (interceptor instanceof WSS4JOutInterceptor) {
        wss4jInterceptor = (WSS4JOutInterceptor) interceptor;
        break;
      }
    }

    assertNotNull(wss4jInterceptor);
    assertTrue(wss4jInterceptor.isAllowMTOM());

    Map<String, Object> properties = wss4jInterceptor.getProperties();
    new WsSecurityConfigFactoryTest().verifyWsSecurityProperties(properties);
  }
  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) + "毫秒");
    }
  }
 /** Construction of ConferenceServiceHandler class */
 public ConferenceServiceHandler(final String webServiceUrl) {
   if (webServiceUrl.contains("rest")) {
     final JsonInvocationHandler jsonInvocationHandler =
         JsonInvocationHandler.getInstance(webServiceUrl);
     port = (JConferenceService) jsonInvocationHandler.getProxy(JConferenceService.class);
   } else {
     final URL wsdlURL =
         ConferenceServiceHandler.class
             .getClassLoader()
             .getResource("wsdl/current/JConferenceService.wsdl");
     final JConferenceService_Service ss = new JConferenceService_Service(wsdlURL, SERVICE_NAME);
     port = ss.getJConferenceServicePort();
     final BindingProvider provider = (BindingProvider) port;
     provider
         .getRequestContext()
         .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, webServiceUrl + "/JConferenceService");
     // https support
     CommonUtils.httpsConnectionSupport(port);
     // Add custom SOAPAction header interceptor here
     final Client client = ClientProxy.getClient(port);
     final Endpoint cxfEndpoint = client.getEndpoint();
     cxfEndpoint.getOutInterceptors().add(new SoapHeaderOutInterceptor());
   }
 }
示例#24
0
  /**
   * 利用cxf工具, 将cxf的bin目录配置到环境变量 注意, cxf挑剔jdk版本
   *
   * @param args
   */
  public static void main(String[] args) {

    /**
     * 生成webservie客户端代理的命令<br>
     * wsdl2java -d 根目录 -p 包结构 wsdlurl<br>
     * wsdl2java -d D:\WorkCatlog\sts_workspace\source\Example\src\main\java -p
     * webservice2.client.src http://localhost:9999/ws?wsdl<br>
     * wsdl2js http://localhost:9999/ws?wsdl
     */
    HelloWorld factory = new HelloWorld();
    HelloWorldService hwService = factory.getHelloWorldServiceImpPort();

    // 客户端增加拦截器, 也需要cxf的API
    org.apache.cxf.endpoint.Client client = ClientProxy.getClient(hwService);
    // client.getInInterceptors().add(new LoggingInInterceptor());
    // client.getOutInterceptors().add(new LoggingOutInterceptor());

    // 增加自定义的客户端out拦截器, 添加用户名和密码到header
    client.getOutInterceptors().add(new AddLoginInfo2HeaderOutInterceptor("aaa", "ccc"));
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    User user = new User();
    user.setName("聂宾潇");
    List<Cat> cats = hwService.queryCatByUser(user);
    for (Cat cat : cats) {
      System.out.println(cat.getName() + ":" + cat.getColor());
    }

    StringCat stringCats = hwService.getAllCats();
    List<Entry> entrys = stringCats.getEntrys();
    for (Entry entry : entrys) {
      System.out.println(entry.getKey() + ":" + entry.getValue().getName());
    }

    /**
     * soap消息请求和输出体
     *
     * <pre>
     * [2015-08-23 20:47:35] [INFO] [org.apache.cxf.interceptor.AbstractLoggingInterceptor]Inbound Message
     * 			----------------------------
     * 			ID: 1
     * 			Address: /ws
     * 			Encoding: UTF-8
     * 			Content-Type: text/xml; charset=UTF-8
     * 			Headers: {content-type=[text/xml; charset=UTF-8], connection=[keep-alive], Host=[localhost:9999], Content-Length=[225], SOAPAction=[""], User-Agent=[Apache CXF 2.3.2], Content-Type=[text/xml; charset=UTF-8], Accept=[*/*], Pragma=[no-cache], Cache-Control=[no-cache]}
     * 			Payload:
     * 					<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
     * 						<soap:Body>
     * 							<ns2:queryCatByUser xmlns:ns2="http://service.webservice2/">
     * 								<user>
     * 									<name>聂宾潇</name>
     * 								</user>
     * 							</ns2:queryCatByUser>
     * 						</soap:Body>
     * 			 		</soap:Envelope>
     * 			--------------------------------------
     *
     *
     * 			[2015-08-23 20:47:35] [INFO] [org.apache.cxf.interceptor.AbstractLoggingInterceptor]Outbound Message
     * 			---------------------------
     * 			ID: 1
     * 			Encoding: UTF-8
     * 			Content-Type: text/xml
     * 			Headers: {}
     * 			Payload:
     * 					<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
     * 						<soap:Body>
     * 							<ns2:queryCatByUserResponse xmlns:ns2="http://service.webservice2/">
     * 								<cats><color>red</color><name>小呆比</name></cats>
     * 								<cats><color>yellow</color><name>大代笔</name></cats>
     * 							</ns2:queryCatByUserResponse>
     * 						</soap:Body>
     * 					</soap:Envelope>
     * </pre>
     */
  }