Esempio n. 1
0
  public static Test suite() throws Exception {
    FrameworkSettings.getProperty();
    String frameworkPath = FrameworkSettings.getFrameworkPath();
    System.setProperty("java.util.logging.config.file", frameworkPath + "/lib/log4j.properties");
    TestSuite testSuite = new TestSuite();

    // testSuite.addTestSuite(SendMediatorTest.class);
    testSuite.addTestSuite(ANonSendTest.class);
    testSuite.addTestSuite(NonSendTest.class);
    testSuite.addTestSuite(RegeprSendTest.class);

    return testSuite;
  }
Esempio n. 2
0
  public OMElement runSecurityClient(
      int scenarioNo, String serviceName, String soapAction, String body) throws Exception {

    FrameworkSettings.getProperty();
    String clientRepo = null;
    String trustStore = null;
    String endpointHttpS = null;
    String endpointHttp = null;
    String securityPolicy = null;
    String clientKey = null;

    File filePath = new File("./");
    String relativePath = filePath.getCanonicalPath();
    File findFile =
        new File(
            relativePath + File.separator + "config" + File.separator + "framework.properties");
    if (!findFile.isFile()) {
      filePath = new File("./../");
      relativePath = filePath.getCanonicalPath();
    }

    /*Properties properties = new Properties();
    FileInputStream freader = new FileInputStream(relativePath + File.separator + "proxyservices" + File.separator + "src" + File.separator + "test" + File.separator + "resources"+ File.separator + "ClientSecurityFiles" + File.separator + "client.properties");
    properties.load(freader);*/
    if (FrameworkSettings.STRATOS.equalsIgnoreCase("true")) {
      clientRepo =
          FrameworkSettings.TEST_FRAMEWORK_HOME
              + File.separator
              + "lib"
              + File.separator
              + "stratos-artifacts"
              + File.separator
              + "client_repo";
      endpointHttpS =
          "https://"
              + FrameworkSettings.HOST_NAME
              + ":"
              + FrameworkSettings.HTTPS_PORT
              + "/services/"
              + FrameworkSettings.TENANT_NAME
              + "/"
              + serviceName;
      endpointHttp =
          "http://"
              + FrameworkSettings.HOST_NAME
              + ":"
              + FrameworkSettings.HTTP_PORT
              + "/services/"
              + FrameworkSettings.TENANT_NAME
              + "/"
              + serviceName;
      clientKey =
          FrameworkSettings.TEST_FRAMEWORK_HOME
              + File.separator
              + "lib"
              + File.separator
              + "stratos-artifacts"
              + File.separator
              + "wso2carbon.jks";
      trustStore =
          FrameworkSettings.TEST_FRAMEWORK_HOME
              + File.separator
              + "lib"
              + File.separator
              + "stratos-artifacts"
              + File.separator
              + "wso2carbon.jks";
      securityPolicy =
          relativePath
              + File.separator
              + "proxyservices"
              + File.separator
              + "src"
              + File.separator
              + "test"
              + File.separator
              + "resources"
              + File.separator
              + "ClientSecurityFiles";

    } else if (FrameworkSettings.STRATOS.equalsIgnoreCase("false")) {
      clientRepo =
          FrameworkSettings.CARBON_HOME
              + File.separator
              + "samples"
              + File.separator
              + "axis2Client"
              + File.separator
              + "client_repo";
      endpointHttpS =
          "https://"
              + FrameworkSettings.HOST_NAME
              + ":"
              + FrameworkSettings.HTTPS_PORT
              + "/services/"
              + serviceName;
      endpointHttp =
          "http://"
              + FrameworkSettings.HOST_NAME
              + ":"
              + FrameworkSettings.HTTP_PORT
              + "/services/"
              + serviceName;
      clientKey =
          FrameworkSettings.CARBON_HOME
              + File.separator
              + "resources"
              + File.separator
              + "security"
              + File.separator
              + "wso2carbon.jks";
      trustStore =
          FrameworkSettings.CARBON_HOME
              + File.separator
              + "resources"
              + File.separator
              + "security"
              + File.separator
              + "wso2carbon.jks";
      securityPolicy =
          relativePath
              + File.separator
              + "proxyservices"
              + File.separator
              + "src"
              + File.separator
              + "test"
              + File.separator
              + "resources"
              + File.separator
              + "ClientSecurityFiles";
    }
    OMElement result;

    System.setProperty("javax.net.ssl.trustStore", trustStore);
    System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");

    ConfigurationContext ctx =
        ConfigurationContextFactory.createConfigurationContextFromFileSystem(clientRepo, null);
    ServiceClient sc = new ServiceClient(ctx, null);
    sc.engageModule("rampart");
    sc.engageModule("addressing");

    Options opts = new Options();

    if (scenarioNo == 1) {
      opts.setTo(new EndpointReference(endpointHttpS));
    } else {
      opts.setTo(new EndpointReference(endpointHttp));
    }

    opts.setAction(soapAction);

    if (scenarioNo != 0) {
      try {
        String securityPolicyPath =
            securityPolicy + File.separator + "scenario" + scenarioNo + "-policy.xml";
        opts.setProperty(
            RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(securityPolicyPath, clientKey));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    sc.setOptions(opts);
    result = sc.sendReceive(AXIOMUtil.stringToOM(body));
    System.out.println(result.getFirstElement().getText());
    return result;
  }