Search in sources :

Example 91 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project carbon-business-process by wso2.

the class HTTPBindingHandler method invoke.

public HTTPBindingResponse invoke(final PartnerRoleMessageExchange partnerRoleMessageExchange, final BPELMessageContext bpelMessageContext) throws AxisFault {
    MessageContext messageContext;
    OperationClient operationClient = AxisServiceUtils.getOperationClient(bpelMessageContext, configurationContext);
    operationClient.getOptions().setAction("\"\"");
    operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
    addPropertyToOperationClient(operationClient, WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR, "&");
    addPropertyToOperationClient(operationClient, Constants.Configuration.ENABLE_REST, true);
    addPropertyToOperationClient(operationClient, Constants.Configuration.HTTP_METHOD, getVerb().trim());
    addPropertyToOperationClient(operationClient, WSDL2Constants.ATTR_WHTTP_LOCATION, getHTTPLocation(partnerRoleMessageExchange.getOperationName()));
    addPropertyToOperationClient(operationClient, Constants.Configuration.CONTENT_TYPE, inferContentType(getVerb()));
    addPropertyToOperationClient(operationClient, Constants.Configuration.MESSAGE_TYPE, inferContentType(getVerb()));
    SOAPEnvelope soapEnvelope = getFactory(operationClient.getOptions().getSoapVersionURI()).getDefaultEnvelope();
    messageContext = new MessageContext();
    populateSOAPBody(soapEnvelope, partnerRoleMessageExchange);
    messageContext.setEnvelope(soapEnvelope);
    operationClient.addMessageContext(messageContext);
    String mexEndpointUrl = ((MutableEndpoint) partnerRoleMessageExchange.getEndpointReference()).getUrl();
    if (!mexEndpointUrl.equals(getServiceLocation())) {
        operationClient.getOptions().setTo(new EndpointReference(mexEndpointUrl));
    }
    operationClient.getOptions().setTo(bpelMessageContext.getUep());
    operationClient.execute(true);
    MessageContext responseMessageContext = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    MessageContext faultMessageContext = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_FAULT_VALUE);
    return new HTTPBindingResponse(responseMessageContext, faultMessageContext);
}
Also used : OperationClient(org.apache.axis2.client.OperationClient) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) MutableEndpoint(org.apache.ode.bpel.epr.MutableEndpoint) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 92 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext 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 93 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project carbon-business-process by wso2.

the class BPELDeployer method createBPELRepository.

private File createBPELRepository(ConfigurationContext configCtx) throws DeploymentException {
    String axisRepoPath = configCtx.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(axisRepoPath)) {
        throw new DeploymentException("URL Repositories are not supported: " + axisRepoPath);
    }
    File tenantsRepository = new File(axisRepoPath);
    File bpelRepo = new File(tenantsRepository, BPELConstants.BPEL_REPO_DIRECTORY);
    if (!bpelRepo.exists()) {
        boolean status = bpelRepo.mkdir();
        if (!status) {
            throw new DeploymentException("Failed to create BPEL repository directory " + bpelRepo.getAbsolutePath() + ".");
        }
    }
    return bpelRepo;
}
Also used : DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 94 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project carbon-business-process by wso2.

the class BPELDeployer method init.

public void init(ConfigurationContext configurationContext) {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    log.info("Initializing BPEL Deployer for tenant " + tenantId + ".");
    File bpelRepo = null;
    try {
        BPELDeployerServiceComponent.getTenantRegistryLoader().loadTenantRegistry(tenantId);
        bpelRepo = createBPELRepository(configurationContext);
    } catch (DeploymentException e) {
        log.warn("BPEL repository creation failed.", e);
    } catch (RegistryException e) {
        log.warn("Initialization of tenant process store failed for tenant: " + tenantId + " This can cause issues in deployment of BPEL packages.", e);
    }
    BPELServer bpsServer = BPELDeployerServiceComponent.getBPELServer();
    tenantProcessStore = bpsServer.getMultiTenantProcessStore().createProcessStoreForTenant(configurationContext);
    tenantProcessStore.setBpelArchiveRepo(bpelRepo);
    configurationContext.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, bpsServer.getHttpConnectionManager());
    try {
        tenantProcessStore.init();
    } catch (Exception re) {
        log.warn("Initialization of tenant process store failed for tenant: " + tenantId + " This can cause issues in deployment of BPEL packages.", re);
    }
}
Also used : DeploymentException(org.apache.axis2.deployment.DeploymentException) BPELServer(org.wso2.carbon.bpel.core.ode.integration.BPELServer) File(java.io.File) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 95 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project carbon-business-process by wso2.

the class BPELUploader method uploadService.

public void uploadService(UploadedFileItem[] fileItems) throws AxisFault {
    // First lets filter for jar resources
    ConfigurationContext configurationContext = getConfigContext();
    String repo = configurationContext.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(repo)) {
        throw new AxisFault("URL Repositories are not supported: " + repo);
    }
    // Writting the artifacts to the proper location
    String bpelDirectory = repo + File.separator + BPELConstants.BPEL_REPO_DIRECTORY;
    String bpelTemp = CarbonUtils.getCarbonHome() + BPELConstants.BPEL_PACKAGE_TEMP_DIRECTORY;
    File bpelTempDir = new File(bpelTemp);
    if (!bpelTempDir.exists() && !bpelTempDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + bpelTempDir.getAbsolutePath());
    }
    File bpelDir = new File(bpelDirectory);
    if (!bpelDir.exists() && !bpelDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + bpelDir.getAbsolutePath());
    }
    for (UploadedFileItem uploadedFile : fileItems) {
        String fileName = uploadedFile.getFileName();
        if (fileName == null || fileName.equals("")) {
            throw new AxisFault("Invalid file name. File name is not available");
        }
        if (uploadedFile.getFileType().equals(BPELConstants.BPEL_PACKAGE_EXTENSION)) {
            try {
                writeResource(uploadedFile.getDataHandler(), bpelTemp, fileName, bpelDir);
            } catch (IOException e) {
                throw new AxisFault("IOError: Writing resource failed.", e);
            }
        } else {
            throw new AxisFault("Invalid file type : " + uploadedFile.getFileType() + " ." + BPELConstants.BPEL_PACKAGE_EXTENSION + " file type is expected");
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) UploadedFileItem(org.wso2.carbon.bpel.deployer.services.types.UploadedFileItem) IOException(java.io.IOException) File(java.io.File)

Aggregations

ConfigurationContext (org.apache.axis2.context.ConfigurationContext)143 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)97 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)58 Parameter (org.apache.axis2.description.Parameter)52 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)52 Test (org.junit.Test)48 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)45 OMElement (org.apache.axiom.om.OMElement)42 AxisFault (org.apache.axis2.AxisFault)27 AxisService (org.apache.axis2.description.AxisService)25 EndpointReference (org.apache.axis2.addressing.EndpointReference)23 MessageContext (org.apache.synapse.MessageContext)22 Options (org.apache.axis2.client.Options)21 MessageContext (org.apache.axis2.context.MessageContext)21 ServiceContext (org.apache.axis2.context.ServiceContext)15 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 HashMap (java.util.HashMap)14 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)14 ArrayList (java.util.ArrayList)13