コード例 #1
0
  /*
   * TODO: This is a first pass at filtering the properties that are set on the
   * RequestContext.  Right now it's called during the invoke, but needs to be
   * moved over to when the property is set.  This should not be in the path
   * of performance.
   */
  private void setupProperties(MessageContext mc) { // , Options ops) {

    // Enable MTOM
    Message msg = mc.getMessage();
    if (msg.isMTOMEnabled()) {
      mc.setProperty(Configuration.ENABLE_MTOM, "true");
    }

    // Enable session management
    if (mc.isMaintainSession()) {
      mc.getAxisMessageContext().getOptions().setManageSession(true);
    }

    // Check to see if BASIC_AUTH is enabled.  If so, make sure
    // the properties are setup correctly.
    if (mc.containsKey(BindingProvider.USERNAME_PROPERTY)
        || mc.containsKey(BindingProvider.PASSWORD_PROPERTY)) {

      String userId = (String) mc.getProperty(BindingProvider.USERNAME_PROPERTY);
      if (userId == null || userId == "") {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("checkUserName"));
      }

      String password = null;
      if (mc.containsKey(BindingProvider.PASSWORD_PROPERTY)) {
        password = (String) mc.getProperty(BindingProvider.PASSWORD_PROPERTY);
      }

      URL url = null;
      try {
        url = new URL((String) mc.getProperty(BindingProvider.ENDPOINT_ADDRESS_PROPERTY));
      } catch (MalformedURLException e) {
        throw ExceptionFactory.makeWebServiceException(e);
      }

      HttpTransportProperties.Authenticator basicAuthentication =
          new HttpTransportProperties.Authenticator();
      basicAuthentication.setUsername(userId);
      basicAuthentication.setPassword(password);
      basicAuthentication.setHost(url.getHost());
      basicAuthentication.setPort(url.getPort());
      basicAuthentication.setPreemptiveAuthentication(true);

      mc.setProperty(HTTPConstants.AUTHENTICATE, basicAuthentication);
    }
  }
コード例 #2
0
  @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);
    }
  }