Пример #1
0
  private void run() throws Exception {

    ConfigurationContext configurationContext = generateConfigContext();

    ServiceClient serviceClient = new ServiceClient(configurationContext, null);

    //		String replyAddress = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress() + "/" +
    // ServiceClient.ANON_OUT_ONLY_OP;
    String acksToAddress = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress();

    Options clientOptions = new Options();
    setUpOptions(clientOptions, acksToAddress);

    serviceClient.setOptions(clientOptions);

    serviceClient.fireAndForget(getPingOMBlock("ping1"));
    serviceClient.fireAndForget(getPingOMBlock("ping2"));
    serviceClient.fireAndForget(getPingOMBlock("ping3"));

    boolean complete = false;
    while (!complete) {
      SequenceReport sequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
      if (sequenceReport != null && sequenceReport.getCompletedMessages().size() == 3)
        complete = true;
      else {
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e1) {
          e1.printStackTrace();
        }
      }
    }

    SandeshaClient.terminateSequence(serviceClient);

    Thread.sleep(3000);

    configurationContext.getListenerManager().stop();
    serviceClient.cleanup();
  }
  @Override
  public void execute(WorkflowDTO workflowDTO) throws WorkflowException {

    if (log.isDebugEnabled()) {
      log.info("Executing Application creation Workflow..");
    }
    super.execute(workflowDTO);
    try {
      ServiceClient client =
          new ServiceClient(
              ServiceReferenceHolder.getContextService().getClientConfigContext(), null);

      Options options = new Options();
      options.setAction("http://workflow.application.apimgt.carbon.wso2.org/initiate");
      options.setTo(new EndpointReference(serviceEndpoint));

      if (contentType != null) {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType);
      } else {
        options.setProperty(
            Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_APPLICATION_XML);
      }

      HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();

      if (username != null && password != null) {
        auth.setUsername(username);
        auth.setPassword(password);
        auth.setPreemptiveAuthentication(true);
        List<String> authSchemes = new ArrayList<String>();
        authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
        auth.setAuthSchemes(authSchemes);
        options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
        options.setManageSession(true);
      }

      client.setOptions(options);

      String payload =
          "<wor:ApplicationApprovalWorkFlowProcessRequest xmlns:wor=\"http://workflow.application.apimgt.carbon.wso2.org\">\n"
              + "        <wor:applicationName>$1</wor:applicationName>\n"
              + "        <wor:applicationTier>$2</wor:applicationTier>\n"
              + "        <wor:applicationCallbackUrl>$3</wor:applicationCallbackUrl>\n"
              + "        <wor:applicationDescription>$4</wor:applicationDescription>\n"
              + "        <wor:tenantDomain>$5</wor:tenantDomain>\n"
              + "        <wor:userName>$6</wor:userName>\n"
              + "        <wor:workflowExternalRef>$7</wor:workflowExternalRef>\n"
              + "        <wor:callBackURL>$8</wor:callBackURL>\n"
              + "      </wor:ApplicationApprovalWorkFlowProcessRequest>";

      ApplicationWorkflowDTO appWorkFlowDTO = (ApplicationWorkflowDTO) workflowDTO;
      Application application = appWorkFlowDTO.getApplication();
      String callBackURL = appWorkFlowDTO.getCallbackUrl();

      payload = payload.replace("$1", application.getName());
      payload = payload.replace("$2", application.getTier());
      payload = payload.replace("$3", application.getCallbackUrl());
      payload = payload.replace("$4", application.getDescription());
      payload = payload.replace("$5", appWorkFlowDTO.getTenantDomain());
      payload = payload.replace("$6", appWorkFlowDTO.getUserName());
      payload = payload.replace("$7", appWorkFlowDTO.getExternalWorkflowReference());
      payload = payload.replace("$8", callBackURL != null ? callBackURL : "?");

      client.fireAndForget(AXIOMUtil.stringToOM(payload));

    } catch (AxisFault axisFault) {
      log.error("Error sending out message", axisFault);
      throw new WorkflowException("Error sending out message", axisFault);
    } catch (XMLStreamException e) {
      log.error("Error converting String to OMElement", e);
      throw new WorkflowException("Error converting String to OMElement", e);
    }
  }