예제 #1
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;
  }
  @Override
  public void runSuccessCase() {
    log.debug("Running Throttle Mediator SuccessCase ");
    int throttleCounter = 0;
    OMElement result = null;

    try {
      ConfigServiceAdminStub configServiceAdminStub =
          new ConfigServiceAdminStubCommand().initConfigServiceAdminStub(sessionCookie);
      LogViewerStub logViewerStub = new InitializeLogViewerAdmin().executeAdminStub();

      String xmlPath =
          frameworkPath
              + File.separator
              + "mediators-throttle"
              + File.separator
              + "src"
              + File.separator
              + "test"
              + File.separator
              + "resources"
              + File.separator
              + "throttleOnAcceptSeqKey.xml";
      OMElement omElement = ConfigHelper.createOMElement(xmlPath);

      new ConfigServiceAdminStubCommand(configServiceAdminStub)
          .updateConfigurationExecuteSuccessCase(omElement);

      /*Sending StockQuoteClient requests */
      for (int i = 0; i <= THROTTLE_MAX_MSG_COUNT; i++) {
        StockQuoteClient stockQuoteClient = new StockQuoteClient();
        if (FrameworkSettings.STRATOS.equalsIgnoreCase("false")) {
          result =
              stockQuoteClient.stockQuoteClientforProxy(
                  "http://" + FrameworkSettings.HOST_NAME + ":" + FrameworkSettings.HTTP_PORT,
                  null,
                  "IBM");
        } else if (FrameworkSettings.STRATOS.equalsIgnoreCase("true")) {
          result =
              stockQuoteClient.stockQuoteClientforProxy(
                  "http://"
                      + FrameworkSettings.HOST_NAME
                      + ":"
                      + FrameworkSettings.HTTP_PORT
                      + "/services/"
                      + FrameworkSettings.TENANT_NAME
                      + "/",
                  null,
                  "IBM");
        }

        System.out.println(result);
        if (!result.toString().contains("IBM")) {
          log.error("Required response not found");
          Assert.fail("Required response not found");
        }
        log.info(result);
        throttleCounter++;
      }
      if (throttleCounter > THROTTLE_MAX_MSG_COUNT) {
        if (result.toString().contains("IBM")) {
          log.error("Required response not found.replying service");
          Assert.fail("Required response not found.replying service");
        }
      } else {
        log.error("Throttling response count does not match or max response count error");
        Assert.fail("Throttling response count does not match");
      }
    } catch (Exception e) {
      if (!e.getMessage().contains("**Access Denied**")) {
        log.error("Throttle Mediator doesn't work : " + e.getMessage());
      }
    }
  }
  @Override
  public void runSuccessCase() {
    log.debug("Running Custom Level Log Mediator SuccessCase ");
    OMElement result = null;
    boolean isFound_search_l1 = false;
    boolean isFound_search_l2 = false;
    boolean isFound_search_l3 = false;

    StockQuoteClient stockQuoteClient = new StockQuoteClient();

    try {
      ConfigServiceAdminStub configServiceAdminStub =
          new ConfigServiceAdminStubCommand().initConfigServiceAdminStub(sessionCookie);
      LogViewerStub logViewerStub = new InitializeLogViewerAdmin().executeAdminStub();

      String xmlPath =
          frameworkPath
              + File.separator
              + "components"
              + File.separator
              + "mediators-log"
              + File.separator
              + "src"
              + File.separator
              + "test"
              + File.separator
              + "resources"
              + File.separator
              + "custom"
              + File.separator
              + "synapse.xml";

      OMElement omElement = ConfigHelper.createOMElement(xmlPath);

      new ConfigServiceAdminStubCommand(configServiceAdminStub)
          .updateConfigurationExecuteSuccessCase(omElement);

      /*Sending a StockQuoteClient request*/
      if (FrameworkSettings.STRATOS.equalsIgnoreCase("false")) {
        result =
            stockQuoteClient.stockQuoteClientforProxy(
                "http://" + FrameworkSettings.HOST_NAME + ":" + FrameworkSettings.HTTP_PORT,
                null,
                "IBM");
      } else if (FrameworkSettings.STRATOS.equalsIgnoreCase("true")) {
        result =
            stockQuoteClient.stockQuoteClientforProxy(
                "http://"
                    + FrameworkSettings.HOST_NAME
                    + ":"
                    + FrameworkSettings.HTTP_PORT
                    + "/services/"
                    + FrameworkSettings.TENANT_NAME
                    + "/",
                null,
                "IBM");
      }
      log.info(result);

      System.out.println(result);

      if (!result.toString().contains("IBM")) {
        Assert.fail();
        log.error("Custom Level Log Mediation Failed");
      }
      LogMessage[] logMessages =
          new LogViewerAdminCommand(logViewerStub).addEntrySuccessCase("LogMediator");
      int removeMessageLength = 0;
      if (logMessages.length > 4) {
        removeMessageLength = logMessages.length - 3;
      } else {
        removeMessageLength = 0;
      }
      for (int i = removeMessageLength; i <= logMessages.length - 1; i++) {
        System.out.println(logMessages[i].getLogMessage());
        if (logMessages[i].getLogMessage().contains(search_l1)) {
          isFound_search_l1 = true;
        }
        if (logMessages[i].getLogMessage().contains(search_l2)) {
          isFound_search_l2 = true;
        }
        if (logMessages[i].getLogMessage().contains(search_l3)) {
          isFound_search_l3 = true;
        }
      }
      assertTrue("inComing = ***Incoming Message***@ not found in log message", isFound_search_l1);
      assertTrue(
          "inExpression = Echo String - urn:getQuote not found in log message", isFound_search_l2);
      assertTrue("outgoing = ***Outgoing Message*** not found in log message", isFound_search_l3);
    } catch (Exception e) {
      log.error("Custom Level Log Mediator doesn't work : " + e.getMessage());
    }
  }
예제 #4
0
  @Override
  public void runSuccessCase() {
    log.debug("Running Chunk Default SuccessCase ");
    StockQuoteClient stockQuoteClient = new StockQuoteClient();
    OMElement result = null;

    try {
      ConfigServiceAdminStub configServiceAdminStub =
          new ConfigServiceAdminStubCommand().initConfigServiceAdminStub(sessionCookie);

      // home/thilini/Desktop/new/component-test-framework/components/synapse-nhttp-transport/src/test/resources
      String xmlPath =
          frameworkPath
              + File.separator
              + "components"
              + File.separator
              + "synapse-nhttp-transport"
              + File.separator
              + "src"
              + File.separator
              + "test"
              + File.separator
              + "resources"
              + File.separator
              + "chunking_default.xml";
      System.out.println(xmlPath);
      OMElement omElement = ConfigHelper.createOMElement(xmlPath);

      new ConfigServiceAdminStubCommand(configServiceAdminStub)
          .updateConfigurationExecuteSuccessCase(omElement);
      String trpUrl = null;
      if (FrameworkSettings.STRATOS.equalsIgnoreCase("false")) {
        trpUrl = "http://" + FrameworkSettings.HOST_NAME + ":" + FrameworkSettings.HTTP_PORT;
        result = stockQuoteClient.stockQuoteClientforProxy(trpUrl, null, "IBM");
      } else if (FrameworkSettings.STRATOS.equalsIgnoreCase("true")) {
        result =
            stockQuoteClient.stockQuoteClientforProxy(
                "http://"
                    + FrameworkSettings.HOST_NAME
                    + "/services/"
                    + FrameworkSettings.TENANT_NAME
                    + "/",
                null,
                "IBM");
      }
      log.info(result);
      System.out.println(result);
      // <ns:getQuoteResponse xmlns:ns="http://services.samples"><ns:return
      // xmlns:ax21="http://services.samples/xsd"
      // xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      // xsi:type="ax21:GetQuoteResponse"><ax21:change>4.488382103511101</ax21:change><ax21:earnings>-8.983387861433535</ax21:earnings><ax21:high>-54.85240340206867</ax21:high><ax21:last>55.185600908158364</ax21:last><ax21:lastTradeTimestamp>Tue Oct 19 11:18:43 IST 2010</ax21:lastTradeTimestamp><ax21:low>-54.739935633390765</ax21:low><ax21:marketCap>1.4210456725425582E7</ax21:marketCap><ax21:name>IBM Company</ax21:name><ax21:open>57.531671038463294</ax21:open><ax21:peRatio>23.993007092941014</ax21:peRatio><ax21:percentageChange>7.542848922991673</ax21:percentageChange><ax21:prevClose>59.50513061225283</ax21:prevClose><ax21:symbol>IBM</ax21:symbol><ax21:volume>15739</ax21:volume></ns:return></ns:getQuoteResponse>

      /*Test HTTP Header Contents*/

      URL url = new URL(trpUrl);
      URLConnection conn = url.openConnection();

      for (int i = 0; ; i++) {
        String name = conn.getHeaderFieldKey(i);
        String value = conn.getHeaderField(i);
        if (name == null && value == null) {
          break;
        }
        if (name == null) {
          System.out.println("Server HTTP version, Response code:");
          System.out.println(value);
          System.out.print("\n");
        } else {
          System.out.println(name + "=" + value);
        }
      }

      /*
      int contentLength = ((HttpURLConnection) url.openConnection())
              .getContentLength();
      String trnsEncoding = ((HttpURLConnection) url.openConnection())
              .getContentType();

      System.out.println("********** " + contentLength + "********** ");
      System.out.println("********** " + trnsEncoding + "********** ");*/

      /*  if (!contentType.contains("application/xml; charset=UTF-8")) {
          Assert.fail("Message Relay Content Type Test not Failed");
          log.error("Message Relay Content Type Test not Failed");
      }*/

    } catch (Exception e) {
      e.printStackTrace();
      log.error("Chunk Default Test doesn't work : " + e.getMessage());
    }
  }