Brian Fitzpatrick [
http://community.jboss.org/people/bfitzpat] modified the blog post:
"Using the Annotation Properties view to create an ESB 4.9 Action"
To view the blog post, visit:
http://community.jboss.org/community/jbosstools/blog/2010/09/30/using-the...
--------------------------------------------------------------
In my
http://community.jboss.org/en/jbosstools/blog/2010/09/13/extending-the-ec...
last article, I talked about how to extend the Annotation Properties view provided as part
of WTP in Eclipse Helios. And that gets into the implementation details of adding your own
annotations.
Here, I'd like to focus on how you'd use the view in conjunction with ESB support
in JBoss Tools to actually create a new ESB action using the annotations added as part of
ESB 4.9. Now instead of extending the AbstractActionPipelinedProcessor class you can
create your own POJO and annotate to indicate various configuration options, as documented
http://community.jboss.org/docs/DOC-15525 here.
Let's say you want to create a simple PrintMessageAction, similar to the example that
extends AbstractActionPipelinedProcessor, but want to see the differences between the two
implementations. (You can find the original example implementation in the ESB
Programmer's Guide
http://docs.redhat.com/docs/en-US/JBoss_Enterprise_SOA_Platform/5/html/ES...
here.)
The original example code looks like this (Listing 1):
public class PrintMessage extends AbstractActionPipelineProcessor { private String
information; private Integer repeatCount; public PrintMessage(ConfigTree config) {
information = config.getAttribute("information"); repeatCount = new
Integer(config.getAttribute("repeatCount")); } public Message process(Message
message) throws ActionProcessingException { for (int i=0; i < repeatCount; i++)
{ System.out.println(information); } }}
As you can see, if you already had a PrintMessage class, you'd have to revamp it a bit
to get it to work. Let's say you have this class (Listing 2):
import org.jboss.soa.esb.message.Message;public class PrintMessage { private String
information; private Integer repeatCount; public void printMessage(Message message)
{ for (int i=0; i < repeatCount; i++) { System.out.println(information);
} }}
If you use the new ESB annotations available in ESB 4.9, this becomes much more
straightforward (Listing 3):
import org.jboss.soa.esb.message.Message;public class PrintMessage { @ConfigProperty //
this will come from the ESB configuration private String information; @ConfigProperty //
this also will come from the ESB configuration private Integer repeatCount; @Process
// and this is the actual action that will get invoked public void printMessage(Message
message) { for (int i=0; i < repeatCount; i++) {
System.out.println(information); } }}
By now you're wondering - so how does the tooling come into this? Well, with the new
Annotation Properties view and the ESB annotations we hooked up in the upcoming JBoss
Tools 3.2 Beta1 release, you can let the tooling add the annotations for you.
In JBoss Tools, let's say that you have your original PrintMessage class (Listing 2)
open in your ESB project and you want to turn it into an ESB action you can configure for
the project.
To open and use the Annotation Properties view
1. Go to Window->Show View->Other
2. Type "Annotation" in the search box
3. Select JAX-WS->Annotation Properties
http://community.jboss.org/servlet/JiveServlet/showImage/38-1970-9586/ann...
http://community.jboss.org/servlet/JiveServlet/downloadImage/38-1970-9586...
4. Click OK.
By default, all available annotations are enabled in the view. This will most likely cause
you to see a message such as "No suitable library can be found on the projects
classpath." To get around this since we're just interested in ESB annotations at
this point, we simply filter out the other types.
To change the filtered annotation types:
1. In the View Menu for the Annotation Properties view, select "Filters..."
2. When the Selection Needed dialog appears, make sure that all other annotation types are
checked except for JBoss ESB
http://community.jboss.org/servlet/JiveServlet/showImage/38-1970-9584/ann...
http://community.jboss.org/servlet/JiveServlet/downloadImage/38-1970-9584...
3. Click OK
Now, with your PrintMessage class open and the Annotation Properties view open and
filtered for ESB annotations, select the "information" class variable. In the
Annotations list, you should see org.jboss.soa.esb.configure.ConfigProperty appear, as in
the following image:
http://community.jboss.org/servlet/JiveServlet/showImage/38-1970-9541/Inf...
http://community.jboss.org/servlet/JiveServlet/downloadImage/38-1970-9541...
If you click the "Values" checkbox beside the ConfigProperty annotation,
you'll see @ConfigProperty() appear above the variable. Do it again for the
repeatCount variable as well.
http://community.jboss.org/servlet/JiveServlet/showImage/38-1970-9542/rep...
http://community.jboss.org/servlet/JiveServlet/downloadImage/38-1970-9542...
The last step is to click on the method line for printMessage(Message message) and check
the @Process annotation box.
http://community.jboss.org/servlet/JiveServlet/showImage/38-1970-9543/pri...
http://community.jboss.org/servlet/JiveServlet/downloadImage/38-1970-9543...
And that's it for this example. You'll notice if you look closely at the
@ConfigProperty annotation in the Annotation Properties view that you can expand it and
set different properties on the annotation as well. So there is room for further
configuration there.
Once you configure your action in an ESB configuration file and deploy it, you can test
it. In this case, I'm using a simple JMS queue to send a message to the service to
trigger it. The action gets the configuration from the properties we set in the
jboss-esb.xml file, and we can see the output in the console:
http://community.jboss.org/servlet/JiveServlet/showImage/38-1970-9583/esb...
http://community.jboss.org/servlet/JiveServlet/downloadImage/38-1970-9583...
So starting with the JBoss Tools 3.2 Beta you'll have some new tools in the ESB
toolbox for custom actions!
--------------------------------------------------------------
Comment by going to Community
[
http://community.jboss.org/community/jbosstools/blog/2010/09/30/using-the...]