IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Services Web Java Discussion :

Et si les EJB ne marchaient pas avec Jersey et REST?


Sujet :

Services Web Java

  1. #1
    Membre confirmé
    Inscrit en
    Mai 2008
    Messages
    118
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 118
    Par défaut Et si les EJB ne marchaient pas avec Jersey et REST?
    Bonjour....,
    Je veux utiliser les EJB dans mon web service. Mais celá n´a jamais marché !
    Pourquoi ?
    EJB, trés simple :
    package com.Bridge.finalStep;

    import javax.annotation.PostConstruct;
    import javax.ejb.Singleton;
    import javax.xml.ws.WebServiceRef;

    /**
    *
    * @author mdieng
    */
    @Singleton
    public class JavaBeans {

    private String word ;
    private int tLang, fLang;
    public JavaBeans(){

    }


    /*
    * return the given word
    */
    public String getWord(){
    return word;
    }
    /*
    * the word to set
    */
    public void setWord(String word){
    this.word=word;
    }
    /*
    * return the original language of the word to translate
    */
    public int getfLang(){
    return fLang;
    }
    /*
    * setting the from language
    */
    public void setfLang(int fLang){
    this.fLang=fLang;
    }
    /*
    * return the destination language
    */
    public int gettLang(){
    return tLang;
    }
    /*
    * setting the destination language
    */
    public void settlang(int tLang){
    this.tLang=tLang;
    }


    }
    Voici le webservice qui lui est associé :
    package com.Bridge.finalStep;

    import java.util.ArrayList;
    import java.util.List;
    import javax.ejb.EJB;
    import javax.ejb.Stateless;
    import javax.ws.rs.core.Context;
    import javax.ws.rs.core.UriInfo;
    import javax.ws.rs.Consumes;
    import javax.ws.rs.PUT;
    import javax.ws.rs.Path;
    import javax.ws.rs.GET;
    import javax.ws.rs.Produces;
    import javax.xml.ws.WebServiceRef;

    /**
    * REST Web Service
    *
    * @author mdieng
    */

    @Path("translating")
    @Stateless
    public class TranslatingResource {
    @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/api.xlingua.de/XLinguaService.svc.wsdl")
    private XLinguaService service;

    private java.lang.Integer fLang ;
    private java.lang.Integer tLang;
    private java.lang.String word ;

    /* @EJB
    private JavaBeans javaBeans;
    @Context
    private UriInfo context;

    /** Creates a new instance of TranslatingResource */
    public TranslatingResource() {

    }

    /**
    * Retrieves representation of an instance of com.Bridge.finalStep.TranslatingResource
    * @return an instance of com.microsoft.schemas._2003._10.serialization.arrays.ArrayOfanyType
    */
    @GET
    public ArrayList<String> getXml() {
    ArrayList<String> array = new ArrayList<String>();

    try { // Call Web Service Operation
    com.Bridge.finalStep.IXLinguaService port = service.getWSHttpBindingIXLinguaService();
    // TODO initialize WS operation arguments here
    java.lang.Integer fLang = this.flang;
    java.lang.Integer tLang = this.tlang;
    java.lang.String word = this.mot;
    // TODO process result here
    com.Bridge.finalStep.ArrayOfanyType result = port.getTranslations(fLang, tLang, word);
    array.add(result.getAnyType().toString());
    } catch (Exception ex) {
    // TODO handle custom exceptions here
    }


    return array;

    }

    /**
    * PUT method for updating or creating an instance of TranslatingResource
    * @param content representation for the resource
    * @return an HTTP response with content of the updated or created resource.
    */
    @PUT
    @Consumes("application/xml")
    public void putXml(int l1, int l2, String w) {
    /* javaBeans.setfLang(l1);
    javaBeans.setfLang(l2);
    javaBeans.setWord(w);*/
    }
    }
    Mais quand je teste, j´ai cette erreure, vraiment trés méchante !

    java.lang.ClassCastException: com.sun.xml.ws.util.ServiceConfigurationError cannot be cast to java.lang.Exception
    at javax.ejb.EJBException.getCausedByException(EJBException.java:83)
    at com.sun.jersey.server.impl.ejb.EJBExceptionMapper.toResponse(EJBExceptionMapper.java:60)
    at com.sun.jersey.server.impl.ejb.EJBExceptionMapper.toResponse(EJBExceptionMapper.java:51)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.mapException(WebApplicationImpl.java:1097)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.mapMappableContainerException(WebApplicationImpl.java:1062)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:781)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:740)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:731)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:372)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:452)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:633)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    Je ne sais vraiment pas la raison.

  2. #2
    Membre confirmé
    Inscrit en
    Mai 2008
    Messages
    118
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 118
    Par défaut EJB...
    Bonjour,
    Le probleme était trés simple :
    Les EJB ne comprennent que du code java.
    Moi je voulais appeller des fonction d´un WCF dans mon EJB d´ou ce probleme.
    La solution est la suivante:
    1. créer un client de mon WS
    2. créer mon nouveau WS
    3. creer une classe java standard tres simple.
    4. click droid dans ma classe java ---> call webservic opération
    5. choisir la fonction á appeller
    6. Je peut maintemant appeller les fonction de ma classe java dans mon web service comme des fonctions java simples.

    Merci pour tous ceux qui pensaient á nous aider

Discussions similaires

  1. Réponses: 0
    Dernier message: 05/03/2011, 13h39
  2. Réponses: 7
    Dernier message: 19/03/2010, 16h31
  3. [FPDF] Les accents ne passent pas avec FPDF
    Par beegees dans le forum Bibliothèques et frameworks
    Réponses: 13
    Dernier message: 02/03/2009, 09h16
  4. fonctionne avec les sessions pas avec le reste
    Par hugo69 dans le forum Langage
    Réponses: 6
    Dernier message: 22/11/2005, 09h38
  5. [CSS] Bug IE avec height ne marche pas avec les %
    Par El Riiico dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 23/06/2005, 17h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo