Java Code Examples for org.apache.axis2.client.ServiceClient#fireAndForget()

The following examples show how to use org.apache.axis2.client.ServiceClient#fireAndForget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplicationRegistrationWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Override
public void cleanUpPendingTask(String workflowExtRef) throws WorkflowException {
    super.cleanUpPendingTask(workflowExtRef);
    String errorMsg = null;

    try {
        String action = WorkflowConstants.DELETE_REGISTRATION_WS_ACTION;
        ServiceClient client = getClient(action);
        String payload = "  <p:CancelApplicationRegistrationWorkflowProcessRequest " +
                "   xmlns:p=\"http://workflow.application.apimgt.carbon.wso2.org\">\n" +
                "   	<p:workflowRef>" + workflowExtRef + "</p:workflowRef>\n" +
                "   </p:CancelApplicationRegistrationWorkflowProcessRequest>";

        client.fireAndForget(AXIOMUtil.stringToOM(payload));
    } catch (AxisFault axisFault) {
        errorMsg = "Error sending out cancel pending registration approval process message. Cause: " + axisFault
                .getMessage();
        throw new WorkflowException(errorMsg, axisFault);
    } catch (XMLStreamException e) {
        errorMsg = "Error converting registration cleanup String to OMElement. Cause: " + e.getMessage();
        throw new WorkflowException(errorMsg, e);
    }
}
 
Example 2
Source File: WSEventDispatcher.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
protected void sendNotification(OMElement topicHeader,
                                OMElement payload,
                                String endpoint)
        throws AxisFault {
    // The parameter args is used as a mechanism to pass any argument into this method, which
    // is used by the implementations that extend the behavior of the default Carbon Event
    // Dispatcher.
    ServiceClient serviceClient = new ServiceClient();

    Options options = new Options();
    options.setTo(new EndpointReference(endpoint));
    options.setAction(EventingConstants.WSE_PUBLISH);
    serviceClient.setOptions(options);
    serviceClient.addHeader(topicHeader);

    serviceClient.fireAndForget(payload);
}
 
Example 3
Source File: WSEventDispatcher.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
protected synchronized void sendNotification(OMElement topicHeader,
                                OMElement tenantDomainHeader,
                                OMElement payload,
                                String endpoint)
        throws AxisFault {
    // The parameter args is used as a mechanism to pass any argument into this method, which
    // is used by the implementations that extend the behavior of the default Carbon Event
    // Dispatcher.
    ConfigurationContextService configurationContextService =
            WSEventBrokerHolder.getInstance().getConfigurationContextService();

    ServiceClient serviceClient =
            new ServiceClient(configurationContextService.getClientConfigContext(), null);

    Options options = new Options();
    options.setTo(new EndpointReference(endpoint));
    options.setAction(EventingConstants.WSE_PUBLISH);
    serviceClient.setOptions(options);
    serviceClient.addHeader(topicHeader);

    if (tenantDomainHeader != null){
        serviceClient.addHeader(tenantDomainHeader);
    }

    serviceClient.fireAndForget(payload);
}
 
Example 4
Source File: SubscriptionUpdateWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Override
public void cleanUpPendingTask(String workflowExtRef) throws WorkflowException {
    String errorMsg = null;
    super.cleanUpPendingTask(workflowExtRef);
    try {
        String action = WorkflowConstants.DELETE_SUBSCRIPTION_WS_ACTION;
        ServiceClient client = getClient(action);
        String payload = "<wor:CancelSubscriptionApprovalWorkflowProcessRequest " +
                "           xmlns:wor=\"http://workflow.subscription.apimgt.carbon.wso2.org\">\n" +
                "           <wor:workflowExtRef>" + workflowExtRef + "</wor:workflowExtRef>\n" +
                "        </wor:CancelSubscriptionApprovalWorkflowProcessRequest>";

        client.fireAndForget(AXIOMUtil.stringToOM(payload));
    } catch (AxisFault axisFault) {
        errorMsg = "Error sending out cancel pending subscription approval process message. cause: " + axisFault
                .getMessage();
        throw new WorkflowException(errorMsg, axisFault);
    } catch (XMLStreamException e) {
        errorMsg = "Error converting subscription cleanup String to OMElement. cause: " + e.getMessage();
        throw new WorkflowException(errorMsg, e);
    }
}
 
Example 5
Source File: SubscriptionCreationWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Override
public void cleanUpPendingTask(String workflowExtRef) throws WorkflowException {
    String errorMsg = null;
    super.cleanUpPendingTask(workflowExtRef);
    try {
        String action = WorkflowConstants.DELETE_SUBSCRIPTION_WS_ACTION;
        ServiceClient client = getClient(action);
        String payload = "<wor:CancelSubscriptionApprovalWorkflowProcessRequest " +
                "           xmlns:wor=\"http://workflow.subscription.apimgt.carbon.wso2.org\">\n" +
                "           <wor:workflowExtRef>" + workflowExtRef + "</wor:workflowExtRef>\n" +
                "        </wor:CancelSubscriptionApprovalWorkflowProcessRequest>";

        client.fireAndForget(AXIOMUtil.stringToOM(payload));
    } catch (AxisFault axisFault) {
        errorMsg = "Error sending out cancel pending subscription approval process message. cause: " + axisFault
                .getMessage();
        throw new WorkflowException(errorMsg, axisFault);
    } catch (XMLStreamException e) {
        errorMsg = "Error converting subscription cleanup String to OMElement. cause: " + e.getMessage();
        throw new WorkflowException(errorMsg, e);
    }
}
 
Example 6
Source File: UserSignUpWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Override
public void cleanUpPendingTask(String workflowExtRef) throws WorkflowException {
    String errorMsg;

    super.cleanUpPendingTask(workflowExtRef);
    try {
        String action = WorkflowConstants.DELETE_USER_WS_ACTION;
        ServiceClient client = getClient(action);

        String payload = "<p:CancelUserSignupProcessRequest " +
                "        xmlns:p=\"http://workflow.registeruser.apimgt.carbon.wso2.org\">" +
                "           <p:workflowRef>" + workflowExtRef + "</p:workflowRef>" +
                "        </p:CancelUserSignupProcessRequest>";

        client.fireAndForget(AXIOMUtil.stringToOM(payload));
    } catch (AxisFault axisFault) {
        errorMsg = "Error sending out cancel pending user signup approval process message. Cause: " + axisFault
                .getMessage();
        throw new WorkflowException(errorMsg, axisFault);
    } catch (XMLStreamException e) {
        errorMsg = "Error converting cancel user signup String to OMElement. Cause: " + e.getMessage();
        throw new WorkflowException(errorMsg, e);
    }
}
 
Example 7
Source File: ApplicationCreationWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Override
public void cleanUpPendingTask(String workflowExtRef) throws WorkflowException {
    String errorMsg;

    super.cleanUpPendingTask(workflowExtRef);
    try {
        String action = WorkflowConstants.DELETE_APPLICATION_WS_ACTION;
        ServiceClient client = getClient(action);

        String payload = "<p:CancelApplicationApprovalWorkflowProcessRequest " +
                "        xmlns:p=\"http://workflow.application.apimgt.carbon.wso2.org\">\n" +
                "           <p:workflowRef>" + workflowExtRef +
                "</p:workflowRef>\n" +
                "        </p:CancelApplicationApprovalWorkflowProcessRequest>";

        client.fireAndForget(AXIOMUtil.stringToOM(payload));
    } catch (AxisFault axisFault) {
        errorMsg = "Error sending out cancel pending application approval process message. cause: " + axisFault
                .getMessage();
        throw new WorkflowException(errorMsg, axisFault);
    } catch (XMLStreamException e) {
        errorMsg = "Error converting application cleanup String to OMElement. cause: " + e.getMessage();
        throw new WorkflowException(errorMsg, e);
    }
}
 
Example 8
Source File: ServiceChainingTest.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"wso2.esb"})
public void testTenantIDInTenantResponsePath() throws Exception {
    // create a tenant
    TenantManagementServiceClient tenantMgtAdminServiceClient = new TenantManagementServiceClient(contextUrls.getBackEndUrl(), sessionCookie);
    tenantMgtAdminServiceClient.addTenant("t5.com", "jhonporter", "jhon", "demo");
    // log as tenant
    AuthenticatorClient authClient = new AuthenticatorClient(contextUrls.getBackEndUrl());
    String session = authClient.login("[email protected]", "jhonporter", "localhost");
    // load configuration in tenant space
    esbUtils.loadESBConfigurationFrom("artifacts/ESB/ServiceChainingConfig.xml", contextUrls.getBackEndUrl(), session);
    // Create service client
    ServiceClient sc = getServiceClient("http://localhost:8480/services/t/t5.com/ServiceChainingProxy", null,
                                        "wso2");
    sc.fireAndForget(createStandardSimpleRequest("wso2"));
    // Get logs by tenant name
    LogViewerClient logViewerClient = new LogViewerClient(contextUrls.getBackEndUrl(), sessionCookie);
    ArrayList<LogEvent> logs = Utils.getLogsWithExpectedValue(logViewerClient, "INFO", "RECEIVE");
    Assert.assertNotNull(logs, "Expected logs were not found");
    LogEvent receiveSeqLog_1 = getLogEventByMessage(logs, "DEBUG SEQ 1 = FIRST RECEIVE SEQUENCE");
    Assert.assertNotNull(receiveSeqLog_1);
    LogEvent receiveSeqLog_2 = getLogEventByMessage(logs, "DEBUG SEQ 2 = SECOND RECEIVE SEQUENCE");
    Assert.assertNotNull(receiveSeqLog_2);
}
 
Example 9
Source File: AxisServiceClientUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static void sendRequestOneWay(String payloadStr, EndpointReference targetEPR)
        throws XMLStreamException, AxisFault {
    OMElement payload = AXIOMUtil.stringToOM(payloadStr);
    Options options = new Options();
    options.setTo(targetEPR);
    //options.setAction("urn:" + operation); //since soapAction = ""

    //Blocking invocation
    ServiceClient sender = new ServiceClient();
    sender.setOptions(options);
    sender.fireAndForget(payload);
}
 
Example 10
Source File: UserSignUpWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {

    if (log.isDebugEnabled()) {
        log.debug("Executing User SignUp Webservice Workflow for " + workflowDTO.getWorkflowReference());
    }

    try {
        String action = WorkflowConstants.REGISTER_USER_WS_ACTION;
        ServiceClient client = getClient(action);

        //get the default empty payload
        String payload = WorkflowConstants.REGISTER_USER_PAYLOAD;

        String callBackURL = workflowDTO.getCallbackUrl();
        String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(workflowDTO.getWorkflowReference());

        payload = payload.replace("$1", tenantAwareUserName);
        payload = payload.replace("$2", workflowDTO.getTenantDomain());
        payload = payload.replace("$3", workflowDTO.getExternalWorkflowReference());
        payload = payload.replace("$4", callBackURL != null ? callBackURL : "?");

        client.fireAndForget(AXIOMUtil.stringToOM(payload));
        super.execute(workflowDTO);
    } 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);
    }
    return new GeneralWorkflowResponse();
}
 
Example 11
Source File: StockQuoteClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * Send place order request
 *
 * @param trpUrl transport url
 * @param addUrl address url
 * @param symbol symbol
 * @throws AxisFault if error occurs when sending request
 */
public void sendPlaceOrderRequest(String trpUrl, String addUrl, String symbol) throws AxisFault {
    double price = getRandom(100, 0.9, true);
    int quantity = (int) getRandom(10000, 1.0, true);
    ServiceClient serviceClient = getServiceClient(trpUrl, addUrl, "placeOrder");
    try {
        serviceClient.fireAndForget(createPlaceOrderRequest(price, quantity, symbol));
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 12
Source File: AxisServiceClientUtils.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public static void sendRequestOneWay(String payloadStr, EndpointReference targetEPR)
        throws XMLStreamException, AxisFault {
    OMElement payload = AXIOMUtil.stringToOM(payloadStr);
    Options options = new Options();
    options.setTo(targetEPR);
    //options.setAction("urn:" + operation); //since soapAction = ""

    //Blocking invocation
    ServiceClient sender = new ServiceClient();
    sender.setOptions(options);
    sender.fireAndForget(payload);
}
 
Example 13
Source File: RequestSender.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public void sendRequestOneWay(String payloadStr, EndpointReference targetEPR)
        throws XMLStreamException, AxisFault {
    OMElement payload = AXIOMUtil.stringToOM(payloadStr);
    Options options = new Options();
    options.setTo(targetEPR);
    ServiceClient sender = new ServiceClient();
    sender.setOptions(options);
    log.info("Request: " + payload.toString());
    sender.fireAndForget(payload);
}
 
Example 14
Source File: StockQuoteClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Send place order request
 *
 * @param trpUrl transport url
 * @param addUrl address url
 * @param symbol symbol
 * @throws AxisFault if error occurs when sending request
 */
public void sendPlaceOrderRequest(String trpUrl, String addUrl, String symbol) throws AxisFault {
    double price = getRandom(100, 0.9, true);
    int quantity = (int) getRandom(10000, 1.0, true);
    ServiceClient serviceClient = getServiceClient(trpUrl, addUrl, "placeOrder");
    try {
        serviceClient.fireAndForget(createPlaceOrderRequest(price, quantity, symbol));
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 15
Source File: ApplicationCreationWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("Executing Application creation Workflow.");
    }
    super.execute(workflowDTO);
    try {
        String action = WorkflowConstants.CREATE_APPLICATION_WS_ACTION;
        ServiceClient client = getClient(action);
        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() == null ? "" :
                application.getCallbackUrl());
        payload = payload.replace("$4", application.getDescription() == null ? "" :
                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);
    }
    return new GeneralWorkflowResponse();
}
 
Example 16
Source File: RequestExecutor.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
private void callService(OMElement messagePayload) throws AxisFault {

        ServiceClient client = new ServiceClient(WorkflowImplServiceDataHolder.getInstance()
                                                         .getConfigurationContextService()
                                                         .getClientConfigContext(), null);
        Options options = new Options();
        options.setAction(WFImplConstant.DEFAULT_APPROVAL_BPEL_SOAP_ACTION);

        String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();

        String host = bpsProfile.getWorkerHostURL();
        String serviceName = StringUtils.deleteWhitespace(WorkflowManagementUtil
                                                                  .getParameter(parameterList, WFConstant
                                                                          .ParameterName.WORKFLOW_NAME, WFConstant
                                                                          .ParameterHolder.WORKFLOW_IMPL)
                                                                  .getParamValue());
        serviceName = StringUtils.deleteWhitespace(serviceName);

        if (host.endsWith("/")) {
            host = host.substring(0,host.lastIndexOf("/"));
        }

        String endpoint;
        if (tenantDomain != null && !tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
            endpoint = host + "/t/" + tenantDomain + "/" + serviceName + WFConstant.TemplateConstants.SERVICE_SUFFIX;
        } else {
            endpoint = host + "/" + serviceName + WFConstant.TemplateConstants.SERVICE_SUFFIX;
        }

        options.setTo(new EndpointReference(endpoint));

        options.setProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE, SOAP11Constants
                .SOAP_11_CONTENT_TYPE);

        HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
        auth.setUsername(bpsProfile.getUsername());
        auth.setPassword(String.valueOf(bpsProfile.getPassword()));
        auth.setPreemptiveAuthentication(true);
        List<String> authSchemes = new ArrayList<>();
        authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
        auth.setAuthSchemes(authSchemes);
        options.setProperty(HTTPConstants.AUTHENTICATE, auth);

        options.setManageSession(true);

        client.setOptions(options);
        client.fireAndForget(messagePayload);

    }
 
Example 17
Source File: ApplicationRegistrationWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("Executing Application registration Workflow..");
    }
    try {
        String action = WorkflowConstants.CREATE_REGISTRATION_WS_ACTION;
        ServiceClient client = getClient(action);
        String payload =
                "<wor:ApplicationRegistrationWorkFlowProcessRequest 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:keyType>$9</wor:keyType>\n"
                        + "      </wor:ApplicationRegistrationWorkFlowProcessRequest>";

        ApplicationRegistrationWorkflowDTO appRegDTO = (ApplicationRegistrationWorkflowDTO) workflowDTO;
        Application application = appRegDTO.getApplication();
        String callBackURL = appRegDTO.getCallbackUrl();
        String applicationCallbackUrl = application.getCallbackUrl();
        String applicationDescription = application.getDescription();

        payload = payload.replace("$1", application.getName());
        payload = payload.replace("$2", application.getTier());
        payload = payload.replace("$3", applicationCallbackUrl != null ? applicationCallbackUrl : "?");
        payload = payload.replace("$4", applicationDescription != null ? applicationDescription : "?");
        payload = payload.replace("$5", appRegDTO.getTenantDomain());
        payload = payload.replace("$6", appRegDTO.getUserName());
        payload = payload.replace("$7", appRegDTO.getExternalWorkflowReference());
        payload = payload.replace("$8", callBackURL != null ? callBackURL : "?");
        payload = payload.replace("$9", appRegDTO.getKeyType());

        client.fireAndForget(AXIOMUtil.stringToOM(payload));
        super.execute(workflowDTO);
    } 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);
    }
    return new GeneralWorkflowResponse();
}
 
Example 18
Source File: SubscriptionCreationWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * This method is used to execute the workflow without giving a workflow response back to the caller to execute
 * some other task after completing the workflow
 *
 * @param workflowDTO - The WorkflowDTO which contains workflow contextual information related to the workflow.
 * @throws WorkflowException
 */
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    try {
        String action = WorkflowConstants.CREATE_SUBSCRIPTION_WS_ACTION;
        ServiceClient client = getClient(action);
        String payload = "<wor:SubscriptionApprovalWorkFlowProcessRequest " +
                "         xmlns:wor=\"http://workflow.subscription.apimgt.carbon.wso2.org\">\n" +
                "         <wor:apiName>$1</wor:apiName>\n" +
                "         <wor:apiVersion>$2</wor:apiVersion>\n" +
                "         <wor:apiContext>$3</wor:apiContext>\n" +
                "         <wor:apiProvider>$4</wor:apiProvider>\n" +
                "         <wor:subscriber>$5</wor:subscriber>\n" +
                "         <wor:applicationName>$6</wor:applicationName>\n" +
                "         <wor:tierName>$7</wor:tierName>\n" +
                "         <wor:workflowExternalRef>$8</wor:workflowExternalRef>\n" +
                "         <wor:callBackURL>$9</wor:callBackURL>\n" +
                "      </wor:SubscriptionApprovalWorkFlowProcessRequest>";

        SubscriptionWorkflowDTO subsWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
        String callBackURL = subsWorkflowDTO.getCallbackUrl();

        payload = payload.replace("$1", subsWorkflowDTO.getApiName());
        payload = payload.replace("$2", subsWorkflowDTO.getApiVersion());
        payload = payload.replace("$3", subsWorkflowDTO.getApiContext());
        payload = payload.replace("$4", subsWorkflowDTO.getApiProvider());
        payload = payload.replace("$5", subsWorkflowDTO.getSubscriber());
        payload = payload.replace("$6", subsWorkflowDTO.getApplicationName());
        payload = payload.replace("$7", subsWorkflowDTO.getTierName());
        payload = payload.replace("$8", subsWorkflowDTO.getExternalWorkflowReference());
        payload = payload.replace("$9", callBackURL != null ? callBackURL : "?");

        client.fireAndForget(AXIOMUtil.stringToOM(payload));
        super.execute(workflowDTO);
    } 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);
    }
    return new GeneralWorkflowResponse();
}
 
Example 19
Source File: SubscriptionUpdateWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * This method is used to execute the workflow without giving a workflow response back to the caller to execute
 * some other task after completing the workflow
 *
 * @param workflowDTO - The WorkflowDTO which contains workflow contextual information related to the workflow.
 * @throws WorkflowException
 */
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    try {
        String action = WorkflowConstants.UPDATE_SUBSCRIPTION_WS_ACTION;
        ServiceClient client = getClient(action);
        String payload = "<wor:SubscriptionApprovalWorkFlowProcessRequest " +
                "         xmlns:wor=\"http://workflow.subscription.apimgt.carbon.wso2.org\">\n" +
                "         <wor:apiName>$1</wor:apiName>\n" +
                "         <wor:apiVersion>$2</wor:apiVersion>\n" +
                "         <wor:apiContext>$3</wor:apiContext>\n" +
                "         <wor:apiProvider>$4</wor:apiProvider>\n" +
                "         <wor:subscriber>$5</wor:subscriber>\n" +
                "         <wor:applicationName>$6</wor:applicationName>\n" +
                "         <wor:tierName>$7</wor:tierName>\n" +
                "         <wor:workflowExternalRef>$8</wor:workflowExternalRef>\n" +
                "         <wor:callBackURL>$9</wor:callBackURL>\n" +
                "      </wor:SubscriptionApprovalWorkFlowProcessRequest>";

        SubscriptionWorkflowDTO subsWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
        String callBackURL = subsWorkflowDTO.getCallbackUrl();

        payload = payload.replace("$1", subsWorkflowDTO.getApiName());
        payload = payload.replace("$2", subsWorkflowDTO.getApiVersion());
        payload = payload.replace("$3", subsWorkflowDTO.getApiContext());
        payload = payload.replace("$4", subsWorkflowDTO.getApiProvider());
        payload = payload.replace("$5", subsWorkflowDTO.getSubscriber());
        payload = payload.replace("$6", subsWorkflowDTO.getApplicationName());
        payload = payload.replace("$7", subsWorkflowDTO.getTierName());
        payload = payload.replace("$8", subsWorkflowDTO.getExternalWorkflowReference());
        payload = payload.replace("$9", callBackURL != null ? callBackURL : "?");

        client.fireAndForget(AXIOMUtil.stringToOM(payload));
        super.execute(workflowDTO);
    } 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);
    }
    return new GeneralWorkflowResponse();
}
 
Example 20
Source File: MessageSender.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
private void sendNotification(AxisService service,
                              String discoveryProxyEPR, int notificationType) throws DiscoveryException {

    if (!isDiscoverable(service)) {
        return;
    }

    Config config = getDiscoveryConfig(service);

    try {
        // create the service client object before getting the eprs
        // in order to get the EPRs
        ServiceClient serviceClient = initServiceClient(discoveryProxyEPR, notificationType,
                service.getAxisConfiguration());

        // create the hello/bye message and send
        String uniqueID = getServiceID(config, service);
        EndpointReference endpointReference = new EndpointReference(uniqueID);
        TargetService targetService = new TargetService(endpointReference);

        targetService.setTypes(new QName[] { Util.getTypes(service) });

        URI[] scopes = new URI[config.getScopes().size()];
        for (int i = 0; i < config.getScopes().size(); i++) {
            scopes[i] = new URI(config.getScopes().get(i));
        }
        targetService.setScopes(scopes);

        String[] eprs = service.getEPRs();
        URI[] xAddres = new URI[eprs.length];
        for (int i = 0; i < eprs.length; i++) {
            String epr = eprs[i];
            if (epr.endsWith("/")) {
                epr = epr.substring(0, epr.length() - 1);
            }
            xAddres[i] = new URI(epr);
        }
        targetService.setXAddresses(xAddres);
        targetService.setMetadataVersion(config.getMetadataVersion());

        if(notificationType == DiscoveryConstants.NOTIFICATION_TYPE_HELLO){
            serviceClient.addStringHeader(
                    new QName(DiscoveryConstants.DISCOVERY_HEADER_ELEMENT_NAMESPACE,
                            DiscoveryConstants.DISCOVERY_HEADER_SERVICE_NAME,
                            DiscoveryConstants.DISCOVERY_HEADER_ELEMENT_NAMESPACE_PREFIX),
                    getNameForService(service));
            serviceClient.addStringHeader(new QName(
                    DiscoveryConstants.DISCOVERY_HEADER_ELEMENT_NAMESPACE,
                    DiscoveryConstants.DISCOVERY_HEADER_WSDL_URI,
                    DiscoveryConstants.DISCOVERY_HEADER_ELEMENT_NAMESPACE_PREFIX),
                    Util.getWsdlInformation(service.getName(), service.getAxisConfiguration()));
        }

        Notification notification = new Notification(notificationType, targetService);
        serviceClient.fireAndForget(DiscoveryOMUtils.toOM(notification,
                OMAbstractFactory.getOMFactory()));
        serviceClient.cleanup();

    } catch (Exception e) {
        throw new DiscoveryException("Error while sending the WS-Discovery notification " +
                "for the service " + getNameForService(service), e);
    }
}