Visualizzazione post con etichetta jboss7. Mostra tutti i post
Visualizzazione post con etichetta jboss7. Mostra tutti i post

venerdì 31 agosto 2012

applicazione war con due entity manager contemporanemente

ambiente: jboss-7.1.1 
applicazione: war con due entity, due session bean repository, un service rest che opera usando entrambi i session bean.
caricare il driver mysql tra i moduli di jboss7

(scarica da qui: https://github.com/fiorenzino/dual-jpa.git)

ricordarsi di:
1) persistence.xml aggiungere i nomi delle classi che deve gestire ciascun em
2) persistence.xml non usare <property name="hibernate.hbm2ddl.auto" value="update" /> altrimenti crea le tabelle in entrambi i db (consiglio di crearle prima di deployare)


esempio di entity:

@Entity
public class UserA implements Serializable {

private Long id;
private String name;
....


@Entity
public class UserB implements Serializable {

private Long id;
private String name;

....



esempio di persistence.xml:

<?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="PuA">
<jta-data-source>java:jboss/datasources/ExampleA</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
<class>it.coopservice.test.model.UserA</class>
</persistence-unit>
<persistence-unit name="PuB">
<jta-data-source>java:jboss/datasources/ExampleB</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
<class>it.coopservice.test.model.UserB</class>
</persistence-unit>
</persistence>

3) nei repository iniettare gli entity manager specificando la persistence unit:

esempio di session bean: 



@Stateless
@LocalBean
public class SessionA implements Serializable {
@PersistenceContext(unitName = "PuA")
protected EntityManager em;
...



@Stateless
@LocalBean
public class SessionB implements Serializable {
@PersistenceContext(unitName = "PuB")
protected EntityManager em;

...


4) nello standalone.xml mappare i datasource usando driver XA (altrimenti non sarà possibile effettuare operazioni nella stessa transazione su entrambi i datasource:

esempio di datasource in standalone.xml:


<datasources>
<xa-datasource jndi-name="java:jboss/datasources/ExampleA" pool-name="ExampleAD" enabled="true" use-ccm="false">
<xa-datasource-property name="URL">jdbc:mysql://localhost:3306/exampleA</xa-datasource-property>
<driver>com.mysql</driver>
<xa-pool>
   <is-same-rm-override>false</is-same-rm-override>
   <interleaving>false</interleaving>
   <pad-xid>false</pad-xid>
   <wrap-xa-resource>true</wrap-xa-resource>
</xa-pool>
<security>
   <user-name>root</user-name>
   <password>flower</password>
</security>
<recovery>
   <recover-credential>
<user-name>root</user-name>
<password>flower</password>
   </recover-credential>
</recovery>
    </xa-datasource>
<xa-datasource jndi-name="java:jboss/datasources/ExampleB" pool-name="ExampleBD" enabled="true" use-ccm="false">
<xa-datasource-property name="URL">jdbc:mysql://localhost:3306/exampleB</xa-datasource-property>
<driver>com.mysql</driver>
<xa-pool>
   <is-same-rm-override>false</is-same-rm-override>
   <interleaving>false</interleaving>
   <pad-xid>false</pad-xid>
   <wrap-xa-resource>true</wrap-xa-resource>
</xa-pool>
<security>
   <user-name>root</user-name>
   <password>flower</password>
</security>
<recovery>
   <recover-credential>
<user-name>root</user-name>
<password>flower</password>
   </recover-credential>
</recovery>
    </xa-datasource>
</datasources>



 <drivers>
                    <driver name="com.mysql" module="com.mysql">
                        <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                    </driver>
 </drivers>




a questo punto sara' possibile usare un service che si inettta entrambi i session bean delegati a ciascun respository e fare operazioni transazionali:


esempio di service che opera su entrambi i session beans:

@Stateless
@LocalBean
public class ServiceAB implements Serializable {

@Inject
SessionA sessionA;

@Inject
SessionB sessionB;

public String createAB(String nameA, String nameB) {
UserA userA = new UserA(nameA);
Long idA = sessionA.persist(userA);
UserB userB = new UserB(nameB);
Long idB = sessionB.persist(userB);
return "a:" + idA + " - b:" + idB;
}
}



esempio di servizio rest per fare i test :


@Path("/v1/test")
@Stateless
@LocalBean
public class Rest implements Serializable {

@Inject
SessionA sessionA;
@Inject
SessionB sessionB;

@Inject
ServiceAB serviceAB;

@GET
@Path("/addA/{name}")
@Produces(MediaType.TEXT_PLAIN)
public Long addA(@PathParam("name") String name) {
UserA userA = new UserA();
userA.setName(name);
return sessionA.persist(userA);
}

@GET
@Path("/addB/{name}")
@Produces(MediaType.TEXT_PLAIN)
public Long addB(@PathParam("name") String name) {
UserB userB = new UserB();
userB.setName(name);
return sessionB.persist(userB);
}

@GET
@Path("/addAB/{nameA}/{nameB}")
@Produces(MediaType.TEXT_PLAIN)
public String addAB(@PathParam("nameA") String nameA,
@PathParam("nameB") String nameB) {
return serviceAB.createAB(nameA, nameB);
}
}

ricordarsi di aggiungere un rest activator:


@ApplicationPath("/rest")
public class JaxRsActivator extends javax.ws.rs.core.Application {

}






giovedì 28 giugno 2012

openshift: hot deploy

Da provare!!
basta aggiungere un solo file (hot_deploy) nella cartella .openshift/markers/ per evitare che openshift faccia il reboot dell'application server.


bisogna vedere come si comporta (forse va aggiunto nel commit il file ROOT.war.dodeploy per effettuare il rideploy a caldo)


https://openshift.redhat.com/community/blogs/new-openshift-release-june-26-2012-jboss-eap-hot-deployments-pricing-and-more


Hot Deployment

Hot deployment is slowly being added. We've started with the Jboss AS 7 cartridge, but will be implementing the same feature with the others soon. Hot deployment allows you to push to your application without having to restart it. This helps with zero downtime deployments. To use it add the following marker to your git repo:
.openshift/markers/hot_deploy
Just git add, commit and push it and we'll attempt to deploy the new code without stopping JBoss. Keep in mind you still have to live inside your memory footprint. 
So, if you have a memory intensive app that has a memory intensive build, you may want to look at using Jenkins to build so the process happens inside a different gear.

openshift: come gestire la rotazione dei log

Utile post dal forum per gestire la rotazione dei log ed eventuale eliminazione/compressione:
https://openshift.redhat.com/community/forums/openshift/log-rotation-not-enabled





cd $OPENSHIFT_LOGS_DIR   
 
   find . -type f ( -name access_log-* , -name error_log-* ) -mtime +180  
   #  Add this to the above command to backup as a gzipped tarball:    | xargs tar -czvf  backup-logs-$(date +%Y%m%d).tar.gz   
   #  Add this to the above command to delete 'em:   -exec rm {} \;      or     | xargs rm)   

martedì 5 giugno 2012

openshift+jboss: RewriteValve from 80 to 443

riportato dal forum:


1. In your application, create a file called jboss-web.xml in src/main/webapp/WEB-INF/ directory with this content.
 sh$ cat  src/main/webapp/WEB-INF/jboss-web.xml   
<jboss-web>
      <security-domain>jboss-web-policy</security-domain>
       <valve>
             <class-name>org.jboss.web.rewrite.RewriteValve</class-name>
       </valve>
</jboss-web>
2. Create a rewrite.properties file in the src/main/webapp/WEB-INF/ directory with checking for http and redirecting to https.
sh$ cat src/main/webapp/WEB-INF/rewrite.properties  
RewriteCond %{HTTP:X-Forwarded-Proto} http   
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]    

links utili

sabato 19 maggio 2012

jboss7 deployment timeout

Se il server va in timeout durante il deploy, undeploya tutte le applicazioni.

per evitarlo:


 <subsystem xmlns="urn:jboss:domain:deployment-scanner:1.1">
            <deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-interval="5000" deployment-timeout="6000"/>
        </subsystem>

java.lang.IllegalStateException: Parameter count exceeded allowed maximum: 512

immagina di avere una mega griglia con numero di parametri variabile ed alto...
quando viene fatto il submit e partono i valori jboss7 risponde:


java.lang.IllegalStateException: Parameter count exceeded allowed maximum: 512


https://community.jboss.org/thread/197650?_sscc=t

Add the following system property to the configuration file(eg standalone.xml).
<property name="org.apache.tomcat.util.http.Parameters.MAX_COUNT" value="10000"/>
grande openshift!!

domenica 29 aprile 2012

openshift: non esiste +$OPENSHIFT_APP_DIR

modificare script post_deplo!!
da $OPENSHIFT_APP_DIR/ a $OPENSHIFT_HOMEDIR/$OPENSHIFT_APP_NAME/

openshift: remove file with git

Remember this:


git rm -rf src/ pom.xml
git commit -a -m "removing default files"

martedì 13 marzo 2012

openshift: gestire + di un account sullo stesso pc

Immaginate di avere più computer con cui gestire openshift oppure immaginate di voler condividere lo sviluppo di un applicazione con un vs collega.
Come fate ad accedere dal II pc o dal pc del vs collega?

Strada semplice:


1) generate sul II pc o sul pc del vs collega una nuova chiave ssh:
ssh-keygen -trsa

2) aggiungiamola sul server openshift:
rhc sshkey add -i aliasDellaNuovaChiave -k /percorso/su/file/system/.ssh/id_rsa.pub -l account@gmail.com

3) per aggiungere l'host di openshift tra quelli in trust sul nostro pc:
prima eseguiamo:
rhc-domain-info -l account@gmail.com
prendiamo la stringa ssh://utente@hostname e proviamo a fare una connessione ssh
ssh xxxxxxxxxxxxxxxxxxxxxxdee2a911d@app-domain.rhcloud.com

Il gioco è fatto!!
Adesso possiamo scaricare il ns progetto usando:

git clone ssh://xxxxxxxxxxxxxxxxxxxxxxdee2a911d@app-domain.rhcloud.com/~/git/app.git/


BUON DIVERTIMENTO

giovedì 1 marzo 2012

openshift: usare scp per scaricare dati

Non credevo fosse possibile..ma in realta' se e' possibile collegarsi via ssh, perche' non fare copie remote via scp??

Leggendo nei forum, si suggeriva:

scp UUID@AppName-NameSpace.rhcloud
.com:~/AppName/logs/* 
A cosa puo' servire?
semplice..fare backup su altri server...
per scaricare l'intera configurazione?
..backup for me!!

domenica 12 febbraio 2012

jsf2: stringhe vuote convertite in zero.. automaticamente

Nelle ultime versioni di jsf c'è una nuova future voluta (che non mi piace affatto!!) che consente di gestire la conversione automatica tra valori vuoti e 0..
faccio un esempio: quando avete un array di select items capita di spesso di inserire un valore vuoto con label "seleziona" - il valore vuoto serve per non far scattare il filtro nel meccanismo di ricerca.
Se invece il vuoto viene convertito in 0, a quel punto il meccanismo di ricerca lo utilizza...


per ulteriori informazioni a riguardo:


Una possibile soluzione in jboss è di aggiungere nel file jboss7/bin/standalone.conf  questo parametro:
-Dorg.apache.el.parser.COERCE_TO_ZERO=false

Nel file web.xml aggiungete invece:
<context-param>
        <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
        <param-value>true</param-value>
</context-param>


funziona...peccato che su openshift non si possano aggiungere variabili d'ambiente custom!!!

openshift: aggiungere alias

Se registrate un dominio per pochi euro (dominio+dns+posta = 10/20 euro).
Create presso il vs DNS una CNAME del tipo: test.dominio.it. [NOTATE IL PUNTO!] 

che ridirge verso 

appname-domainname.rhcloud.com

Comunicate ad openshift questo CNAME, tramite il comando rhc-ctl-app:
rhc-ctl-app -a appname -c add-alias --alias appname.domainname.it -l account@gmail.com

E voilà la vs applicazione è raggiungibile a tutto il mondo!

ricordatevi ogni tanto di verificare che il jboss sia ancora attivo (openshift è ancora in beta...ogni tanto va tutto giù senza preavviso)!!!!


openshift: usiamo il cron per riavviare jboss di notte!

Date le poche risorse a disposizione, potrebbe essere utile riavviare jboss tutte le notti alle 3:00 (..si lo so che una buon applicazione non ne dovrebbe aver bisogno...):

  1) abilitiamo il cron alla ns applicazione
rhc-ctl-app -a giavacms -e add-cron-1.4

  2) creaiamo cartelle e script per usare i cron su openshift
mkdir -p .openshift/cron/hourly

 3) creiamo il ns file di restart di jboss 
touch .openshift/cron/hourly/restart_jboss.sh

4) aggiungiamo il seguente contenuto al suo interno

#!/bin/bash
echo "--------------------------------------------" >> $OPENSHIFT_REPO_DIR/cron_jboss/cron.log
date >> $OPENSHIFT_REPO_DIR/cron_jboss/cron.log
NOW=$(date +"%H")
echo $NOW >> $OPENSHIFT_REPO_DIR/cron_jboss/cron.log
echo 'resto' $RESTO '- cnfr' $CNFR >> $OPENSHIFT_REPO_DIR/cron_jboss/cron.log
if [ "$NOW" -eq "03"\ ];then
        $OPENSHIFT_APP_CTL_SCRIPT restart;
        echo "restart jboss now:" >> $OPENSHIFT_REPO_DIR/cron_jboss/cron.log
else
        echo "no restart jboss now!!" >> $OPENSHIFT_REPO_DIR/cron_jboss/cron.log
fi
date >> $OPENSHIFT_REPO_DIR/cron_jboss/cron.log
echo "--------------------------------------------" >> $OPENSHIFT_REPO_DIR/cron_jboss/cron.log


5) creiamo una cartella in cui archiviare il log di restart:
mkdir cron_jboss
touch cron_jboss//cron.log

6) committiamo tutti i files su openshift
git add .openshift/*
git add cron_jboss/*
git commit -m"start with cron" .openshift/*
git commit -m"start with cron" cron_jboss/*
git push



7) link utili
https://www.redhat.com/openshift/community/forums/express/restart-jboss-with-cron
http://docs.redhat.com/docs/en-US/OpenShift_Express/2.0/html/User_Guide/sect-User_Guide-Scheduling_Timed_Jobs_with_Cron.html



giovedì 29 dicembre 2011

openshift: vedere lo spazio disco occupato

[UPDATE]

adesso c'è quota!!

è possibile aggiungerlo negli script client side (tipo post_deploy/pre_deploy) etc.



Al momento non c'è un comando che mostra chiaramente l'occupazione disco...
un domani forse verrà aggiunto tra le informazioni restituite da rhc-user-info -laccountname

Per ora, come recita:

https://www.redhat.com/openshift/community/forums/express/questions-on-express-quota
basta fare un login ssh 
ssh  $UUID@$HOSTNAME 

 e lanciare il comando:
$ du -sh ~ /tmp

( o simili 
http://www.magicmill.net/linux/grap/grap-11.html)
se lo spazio occupato è troppo alto, cominciate con le pulizie di natale con:
rhc-ctl-app -a nomeapplicazione -c tidy  -l account@gmail.com

martedì 27 dicembre 2011

openshift: vedere il threaddump

prima eseguire il comando:
rhc-ctl-app -a appname -c threaddump -lxxxxx@gmail.com


e poi per rivedere il threaddump:

rhc-tail-files -f appname/jbossas-7.0/stdout.log -lxxxxx@gmail.com -a appname

verrò fuori qualcosa come:


Heap
 PSYoungGen      total 27136K, used 22338K [0x00000000fe000000, 0x00000000fff90000, 0x0000000100000000)
  eden space 22080K, 99% used [0x00000000fe000000,0x00000000ff588ad0,0x00000000ff590000)
  from space 5056K, 5% used [0x00000000ffa70000,0x00000000ffab8000,0x00000000fff60000)
  to   space 4992K, 0% used [0x00000000ff590000,0x00000000ff590000,0x00000000ffa70000)
 PSOldGen        total 64896K, used 34863K [0x00000000fa000000, 0x00000000fdf60000, 0x00000000fe000000)
  object space 64896K, 53% used [0x00000000fa000000,0x00000000fc20bd88,0x00000000fdf60000)
 PSPermGen       total 78656K, used 78637K [0x00000000f4200000, 0x00000000f8ed0000, 0x00000000fa000000)
  object space 78656K, 99% used [0x00000000f4200000,0x00000000f8ecb6b8,0x00000000f8ed0000)

per capire cosa sono:
http://javandoblog.blogspot.com/2010/08/per-chi-sviluppa-in-java-prima-o-poi.html

lunedì 26 dicembre 2011

openshift: che figata!

Sono anni che sogno di avere un jboss in hosting...e adesso con openshift è possibile!

adesso è possibile avere un virtual server a propria diposizione con mysql, phpmyadmin, 300 mega di ram e 500 mega di spazio disco:

Alcune highlights dell'ultima ora:

1) aggiungere un alias alla propria applicazione:
immaginate di comprare un nome per la vs applicazione su uno dei tanti rivenditori in rete, comprando anche l'uso del dns..a questo punto basta usare il comando:
rhc-ctl-app -a nomeapplicazione -c add-alias --alias www.hostname.org -l account@gmail.com

2) connesioni ssh al ns host:
rhc-user-info -l account@gmail.com

per ogni applicazione ci sarà un url git:
Git URL: ssh://xxxxxxxxxxxxxxxxxxxxxxxxxx@xxxxxx.rhcloud.com

ssh -t xxxxxxxxxxxxxxxxxxxxxxxxxx@xxxxxx.rhcloud.com

e voilà siete dentro la vs macchina:


Welcome to OpenShift shell

    This shell will assist you in managing openshift applications.

    !!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
    Shell access is quite powerful and it is possible for you to
    accidentally damage your application.  Procede with care!
    If worse comes to worse, destroy your application with rhc-ctl-app
    and recreate it
    !!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!

    type "help" for more info.


3) pulizia dello spazio disco non +usato (tmp/log/git history)


rhc-ctl-app -a nomeapplicazione -c tidy  -l account@gmail.com


che farà le seguenti mosse:

Stopping app...
Running 'git gc --prune --aggressive'
Emptying log dir: /var/lib/libra/xxxxxxxxxxxxxxxxxxx/nomeapplicazione/logs/
Emptying tmp dir: /tmp/
Emptying tmp dir: /var/lib/libra/xxxxxxxxxxxxxxxxxxx/nomeapplicazione/tmp/
Emptying tmp dir: /var/lib/libra/xxxxxxxxxxxxxxxxxxx/nomeapplicazione/jbossas-7.0/standalone/tmp/
Starting app...


4) riavviare mysql:
rhc-ctl-app -a nomeapplicazione -e restart-mysql-5.1



utilissimi link per cominciare a giocare:



http://www.jboss.org/openshift/articles.html


da cui:
http://community.jboss.org/blogs/scott.stark/2011/08/10/openshift-expressflex-cartridge-comparision
http://community.jboss.org/blogs/scott.stark/2011/08/10/jbossas7-configuration-in-openshift-express
http://community.jboss.org/blogs/scott.stark/2011/08/10/differences-between-the-express-and-flex-jbossas7-configurations
http://community.jboss.org/wiki/TrackingThreadsInJBossAS7
http://community.jboss.org/blogs/scott.stark/2011/08/10/jbossas7-configuration-in-openshift-express
https://www.redhat.com/openshift/blogs/seeing-cdi-working-in-openshift
https://www.redhat.com/openshift/community/blogs/how-to-create-an-openshift-github-quick-start-project


importante:
http://jaitechwriteups.blogspot.com/2011/08/deploy-java-ee-application-on-openshift.html


pannello di controllo
https://openshift.redhat.com/app/control_panel




martedì 20 settembre 2011

jboss 7: non ci sono i quartz mdb..ma c'è @Schedule

come dicono sul forum ufficiale, " TimerService is already available in 7.0.1 "

http://community.jboss.org/thread/172213?tstart=60

I would suggest to change the MDBs to singletons (EJB3.1) and use the EJB3.1 Timer Service of JEE6. The migration should be quite simple if you do not rely too much on quartz


Per chi non avesse mai provato i nuovi timer in jee6:
http://blogs.oracle.com/arungupta/entry/totd_146_understanding_the_ejb

provare!!!

jboss7: creare servizi rest - json

In jboss7 è semplice creare servizi rest!

Per iniziare basta dare un okkio al progetto di esempio distribuito come applicazione di esempio:
https://docs.jboss.org/author/display/AS7/Kitchensink+quickstart

L'unica difficoltà incontrata, nasce nel voler generare contenuti di tipo json, ovvero segnando i metodi con: @Produces("application/json")
Il problema riscontrato nasce nel mapping di relazioni di tipo @OneToMany, o meglio nell'escludere queste relazioni dal mapping del risultato (evitando l'errore:
org.codehaus.jackson.map.JsonMappingException: failed to lazily initialize a collection of role
date un okkio a questo post sul jbo7 forum: http://community.jboss.org/thread/169352 )

Facciamo un esempio pratico...
Immaginiamo di avere due entity Percorso, Punto (un percorso ha una relazione @OneToMany con i punti che lo costituiscono).

@Table(name = "percorsi")
@Entity
@XmlRootElement
public class Percorso implements Serializable {
private Long id;
private String nome;
        private List<Punto> punti;
.....

        @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}

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

public String getNome() {
return nome;
}

public void setNome(String nome) {
this.nome = nome;
}

       @OneToMany(fetch = FetchType.LAZY, mappedBy = "percorso")
@XmlTransient
@JsonIgnore
public List<Punto> getPunti() {
if (punti == null)
this.punti = new ArrayList<Punto>();
return this.punti;
}

public void setPunti(List<Punto> punti) {
this.punti = punti;
}
}

@Table(name = "punti")
@Entity
@XmlRootElement
public class Punto implements Serializable {
private Long id;
private Percorso percorso;


       @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}

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


        @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_percorso")
@XmlTransient
@JsonIgnore
public Percorso getPercorso() {
return percorso;
}

public void setPercorso(Percorso percorso) {
this.percorso = percorso;
}
}

Immaginiamo di generare un servizio rest,

@Path("/v1/percorsi")
@RequestScoped
public class PercorsiREST {

.....

che permette di recuperare un percorso:

        // repository che gestisce il caricamento da db dei dati
        @Inject
PercorsiRepository percorsiRepository;

@GET
@Path("/{id:[0-9][0-9]*}")
@Produces("application/json")
public Percorso getPercorsoById(@PathParam("id") long id) {
Percorso percorso = percorsiRepository.fetch(id);
if (percorso == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
return percorso;
}

Saremo in grado di invocarlo all'indirizzo: http://localhost:8080/primetracks/rest/v1/percorsi/3 e restituirà una risposta json del tipo:
 
 [{"id":3,"nome":"04-08-2011"}]

Dato che la collezione di punti è stata annotata con @JsonIgnore i punti non verranno restituiti nel corpo della risposta.
Conoscendo l'id del percorso andremo ad invocare un secondo metodo, che fornisce i punti che lo compongono:

        @GET
@Path("/{id:[0-9][0-9]*}/punti")
@Produces("application/json")
public List<Punto> getPuntiByPercorsoId(@PathParam("id") long id) {
Percorso percorso = percorsiRepository.fetch(id);
if (percorso == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
return percorso.getPunti();
}
Che invocheremo all'indirizzo: http://localhost:8080/primetracks/rest/v1/percorsi/3/punti e restituirà una risposta json del tipo:

[{"id":130}, {"id":131}]

Do notare come l'annotazione @XmlTransient , svolge la stessa funzione nel caso si voglia mostrare il risultato in formato xml, usando @Produces("text/xml") al posto  di @Produces("application/json").

Ultima nota, per usare l'annotazione @JsonIgnore va aggiunto in maven:
                 <dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.6.3</version>
</dependency>
Inoltre per usare a runtime questa libreria, presente tra i moduli di jboss7, va aggiunto nel META-INF/MANIFEST.MF:
Dependencies: org.codehaus.jackson.jackson-core-asl


Provate!!



mercoledì 17 agosto 2011

jboss7 JSF error after AS6 to AS7 migration: java.lang.ClassNotFoundException: sun.util.calendar.ZoneInfo

vedi questo post:

http://community.jboss.org/thread/169938?tstart=0

jboss7: aggiungere le dipendenze nel manifest del war/jar con maven


come suggerito da Shane Bryzak,

nella seam-dev mailL:

per aggiungere jboss-logging in AS7 va aggiunto nel file manifest (META-INF/MANIFEST.MF) del ns war/jar:

Dependencies: org.jboss.logging,org.jboss.logmanager

E' possibile usare "manifestEntries" di maven per automatizzare la scrittura nel file:

<build>
<finalName>seam-university</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifestEntries>
<Dependencies>org.slf4j.impl,org.jboss.logging,org.jboss.logmanager</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>