Send mail in Apache TomEE

Make javax.mail and impl as maven scope provided, as TomEE comes with geronimo mail implementation.

Also use resource injection of mail session:

https://dwuysan.wordpress.com/2016/02/17/sending-email-on-apache-tomee/

(If mail account is Gmail, turn ON ‘Allow less secure apps’)

In Tomee.xml:

<?xml version="1.0" encoding="UTF-8"?>
<tomee>
    <!-- see http://tomee.apache.org/containers-and-resources.html -->
 
    <!-- activate next line to be able to deploy applications in apps -->
    <!-- <Deployments dir="apps" /> -->
    <Resource id="tomee/mail/GMailSMTP" type="javax.mail.Session">
    mail.smtp.host=smtp.gmail.com
    mail.smtp.starttls.enable=true
    mail.smtp.port=587
    mail.transport.protocol=smtp
    mail.smtp.auth=true
    mail.smtp.user=<!-- your email address -->
    password=<!-- your password, and not 'mail.smtp.password' -->
    </Resource>
</tomee>

Injection of resource:

@Stateless
@LocalBean
@Path(value = "workline")
public class MailService {
    @Resource(mappedName = "java:comp/env/tomee/mail/GMailSMTP")
    private Session smtpSession;
 
    public boolean sendMail() throws NamingException {
        final Message message = new MimeMessage(this.smtpSession);
        try {
            message.setRecipients(Message.RecipientType.TO, new Address[]{
                new InternetAddress("someone@gmail.com")
            });
            message.setSubject("Email from TomEE");
            message.setSentDate(new Date());
            message.setText("Email from TomEE");
            Transport.send(message);
        } catch (Exception e) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, e);
            return false;
        }
        return true;
    }
}

A raw implementation:

package com.origami.rpp.util;

import com.origami.config.SisVars;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

/**
 *
 * @author Origami
 */
public class Email {

    protected List<File> adjuntos = new ArrayList<>();
    protected String usuarioCorreo = SisVars.correo;
    protected String password = SisVars.pass;
    protected String rutaArchivo1;
    protected String nombreArchivo1;
    protected String rutaArchivo2;
    protected String nombreArchivo2;
    protected String destinatario;
    protected String copiaOcultaBCC;
    protected String copiaCC;
    protected String asunto;
    protected String mensaje;

    public Email(String destinatario, String copiaOcultaBCC, String copiaCC, String asunto, String mensaje, List<File> files) {
        this.destinatario = destinatario;
        this.copiaOcultaBCC = copiaOcultaBCC;
        this.copiaCC = copiaCC;
        this.asunto = asunto;
        this.mensaje = mensaje;
        if(files != null) this.adjuntos = files;
    }

    public Email(String destinatario, String asunto, String mensaje, List<File> files) {
        this(destinatario, null, null, asunto, mensaje, files);
    }

    public boolean sendMail() {
        try {
            //INGRESO DE LAS POROPIEDADES DE LA CONEXION
            Properties props = new Properties();
            props.setProperty("mail.transport.protocol", "smtp");
            props.setProperty("mail.smtp.host", SisVars.smtp_Host);
            props.setProperty("mail.smtp.starttls.enable", "true");
            props.setProperty("mail.smtp.port", SisVars.smtp_Port);
            props.setProperty("mail.smtp.user", usuarioCorreo);
            props.setProperty("mail.smtp.auth", "true");
            //INSTANCIA DE LA SESSION
            Session session = Session.getInstance(props, null);
            //CUERPO DEL MENSAJE
            MimeMessage mimeMessage = new MimeMessage(session);
            mimeMessage.setFrom(new InternetAddress(usuarioCorreo, "EMPRESA PUBLICA MUNICIPAL DEL REGISTRO DE LA PROPIEDAD DEL CANTON PORTOVIEJO EP"));
            mimeMessage.setSubject(asunto);
            mimeMessage.setSentDate(new Date());
            mimeMessage.addRecipients(Message.RecipientType.TO, InternetAddress.parse(destinatario));
            if (copiaOcultaBCC != null) {
                mimeMessage.addRecipients(Message.RecipientType.BCC, InternetAddress.parse(copiaOcultaBCC));
            }
            if (copiaCC != null) {
                mimeMessage.addRecipients(Message.RecipientType.CC, InternetAddress.parse(copiaCC));
            }
            //TEXTO DEL MENSAJE
            MimeBodyPart texto = new MimeBodyPart();
            texto.setText(mensaje);
            //CONTENEDOR DE LAS PARTES
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(texto);
            //ADJUNTAR LOS ARCHIVO EN PARTES
            MimeBodyPart file;
            for (File f : adjuntos ) {
                file = new MimeBodyPart();
                file.attachFile(f.getAbsolutePath());
                multipart.addBodyPart(file);
            }
            //AGREGAR MULTIPART EN CUERPO DEL MENSAJE
            mimeMessage.setContent(multipart);
            // ENVIAR MENSAJE
            Transport transport = session.getTransport("smtp");
            transport.connect(usuarioCorreo, password);
            transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
            transport.close();
            
            
            
        } catch (MessagingException ex) {
            Logger.getLogger(Email.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception e) {
            Logger.getLogger(Email.class.getName()).log(Level.SEVERE, null, e);
        }
        return true;
    }

}
Advertisements

Fix JMX RMI port configuration

Set the following ports in java command line:

com.sun.management.jmxremote.port
com.sun.management.jmxremote.rmi.port

Example on unique port 9229:

-Djava.net.preferIPv4Stack=true 
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9229 
-Dcom.sun.management.jmxremote.rmi.port=9229
-Djava.rmi.server.hostname=190.57.138.218 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false

In Tomcat / TomEE set them in bin/setenv.sh file:

export CATALINA_OPTS="$CATALINA_OPTS -server -Xmx6000m -Xms512m -XX:MaxPermSize=400m -Djava.net.preferIPv4Stack=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9229 -Dcom.sun.management.jmxremote.rmi.port=9229 -Djava.rmi.server.hostname=190.57.138.218 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

export JAVA_OPTS="-client -Xms8m -Xmx128m -XX:MaxPermSize=64m -Djava.net.preferIPv4Stack=true"

Due to a bug this doesnt works in java versions <= 1.7.0_51. Please upgrade the java/JDK version.

Resources:

http://stackoverflow.com/questions/20884353/why-java-opens-3-ports-when-jmx-is-configured/21552812#21552812

Simple JSF View Scope for Spring

Light version of:

https://github.com/michail-nikolaev/primefaces-spring-scopes
https://github.com/javaplugs/spring-jsf

without destruction callback listener support

and

http://forum.spring.io/forum/spring-projects/web/72898-view-scope-with-spring

ideas


package org.nkey.primefaces.scopes.test.spring.scope;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;

import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.PreDestroyViewMapEvent;
import javax.servlet.http.HttpSession;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;

/**
 * @author m.nikolaev Date: 21.11.12 Time: 0:37
 */
public class ViewScope implements Scope, Serializable{
    private static final Logger LOGGER = LoggerFactory.getLogger(ViewScope.class);
    
    @Override
    public Object get(String name, ObjectFactory objectFactory) {
        final Map<String, Object> viewMap = FacesContext.getCurrentInstance().getViewRoot().getViewMap();

		if (viewMap.containsKey(name)) {
			Object bean = viewMap.get(name);			

			// // restore a transient autowired beans after re-serialization bean
			//WebApplicationContext webAppContext = ContextLoader.getCurrentWebApplicationContext();
			//AutowireCapableBeanFactory autowireFactory = webAppContext.getAutowireCapableBeanFactory();
			
			//if (webAppContext.containsBean(name)) {
				// Reconfigure resored bean instance.
				//bean = autowireFactory.configureBean(bean, name);
			//}
			// // end restore
			
			return bean;
		} else {
			final Object object = objectFactory.getObject();
			viewMap.put(name, object);

			return object;
		}
    }

    @Override
    public Object remove(String name) {
        return FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove(name);
    }

    @Override
    public String getConversationId() {
        return null;
    }

    @Override
    public void registerDestructionCallback(String name, Runnable callback) {
        
    }

    @Override
    public Object resolveContextualObject(String key) {
        return null;
    }


package org.nkey.primefaces.scopes.test.spring.scope;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * @author m.nikolaev Date: 21.11.12 Time: 1:01
 */
@Qualifier
@Scope("view")
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface SpringViewScoped {
}

applicationContext.xml

<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
        <property name="scopes">
            <map>
                <entry key="view">
                    <bean class="org.nkey.primefaces.scopes.test.spring.scope.ViewScope"/>
                </entry>
            </map>
        </property>
    </bean>

NoSuchMethodError when having an Map abstract class extending abstractmap in EclipseLink

Entity Bean inheritance definition

Base superclass extending IdentityhashMap:


public class EntityModel<K extends String, V extends Object> extends IdentityHashMap<String, Object>{

    public EntityModel() {
        super();
    }
    
    
    
}

Entity JPA:

@Entity
@Table(name = "acl_usuario")
@SequenceGenerator(name = "global_seq", sequenceName = "global_seq", allocationSize = 20)
public class Usuario extends EntityModel{

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "global_seq")
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    protected Long id;

    @Basic(optional = false)
    @Column(name = "username", length = 50, nullable = false)
    protected String username;

    @Basic(optional = false)
    @Column(name = "pass", length = 20, nullable = false)
    protected String pass;

    @Basic(optional = false)
    @Column(name = "habilitado", nullable = false)
    protected Boolean habilitado;

    @JoinColumn(name = "rol", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Rol rol;

    @OneToMany(mappedBy = "supervisor", fetch = FetchType.LAZY)
    private Collection<OrdenTrabajo> supervisorCollection;

    @OneToMany(mappedBy = "responsable", fetch = FetchType.LAZY)
    private Collection<OrdenTrabajo> responsableCollection;

    public Usuario() {
        super();
        
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public Boolean getHabilitado() {
        return habilitado;
    }

    public void setHabilitado(Boolean habilitado) {
        this.habilitado = habilitado;
    }

    public Rol getRol() {
        return rol;
    }

    public void setRol(Rol rol) {
        this.rol = rol;
    }

    public Collection<OrdenTrabajo> getSupervisorCollection() {
        return supervisorCollection;
    }

    public void setSupervisorCollection(Collection<OrdenTrabajo> supervisorCollection) {
        this.supervisorCollection = supervisorCollection;
    }

    public Collection<OrdenTrabajo> getResponsableCollection() {
        return responsableCollection;
    }

    public void setResponsableCollection(Collection<OrdenTrabajo> responsableCollection) {
        this.responsableCollection = responsableCollection;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 59 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) { 
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Usuario other = (Usuario) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

}

With Eclipselink default configuration got NoSuchMethodError.

The fix

Disable eclipselink.weaving.internal configuration. (https://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/p_weaving_internal.htm)

In persistence.xml


  <property name="eclipselink.weaving.internal" value="false"/>

In property map


propertiesMap.put(PersistenceUnitProperties.WEAVING_INTERNAL, "false");

In Spring


<bean id="jpaVendorAdapter" class="de.mischur.library.utils.ExtendedEclipseLinkJpaVendorAdapter">
    <property name="weavingInternal" value="false">
</property></bean>

Include facelet programatically JSF

The purpose is to use programmatically, then you should be using FaceletContext#includeFacelet() . Assuming that you’re inside your custom component:

FacesContext facesContext = FacesContext.getCurrentInstance();
FaceletContext faceletContext = (FaceletContext) facesContext.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
faceletContext.includeFacelet(this, "include.xhtml"); // this is your current UIComponent.

Here’s another kickoff example which demonstrates dynamic include by command button:

<h:form>
    <h:commandButton value="include" action="#{bean.include}" />
</h:form>
<h:panelGroup id="include" />

with

public void include() throws IOException {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    FaceletContext faceletContext = (FaceletContext) facesContext.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
    faceletContext.includeFacelet(facesContext.getViewRoot().findComponent("foo"), "include.xhtml");
}

via: http://stackoverflow.com/questions/10853177/how-to-use-the-includehandler-inside-my-custom-component

Include composite component programatically JSF

use FaceletContext#includeFacelet() to include the composite component resource in the given parent.

public static void includeCompositeComponent(UIComponent parent, String libraryName, String resourceName, String id) {
    // Prepare.
    FacesContext context = FacesContext.getCurrentInstance();
    Application application = context.getApplication();
    FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);

    // This basically creates <ui:component> based on <composite:interface>.
    Resource resource = application.getResourceHandler().createResource(resourceName, libraryName);
    UIComponent composite = application.createComponent(context, resource);
    composite.setId(id); // Mandatory for the case composite is part of UIForm! Otherwise JSF can't find inputs.

    // This basically creates <composite:implementation>.
    UIComponent implementation = application.createComponent(UIPanel.COMPONENT_TYPE);
    implementation.setRendererType("javax.faces.Group");
    composite.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, implementation);

    // Now include the composite component file in the given parent.
    parent.getChildren().add(composite);
    parent.pushComponentToEL(context, composite); // This makes #{cc} available.
    try {
        faceletContext.includeFacelet(implementation, resource.getURL());
    } catch (IOException e) {
        throw new FacesException(e);
    } finally {
        parent.popComponentFromEL(context);
    }
}

Imagine that you want to include <my:testComposite id="someId"> from URI xmlns:my="http://java.sun.com/jsf/composite/mycomponents", then use it as follows:

includeCompositeComponent(parent, "mycomponents", "testComposite.xhtml", "someId");

This has also been added to JSF utility library OmniFaces as Components#includeCompositeComponent() (since V1.5).

Since JSF 2.2, the ViewDeclarationLanguage class got a new createComponent() method taking the taglib URI and tag name which could also be used for this purpose. So, if you’re using JSF 2.2, the approach should be done as follows:

public static void includeCompositeComponent(UIComponent parent, String taglibURI, String tagName, String id) {
    FacesContext context = FacesContext.getCurrentInstance();
    UIComponent composite = context.getApplication().getViewHandler()
        .getViewDeclarationLanguage(context, context.getViewRoot().getViewId())
        .createComponent(context, taglibURI, tagName, null);
    composite.setId(id);
    parent.getChildren().add(composite);
}

Imagine that you want to include <my:testComposite id="someId"> from URI xmlns:my="http://xmlns.jcp.org/jsf/composite/mycomponents", then use it as follows:

includeCompositeComponent(parent, "http://xmlns.jcp.org/jsf/composite/mycomponents", "testComposite", "someId");

VIA:
http://stackoverflow.com/questions/5370184/how-to-programmatically-or-dynamically-create-a-composite-component-in-jsf-2
http://stackoverflow.com/questions/10853177/how-to-use-the-includehandler-inside-my-custom-component

 

JPA Global Sequence provider EJB Singleton


package com.origami.censocat.service;

import java.util.concurrent.atomic.AtomicLong;
import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Singleton;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * @author Fernando
 */
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
@Lock(LockType.WRITE)
public class GlobalSequenceProvider implements GlobalSequenceProviderLocal {
    
    @PersistenceContext(unitName = "CensoCat_PU")
    private EntityManager em;
    
    private Long actualId;
    private Long limitId;
    private final Long interval = 20L;

    public GlobalSequenceProvider() {
    }
    
    protected Boolean esDisponible(){
        if(actualId==null || actualId>=limitId){
            return false;
        }
        return true;
    }
    
    @Override
    public Long getNextId(){
        if(!this.esDisponible()){
            // obtener nuevo intervalo de secuencia
            genNextInterval();
        }
        actualId++;
        return actualId;
    }
    
    protected void genNextInterval(){
        Query q = em.createNativeQuery("select nextval('global_seq')");
        actualId = (Long)q.getSingleResult();
        limitId = actualId + interval;
    }
    
}

Apache Tomee 1.7 Plume Datasource configuration

In this example we will configure an postgresql datasource.

First download an place in /lib folder the postgresql JDBC driver jar

Open /conf/tomee.xml and put the datasource resource block:

<?xml version="1.0" encoding="UTF-8"?>
<tomee>
  <!-- see http://tomee.apache.org/containers-and-resources.html -->
  
  <Resource id="censocat_db" type="DataSource">
    #  PostgreSQL connection
    JdbcDriver   org.postgresql.Driver
    JdbcUrl  jdbc:postgresql://localhost/censocat
    UserName     sisapp
    Password     sis98
  </Resource>
  
</tomee>

Persistence.xml configuration:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="CensoCat_PU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>censocat_db</jta-data-source>
    <shared-cache-mode>NONE</shared-cache-mode>
    <properties>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
      <property name="eclipselink.ddl-generation.output-mode" value="database"/>
    </properties>
  </persistence-unit>
</persistence>

EJB injection of EM:

    @PersistenceContext(unitName = "CensoCat_PU")
    private EntityManager entityManager;

Common DataSource Configurations share [gp] share [fb] share [tw] share [pin] contribute
See the DataSource Configuration for details on all configuration options for DataSources.

HSQLDB
The drivers are included with OpenEJB 3.0 and HSQLDB is the default database.

<Resource id="HSQLDB Database" type="DataSource">
    JdbcDriver org.hsqldb.jdbcDriver
    JdbcUrl jdbc:hsqldb:file:hsqldb
    UserName sa
    Password
</Resource>

Derby (Embedded)

<Resource id="Derby Database" type="DataSource">
    #Embedded Derby example

    JdbcDriver org.apache.derby.jdbc.EmbeddedDriver
    JdbcUrl jdbc:derby:derbyDB;create=true
    UserName admin
    Password pass
</Resource>

MySQL

<Resource id="MySQL Database" type="DataSource">
    #  MySQL example
    #
    #  This connector will not work until you download the driver at:
    #  http://www.mysql.com/downloads/api-jdbc-stable.html

    JdbcDriver  com.mysql.jdbc.Driver
    JdbcUrl jdbc:mysql://localhost/test
    UserName    test
</Resource>

Oracle

<Resource id="Oracle Database" type="DataSource">
    #  Oracle example
    #
    #  This connector will not work until you download the driver at:
    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
    JdbcDriver  oracle.jdbc.OracleDriver
    JdbcUrl jdbc:oracle:thin:@localhost:1521:orcl
    UserName    scott
    Password    tiger
</Resource>

OracleXA

<Resource id="OracleXA Database" type="DataSource">
    #  OracleXA example
    #
    #  This connector will not work until you download the driver at:
    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
    JdbcDriver  oracle.jdbc.xa.client.OracleXADataSource
    JdbcUrl jdbc:oracle:thin:@localhost:1521:orcl
    UserName    scott
    Password    tiger
</Resource>

PosgreSQL

<Resource id="PostgreSQL Database" type="DataSource">
    #  PostgreSQL example
    #
    #  This connector will not work until you download the driver at:
    #  http://jdbc.postgresql.org/download.html
    JdbcDriver   org.postgresql.Driver
    JdbcUrl  jdbc:postgresql://localhost/test
    UserName     postgres
    Password     pass
</Resource>

InstantDB

<Resource id="InstantDB Database" type="DataSource">
    #  InstantDB example
    #
    JdbcDriver   org.enhydra.instantdb.jdbc.idbDriver
    JdbcUrl  jdbc:idb:conf/instantdb.properties
    UserName     Admin
    Password     pass
</Resource>

Internally, from TomEE 1.5.0, JDBC pools are managed via Tomcat-pool. You can still switch back to Apache Commons DBCP by adding the following property: DataSourceCreator dbcp. To get the full list of available configuration properties, have a look to Apache Commons DBCP configuration.

Netbeans fails to start Apache Tomee 1.7

In server.xml, remove the server=”Apache TomEE” attribute from the connector:

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" xpoweredBy="false"
           server="Apache TomEE" />

In bin/catalina.bat: line 179 and 184 change:

:noJuliConfig
set "JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%"

..

:noJuliManager
set "JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER%"

to

:noJuliConfig
set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%

.. 

:noJuliManager
set JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER%

(Basically remove the “”)

Using jackson in tomee as JAXB-Json provider

Jackson is fast JSON processor with nice default behavior, e.g. single element collections are represented as JSON arrays, and there are no wrapping elements.

Because the default is already reasonable, there is no additional configuration needed. The provider can be specified directly in the /src/main/webapp/WEB-INF/openejb-jar.xml descriptor:

<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openejb.org/openejb-jar/1.1">
    <pojo-deployment class-name="jaxrs-application">
        <properties>
            cxf.jaxrs.providers = com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
        </properties>
    </pojo-deployment>
</openejb-jar>

In addition the jackson dependency needs to be declared in the pom.xml:

<dependency>
	<groupId>com.fasterxml.jackson.jaxrs</groupId>
	<artifactId>jackson-jaxrs-json-provider</artifactId>
	<version>2.4.3</version>
</dependency>

A better solution would be to install jackson directly on the server (/apache-tomee-plus-1.7.1/lib), what would keep your WAR skinny.

via: http://www.adam-bien.com/roller/abien/entry/using_jackson_in_tomee_as