use of org.apache.axis2.context.ConfigurationContext 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);
}
}
use of org.apache.axis2.context.ConfigurationContext in project ofbiz-framework by apache.
the class SOAPClientEngine method serviceInvoker.
// Invoke the remote SOAP service
private Map<String, Object> serviceInvoker(ModelService modelService, Map<String, Object> context) throws GenericServiceException {
Delegator delegator = dispatcher.getDelegator();
if (modelService.location == null || modelService.invoke == null) {
throw new GenericServiceException("Cannot locate service to invoke");
}
ServiceClient client = null;
QName serviceName = null;
String axis2Repo = "/framework/service/config/axis2";
String axis2RepoLocation = System.getProperty("ofbiz.home") + axis2Repo;
String axis2XmlFile = "/framework/service/config/axis2/conf/axis2.xml";
String axis2XmlFileLocation = System.getProperty("ofbiz.home") + axis2XmlFile;
try {
ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(axis2RepoLocation, axis2XmlFileLocation);
client = new ServiceClient(configContext, null);
Options options = new Options();
EndpointReference endPoint = new EndpointReference(this.getLocation(modelService));
options.setTo(endPoint);
client.setOptions(options);
} catch (AxisFault e) {
throw new GenericServiceException("RPC service error", e);
}
List<ModelParam> inModelParamList = modelService.getInModelParamList();
if (Debug.infoOn()) {
Debug.logInfo("[SOAPClientEngine.invoke] : Parameter length - " + inModelParamList.size(), module);
}
if (UtilValidate.isNotEmpty(modelService.nameSpace)) {
serviceName = new QName(modelService.nameSpace, modelService.invoke);
} else {
serviceName = new QName(modelService.invoke);
}
int i = 0;
Map<String, Object> parameterMap = new HashMap<>();
for (ModelParam p : inModelParamList) {
if (Debug.infoOn()) {
Debug.logInfo("[SOAPClientEngine.invoke} : Parameter: " + p.name + " (" + p.mode + ") - " + i, module);
}
// exclude params that ModelServiceReader insert into (internal params)
if (!p.internal) {
parameterMap.put(p.name, context.get(p.name));
}
i++;
}
OMElement parameterSer = null;
try {
String xmlParameters = SoapSerializer.serialize(parameterMap);
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlParameters));
OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(reader);
parameterSer = builder.getDocumentElement();
} catch (Exception e) {
Debug.logError(e, module);
}
Map<String, Object> results = null;
try {
OMFactory factory = OMAbstractFactory.getOMFactory();
OMElement payload = factory.createOMElement(serviceName);
payload.addChild(parameterSer.getFirstElement());
OMElement respOMElement = client.sendReceive(payload);
client.cleanupTransport();
results = UtilGenerics.cast(SoapSerializer.deserialize(respOMElement.toString(), delegator));
} catch (Exception e) {
Debug.logError(e, module);
}
return results;
}
use of org.apache.axis2.context.ConfigurationContext in project jaggery by wso2.
the class TomcatJaggeryWebappsDeployer method handleWebappDeployment.
/**
* Deployment procedure of Jaggery apps
*
* @param webappFile The Jaggery app file to be deployed
* @param contextStr jaggery app context string
* @param webContextParams context-params for this Jaggery app
* @param applicationEventListeners Application event listeners
* @throws CarbonException If a deployment error occurs
*/
protected void handleWebappDeployment(File webappFile, String contextStr, List<WebContextParameter> webContextParams, List<Object> applicationEventListeners) throws CarbonException {
String filename = webappFile.getName();
ArrayList<Object> listeners = new ArrayList<Object>(1);
// listeners.add(new CarbonServletRequestListener());
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setAuthConstraint(true);
SecurityCollection securityCollection = new SecurityCollection();
securityCollection.setName("ConfigDir");
securityCollection.setDescription("Jaggery Configuration Dir");
securityCollection.addPattern("/" + JaggeryCoreConstants.JAGGERY_CONF_FILE);
securityConstraint.addCollection(securityCollection);
WebApplicationsHolder webApplicationsHolder = WebAppUtils.getWebappHolder(webappFile.getAbsolutePath(), configurationContext);
try {
JSONObject jaggeryConfigObj = readJaggeryConfig(webappFile);
Tomcat tomcat = DataHolder.getCarbonTomcatService().getTomcat();
Context context = DataHolder.getCarbonTomcatService().addWebApp(contextStr, webappFile.getAbsolutePath(), new JaggeryDeployerManager.JaggeryConfListener(jaggeryConfigObj, securityConstraint));
// deploying web app for url mapping inside virtual host
if (DataHolder.getHotUpdateService() != null) {
List<String> hostNames = DataHolder.getHotUpdateService().getMappigsPerWebapp(contextStr);
for (String hostName : hostNames) {
Host host = DataHolder.getHotUpdateService().addHost(hostName);
/* ApplicationContext.getCurrentApplicationContext().putUrlMappingForApplication(hostName, contextStr);
*/
Context contextForHost = DataHolder.getCarbonTomcatService().addWebApp(host, "/", webappFile.getAbsolutePath(), new JaggeryDeployerManager.JaggeryConfListener(jaggeryConfigObj, securityConstraint));
log.info("Deployed JaggeryApp on host: " + contextForHost);
}
}
Manager manager = context.getManager();
if (isDistributable(context, jaggeryConfigObj)) {
// Clusterable manager implementation as DeltaManager
context.setDistributable(true);
// Using clusterable manager
CarbonTomcatClusterableSessionManager sessionManager;
if (manager instanceof CarbonTomcatClusterableSessionManager) {
sessionManager = (CarbonTomcatClusterableSessionManager) manager;
sessionManager.setOwnerTenantId(tenantId);
} else {
sessionManager = new CarbonTomcatClusterableSessionManager(tenantId);
context.setManager(sessionManager);
}
Object alreadyinsertedSMMap = configurationContext.getProperty(CarbonConstants.TOMCAT_SESSION_MANAGER_MAP);
if (alreadyinsertedSMMap != null) {
((Map<String, CarbonTomcatClusterableSessionManager>) alreadyinsertedSMMap).put(context.getName(), sessionManager);
} else {
sessionManagerMap.put(context.getName(), sessionManager);
configurationContext.setProperty(CarbonConstants.TOMCAT_SESSION_MANAGER_MAP, sessionManagerMap);
}
} else {
if (manager instanceof CarbonTomcatSessionManager) {
((CarbonTomcatSessionManager) manager).setOwnerTenantId(tenantId);
} else if (manager instanceof CarbonTomcatSessionPersistentManager) {
((CarbonTomcatSessionPersistentManager) manager).setOwnerTenantId(tenantId);
log.debug(manager.getInfo() + " enabled Tomcat HTTP Session Persistent mode using " + ((CarbonTomcatSessionPersistentManager) manager).getStore().getInfo());
} else {
context.setManager(new CarbonTomcatSessionManager(tenantId));
}
}
context.setReloadable(false);
JaggeryApplication webapp = new JaggeryApplication(this, context, webappFile);
webapp.setServletContextParameters(webContextParams);
webapp.setState("Started");
webApplicationsHolder.getStartedWebapps().put(filename, webapp);
webApplicationsHolder.getFaultyWebapps().remove(filename);
registerApplicationEventListeners(applicationEventListeners, context);
log.info("Deployed webapp: " + webapp);
} catch (Throwable e) {
// catching a Throwable here to avoid web-apps crashing the server during startup
StandardContext context = new StandardContext();
context.setName(webappFile.getName());
context.addParameter(WebappsConstants.FAULTY_WEBAPP, "true");
JaggeryApplication webapp = new JaggeryApplication(this, context, webappFile);
webapp.setProperty(WebappsConstants.WEBAPP_FILTER, JaggeryConstants.JAGGERY_WEBAPP_FILTER_PROP);
String msg = "Error while deploying webapp: " + webapp;
log.error(msg, e);
webapp.setFaultReason(new Exception(msg, e));
webApplicationsHolder.getFaultyWebapps().put(filename, webapp);
webApplicationsHolder.getStartedWebapps().remove(filename);
throw new CarbonException(msg, e);
}
}
use of org.apache.axis2.context.ConfigurationContext in project wso2-axis2-transports by wso2.
the class JMSSenderTestCase method testTransactionCommandParameter.
/**
* Test case for EI-1244.
* test transport.jms.TransactionCommand parameter in transport url when sending the message.
* This will verify the fixes which prevent possible OOM issue when publishing messages to a broker using jms.
*
* @throws Exception
*/
public void testTransactionCommandParameter() throws Exception {
JMSSender jmsSender = PowerMockito.spy(new JMSSender());
JMSOutTransportInfo jmsOutTransportInfo = Mockito.mock(JMSOutTransportInfo.class);
JMSMessageSender jmsMessageSender = Mockito.mock(JMSMessageSender.class);
Session session = Mockito.mock(Session.class);
Mockito.doReturn(session).when(jmsMessageSender).getSession();
PowerMockito.whenNew(JMSOutTransportInfo.class).withArguments(any(String.class)).thenReturn(jmsOutTransportInfo);
Mockito.doReturn(jmsMessageSender).when(jmsOutTransportInfo).createJMSSender(any(MessageContext.class));
PowerMockito.doNothing().when(jmsSender, "sendOverJMS", ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
jmsSender.init(new ConfigurationContext(new AxisConfiguration()), new TransportOutDescription("jms"));
MessageContext messageContext = new MessageContext();
// append the transport.jms.TransactionCommand
String targetAddress = "jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=" + "QueueConnectionFactory&transport.jms.TransactionCommand=begin" + "&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory";
Transaction transaction = new TestJMSTransaction();
messageContext.setProperty(JMSConstants.JMS_XA_TRANSACTION, transaction);
jmsSender.sendMessage(messageContext, targetAddress, null);
Map<Transaction, ArrayList<JMSMessageSender>> jmsMessageSenderMap = Whitebox.getInternalState(JMSSender.class, "jmsMessageSenderMap");
Assert.assertEquals("Transaction not added to map", 1, jmsMessageSenderMap.size());
List senderList = jmsMessageSenderMap.get(transaction);
Assert.assertNotNull("List is null", senderList);
Assert.assertEquals("List is empty", 1, senderList.size());
}
use of org.apache.axis2.context.ConfigurationContext in project wso2-axis2-transports by wso2.
the class DefaultSMSMessageBuilderImpl method buildMessaage.
public MessageContext buildMessaage(SMSMessage msg, ConfigurationContext configurationContext) throws InvalidMessageFormatException {
String message = msg.getContent();
String sender = msg.getSender();
String receiver = msg.getReceiver();
String[] parts = message.split(":");
// may be can add feature to send message format for a request like ????
if (parts.length < 2) {
throw new InvalidMessageFormatException("format must be \"service_name \" : \"opration_name\" : " + "\"parm_1=val_1\" :..:\"param_n = val_n\"");
} else {
AxisConfiguration repo = configurationContext.getAxisConfiguration();
MessageContext messageContext = configurationContext.createMessageContext();
parts = trimSplited(parts);
try {
AxisService axisService = repo.getService(parts[0]);
if (axisService == null) {
throw new InvalidMessageFormatException("Service : " + parts[0] + "does not exsist");
} else {
messageContext.setAxisService(axisService);
AxisOperation axisOperation = axisService.getOperation(new QName(parts[1]));
if (axisOperation == null) {
throw new InvalidMessageFormatException("Operation: " + parts[1] + " does not exsist");
}
messageContext.setAxisOperation(axisOperation);
messageContext.setAxisMessage(axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
Map params = getParams(parts, 2);
SOAPEnvelope soapEnvelope = createSoapEnvelope(messageContext, params);
messageContext.setServerSide(true);
messageContext.setEnvelope(soapEnvelope);
TransportInDescription in = configurationContext.getAxisConfiguration().getTransportIn("sms");
TransportOutDescription out = configurationContext.getAxisConfiguration().getTransportOut("sms");
messageContext.setIncomingTransportName("sms");
messageContext.setProperty(SMSTransportConstents.SEND_TO, sender);
messageContext.setProperty(SMSTransportConstents.DESTINATION, receiver);
messageContext.setTransportIn(in);
messageContext.setTransportOut(out);
handleSMSProperties(msg, messageContext);
return messageContext;
}
} catch (AxisFault axisFault) {
log.debug("[DefaultSMSMessageBuilderImpl] Error while extracting the axis2Service \n" + axisFault);
}
}
return null;
}
Aggregations