Problème avec EJB-WebServices

Fermé
Streamooc Messages postés 79 Date d'inscription samedi 17 juin 2017 Statut Membre Dernière intervention 8 février 2023 - 5 nov. 2018 à 20:14
KX Messages postés 16733 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 31 janvier 2024 - 6 nov. 2018 à 11:39
Bonjour à tous.
J'utilise un client java pour appeler les méthodes de mon webService et j'utilise la version 12 de Wildfly pour le déploiement.J'utilise les EJB.
Lorsque j'exécute mon client java j'obtiens ce message que j'ai cherché de résoudre en vain.J'ai besoin d'aides si quelqu'un pourra m'aider s'il vous plaît c'est urgent:
nov. 05, 2018 7:07:50 PM org.wildfly.naming.client.Version <clinit>
INFO: WildFly Naming version 1.0.7.Final
nov. 05, 2018 7:07:50 PM org.wildfly.security.Version <clinit>
INFO: ELY00001: WildFly Elytron version 1.2.2.Final
nov. 05, 2018 7:07:50 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.6.2.Final
nov. 05, 2018 7:07:50 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.6.2.Final
nov. 05, 2018 7:07:51 PM org.jboss.threads.Version <clinit>
INFO: JBoss Threads version 2.3.1.Final
nov. 05, 2018 7:07:51 PM org.jboss.ejb.client.legacy.RemotingLegacyConfiguration getConfiguredEndpoint
INFO: EJBCLIENT000070: Using legacy jboss-ejb-client.properties Remoting configuration
nov. 05, 2018 7:07:51 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 5.0.5.Final
nov. 05, 2018 7:07:51 PM org.jboss.ejb.client.legacy.ElytronLegacyConfiguration getConfiguredAuthenticationContext
INFO: EJBCLIENT000069: Using legacy jboss-ejb-client.properties security configuration
nov. 05, 2018 7:07:52 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 4.0.9.Final
nov. 05, 2018 7:07:52 PM org.jboss.ejb.client.legacy.LegacyPropertiesConfiguration configure
INFO: EJBCLIENT000072: Using legacy jboss-ejb-client.properties EJB client configuration
Exception in thread "main" javax.ejb.EJBException: java.io.IOException: WFHTTP000005: Invalid response code 404 (full response ClientResponse{responseHeaders={x-powered-by=[Undertow/1], server=[WildFly/11], content-length=[74], content-type=[text/html], date=[Mon, 05 Nov 2018 18:07:52 GMT]}, responseCode=404, status='', protocol=HTTP/2.0})
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:207)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:112)
at com.sun.proxy.$Proxy2.addCompte(Unknown Source)
at ClientEJB.main(ClientEJB.java:25)
Caused by: java.io.IOException: WFHTTP000005: Invalid response code 404 (full response ClientResponse{responseHeaders={x-powered-by=[Undertow/1], server=[WildFly/11], content-length=[74], content-type=[text/html], date=[Mon, 05 Nov 2018 18:07:52 GMT]}, responseCode=404, status='', protocol=HTTP/2.0})
at org.wildfly.httpclient.common.HttpTargetContext$1$1.lambda$completed$3(HttpTargetContext.java:217)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
at java.lang.Thread.run(Unknown Source)




//Voici le contenu de jboss-ejb-client.properties:
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=127.0.0.1
remote.connection.default.port=4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=root
remote.connection.default.password=

//Voici le client java:
public class ClientEJB {
public static void main(String[] args) {
try {
Properties p=new Properties();
//p.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

p.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
p.put(Context.PROVIDER_URL,"http://localhost:8080");


Context ctx=new InitialContext(p);
IBanqueRemote stub=(IBanqueRemote) ctx.lookup("ejb:/banqueEJBjboss/BK!metier.session.IBanqueRemote");
//Ajouter un compte
stub.addCompte(new Compte(7000, new Date()));
//Consulter tous les comptes
List<Compte> cptes=stub.getAllComptes();
for(Compte c:cptes) {
System.out.println(c.getSolde());
}
} catch (NamingException e) {
e.printStackTrace();
}
}

}

1 réponse

KX Messages postés 16733 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 31 janvier 2024 3 015
5 nov. 2018 à 23:24
Bonjour,

"Invalid response code 404"
C'est une réponse du protocole HTTP pour dire que l'URL demandée n'existe pas (404 = Not Found)
Mais je ne vois pas bien le rapport entre HTTP et EJB ce sont deux protocoles qui n'ont rien à voir.

De plus, ton code
ctx.lookup("ejb:/banqueEJBjboss...");
me surprends. Qu'est-ce que banqueEJBjboss ?
Avec des EJB "standards" on utiliserait plutôt
ctx.lookup("java:comp/env/ejb...");
mais ici tu utilises des spécificités de JBoss/Wildfly (qui contournent les EJB via JBoss Remoting pour faire du HTTP...)

Il faudrait regarder la documentation : Remote EJB invocations via JNDI (WildFly 12)
Et si je comprends bien ce serait plutôt
ejb:/jboss-as-ejb-remote-app//BK!metier.session.IBanqueRemote


Remarque : un projet en 2018 (presque 2019) a-t-il encore vraiment besoin des EJB !?
0
Streamooc Messages postés 79 Date d'inscription samedi 17 juin 2017 Statut Membre Dernière intervention 8 février 2023
6 nov. 2018 à 03:22
Bonjour KX merci pour la réponse.
Au fait banqueEJBjboss est le projet EJB que j'ai créé et celui-ci utilise les webServices.ClientEJB représente un simple java project que j'ai créé pour pouvoir utiliser les services fournis par banqueEJBjboss.

Ci-dessous les parties de banqueEJBjboss:

@Entity
@Table(name="COMPTES")
public class Compte implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="CODE")
private Long code;
@Column(name="SOLDE")
private double solde;
@Temporal(TemporalType.TIMESTAMP)
private Date dateCreation;
}

@Stateless
@WebService
public class BanqueService {
@EJB(beanName="BK")
private IBanqueLocal metier;


/**Ajouter un compte
  • @param soldeInitial
  • /

@WebMethod
public void addCompte(@WebParam(name="solde")double soldeInitial) {
Compte cp=new Compte(soldeInitial, new Date(), true);
metier.addCompte(cp);
}
}

@Remote
public interface IBanqueRemote {
public void addCompte(Compte c);}
@Local
public interface IBanqueLocal {
public void addCompte(Compte c);}


//Projet ClientEJB
D'après la documentation
public class ClientEJB {
public static void main(String[] args) {
try {
Properties p=new Properties();
//p.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

p.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
p.put(Context.PROVIDER_URL,"http://localhost:8080");


Context ctx=new InitialContext(p);
// IBanqueRemote stub=(IBanqueRemote) ctx.lookup("ejb:/banqueEJBjboss/BK!metier.session.IBanqueRemote");

// IBanqueRemote stub=(IBanqueRemote) ctx.lookup("ejb:/jboss-as-ejb-remote-app//BK!metier.session.IBanqueRemote");


IBanqueRemote stub=(IBanqueRemote) ctx.lookup("ejb:/jboss-as-ejb-remote-app/banqueEJBjboss/BK!metier.session.IBanqueRemote");

//Ajouter un compte
stub.addCompte(new Compte(7000, new Date()));
//Consulter tous les comptes
List<Compte> cptes=stub.getAllComptes();
for(Compte c:cptes) {
System.out.println(c.getSolde());
}
} catch (NamingException e) {
e.printStackTrace();
}
}

}

Toujour la même erreur:
INFO: EJBCLIENT000072: Using legacy jboss-ejb-client.properties EJB client configuration
Exception in thread "main" javax.ejb.EJBException: java.io.IOException: WFHTTP000005: Invalid response code 404 (full response ClientResponse{responseHeaders={x-powered-by=[Undertow/1], server=[WildFly/11], content-length=[74], content-type=[text/html], date=[Tue, 06 Nov 2018 01:01:09 GMT]}, responseCode=404, status='', protocol=HTTP/2.0})
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:207)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:112)
at com.sun.proxy.$Proxy2.addCompte(Unknown Source)
at ClientEJB.main(ClientEJB.java:31)
Caused by: java.io.IOException: WFHTTP000005: Invalid response code 404 (full response ClientResponse{responseHeaders={x-powered-by=[Undertow/1], server=[WildFly/11], content-length=[74], content-type=[text/html], date=[Tue, 06 Nov 2018 01:01:09 GMT]}, responseCode=404, status='', protocol=HTTP/2.0})
at org.wildfly.httpclient.common.HttpTargetContext$1$1.lambda$completed$3(HttpTargetContext.java:217)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
at java.lang.Thread.run(Unknown Source)
0
KX Messages postés 16733 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 31 janvier 2024 3 015 > Streamooc Messages postés 79 Date d'inscription samedi 17 juin 2017 Statut Membre Dernière intervention 8 février 2023
6 nov. 2018 à 11:39
Regarde la documentation de WildFly et compare avec ta configuration, il y a d'autres valeurs qui semblent différentes, par exemple
jndiProps.put(Context.PROVIDER_URL,"http-remoting://localhost:8080");
0