Archive for the ‘java’ Category

Jboss / Wildfly maven plugin to deploy on localhost/remote server

This is a very simple solution, that unfortunately took me a couple of hours because I couldn´t find it anywhere…

Place your server properties in the maven settings.xml file (found in the .m2 folder) like this:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

	<profiles>
		<profile>
			<id>wildfly-remote</id>
			<properties>
				<wildfly-hostname>199.181.11.11</wildfly-hostname>
				<wildfly-port>9990</wildfly-port>
				<wildfly-username>remoteuser</wildfly-username>
				<wildfly-password>remotepassword</wildfly-password>
			</properties>
		</profile>

		<profile>
			<id>wildfly-local</id>
			<properties>
				<wildfly-home>/home/laura/wildfly-8.0.0.Final</wildfly-home>
				<wildfly-hostname>127.0.0.1</wildfly-hostname>
				<wildfly-port>9990</wildfly-port>
				<wildfly-username>laura</wildfly-username>
				<wildfly-password>localpassword</wildfly-password>
			</properties>
		</profile>

	</profiles>

	<activeProfiles>
		<activeProfile>wildfly-local</activeProfile>
		<activeProfile>wildfly-remote</activeProfile>
	</activeProfiles>

</settings>

In the pom.xml file place the plugins under build>plugins> and set the server configuration parameters as maven properties (without adding the in your pom):

<plugin>
				<groupId>org.wildfly.plugins</groupId>
				<artifactId>wildfly-maven-plugin</artifactId>
				<version>1.0.0.Final</version>
				<configuration>
					<hostname>${wildfly-hostname}</hostname>
					<port>${wildfly-port}</port>
					<username>${wildfly-username}</username>
					<password>${wildfly-password}</password>
				</configuration>
				<executions>
					<execution>
<!-- 						<phase>package</phase> -->
<!-- 						<goals> -->
<!-- 							<goal>deploy</goal> -->
<!-- 						</goals> -->
					</execution>
				</executions>
			</plugin>

To deploy on the localhost server run the following command:

wildfly:deploy -P wildfly-local

To deploy on the remote server run:

wildfly:deploy -P wildfly-remote

You can also run undeploy, redeploy…For further information see: https://docs.jboss.org/wildfly/plugins/maven/latest/

Primefaces dialog framework: how to make it work

If you have tried some primefaces features, you have probably noticed than some of those pretty things in the official showcase don´t work straight and easy in the application you´re developing. The problem is that even the latest 4.0 version is bugged.

I have been trying to use a Dialog Framework, but there´s something missing from the JqueryUI library and I have found out that the only way to make it work was including an external one, like:

There´s something missing from the JqueryUI library and I have found out that the only way to make it work was including the jqueryUI library (with the h:outputScript component).

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<h:head>
<title>Enter Product Mapping</title>
</h:head>

<h:outputScript name="js/jquery-ui-1.10.4.custom.min.js"/>

<p:commandButton value="Map"
actionListener="#{managedBean.showDialog}" />
</h:form>

</h:body>
</html>

Importing the jqueryui library is the only way to let the browser find the dialog properties (like “draggable”, “resizable”, “width”…). So I could make the following method work:

public void showDialog(){

Map<String,Object> options = new HashMap<String, Object>();
options.put("contentHeight", 340);
options.put("height", 400);
options.put("width",700);

RequestContext.getCurrentInstance().openDialog("dialog",options,null);

}

It will open the dialog that you need to put in another page (in this case the dialog.xhtml file):

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Enter Product mapping</title>
</h:head>
<h:body>
<h:form id="form">

<h:panelGrid id="grid" columns="3">

<f:facet name="header">
<p:messages for="query" />
</f:facet>

<h:outputLabel value="Username" />
<p:inputText id="username" value="#{managedBean.userName}" />
<p:message for="username" />

<h:commandButton value="Save" id="btn" process="@form" actionListener="#{managedBean.updateDialog}" />

</h:panelGrid>
</h:form>

</h:body>

</ui:composition>

The actionListener refers to a method in the managed bean class, that will process the submitted form.

To make it work you also need to add some properties in the faces-config.xml:

..

<application>

..

<action-listener>org.primefaces.application.DialogActionListener</action-listener>
<navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
<view-handler>org.primefaces.application.DialogViewHandler</view-handler>

....

</application>

...

Ant task to execute a main class with command line args parameters

Yeah, once again another HelloWorld stuff on the web. I was just curious to try to execute a Main class with an Ant script and found out that I couldn´t find the straight working snippets online easily, because I couldn´t get to know how to set the classpath. So I have wasted some minutes to make it work.

Let´s consider a little more than the classic HelloWorld example and pass a command line parameter as well:

package de.demo;

public class HelloWorld {

public static void main(String[] args) {
System.out.println("Hello Main! \n"  + "Parameter: "+ args[0]);
}

}

Then run following build.xml script:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<project basedir="." default="run" name="Ant Hello World">
	
	<property name="src" value="." />

	<path id="classpath">
		<fileset dir="${src}">
		</fileset>
	</path>

	<target name="compile">
		<javac srcdir="." />
	</target>

	<target name="run" depends="compile">
		<!-- Print directly in the console -->
		<echo message="Hello World!" />
		<!-- Run main class with parameters-->
		<java classname="de.demo.HelloWorld">
			<arg value="10"/>
			<classpath refid="classpath">
			</classpath>
		</java>
	</target>

</project>

In the console you will see something like:

Buildfile: C:\Users\liparulol\workspace\AntDemos\buildHelloWorld.xml
compile:
[javac] C:\Users\liparulol\workspace\AntDemos\buildHelloWorld.xml:14: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 1 source file
run:
[echo] Hello World!
1 Hello Main!
1 Parameter10
BUILD SUCCESSFUL
Total time: 745 milliseconds

That´s it!

Arquillian testing with Maven in Eclipse: Deployment scenario issue (Glassfish embedded example)

To run a test with Arquillian using Maven you might consider embedded, local or remote containers. You can set them all in your pom.xml file and specify deployment profiles like the following:

 <profile>
			<id>arquillian-glassfish-embedded</id>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
			<dependencies>
				<dependency>
					<groupId>org.jboss.arquillian.container</groupId>
					<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
					<version>1.0.0.CR4</version>
					<scope>test</scope>
				</dependency>
				<dependency>
					<groupId>org.glassfish.main.extras</groupId>
					<artifactId>glassfish-embedded-all</artifactId>
					<version>4.0</version>
					<scope>provided</scope>
				</dependency>

				<dependency>
					<groupId>org.glassfish.jersey.core</groupId>
					<artifactId>jersey-client</artifactId>
					<version>2.4.1</version>
					<scope>provided</scope>
				</dependency>

				<dependency>
					<groupId>org.glassfish.jersey.containers</groupId>
					<artifactId>jersey-container-servlet</artifactId>
					<version>2.4.1</version>
					<scope>provided</scope>
				</dependency>

			</dependencies>
		</profile>

The container must be configured in the arquillian.xml file. A simple one might look like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://jboss.org/schema/arquillian"
   xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
   <!--  this is only needed if you want to override AS7  -->
   <!--  <defaultProtocol type="Servlet 3.0"/> -->
   <container qualifier="arquillian-glassfish-embedded">
   	<configuration>
   		<property name="bindHttpPort">9090</property>
   	</configuration>
   </container>
   <!-- 
   <container qualifier="tomcat">
   	<configuration>
   		<property name="user">tomcat</property>
   		<property name="pass">tomcat</property>
   	</configuration>
   </container>
    -->
</arquillian>

Setting the container in the pom.xml and the arquillian.xml files is not enough to run the test in Eclipse.
You would get the following error:

org.jboss.arquillian.container.test.impl.client.deployment.ValidationException: DeploymentScenario contains a target (_DEFAULT_) not matching any defined Container in the registry.
Please include at least 1 Deployable Container on your Classpath.
          at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.throwNoContainerFound(DeploymentGenerator.java:250)
          at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.throwTargetNotFoundValidationException(DeploymentGenerator.java:243)
          at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.validate(DeploymentGenerator.java:102)
          at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:84)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
          at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
          at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
…

To make the test run you need to set the active maven profiles in Eclipse. Simply right click on the project and select Properties>Maven and add “arquillian-glassfish-embedded” in the Active maven profiles textbox.

Glassfish 4.0 : “Hello world” application with Maven 3

The following steps will allow you to develop and deploy a first demo web-app with Glassfish Server 4.
1) To install Glassfish 4.0 follow the steps at http://glassfish.java.net/download.html
For example, you can get the zip version and extract into: C:\glassfish4.

2) If you´re working on a Windows Desktop Rename glassfish4/glassfish/bin asadmin to *.s to prevent the following Maven error:
Unable to start domain "domain1". IOException: Cannot run program"C:\glassfishv3\glassfish\bin\asadmin": CreateProcess error=193, %1 is not a valid Win32-Application

In this way The system will run asadmin.bat, instead of calling the Linux script (provided with no file extension by Glassfish).

3) On Eclipse install Glassfish plugin (https://marketplace.eclipse.org/content/glassfish-tools-kepler) to manage the server graphically. Otherwise you would not be able to installing with the command File>New>Other>Server> etc.
Starting Glassfish for the first time, you will have a user called “admin” with no password. You can manage Glassfish with Admin-Console available at: http://localhost:4848/ or even with asadmin CLI console (under C:\glassfish4\glassfish\bin).

4) To deploy your application using Maven, create the settings.xml file under the .m2 folder (for example, under Windows at the location: C:\Users\username\.m2), providing the glassfish profile credentials: they will automatically imported in the pom.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profiles>
        <profile>
            <id>glassfish-context</id>
            <properties>
                <local.glassfish.home>C:\\glassfish4\\glassfish</local.glassfish.home>
                <local.glassfish.user>admin</local.glassfish.user>
                <local.glassfish.domain>domain1</local.glassfish.domain>
                <local.glassfish.passfile>
            ${local.glassfish.home}\\domains\\${local.glassfish.domain}\\config\\domain-passwords
                </local.glassfish.passfile>
            </properties>
        </profile>
    </profiles>
 
    <activeProfiles>
        <activeProfile>glassfish-context</activeProfile>
    </activeProfiles>
</settings>

5) Create a new Maven project with the maven archetype “maven-archetype-webapp” template. As a default you can already find the index.jsp HelloWorld page.

6) Add the following plugins to the pom.xml:

…
<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.1.1</version>
				<configuration>
					<failOnMissingWebXml>false</failOnMissingWebXml>
					<!-- <webXml>src\main\webapp\WEB-INF\web.xml</webXml> -->
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.glassfish.maven.plugin</groupId>
				<artifactId>maven-glassfish-plugin</artifactId>
				<version>2.1</version>
				<configuration>
				<glassfishDirectory>${local.glassfish.home}</glassfishDirectory>
					<user>admin</user>
					<passwordFile>${local.glassfish.passfile}</passwordFile>
					<domain>
						<name>domain1</name>
						<httpPort>8080</httpPort>
						<adminPort>4848</adminPort>
					</domain>
					<components>
						<component>
							<name>${project.artifactId}</name>
					<artifact>target/${project.build.finalName}.war</artifact>
						</component>
					</components>
					<debug>true</debug>
					<terse>false</terse>
					<echo>true</echo>
				</configuration>
			</plugin>

		</plugins>
		<finalName>Glassfish_HelloWorld</finalName>
	</build>
</project>

7) Launch the maven command:
clean package glassfish:deploy

You may find errors related to the Dynamic Web Module in the Eclipse project, even if the maven gives you “BUILD SUCCESS”. For now it´s ok.

With the given pom.xml the application will be deployed into:
C:\glassfish4\glassfish\domains\domain1\applications

You can see it up and running at: http://localhost:8080/Glassfish_HelloWorld/

You can manage the applications, for example editing the Content Root folder, directly in the administration console.

Demo Code available at:
http://sourceforge.net/p/mavendemo/code/HEAD/tree/GlassfishHelloWorld/

JAXB part 8: generate classes from DTD with maven

After using JAXB with XSD schema, I have finally discovered that it´s MUCH better to make it with files and jaxd binding files.

Supposing you want to generate the classes for a web-app xml file, in the Maven pom.xml you need to add something like:

<plugin>
  <groupId>org.jvnet.jaxb2.maven2</groupId>
   <artifactId>maven-jaxb2-plugin</artifactId>
      <executions>
 	<execution>
        	<goals>
	        	<goal>generate</goal>
		</goals>
		<configuration>
		<!-- if you want to put DTD somewhere else <schemaDirectory>src/main/jaxb</schemaDirectory> -->
			<schemaDirectory>src/main/resources/web</schemaDirectory>
			   <generateDirectory>${basedir}/src/main/java</generateDirectory>
				<packagename>com.my.package</packagename>
		 		    <extension>true</extension>
					<schemaLanguage>DTD</schemaLanguage>
					    <schemaIncludes>
						<schemaInclude>*.dtd</schemaInclude>
					    </schemaIncludes>
					<bindingIncludes>
					    <bindingInclude>*.jaxb</bindingInclude>
						</bindingIncludes>
						<args>
						   <arg>-Xinject-listener-code</arg>
						</args>
						</configuration>
					</execution>
				</executions>
		<dependencies>
			<dependency>
				<groupId>org.jvnet.jaxb2-commons</groupId>
				<artifactId>property-listener-injector</artifactId>
				<version>1.0</version>
			</dependency>
		</dependencies>
</plugin>

In the specified schema directory there must be both the .dtd and the .jaxb binding files.
To specify a package for the generated classes, in the jaxb file like:

<?xml version="1.0" ?>
     <xml-java-binding-schema xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
  xmlns:ci="http://jaxb.dev.java.net/plugin/listener-injector">
         <options package="deploy.service.webapp" />
            <xjc:serializable/>
    </xml-java-binding-schema>

You can find a full demo of a web-app xml schema classes generation at sourceforge: JAXB DTD maven demo

JAXB part 7: increase performance with singleton JaxbContext instance

Currently I am developing an application to rename some jboss configuration content.
Using JAXB, I had made marshalling and unmarshalling methods, creating a new JAXBcontext instance each time the single methods were invoked (for each xml file!).
The application was incredibly slow. Taking up to 45 minutes to complete the tasks.
Then I have discovered that I could make it all in less than 30% of the time, by using a singleton design pattern to reuse a single instance of the JAXBContext.

All you need to do is:
1) creating a singleton class to instance the context
2) use it in your marshalling/unmarshalling method.

The singleton class is like this:

import javax.xml.bind.DataBindingException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import com.nexus.pacs.conf.xmdesc.Mbean;

import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

public class MbeanJAXBContext {

	private static JAXBContext instance;

	public XmdescJAXBContext() {
	}

	public static synchronized JAXBContext initContext() {
		try {
			if (instance == null)
				instance = JAXBContext.newInstance(Mbean.class);
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return instance;
	}

}

I am using the synchronized keyword to make it thread safe.
Then you can instance your context like this:

public static void marshaller(Mbean mbean, String filePath)
			throws CustomizerException {

	StringWriter stringWriter = new StringWriter();
	String xmlContent;
	File file = new File(filePath);

	try {
		xmlContent = FileUtils.readFileToString(file, "UTF-8");
		FileWriter fileWriter = new FileWriter(file);
		XmdescJAXBContext jaxbHelper = new XmdescJAXBContext();
		JaxbContext jaxbContext= jaxbHelper.initContext();
		Marshaller marshaller = jaxbContext.createMarshaller();

                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
			marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);

		marshaller.setProperty(CharacterEscapeHandler.class.getName(),
					new XmlCharacterHandler());

		 synchronized(marshaller){
		     marshaller.marshal(mbean, stringWriter);
		    }
		
	xmlContent = XmdescContentHandler.addEntityReferences(xmlContent,
					stringWriter.toString());
		fileWriter.write(xmlContent);

		fileWriter.flush();
		fileWriter.close();

		} catch (MarshalException e) {

		throw new CustomizerException("Marshalling the file: " + filePath
					+ "not possible. Wrong file content");

		} catch (JAXBException e) {

		throw new CustomizerException("Could not parse the XML file: "
					+ filePath);

		} catch (IOException e) {

		throw new CustomizerException("Could not access the file: "
					+ filePath);
		}

	}

Awfully I have also noticed that with Ubuntu 12.04, with the singleton instance, the application now takes just a minute to run, while with Windows 7 it still takes 16 minutes. Long live Linux!

You can find a post about the Character Handler in this blog. Have fun!

JAXB part 6: entities references expansion (before unmarshalling)

Let´s consider an xml file with entity references.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mbean PUBLIC "members of the whole firm" "team.dtd">
<team category="developer">
    <Member role="junior">Laura</Member>
    <Member role="senior">Mike</Member>
    &john;
</team>

In your dtd schema you can specify the reference.

<?xml version="1.0" encoding="UTF-8"?>
  <!ENTITY john '<Member role="boss">John</Member>'>

If you need to unmarshal an xml file with entity references, first of all you need to expand them.

public static String xmlStringEntityResolver(String filePath)
			throws ParserConfigurationException, SAXException, IOException,
			TransformerException, JAXBException {

		File file = new File(filePath);
		DocumentBuilderFactory builderFactory = DocumentBuilderFactory
				.newInstance();
		// Specifies that the parser produced by this code will
		// expand entity reference nodes
		builderFactory.setExpandEntityReferences(true);
		DocumentBuilder builder = builderFactory.newDocumentBuilder();
		Document doc = builder.parse(file);
		TransformerFactory transformerFactory = TransformerFactory
				.newInstance();
		Transformer transformer = transformerFactory.newTransformer();
		transformer.setOutputProperty(OutputKeys.INDENT, "yes");

		StringWriter writer = new StringWriter();
		StreamResult result = new StreamResult(writer);
		DOMSource source = new DOMSource(doc);
		transformer.transform(source, result);
		// System.out.println("Expandend xml file: \n" + writer.toString());
		return writer.toString();
	}

Then you can unmarshal the file passing it as a string file.

public static Team unmarshall(String xmlString)
			throws ParserConfigurationException, SAXException, IOException,
			TransformerException, JAXBException {

		// unmarshaller from string
		JAXBContext jaxbContext = JAXBContext.newInstance(Team.class);
		Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
		InputStream stream = new ByteArrayInputStream(
				xmlString.getBytes("UTF-8"));
		Team team = (Team) unmarshaller.unmarshal(stream);

		return team;

	}

I would like to find a better way. I´ll see what I can do.

JAXB part 5: XML Character handler

With JAXB you need to dhandle special characters you can just choose between two options.

Otherwise you need to define your own character handler.

The following class shows you how to handle both CDATA elements and special characters.

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;

import com.sun.xml.bind.marshaller.CharacterEscapeHandler;

public class XmlCharacterHandler implements CharacterEscapeHandler {

	public void escape(char[] buf, int start, int len, boolean isAttValue,
			Writer out) throws IOException {
		StringWriter buffer = new StringWriter();

		for (int i = start; i < start + len; i++) {
			buffer.write(buf[i]);
		}

		String st = buffer.toString();

		if (!st.contains("CDATA")) {
			st = buffer.toString().replace("&", "&amp;").replace("<", "&lt;")
					.replace(">", "&gt;").replace("'", "&apos;")
					.replace("\"", "&quot;");

		}
		out.write(st);
//		System.out.println(st);
	}

}

In your marshaller method just add the following property:

	marshaller.setProperty(CharacterEscapeHandler.class.getName(),
					new XmlCharacterHandler());

JAXB part 4: handling CDATA elements

If you want to specify that element values are CDATA, you can create an adapter class like this:

import javax.xml.bind.annotation.adapters.XmlAdapter;

/**
 * to parse CDATA values.
 * 
 * @author Laura Liparulo
 */
public class AdapterXmlCDATA extends XmlAdapter<String, String> {

    @Override
    public String marshal(String value) throws Exception {
        return "<![CDATA[" + value + "]]>";
    }
    @Override
    public String unmarshal(String value) throws Exception {
        return value;
    }

}

In the bean class, generated by JAXB add the following annotation.

    @XmlJavaTypeAdapter(AdapterXmlCDATA.class)
    protected String description;

In this way any occurrence of the elements with the annotation above will be automatically parsed as CDATA.

Categories
Links: