Search in sources :

Example 1 with ProcessManagementServiceClient

use of org.wso2.carbon.bpel.ui.clients.ProcessManagementServiceClient in project carbon-business-process by wso2.

the class SVGGenerateServlet method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 * Handles the HTTP process request which creates the SVG graph for a bpel process
 *
 * @param request  servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException      if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Log log = LogFactory.getLog(SVGGenerateServlet.class);
    HttpSession session = request.getSession(true);
    // Get the bpel process id
    String pid = CharacterEncoder.getSafeText(request.getParameter("pid"));
    ServletConfig config = getServletConfig();
    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    String processDef = null;
    ProcessManagementServiceClient client = null;
    SVGInterface svg = null;
    String svgStr = null;
    ServletOutputStream sos = null;
    sos = response.getOutputStream();
    try {
        client = new ProcessManagementServiceClient(cookie, backendServerURL, configContext, request.getLocale());
        // Gets the bpel process definition needed to create the SVG from the processId
        processDef = client.getProcessInfo(QName.valueOf(pid)).getDefinitionInfo().getDefinition().getExtraElement().toString();
        BPELInterface bpel = new BPELImpl();
        // Converts the bpel process definition to an omElement which is how the AXIS2 Object Model (AXIOM)
        // represents an XML document
        OMElement bpelStr = bpel.load(processDef);
        /**
         * Process the OmElement containing the bpel process definition
         * Process the subactivites of the bpel process by iterating through the omElement
         */
        bpel.processBpelString(bpelStr);
        // Create a new instance of the LayoutManager for the bpel process
        LayoutManager layoutManager = BPEL2SVGFactory.getInstance().getLayoutManager();
        // Set the layout of the SVG to vertical
        layoutManager.setVerticalLayout(true);
        // Get the root activity i.e. the Process Activity
        layoutManager.layoutSVG(bpel.getRootActivity());
        svg = new SVGImpl();
        // Set the root activity of the SVG i.e. the Process Activity
        svg.setRootActivity(bpel.getRootActivity());
        // Set the content type of the HTTP response as "image/svg+xml"
        response.setContentType("image/svg+xml");
        // Get the SVG graph created for the process as a SVG string
        svgStr = svg.generateSVGString();
        // Checks whether the SVG string generated contains a value
        if (svgStr != null) {
            // stream to write binary data into the response
            sos.write(svgStr.getBytes(Charset.defaultCharset()));
            sos.flush();
            sos.close();
        }
    } catch (ProcessManagementException e) {
        log.error("SVG Generation Error", e);
        String errorSVG = "<svg version=\"1.1\"\n" + "     xmlns=\"http://www.w3.org/2000/svg\"><text y=\"50\">Could not display SVG</text></svg>";
        sos.write(errorSVG.getBytes(Charset.defaultCharset()));
        sos.flush();
        sos.close();
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Log(org.apache.commons.logging.Log) ServletOutputStream(javax.servlet.ServletOutputStream) BPELImpl(org.wso2.carbon.bpel.ui.bpel2svg.impl.BPELImpl) HttpSession(javax.servlet.http.HttpSession) ServletConfig(javax.servlet.ServletConfig) ProcessManagementServiceClient(org.wso2.carbon.bpel.ui.clients.ProcessManagementServiceClient) OMElement(org.apache.axiom.om.OMElement) ProcessManagementException(org.wso2.carbon.bpel.stub.mgt.ProcessManagementException) SVGImpl(org.wso2.carbon.bpel.ui.bpel2svg.impl.SVGImpl)

Example 2 with ProcessManagementServiceClient

use of org.wso2.carbon.bpel.ui.clients.ProcessManagementServiceClient in project carbon-business-process by wso2.

the class PNGGenarateServlet method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request  servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException      if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Log log = LogFactory.getLog(PNGGenarateServlet.class);
    HttpSession session = request.getSession(true);
    String pid = CharacterEncoder.getSafeText(request.getParameter("pid"));
    ServletConfig config = getServletConfig();
    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    String processDef;
    ProcessManagementServiceClient client;
    SVGInterface svg;
    String svgStr;
    try {
        client = new ProcessManagementServiceClient(cookie, backendServerURL, configContext, request.getLocale());
        // Gets the bpel process definition needed to create the SVG from the processId
        processDef = client.getProcessInfo(QName.valueOf(pid)).getDefinitionInfo().getDefinition().getExtraElement().toString();
        BPELInterface bpel = new BPELImpl();
        // Converts the bpel process definition to an omElement which is how the AXIS2 Object Model (AXIOM)
        // represents an XML document
        OMElement bpelStr = bpel.load(processDef);
        /**
         * Process the OmElement containing the bpel process definition
         * Process the subactivites of the bpel process by iterating through the omElement
         */
        bpel.processBpelString(bpelStr);
        // Create a new instance of the LayoutManager for the bpel process
        LayoutManager layoutManager = BPEL2SVGFactory.getInstance().getLayoutManager();
        // Set the layout of the SVG to vertical
        layoutManager.setVerticalLayout(true);
        // Get the root activity i.e. the Process Activity
        layoutManager.layoutSVG(bpel.getRootActivity());
        svg = new SVGImpl();
        // Set the root activity of the SVG i.e. the Process Activity
        svg.setRootActivity(bpel.getRootActivity());
        // Set the content type of the HTTP response as "image/png"
        response.setContentType("image/png");
        // Create an instance of ServletOutputStream to write the output
        ServletOutputStream sos = response.getOutputStream();
        // Convert the image as a byte array of a PNG
        byte[] pngBytes = svg.toPNGBytes();
        // stream to write binary data into the response
        sos.write(pngBytes);
        sos.flush();
        sos.close();
    } catch (ProcessManagementException e) {
        log.error("PNG Generation Error", e);
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Log(org.apache.commons.logging.Log) BPELImpl(org.wso2.carbon.bpel.ui.bpel2svg.impl.BPELImpl) ServletOutputStream(javax.servlet.ServletOutputStream) HttpSession(javax.servlet.http.HttpSession) ServletConfig(javax.servlet.ServletConfig) ProcessManagementServiceClient(org.wso2.carbon.bpel.ui.clients.ProcessManagementServiceClient) OMElement(org.apache.axiom.om.OMElement) ProcessManagementException(org.wso2.carbon.bpel.stub.mgt.ProcessManagementException) SVGImpl(org.wso2.carbon.bpel.ui.bpel2svg.impl.SVGImpl)

Example 3 with ProcessManagementServiceClient

use of org.wso2.carbon.bpel.ui.clients.ProcessManagementServiceClient in project carbon-business-process by wso2.

the class BpelUIUtil method updateBackEnd.

public static void updateBackEnd(ProcessManagementServiceClient processMgtClient, ProcessDeployDetailsList_type0 processDeployDetailsListType, DeploymentDescriptorUpdater deployDescriptorUpdater, String[] selecttype, List<String> scopeNames) throws Exception {
    updateScopeEvents(selecttype, scopeNames, deployDescriptorUpdater);
    ProcessStatus processStatus = ProcessStatus.Factory.fromValue(deployDescriptorUpdater.getProcessstate().toUpperCase());
    processDeployDetailsListType.setProcessState(processStatus);
    processDeployDetailsListType.setIsInMemory(Boolean.parseBoolean(deployDescriptorUpdater.getInmemorystatus()));
    ProcessEventsListType processEventsListType = new ProcessEventsListType();
    EnableEventListType enableEventListType = new EnableEventListType();
    ScopeEventListType scopeEventListType = new ScopeEventListType();
    enableEventListType.setEnableEvent(deployDescriptorUpdater.getEvents());
    scopeEventListType.setScopeEvent(deployDescriptorUpdater.getScopeEvents());
    processEventsListType.setEnableEventsList(enableEventListType);
    processEventsListType.setScopeEventsList(scopeEventListType);
    if (!deployDescriptorUpdater.getGentype().equalsIgnoreCase("selected")) {
        Generate_type1 generate = Generate_type1.Factory.fromValue(deployDescriptorUpdater.getGentype());
        processEventsListType.setGenerate(generate);
    }
    processDeployDetailsListType.setProcessEventsList(processEventsListType);
    CleanUpListType cleanUpList = new CleanUpListType();
    CleanUpType successCleanUpType = new CleanUpType();
    On_type1 successOn = On_type1.success;
    successCleanUpType.setOn(successOn);
    CategoryListType successCategoryList = new CategoryListType();
    String[] sCategories = deployDescriptorUpdater.getSuccesstypecleanups();
    if (sCategories != null) {
        for (String categoryName : sCategories) {
            Category_type1 categoryType1 = Category_type1.Factory.fromValue(categoryName);
            successCategoryList.addCategory(categoryType1);
        }
    }
    successCleanUpType.setCategoryList(successCategoryList);
    cleanUpList.addCleanUp(successCleanUpType);
    CleanUpType failureCleanUpType = new CleanUpType();
    On_type1 failureOn = On_type1.failure;
    failureCleanUpType.setOn(failureOn);
    CategoryListType failureCategoryList = new CategoryListType();
    String[] fCategories = deployDescriptorUpdater.getFailuretypecleanups();
    if (fCategories != null) {
        for (String categoryName : fCategories) {
            Category_type1 categoryType1 = Category_type1.Factory.fromValue(categoryName);
            failureCategoryList.addCategory(categoryType1);
        }
    }
    failureCleanUpType.setCategoryList(failureCategoryList);
    cleanUpList.addCleanUp(failureCleanUpType);
    processDeployDetailsListType.setCleanUpList(cleanUpList);
    processMgtClient.updateDeployInfo(processDeployDetailsListType);
}
Also used : ProcessEventsListType(org.wso2.carbon.bpel.stub.mgt.types.ProcessEventsListType) EnableEventListType(org.wso2.carbon.bpel.stub.mgt.types.EnableEventListType) ProcessStatus(org.wso2.carbon.bpel.stub.mgt.types.ProcessStatus) On_type1(org.wso2.carbon.bpel.stub.mgt.types.On_type1) Category_type1(org.wso2.carbon.bpel.stub.mgt.types.Category_type1) Generate_type1(org.wso2.carbon.bpel.stub.mgt.types.Generate_type1) CategoryListType(org.wso2.carbon.bpel.stub.mgt.types.CategoryListType) ScopeEventListType(org.wso2.carbon.bpel.stub.mgt.types.ScopeEventListType) CleanUpListType(org.wso2.carbon.bpel.stub.mgt.types.CleanUpListType) CleanUpType(org.wso2.carbon.bpel.stub.mgt.types.CleanUpType)

Aggregations

ServletConfig (javax.servlet.ServletConfig)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 HttpSession (javax.servlet.http.HttpSession)2 OMElement (org.apache.axiom.om.OMElement)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 Log (org.apache.commons.logging.Log)2 ProcessManagementException (org.wso2.carbon.bpel.stub.mgt.ProcessManagementException)2 BPELImpl (org.wso2.carbon.bpel.ui.bpel2svg.impl.BPELImpl)2 SVGImpl (org.wso2.carbon.bpel.ui.bpel2svg.impl.SVGImpl)2 ProcessManagementServiceClient (org.wso2.carbon.bpel.ui.clients.ProcessManagementServiceClient)2 CategoryListType (org.wso2.carbon.bpel.stub.mgt.types.CategoryListType)1 Category_type1 (org.wso2.carbon.bpel.stub.mgt.types.Category_type1)1 CleanUpListType (org.wso2.carbon.bpel.stub.mgt.types.CleanUpListType)1 CleanUpType (org.wso2.carbon.bpel.stub.mgt.types.CleanUpType)1 EnableEventListType (org.wso2.carbon.bpel.stub.mgt.types.EnableEventListType)1 Generate_type1 (org.wso2.carbon.bpel.stub.mgt.types.Generate_type1)1 On_type1 (org.wso2.carbon.bpel.stub.mgt.types.On_type1)1 ProcessEventsListType (org.wso2.carbon.bpel.stub.mgt.types.ProcessEventsListType)1 ProcessStatus (org.wso2.carbon.bpel.stub.mgt.types.ProcessStatus)1 ScopeEventListType (org.wso2.carbon.bpel.stub.mgt.types.ScopeEventListType)1