JAXB stands for Java Architecture for XML Bindings. In a nutshell, JAXB used for convert Java Object to XML and vice versa. We called it marshalling to convert Java object to XML and unmarshalling to convert XML to Java object. JAXB bundled in Java 1.6++, so we do not need another external libraries (but sometimes I loved to adding testing and logging framework). First, you have to know the technology that I used in this tutorial are :
- Maven 3
- TestNG (for unit test)
Some of you would frown and said “hmm, why you put commons-io on this tutorial?”. Simple, I used it in unit-test to get xml file from resource folder and convert to String, I know it can be done with the classic inputstream ways. but remember to not reinventing the wheel :)
By default, CXF will mapping CXFServlet to /cxf context path. I used Servicemix 4.5 which using CXF 2.7.3 inside. its define static in osgiservlet.xml in cxf-rt-transport-http (FYI, for CXF 2.7.3, they are using transport-http ver. 2.6.3). So, based on default configuration, all our CXF service will result like http://localhost:8181/cxf/myservice, this is not good. because sometimes you want define service itself.
I ever had a problem when want to using Jaxb in Servicemix 4.x which used OSGI. Like documentation describe on this page, we will know how to use Jaxb with apache camel. What we have to do is adding line below :
DataFormat jaxb = new JaxbDataFormat("com.foo.bar");
Above endpoint will route the jaxb unmarshal result to another queue. JaxbDataFormat will automatically search entity with JaxB @XMLRootElement inside package. But you will get a problem when implemented those code in OSGI. here is the error message :
Have you ever get confused when trying TestNG for the first time? especially when want to make a unit test with some execution order? I have :). So, I made a little example to encounter those problem. As we know, TestNG has some annotation to point our method/class and indicate when the test will running. Some of which are :
- @BeforeSuite: The annotated method will be run before all tests in this suite have run.
- @BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run.
- @BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked.
- @BeforeClass: The annotated method will be run before the first test method in the current class is invoked.
- @BeforeMethod: The annotated method will be run before each test method.
When I am in production and have issue that has big influence to the others, I always make a branch from trunk in order to not bother development other developer, if my issue has finished, I just have to merge my branch to trunk. then how? there are several way to through it, some of which are :
- Using visual diff/merge tool like meld
- Using reintegrate svn command.
For easily way, especially if your changes is not too much. You can using merge tool application that you can find in internet (remember if it’s paid application, the property is belong to respective owners). I am usually using meld, very easy to use. You can check the diff in file, folder and svn! :D