[JBoss jBPM] - Invoke a WebService from ActionHandler
by dadajboss
Hi all.
I'm trying to invoke a web service from my jBoss/jBPM process.
As Ronald suggests in this post:
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=70723
I write an actionhandler which invokes the webservice and then I associate it on a node-enter event of a node.
But when I run the process from jBoss-jBpm console I get an exception
description The server encountered an internal error () that prevented it from fulfilling this request.
|
| exception
|
| javax.servlet.ServletException: Servlet execution threw an exception
| org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
|
| root cause
|
| java.lang.NoClassDefFoundError: org/apache/axis/client/Service
| com.Process_3.WebServiceAction.execute(WebServiceAction.java:22)
| org.jbpm.graph.def.Action.execute(Action.java:122)
| org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:264)
| org.jbpm.graph.def.GraphElement.executeActions(GraphElement.java:220)
| org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:190)
| org.jbpm.graph.def.GraphElement.fireEvent(GraphElement.java:174)
| org.jbpm.graph.def.Node.enter(Node.java:303)
| org.jbpm.graph.def.Node$$FastClassByCGLIB$$d187eeda.invoke(<generated>)
| net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
| org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:163)
| org.jbpm.graph.def.Node$$EnhancerByCGLIB$$ad2fc36c.enter(<generated>)
| org.jbpm.graph.def.Transition.take(Transition.java:151)
| org.jbpm.graph.def.Node.leave(Node.java:394)
| org.jbpm.graph.node.TaskNode.leave(TaskNode.java:209)
| org.jbpm.graph.node.TaskNode$$FastClassByCGLIB$$923668a4.invoke(<generated>)
| net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
| org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:163)
| org.jbpm.graph.node.TaskNode$$EnhancerByCGLIB$$e933732a.leave(<generated>)
| org.jbpm.graph.exe.Token.signal(Token.java:195)
| org.jbpm.graph.exe.Token.signal(Token.java:140)
| org.jbpm.graph.exe.Token$$FastClassByCGLIB$$74df1c6e.invoke(<generated>)
| net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
| org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:163)
| org.jbpm.graph.exe.Token$$EnhancerByCGLIB$$dc8930e8.signal(<generated>)
| org.jbpm.taskmgmt.exe.TaskInstance.end(TaskInstance.java:485)
| org.jbpm.taskmgmt.exe.TaskInstance.end(TaskInstance.java:399)
| org.jbpm.jsf.core.action.CompleteTaskActionListener.handleAction(CompleteTaskActionListener.java:47)
| org.jbpm.jsf.core.impl.JbpmActionListenerWrapper.processAction(JbpmActionListenerWrapper.java:82)
| javax.faces.event.ActionEvent.processListener(ActionEvent.java:77)
| javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:758)
| javax.faces.component.UICommand.broadcast(UICommand.java:368)
| org.jbpm.jsf.taskform.ui.UITaskFormButtonBase.broadcast(UITaskFormButtonBase.java:56)
| javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:448)
| javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
| com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
| com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:248)
| com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
| javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
| org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
|
This is the ActionHandler code:
package com.Process_3;
|
| import org.jbpm.graph.def.ActionHandler;
| import org.jbpm.graph.exe.ExecutionContext;
| import org.apache.axis.client.Call;
| import org.apache.axis.client.Service;
| import org.apache.axis.encoding.XMLType;
|
|
| import javax.xml.rpc.ParameterMode;
|
|
| public class WebServiceAction implements ActionHandler {
| private static final long serialVersionUID = 1L;
|
| public void execute(ExecutionContext executionContext) throws Exception {
| // Make the call
| String method = new String("Get_CodFisFromLocalita");
| String endpoint = "http://www.nexusonline.it:8088/4DWSDL";
| String city = (String) ("Milano");
|
| Service service = new Service();
| Call call = (Call) service.createCall();
|
| call.setTargetEndpointAddress(new java.net.URL(endpoint));
| call.setOperationName( method );
| call.addParameter(city, XMLType.XSD_STRING, ParameterMode.IN);
| call.setReturnType(XMLType.XSD_STRING);
|
| String ret = (String) call.invoke( new Object[] { city } );
|
| executionContext.getContextInstance().createVariable("sigla", ret);
|
| System.out.println("Result: " + ret);
| }
|
| }
|
Note:
I deploy the process by mean jBPD Eclipse plugin.
Any help will be appreciated.
Thank you!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118727#4118727
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118727
18 years, 6 months
[JBoss Messaging] - Re: LocalTx, ClientTransaction leak?
by ydzsidemiik
I tried not closing the sessions explicitly. Still leaks, but the top of the trace has changed:
Explicit session close:
anonymous wrote :
| org.jboss.resource.connectionmanager.xa.JcaXAResourceWrapper.end(Xid, int)
| com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.delistResource(XAResource, int)
| org.jboss.resource.adapter.jms.JmsSession.close()
| com.acme.gateway.util.jms.JmsOperation.execute()
|
No explicit session close:
anonymous wrote :
| org.jboss.resource.connectionmanager.xa.JcaXAResourceWrapper.end(Xid, int)
| com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.delistResource(XAResource, int)
| org.jboss.resource.adapter.jms.JmsSessionFactoryImpl.close()
| com.acme.gateway.util.jms.JmsOperation.execute()
|
I didn't see any option to increase the maximum depth of the allocation traces in YourKit, so I tried downloading JProfiler. It too seems to cut off in the same place. I wasn't able to find the option to increase the maximum depth in JProfiler either, do you happen to know where it might be located?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118725#4118725
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118725
18 years, 6 months
[EJB 3.0] - hibernate clearing too much in 2nd-level cache w/native quer
by mazz@jboss.com
I'm seeing some interesting things happening with hibernate's second level cache when using native queries in my EJB3/JPA app and was wondering if someone can verify that "this is the way it is supposed to work" and more importantly how can I work around it :)
I have a multi-threaded system where I am doing concurrent database access; in one of those threads, I am in a transaction (call it T1) and the database access involves executing a native query (a native INSERT query to be exact) via entityManager.createNativeQuery(...).executeUpdate().
At the same time, in another set of threads, I'm hammering the database with other queries - nothing fancy, and no native queries.
Those other threads end up slowing down the system and the thread running in T1 is slowed down. So much so that more than 15 seconds go by after T1 is started but before I executeUpdate that native query.
The native query then bombs out with a failure; here's part of the log that shows the problem, stripped of everything not important:
| 18:52:42 INFO ...enter T1...
| ....
| 18:52:57 INFO ...Caused by: javax.persistence.PersistenceException: org.hibernate.cache.CacheException: org.jboss.cache.lock.TimeoutException: failure acquiring lock: fqn=/on_ear,jonpu/org/jboss/on/domain/resource/ResourceType,
|
Look at the timestamps - 18:52.42 plus 15 seconds is 18:52.57
we are hitting a cache timeout before we can complete the native query. The cache timeout is 15s based on the exception message I see later in the logs "Caused by: org.jboss.cache.lock.TimeoutException: write lock for /on_ear,jonpu/org/jboss/on/domain/resource/ResourceType could not be acquired after 15000 ms"
The odd thing is, this native query does not directly involve the entity referred to in this error message (ResourceType). So, I asked myself, "why is hibernate trying to get a write lock for this entity in its second-level cache?" The ResourceType entity is annotated with "@org.hibernate.annotations.Cache(usage= CacheConcurrencyStrategy.TRANSACTIONAL)" and we are using JBossCache.
Looking at the stack trace of the exception, I then saw this:
| at org.jboss.ejb3.entity.JBCCache.clear(JBCCache.java:207)
| at org.hibernate.cache.TransactionalCache.clear(TransactionalCache.java:124)
| at org.hibernate.impl.SessionFactoryImpl.evictEntity(SessionFactoryImpl.java:832)
| at org.hibernate.action.BulkOperationCleanupAction.evictEntityRegions(BulkOperationCleanupAction.java:137)
| at org.hibernate.action.BulkOperationCleanupAction.init(BulkOperationCleanupAction.java:100)
| at org.hibernate.engine.query.NativeSQLQueryPlan.coordinateSharedCacheCleanup(NativeSQLQueryPlan.java:134)
| at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:144)
|
It looks like hibernate is trying to perform some cache clearing with the bulk native query execution and trying to invalidate too much.
What ways are there to turn off or adjust this behavior? I don't want to extend the 15s time limit since I can't guarantee what's a long enough time and what should truly be considered a timeout.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118709#4118709
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118709
18 years, 6 months
[JBoss Seam] - Lifecycle question
by limousyf
Well it's not a "JSF lifecycle" question in fact, but I guess it's related.
I want to use a stateful bean, backing a xhtml page.
The link is like this:
| <s:link view="/PageactivitesByAssignableMultipleCrossData.xhtml"
| action="#{activitesByAssignableMultipleCrossData.setLotNotRealise}"
| id="SaisieForeCast"
| title="#{msgToolTip.activitesPrevisionnellesByCollaborateurCrossData}">
| <f:param name="realise" value="false" />
| <f:param name="lot" value="true" />
| <f:param name="lotLotId" value="#{forfaitHome.lotLotId}" />
| <h:graphicImage value="/img/folder_user.png" />
| </s:Link>
|
Correct me if I'm wrong but the event order is:
1) instantiate the destination bean
1b) injections
1c) Pass througt the @Create method if there is one
2) execute the "action" method
3) send the GET parameters
4) make the re-direct to display the view
Am I right ?
In fact, my problem is to use a value passed as a parameter during the @Create annotated method.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118701#4118701
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118701
18 years, 6 months
[JBoss Seam] - Strange behaviour of Seam Mail when sending unsynchonized as
by MSchmidke
Hello,
as you can see, I am digging deeper into the Seam Mail thing.
By now, I have a POJO Seam component, event scoped, with an @Asynchronous method send(), which sends a mail (by calling renderer.render).
>From the application, this method is called twice one immediately after the other.
This results in some strange behaviour (and no mails being sent).
It seems I solved this by adding "@Synchronized" to the component (since it is a timing issue, I can never be really sure ...)
But I have a question:
Obviously when called two times simultaneously, the one renderer interferes with the other. In my mail class I could solve this by synchronizing it, but what about the front page renderer? If accidentally in the same moment a mail is rendered also a page is rendered?
Will I have some very random-caused irreproducible strange problems in the future?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118700#4118700
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118700
18 years, 6 months
[JBoss Seam] - Re: Wildcard for pages action
by mmichalek
Thanks. JIRA opened: http://jira.jboss.org/jira/browse/JBSEAM-2481
Two other quick things on this:
1) One thing that surprised me when I first used Seam navigation was that you cannot define navigation cases based on the outcome of an action. I know that rules can operate on outcomes, but I like to define navigation cases based on a known action and then have rules which inspect the state within that case. (Otherwise I get strange behavior where a user can back up and click through a wizard using any links because the state to satisfy the rules in still in the conversation).
Here's a code snippet that demonstrates what I mean (in Pages.navigate). Does something like this make sense in general for Seam?
| Navigation navigation = page.getNavigations().get(actionExpression);
| if (navigation==null)
| {
| // New Code here:
| if (actionOutcomeValue != null) {
| navigation = page.getNavigations().get(actionOutcomeValue);
| }
|
2) For anyone interested in doing something like this, you can always provide a custom "org.jboss.seam.navigation.pages" component. For example, I have:
| @Scope(ScopeType.APPLICATION)
| @BypassInterceptors
| @Name("org.jboss.seam.navigation.pages")
| @Install(precedence=APPLICATION, classDependencies="javax.faces.context.FacesContext")
| public class Pages extends org.jboss.seam.navigation.Pages {
|
| @Override
| public boolean navigate(FacesContext context, String actionExpression, String actionOutcomeValue) {...}
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118699#4118699
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118699
18 years, 6 months
[JBoss Portal] - PortletBridge: Facelets not working
by ebephil
Hi,
I thought I'd give the new RichFaces JSR-301 PortletBridge a try to finally have proper support for RichFaces components in my portlets, but it seems like my Facelets CompositionComponents aren't displayed anymore. No error, it just shows nothing in the portlet. It used to work when using the AjaxFacesPortlet class directly.
Anyone experiencing the same behavior? It might easily be a configuration error, took me quite a while to get this far. Or isn't it implemented yet (still in beta as far as I know anyway). The ajaxPortlet sample that comes with the richfaces-source also doesn't seem to be using Facelets.
I am using the JBoss Portal 2.6.3.GA bundle with the included JBoss 4.2.2GA, the latest Facelets jar (1.1.3) and self compiled richfaces and portletbrige jars (built from the richfaces-ui-3.1.3.GA source zip).
My web.xml (with the FaceletPortletViewHandler set):
| <web-app >
|
| <display-name>FooPortlets</display-name>
| <description>Foo Portlets</description>
|
| <context-param>
| <param-name>com.sun.faces.validateXml</param-name>
| <param-value>true</param-value>
| </context-param>
| <context-param>
| <param-name>com.sun.faces.verifyObjects</param-name>
| <param-value>true</param-value>
| </context-param>
|
| <context-param>
| <param-name>facelets.DEVELOPMENT</param-name>
| <param-value>true</param-value>
| </context-param>
| <context-param>
| <param-name>facelets.SKIP_COMMENTS</param-name>
| <param-value>true</param-value>
| </context-param>
| <context-param>
| <param-name>facelets.VIEW_MAPPINGS</param-name>
| <param-value>*.xhtml</param-value>
| </context-param>
|
| <context-param>
| <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
| <param-value>
| org.ajax4jsf.portlet.application.FaceletPortletViewHandler
| </param-value>
| </context-param>
|
| <context-param>
| <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
| <param-value>server</param-value>
| </context-param>
| <context-param>
| <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
| <param-value>.xhtml</param-value>
| </context-param>
|
| <filter>
| <display-name>Ajax4jsf Filter</display-name>
| <filter-name>ajax4jsf</filter-name>
| <filter-class>org.ajax4jsf.Filter</filter-class>
| </filter>
| <filter-mapping>
| <filter-name>ajax4jsf</filter-name>
| <servlet-name>FacesServlet</servlet-name>
| <dispatcher>FORWARD</dispatcher>
| <dispatcher>REQUEST</dispatcher>
| <dispatcher>INCLUDE</dispatcher>
| </filter-mapping>
|
| <servlet>
| <servlet-name>FacesServlet</servlet-name>
| <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
| <load-on-startup>1</load-on-startup>
| </servlet>
| <servlet-mapping>
| <servlet-name>FacesServlet</servlet-name>
| <url-pattern>/faces/*</url-pattern>
| </servlet-mapping>
|
| </web-app>
|
My faces-config.xml (with the viewhandler, statemanager and contextfactory set):
| <faces-config>
|
| <!-- Richfaces configuration -->
| <application>
| <view-handler>
| org.ajax4jsf.portlet.application.PortletViewHandler
| </view-handler>
| <state-manager>
| org.ajax4jsf.portlet.application.PortalStateManager
| </state-manager>
| </application>
| <factory>
| <faces-context-factory>
| org.ajax4jsf.portlet.context.FacesContextFactoryImpl
| </faces-context-factory>
| </factory>
| ...
| </faces-config>
|
And finally my portlet.xml:
| <portlet>
| <portlet-name>AlarmPortlet</portlet-name>
| <display-name>Alarm Portlet</display-name>
|
| <portlet-class>
| javax.portlet.faces.GenericFacesPortlet
| </portlet-class>
| <init-param>
| <name>javax.portlet.faces.defaultViewId.view</name>
| <value>/jsf/alarm/view.xhtml</value>
| </init-param>
| <init-param>
| <name>javax.portlet.faces.defaultViewId.help</name>
| <value>/jsf/alarm/help.xhtml</value>
| </init-param>
| <!-- disable portlet caching -->
| <expiration-cache>-1</expiration-cache>
| <supports>
| <mime-type>text/html</mime-type>
| <portlet-mode>VIEW</portlet-mode>
| </supports>
| <supported-locale>en</supported-locale>
| <supported-locale>de</supported-locale>
| <resource-bundle>AlarmResourceBundle</resource-bundle>
| <security-role-ref>
| <role-name>Admin</role-name>
| <role-link>Admin</role-link>
| </security-role-ref>
| <security-role-ref>
| <role-name>User</role-name>
| <role-link>User</role-link>
| </security-role-ref>
| </portlet>
|
Any help is appreciated :-)
Thanks in advance
Cheers
Phil
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118693#4118693
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118693
18 years, 6 months
[JBoss Seam] - EntityManager trouble
by ErikSlagter
I'm in some trouble with testing my DAO in Eclipse. I'm using TestNG and Eclipse europe together with Seam 2.0.0GA.
I have to got the following test funtion:
| @Test
| public void test(){
| dao = new PaymentDeviceDAO();
| String terminalProvider = "Malle Japie";
| String terminalId = "12345";
|
| device = dao.findById(terminalProvider, terminalId);
| assert device != null;
| }
|
| private EntityManagerFactory emf;
| @Out
| EntityManager em;
|
| protected String datasourceJndiName;
| public EntityManagerFactory getEntityManagerFactory(){
| assert emf != null;
| return emf;
| }
|
| @BeforeClass
| @Parameters("datasourceJndiName")
| public void setDatasourceJndiName(String datasourceJndiName) {
| this.datasourceJndiName = datasourceJndiName;
| init();
| }
|
| public void init(){
| emf = Persistence.createEntityManagerFactory(datasourceJndiName);
| em = emf.createEntityManager();
| assert emf != null;
| }
|
| @AfterClass
| public void destroy(){
| emf.close();
| assert emf.isOpen() == false;
| }
|
What is tries to do is find a PaymentDevice using the two arguments. Nothing special...
datasourceJndiName is defined in the testng.xml filed as "testDb".
When I run this test I get the following Exception:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named testDb
I tried to figure it out myself, by following the dvd example of seam and various forums.
I can't find out anymore where it goes all wrong!?
Can anybody help me?
My configs are defined as following:
persistence.xml
|
| <persistence-unit name="testDb">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/testDataSource</jta-data-source>
| <properties>
| <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
| <property name="hibernate.cache.use_query_cache" value="true"/>
| <property name="hibernate.show_sql" value="false"/>
|
| <property name="jboss.entity.manager.factory.jndi.name" value="java:/testEntityManagerFactory" />
| </properties>
| </persistence-unit>
|
components.xml
<persistence:managed-persistence-context name="entityManager"
| auto-create="true"
| persistence-unit-jndi-name="java:/testEntityManagerFactory" />
mps-ds.xml
<local-tx-datasource>
| <jndi-name>testDataSource</jndi-name>
| <connection-url>jdbc:postgresql://localhost:5432/mps</connection-url>
| <driver-class>org.postgresql.Driver</driver-class>
| <user-name>postgres</user-name>
| <password>secretPassword:)</password>
| <!--
| <exception-sorter-class-name>
| org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
| </exception-sorter-class-name>
| <metadata>
| <type-mapping>mySQL</type-mapping>
| </metadata>
| -->
| </local-tx-datasource>
hibernate.cfg.xml
<hibernate-configuration>
| <session-factory>
|
| <property name="show_sql">false</property>
| <property name="connection.datasource">java:/testDataSource</property>
| <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
| <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
| <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
| <property name="hbm2ddl.auto">create-drop</property>
|
| </session-factory>
| </hibernate-configuration>
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118685#4118685
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118685
18 years, 6 months
[JBoss jBPM] - jBPM in EJB environment
by TMK
Hello,
I want to ust jBPM for controlling the state and the state transitions from a particular business object.
These business objects are represented by entity beans and my client application accesses the server via a stateless session bean. I am a bit confused about the best way to integrate jBPM in my application because I currently ask myself where I have to start the jBPM engine. I can't start the jBPM engine in a stateless session bean because the bean woild forget its state when the request is over.
I think I need a way to integrate jBPM in the way that it lives the whole time over many client requests which are made through my session bean.
Can someone of you help me with this problem?
Regards,
TMK
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118682#4118682
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118682
18 years, 6 months
[JBoss Tools (users)] - Ant Task not dependent upon Eclipse plugins
by wcrosman
Created an Ant Task for building Archive from the .projects file. I know Max and the team created one. This one is not dependent upon the Eclipse build system rather standard Ant jar, ear, war tasks.
Hope this might be useful to someone. Note: I've tested it mainly on jar tasks so it might need tweaked for ears and wars a bit.
Task Defs first then the java
Example targets below.
The first one builds a single archive defined in .packages : The property processArchive value is set
Second no processArchive value is set so all defined archives are processed
if "outputAntTargetsOnly" is set to true the console displays old style packaging-build.xml tasks.
| <!-- Archive Targets -->
| <target name="makeSAR" description="build SAR" depends="compile">
| <taskdef classname="gov.wapa.rmr.ant.JBossArchiveAntTask"
| name="jbossArchive" />
| <mkdir dir='dist' />
| <jbossArchive jbosspackages=".packages"
| outputAntTargetsOnly="false"
| processArchive="AuthenticationMBean.sar" />
| </target>
|
| <target name="makeAll" description="build Archives" depends="compile">
| <taskdef classname="gov.wapa.rmr.ant.JBossArchiveAntTask"
| name="jbossArchive" />
| <mkdir dir='dist' />
| <jbossArchive jbosspackages=".packages" outputAntTargetsOnly="false" />
| </target>
| ...................................................................................
| package gov.wapa.rmr.ant;
|
| import java.io.FileInputStream;
| import java.io.InputStreamReader;
| import java.util.Collection;
| import java.util.HashMap;
|
| import javax.xml.parsers.SAXParserFactory;
|
| import org.apache.tools.ant.BuildException;
| import org.apache.tools.ant.Task;
| import org.apache.tools.ant.taskdefs.Ear;
| import org.apache.tools.ant.taskdefs.Jar;
| import org.apache.tools.ant.taskdefs.War;
| import org.apache.tools.ant.taskdefs.Zip;
| import org.xml.sax.InputSource;
| import org.xml.sax.XMLReader;
| import org.xml.sax.helpers.DefaultHandler;
|
| /************************************************************
| * JBossArchiveAntTask is responsible for
| * JBossArchiveAntTask's functionality.
| *
| * @author Tom Crosman
| ***********************************************************/
| public class JBossArchiveAntTask extends Task {
| /**
| * Packages file defaults to ".packages"
| */
| private String jbossPackages = ".packages";
|
| private boolean outputAntTargetsOnly;
|
| private String processArchive;
|
| /**
| * Invoked by the handler to create a task specific to
| * the JBoss package. Initializes new task to the
| * parent environment. Package scope so only the handler
| * can invoke it.
| * @param type The ant task type to create.
| * @return the initialed task created.
| **/
| Zip createTask(String type) {
| Zip task = null;
| if ("jar".equals(type)) {
| task = new Jar();
| } else if ("war".equals(type)) {
| task = new War();
| } else if (type.indexOf("ear") != -1) {
| task = new Ear();
| } else if (type.indexOf("ejb") != -1) {
| task = new Jar();
| } else {
| throw new IllegalArgumentException("Unsupported type: " + type);
| }
|
| /** copy as much over as possible **/
| task.setDescription(getDescription());
| task.setLocation(getLocation());
| task.setOwningTarget(getOwningTarget());
| task.setProject(getProject());
| task.setRuntimeConfigurableWrapper(getRuntimeConfigurableWrapper());
| task.setTaskName(getTaskName());
| task.setTaskType(getTaskType());
|
| return task;
| }
|
| /**
| * {@inheritDoc}.
| * @see org.apache.tools.ant.Task#execute()
| */
| @Override
| public void execute() throws BuildException {
| JBossPackagesHandler hndlr = new JBossPackagesHandler(this);
| parseMe(hndlr);
| if (isOutputAntTargetsOnly()) {
| System.out
| .println("**************** No Packages Created -- Ant Targets Only ****************");
|
| HashMap<String, StringBuilder> antDefs = hndlr.getArchives();
| if (processArchive != null) {
| StringBuilder b = antDefs.get(processArchive);
| if (b != null) {
| System.out.println(b.toString());
| } else {
| System.out.println("No Archive: " + processArchive);
| }
| } else {
| Collection<StringBuilder> antTasks = antDefs.values();
| for (StringBuilder b : antTasks) {
| System.out.println(b.toString());
| }
| }
| System.out
| .println("**************** No Packages Created -- Ant Targets Only ****************");
| } else {
| HashMap<String, Zip> tasks = hndlr.getTasks();
| if (processArchive != null) {
| Zip task = tasks.get(processArchive);
| if (task != null) {
| task.execute();
| } else {
| System.out.println("No Archive: " + processArchive);
| }
| } else {
| for (Zip tsk : tasks.values()) {
| tsk.execute();
| }
| }
| }
| }
|
| /**
| * Property getter for jbossPackages.
| * @return Returns the jbossPackages.
| */
| public String getJbossPackages() {
| return jbossPackages;
| }
|
| /**
| * Property getter for processArchive.
| * @return Returns the processArchive.
| */
| public String getProcessArchive() {
| return processArchive;
| }
|
| /**
| * Property getter for outputTarget.
| * @return Returns the outputTarget.
| */
| public boolean isOutputAntTargetsOnly() {
| return outputAntTargetsOnly;
| }
|
| /**
| * Configures and launches the parsing of our xml file.
| *
| * @param handler the DocumentHandler that support parsing the
| * authenticate.dtd formatted xml file.
| */
| private void parseMe(DefaultHandler handler) {
| try {
| SAXParserFactory parseFact = SAXParserFactory.newInstance();
| XMLReader parser = parseFact.newSAXParser().getXMLReader();
| parser.setFeature("http://xml.org/sax/features/namespaces", true);
| parser.setFeature("http://xml.org/sax/features/validation", false);
| parser.setContentHandler(handler);
| parser
| .parse(new InputSource(
| new InputStreamReader(
| new FileInputStream(
| getProject()
| .getBaseDir()
| + "/" + jbossPackages))));
| } catch (Exception e) {
| e.printStackTrace();
|
| }
| }
|
| /**
| * Property setter for jbossPackages.
| * @param jbossPackages The jbossPackages to set.
| */
| public void setJbossPackages(String jbossPackages) {
| this.jbossPackages = jbossPackages;
| }
|
| /**
| * Property setter for outputTarget.
| * @param outputTarget The outputTarget to set.
| */
| public void setOutputAntTargetsOnly(boolean outputTarget) {
| this.outputAntTargetsOnly = outputTarget;
| }
|
| /**
| * Property setter for processArchive.
| * @param processArchive The processArchive to set.
| */
| public void setProcessArchive(String processArchive) {
| this.processArchive = processArchive;
| }
|
| }
| ....................................................................................................
| package gov.wapa.rmr.ant;
|
| import java.io.File;
| import java.util.HashMap;
|
| import org.apache.tools.ant.taskdefs.Zip;
| import org.apache.tools.ant.types.ZipFileSet;
| import org.xml.sax.Attributes;
| import org.xml.sax.SAXException;
| import org.xml.sax.helpers.DefaultHandler;
|
| /************************************************************
| * JBossPackagesHandler is responsible for
| * JBossPackagesHandler's functionality.
| *
| * @author Tom Crosman
| ***********************************************************/
| public class JBossPackagesHandler extends DefaultHandler {
|
| private final HashMap<String, StringBuilder> antTaskDefs;
|
| private final HashMap<String, Zip> tasks;
|
| private StringBuilder currArchive;
|
| private String folder;
|
| private HashMap<String, String> fileset;
|
| private Zip currentTask;
|
| private final JBossArchiveAntTask parentTask;
|
| /**
| * Creates a new JBossPackagesHandler.
| * @param bossArchiveAntTask
| */
| public JBossPackagesHandler(JBossArchiveAntTask bossArchiveAntTask) {
| this.parentTask = bossArchiveAntTask;
| antTaskDefs = new HashMap<String, StringBuilder>();
| tasks = new HashMap<String, Zip>();
| }
|
| /**
| * The doFileset method.
| */
| private void doFileset(String fldr) {
| ZipFileSet set = new ZipFileSet();
| set.setDir(new File(fileset.get("dir")));
| currArchive.append(" <zipfileset dir='");
| currArchive.append(fileset.get("xmlDir") + "' ");
| if (folder != null) {
| currArchive.append("prefix='" + folder + "' ");
| set.setPrefix(folder);
|
| }
| String includes = fileset.get("includes");
| String excludes = fileset.get("excludes");
| if (includes != null) {
| currArchive.append("includes='" + includes + "' ");
| set.setIncludes(includes);
| } else {
| set.setIncludes("");
| }
| if (excludes != null) {
| currArchive.append("excludes='" + excludes + "' ");
| set.setExcludes(excludes);
| } else {
| set.setExcludes("");
| }
|
| currArchive.append("/>\n");
| currentTask.addFileset(set);
| fileset = null;
| }
|
| /**
| * {@inheritDoc}.
| * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
| */
| @Override
| public void endElement(String uri, String localName, String name)
| throws SAXException {
| if ("package".equals(localName) && (currArchive != null)) {
| currArchive.append(" </jar>\n");
| currArchive.append("</target>\n");
|
| } else if ("folder".equals(localName)) {
| if (folder != null) {
| int slash = folder.lastIndexOf('/');
| if (slash == -1) {
| folder = null;
| } else {
| folder = folder.substring(0, slash);
| }
|
| }
|
| } else if ("fileset".equals(localName)) {
| // if (folder == null) {
| doFileset(folder);
| // }
| }
| }
|
| /**
| * Property getter for archives.
| * @return Returns the archives.
| */
| public HashMap<String, StringBuilder> getArchives() {
| return antTaskDefs;
| }
|
| /**
| * Property getter for tasks.
| * @return Returns the tasks.
| */
| public HashMap<String, Zip> getTasks() {
| return tasks;
| }
|
| /**
| * {@inheritDoc}.
| * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
| */
| @Override
| public void startElement(String uri, String localName, String name,
| Attributes attributes) throws SAXException {
| if ("package".equals(localName)) {
| String type = attributes.getValue("type");
| String taskName = attributes.getValue("name");
| currentTask = parentTask.createTask(type);
| tasks.put(taskName, currentTask);
|
| try {
| currArchive = new StringBuilder("<target name='");
|
| antTaskDefs.put(taskName, currArchive);
|
| String tName = attributes.getValue("name");
| currArchive.append(tName);
| currArchive.append("' description='build " + tName + "' >\n");
| String tmpToDir = attributes.getValue("todir");
| String toDir =
| tmpToDir.substring(tmpToDir.lastIndexOf("/") + 1);
| currArchive.append(" <mkdir dir='" + toDir + "' />\n");
|
| currArchive.append(" <jar destfile='" + toDir + "/" + tName
| + "'>\n");
|
| currentTask.setDestFile(new File(currentTask.getProject()
| .getBaseDir()
| + "/" + toDir + "/" + tName));
| } catch (IllegalArgumentException iae) {
| currArchive = null;
| currentTask = null;
| iae.printStackTrace();
| }
| } else if ("folder".equals(localName)) {
| if (folder == null) {
| folder = attributes.getValue("name");
| } else {
| folder = folder + "/" + attributes.getValue("name");
| }
| } else if ("fileset".equals(localName)) {
| fileset = new HashMap<String, String>();
| String dir = attributes.getValue("dir").substring(1);
| String xmlDir = dir.substring(dir.indexOf("/") + 1);
| String includes = attributes.getValue("includes");
| String excludes = attributes.getValue("excludes");
| fileset.put("includes", includes);
| fileset.put("excludes", excludes);
| fileset.put("dir", xmlDir);
| fileset.put("xmlDir", xmlDir);
|
| }
|
| }
|
| }
| .............................................................................
|
T
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118659#4118659
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118659
18 years, 6 months