List of usage examples for org.springframework.transaction.support TransactionCallback TransactionCallback
TransactionCallback
From source file:org.apache.ranger.service.RangerTransactionService.java
public void executeAfterTransactionComplete(final Runnable task) { try {//from www . j a v a 2s .com scheduler.schedule(new Runnable() { @Override public void run() { if (task != null) { try { //Create new transaction TransactionTemplate txTemplate = new TransactionTemplate(txManager); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); txTemplate.execute(new TransactionCallback<Object>() { public Object doInTransaction(TransactionStatus status) { task.run(); return null; } }); } catch (Exception e) { LOG.error("Failed to commit TransactionService transaction", e); LOG.error("Ignoring..."); } } } }, 1000L, MILLISECONDS); } catch (Exception e) { LOG.error("Failed to schedule TransactionService transaction:", e); LOG.error("Ignroing..."); } }
From source file:org.apereo.portal.events.aggr.PortalRawEventsAggregatorImpl.java
@RawEventsTransactional @Override// w ww .j a va 2s. c o m public EventProcessingResult doAggregateRawEvents() { //Do RawTX around AggrTX. The AggrTX is MUCH more likely to fail than the RawTX and this results in both rolling back return this.getTransactionOperations().execute(new TransactionCallback<EventProcessingResult>() { @Override public EventProcessingResult doInTransaction(TransactionStatus status) { return doAggregateRawEventsInternal(); } }); }
From source file:org.apereo.portal.i18n.RDBMLocaleStore.java
@Override public void updateUserLocales(final IPerson person, final Locale[] locales) { this.transactionOperations.execute(new TransactionCallback<Object>() { @Override//from w ww . j a v a 2s .com public Object doInTransaction(TransactionStatus status) { return jdbcOperations.execute(new ConnectionCallback<Object>() { @Override public Object doInConnection(Connection con) throws SQLException, DataAccessException { // Delete the existing list of locales final String delete = "DELETE FROM UP_USER_LOCALE WHERE USER_ID=?"; PreparedStatement pstmt = con.prepareStatement(delete); try { pstmt.clearParameters(); pstmt.setInt(1, person.getID()); logger.debug(delete); pstmt.executeUpdate(); } finally { pstmt.close(); } // Insert the new list of locales final String insert = "INSERT INTO UP_USER_LOCALE VALUES (?, ?, ?)"; pstmt = con.prepareStatement(insert); try { for (int i = 0; i < locales.length; i++) { pstmt.clearParameters(); pstmt.setInt(1, person.getID()); pstmt.setString(2, locales[i].toString()); pstmt.setInt(3, i); logger.debug(insert); pstmt.executeUpdate(); } } finally { pstmt.close(); } return null; } }); } }); }
From source file:org.apereo.portal.io.xml.IdentityImportExportTestUtilities.java
public static <T> void testIdentityImportExport(TransactionOperations transactionOperations, final IDataImporter<T> dataImporter, final IDataExporter<?> dataExporter, Resource resource, Function<T, String> getName) throws Exception { final String importData = toString(resource); final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory(); final XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(new StringReader(importData)); //Unmarshall from XML final Unmarshaller unmarshaller = dataImporter.getUnmarshaller(); final StAXSource source = new StAXSource(xmlEventReader); @SuppressWarnings("unchecked") final T dataImport = (T) unmarshaller.unmarshal(source); //Make sure the data was unmarshalled assertNotNull("Unmarshalled import data was null", dataImport); //Import the data dataImporter.importData(dataImport); //Export the data final String name = getName.apply(dataImport); final Object dataExport = transactionOperations.execute(new TransactionCallback<Object>() { /* (non-Javadoc) * @see org.springframework.transaction.support.TransactionCallback#doInTransaction(org.springframework.transaction.TransactionStatus) *///from ww w .j a v a 2 s . co m @Override public Object doInTransaction(TransactionStatus status) { return dataExporter.exportData(name); } }); //Make sure the data was exported assertNotNull("Exported data was null", dataExport); //Marshall to XML final Marshaller marshaller = dataExporter.getMarshaller(); final StringWriter result = new StringWriter(); marshaller.marshal(dataExport, new StreamResult(result)); //Compare the exported XML data with the imported XML data, they should match final String resultString = result.toString(); try { XMLUnit.setIgnoreWhitespace(true); Diff d = new Diff(new StringReader(importData), new StringReader(resultString)); assertTrue("Export result differs from import" + d, d.similar()); } catch (Exception e) { throw new XmlTestException("Failed to assert similar between import XML and export XML", resultString, e); } catch (Error e) { throw new XmlTestException("Failed to assert similar between import XML and export XML", resultString, e); } }
From source file:org.apereo.portal.RDBMUserIdentityStore.java
protected void updateUser(final int userId, final IPerson person, final TemplateUser templateUser) throws Exception { // Remove my existing group memberships IGroupMember me = GroupService.getGroupMember(person.getEntityIdentifier()); for (IEntityGroup eg : me.getParentGroups()) { ILockableEntityGroup leg = getSafeLockableGroup(eg, me); if (leg != null) { removePersonFromGroup(person, me, leg); }//from w w w . j av a 2s . c om } // Copy template user's groups memberships IGroupMember template = GroupService.getEntity(templateUser.getUserName(), IPerson.class); for (IEntityGroup eg : template.getParentGroups()) { ILockableEntityGroup leg = getSafeLockableGroup(eg, me); if (leg != null) { addPersonToGroup(person, me, leg); } } this.transactionOperations.execute(new TransactionCallback<Object>() { @Override public Object doInTransaction(TransactionStatus status) { return jdbcOperations.execute(new ConnectionCallback<Object>() { @Override public Object doInConnection(Connection con) throws SQLException, DataAccessException { PreparedStatement deleteStmt = null; PreparedStatement queryStmt = null; PreparedStatement insertStmt = null; try { // Update UP_USER String update = "UPDATE UP_USER " + "SET USER_DFLT_USR_ID=?, " + "USER_DFLT_LAY_ID=?, " + "NEXT_STRUCT_ID=null " + "WHERE USER_ID=?"; insertStmt = con.prepareStatement(update); insertStmt.setInt(1, templateUser.getUserId()); insertStmt.setInt(2, templateUser.getDefaultLayoutId()); insertStmt.setInt(3, userId); if (log.isDebugEnabled()) log.debug("RDBMUserIdentityStore::addNewUser(): " + update); insertStmt.executeUpdate(); insertStmt.close(); // Start copying... ResultSet rs = null; String delete = null; String query = null; String insert = null; try { // Update UP_USER_PROFILE delete = "DELETE FROM UP_USER_PROFILE " + "WHERE USER_ID=?"; deleteStmt = con.prepareStatement(delete); deleteStmt.setInt(1, userId); if (log.isDebugEnabled()) log.debug( "RDBMUserIdentityStore::updateUser(USER_ID=" + userId + "): " + delete); deleteStmt.executeUpdate(); deleteStmt.close(); query = "SELECT USER_ID, PROFILE_FNAME, PROFILE_NAME, DESCRIPTION, " + "STRUCTURE_SS_ID, THEME_SS_ID " + "FROM UP_USER_PROFILE " + "WHERE USER_ID=?"; queryStmt = con.prepareStatement(query); queryStmt.setInt(1, templateUser.getUserId()); if (log.isDebugEnabled()) log.debug("RDBMUserIdentityStore::updateUser(USER_ID=" + templateUser.getUserId() + "): " + query); rs = queryStmt.executeQuery(); insert = "INSERT INTO UP_USER_PROFILE (USER_ID, PROFILE_ID, PROFILE_FNAME, PROFILE_NAME, DESCRIPTION, LAYOUT_ID, STRUCTURE_SS_ID, THEME_SS_ID) " + "VALUES(?, ?, ?, ?, ?, NULL, ?, ?)"; insertStmt = con.prepareStatement(insert); while (rs.next()) { int id = getNextKey(); String profileFname = rs.getString("PROFILE_FNAME"); String profileName = rs.getString("PROFILE_NAME"); String description = rs.getString("DESCRIPTION"); int structure = rs.getInt("STRUCTURE_SS_ID"); int theme = rs.getInt("THEME_SS_ID"); insertStmt.setInt(1, userId); insertStmt.setInt(2, id); insertStmt.setString(3, profileFname); insertStmt.setString(4, profileName); insertStmt.setString(5, description); insertStmt.setInt(6, structure); insertStmt.setInt(7, theme); if (log.isDebugEnabled()) log.debug("RDBMUserIdentityStore::updateUser(USER_ID=" + userId + ", PROFILE_FNAME=" + profileFname + ", PROFILE_NAME=" + profileName + ", DESCRIPTION=" + description + "): " + insert); insertStmt.executeUpdate(); } rs.close(); queryStmt.close(); insertStmt.close(); // If we made it all the way though, commit the transaction if (RDBMServices.getDbMetaData().supportsTransactions()) con.commit(); } finally { try { rs.close(); } catch (Exception e) { } } } finally { try { deleteStmt.close(); } catch (Exception e) { } try { queryStmt.close(); } catch (Exception e) { } try { insertStmt.close(); } catch (Exception e) { } } return null; } }); } }); }
From source file:org.apereo.portal.RDBMUserIdentityStore.java
protected int addNewUser(final int newUID, final IPerson person, final TemplateUser templateUser) throws Exception { // Copy template user's groups memberships IGroupMember me = GroupService.getGroupMember(person.getEntityIdentifier()); IGroupMember template = GroupService.getEntity(templateUser.getUserName(), Class.forName("org.apereo.portal.security.IPerson")); for (IEntityGroup eg : template.getParentGroups()) { ILockableEntityGroup leg = getSafeLockableGroup(eg, me); if (leg != null) { addPersonToGroup(person, me, leg); }/*from w w w . j ava 2 s. co m*/ } return this.transactionOperations.execute(new TransactionCallback<Integer>() { @Override public Integer doInTransaction(TransactionStatus status) { return jdbcOperations.execute(new ConnectionCallback<Integer>() { @Override public Integer doInConnection(Connection con) throws SQLException, DataAccessException { int uPortalUID = -1; PreparedStatement queryStmt = null; PreparedStatement insertStmt = null; try { // Add to UP_USER String insert = "INSERT INTO UP_USER (USER_ID, USER_NAME, USER_DFLT_USR_ID, USER_DFLT_LAY_ID, NEXT_STRUCT_ID, LST_CHAN_UPDT_DT)" + "VALUES (?, ?, ?, ?, null, null)"; String userName = person.getUserName(); insertStmt = con.prepareStatement(insert); insertStmt.setInt(1, newUID); insertStmt.setString(2, userName); insertStmt.setInt(3, templateUser.getUserId()); insertStmt.setInt(4, templateUser.getDefaultLayoutId()); if (log.isDebugEnabled()) log.debug("RDBMUserIdentityStore::addNewUser(USER_ID=" + newUID + ", USER_NAME=" + userName + ", USER_DFLT_USR_ID=" + templateUser.getUserId() + ", USER_DFLT_LAY_ID=" + templateUser.getDefaultLayoutId() + "): " + insert); insertStmt.executeUpdate(); insertStmt.close(); insertStmt = null; // Start copying... ResultSet rs = null; String query = null; try { // Add to UP_USER_PROFILE query = "SELECT USER_ID, PROFILE_FNAME, PROFILE_NAME, DESCRIPTION, " + "STRUCTURE_SS_ID, THEME_SS_ID " + "FROM UP_USER_PROFILE " + "WHERE USER_ID=?"; queryStmt = con.prepareStatement(query); queryStmt.setInt(1, templateUser.getUserId()); if (log.isDebugEnabled()) log.debug("RDBMUserIdentityStore::addNewUser(USER_ID=" + templateUser.getUserId() + "): " + query); rs = queryStmt.executeQuery(); insert = "INSERT INTO UP_USER_PROFILE (USER_ID, PROFILE_ID, PROFILE_FNAME, PROFILE_NAME, DESCRIPTION, LAYOUT_ID, STRUCTURE_SS_ID, THEME_SS_ID) " + "VALUES(?, ?, ?, ?, ?, NULL, ?, ?)"; insertStmt = con.prepareStatement(insert); while (rs.next()) { int id = getNextKey(); String profileFname = rs.getString("PROFILE_FNAME"); String profileName = rs.getString("PROFILE_NAME"); String description = rs.getString("DESCRIPTION"); int structure = rs.getInt("STRUCTURE_SS_ID"); int theme = rs.getInt("THEME_SS_ID"); insertStmt.setInt(1, newUID); insertStmt.setInt(2, id); insertStmt.setString(3, profileFname); insertStmt.setString(4, profileName); insertStmt.setString(5, description); insertStmt.setInt(6, structure); insertStmt.setInt(7, theme); if (log.isDebugEnabled()) log.debug("RDBMUserIdentityStore::addNewUser(USER_ID=" + newUID + ", PROFILE_FNAME=" + profileFname + ", PROFILE_NAME=" + profileName + ", DESCRIPTION=" + description + "): " + insert); insertStmt.executeUpdate(); } rs.close(); queryStmt.close(); if (insertStmt != null) { insertStmt.close(); insertStmt = null; } // If we made it all the way though, commit the transaction if (RDBMServices.getDbMetaData().supportsTransactions()) con.commit(); uPortalUID = newUID; } finally { try { if (rs != null) rs.close(); } catch (Exception e) { } } } finally { try { if (queryStmt != null) queryStmt.close(); } catch (Exception e) { } try { if (insertStmt != null) insertStmt.close(); } catch (Exception e) { } } return uPortalUID; } }); } }); }
From source file:org.fireflow.console.servlet.repository.UploadDefinitionsServlet.java
protected void uploadSingleDefStep2(final HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //1???//from w w w . j av a 2s . c o m String _publishState = req.getParameter("publishState"); String _validDateFrom = req.getParameter("validDateFrom"); String _validDateTo = req.getParameter("validDateTo"); final String updateLog = req.getParameter("updateLog"); String _version = req.getParameter("version"); boolean publishStateTmp = false; if (_publishState != null && !_publishState.trim().equals("")) { try { publishStateTmp = Boolean.parseBoolean(_publishState); } catch (Exception e) { publishStateTmp = false; } } final boolean publishState = publishStateTmp; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date validDateFromTmp = new Date(); if (_validDateFrom != null && !_validDateFrom.trim().equals("")) { try { validDateFromTmp = format.parse(_validDateFrom); } catch (Exception e) { validDateFromTmp = new Date(); } } final Date validDateFrom = validDateFromTmp; Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2099); cal.set(Calendar.MONTH, 12); cal.set(Calendar.DATE, 31); Date validDateToTmp = cal.getTime(); if (_validDateTo != null && !_validDateTo.trim().equals("")) { try { validDateToTmp = format.parse(_validDateTo); } catch (Exception e) { validDateToTmp = cal.getTime(); } } final Date validDateTo = validDateToTmp; int versionTmp = 0; if (_version != null && !_version.trim().equals("")) { try { versionTmp = Integer.parseInt(_version); } catch (Exception e) { versionTmp = 0; } } final int version = versionTmp; // 2??Fireflow? final org.fireflow.engine.modules.ousystem.User currentUser = WorkflowUtil .getCurrentWorkflowUser(req.getSession()); ProcessDescriptor processDescriptor = (ProcessDescriptor) transactionTemplate .execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { // a?Fire WorkflowSession WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(fireContext, currentUser); WorkflowStatement stmt = session.createWorkflowStatement(); //b???? ProcessDescriptor processDescriptor = null; try { WorkflowProcess inStream = (WorkflowProcess) req.getSession() .getAttribute(PROCESS_DEFINITION); processDescriptor = stmt.uploadProcessObject(inStream, version); ((ProcessDescriptorImpl) processDescriptor).setPublishState(publishState); ((ProcessDescriptorImpl) processDescriptor).setValidDateFrom(validDateFrom); ((ProcessDescriptorImpl) processDescriptor).setValidDateTo(validDateTo); ((ProcessDescriptorImpl) processDescriptor).setUpdateLog(updateLog); stmt.updateProcessDescriptor(processDescriptor); } catch (InvalidModelException e) { throw new RuntimeException(e); } return processDescriptor; } }); // 4??? WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(fireContext, currentUser); WorkflowQuery<ProcessRepository> processQuery = session.createWorkflowQuery(ProcessRepository.class); processQuery.add(Restrictions.eq(ProcessDescriptorProperty.PROCESS_ID, processDescriptor.getProcessId())) .add(Restrictions.eq(ProcessDescriptorProperty.PROCESS_TYPE, processDescriptor.getProcessType())) .add(Restrictions.eq(ProcessDescriptorProperty.VERSION, processDescriptor.getVersion())); ProcessRepository repository = processQuery.unique();// ??ProcessRepository // repository = // processQuery.get(processDescriptor.getId()); req.setAttribute("process_repository", repository); // 5?? RequestDispatcher dispatcher = req .getRequestDispatcher("/fireflow_console/repository/upload_definition_result.jsp"); dispatcher.forward(req, resp); }
From source file:org.fireflow.pdl.fpdl.test.service.callback.TheCallbackServiceProcessTest1.java
@Test public void testCallbackService() { final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(fireflowRuntimeContext, FireWorkflowSystem.getInstance()); final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20); //0??//from w w w. j a va2s.c om final WorkflowProcess process = getWorkflowProcess(); //1??? transactionTemplate.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus arg0) { //? try { ProcessDescriptor descriptor = stmt.uploadProcessObject(process, 0); ((ProcessDescriptorImpl) descriptor).setPublishState(true); stmt.updateProcessDescriptor(descriptor); } catch (InvalidModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }); //2?CallbackManagerinit?Webservice //TODO WorkflowServer?webservice /* WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class, FpdlConstants.PROCESS_TYPE_FPDL20); try { callbackManager.publishAllCallbackServices(); } catch (WebservicePublishException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } */ //3??? transactionTemplate.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus arg0) { //?? try { ProcessInstance processInstance = stmt.startProcess(process.getId(), bizId, null); if (processInstance != null) { processInstanceId = processInstance.getId(); } } catch (InvalidModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (WorkflowProcessNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidOperationException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }); //JaxwsWebservice Environment env = fireflowRuntimeContext.getEngineModule(Environment.class, FpdlConstants.PROCESS_TYPE_FPDL20); URL url = null; try { String contextPath = env.getWebserviceContextPath(); if (!contextPath.startsWith("/")) { contextPath = "/" + contextPath; } if (!contextPath.endsWith("/")) { contextPath = contextPath + "/"; } String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort()) + contextPath; url = new URL(address + serviceQName.getLocalPart() + "?wsdl"); } catch (Exception e) { e.printStackTrace(); } javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName); Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class, javax.xml.ws.Service.Mode.PAYLOAD); String messageStr = "<cal:acceptRequest xmlns:cal=\"http://www.fireflow.org/junit/callbackservice\">" + "<cal:id>" + bizId + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>" + "</cal:acceptRequest>"; java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes()); StreamSource source = new StreamSource(byteInStream); Source response = dispatch.invoke(source); DOMResult result = new DOMResult(); // StreamResult result = new StreamResult(System.out); Transformer transformer = null; try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformer = transformerFactory.newTransformer(); transformer.transform(response, result); } catch (TransformerConfigurationException e) { throw new RuntimeException("Couldn't parse response stream.", e); } catch (TransformerException e) { throw new RuntimeException("Couldn't parse response stream.", e); } Document theResponsePayload = (Document) result.getNode(); Assert.assertNotNull(theResponsePayload); JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload); jxpathContext.registerNamespace("ns0", targetNsUri); String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2"); Assert.assertEquals(responseResult, response2); this.assertResult(session); }
From source file:org.fireflow.pdl.fpdl.test.service.callback.WebserviceStartProcessTest.java
@Test public void testCallbackService() { final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(fireflowRuntimeContext, FireWorkflowSystem.getInstance()); final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20); //0??// www. jav a 2 s . c o m final WorkflowProcess process = getWorkflowProcess(); //1??? transactionTemplate.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus arg0) { //? try { ProcessDescriptor descriptor = stmt.uploadProcessObject(process, 0); ((ProcessDescriptorImpl) descriptor).setPublishState(true); stmt.updateProcessDescriptor(descriptor); } catch (InvalidModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }); //2?CallbackManagerinit?Webservice //TODO WorkflowServer?webservice // WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class, FpdlConstants.PROCESS_TYPE_FPDL20); // try { // callbackManager.publishAllCallbackServices(); // } catch (WebservicePublishException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } //JaxwsWebservice Environment env = fireflowRuntimeContext.getEngineModule(Environment.class, FpdlConstants.PROCESS_TYPE_FPDL20); URL url = null; try { String contextPath = env.getWebserviceContextPath(); if (!contextPath.startsWith("/")) { contextPath = "/" + contextPath; } if (!contextPath.endsWith("/")) { contextPath = contextPath + "/"; } String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort()) + contextPath; url = new URL(address + serviceQName.getLocalPart() + "?wsdl"); } catch (Exception e) { e.printStackTrace(); } javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName); Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class, javax.xml.ws.Service.Mode.PAYLOAD); String messageStr = "<cal:acceptRequest xmlns:cal=\"" + targetNsUri + "\">" + "<cal:id>" + bizId + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>" + "</cal:acceptRequest>"; java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes()); StreamSource source = new StreamSource(byteInStream); Source response = dispatch.invoke(source); DOMResult result = new DOMResult(); // StreamResult result = new StreamResult(System.out); Transformer transformer = null; try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformer = transformerFactory.newTransformer(); transformer.transform(response, result); } catch (TransformerConfigurationException e) { throw new RuntimeException("Couldn't parse response stream.", e); } catch (TransformerException e) { throw new RuntimeException("Couldn't parse response stream.", e); } Document theResponsePayload = (Document) result.getNode(); Assert.assertNotNull(theResponsePayload); JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload); jxpathContext.registerNamespace("ns0", targetNsUri); String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2"); String response1 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response1"); Assert.assertEquals(responseResult, response2); Assert.assertNotNull(response1); this.processInstanceId = response1; this.assertResult(session); }
From source file:org.fireflow.pdl.fpdl20.test.service.callback.TheCallbackServiceProcessTest1.java
@Test public void testCallbackService() { final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(runtimeContext, FireWorkflowSystem.getInstance()); final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20); //0??/*from ww w .jav a 2 s .c o m*/ final WorkflowProcess process = getWorkflowProcess(); //1??? transactionTemplate.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus arg0) { //? try { stmt.uploadProcessObject(process, true, null, null); } catch (InvalidModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }); //2?CallbackManagerinit?Webservice WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class, FpdlConstants.PROCESS_TYPE_FPDL20); try { callbackManager.publishAllCallbackServices(); } catch (WebservicePublishException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //3??? transactionTemplate.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus arg0) { //?? try { ProcessInstance processInstance = stmt.startProcess(process.getId(), bizId, null); if (processInstance != null) { processInstanceId = processInstance.getId(); } } catch (InvalidModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (WorkflowProcessNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidOperationException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }); //JaxwsWebservice Environment env = runtimeContext.getEngineModule(Environment.class, FpdlConstants.PROCESS_TYPE_FPDL20); URL url = null; try { String contextPath = env.getWebserviceContextPath(); if (!contextPath.startsWith("/")) { contextPath = "/" + contextPath; } if (!contextPath.endsWith("/")) { contextPath = contextPath + "/"; } String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort()) + contextPath; url = new URL(address + serviceQName.getLocalPart() + "?wsdl"); } catch (Exception e) { e.printStackTrace(); } javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName); Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class, javax.xml.ws.Service.Mode.PAYLOAD); String messageStr = "<cal:acceptRequest xmlns:cal=\"http://www.fireflow.org/junit/callbackservice\">" + "<cal:id>" + bizId + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>" + "</cal:acceptRequest>"; java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes()); StreamSource source = new StreamSource(byteInStream); Source response = dispatch.invoke(source); DOMResult result = new DOMResult(); // StreamResult result = new StreamResult(System.out); Transformer transformer = null; try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformer = transformerFactory.newTransformer(); transformer.transform(response, result); } catch (TransformerConfigurationException e) { throw new RuntimeException("Couldn't parse response stream.", e); } catch (TransformerException e) { throw new RuntimeException("Couldn't parse response stream.", e); } Document theResponsePayload = (Document) result.getNode(); Assert.assertNotNull(theResponsePayload); JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload); jxpathContext.registerNamespace("ns0", targetNsUri); String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2"); Assert.assertEquals(responseResult, response2); this.assertResult(session); }