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);
}
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();
}
}
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;
}
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);
}
}
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");
}
}
}
Aggregations