J'essaie d'appeler mes EJB dans un environnement distant et j'utilise Wildfly comme conteneur.Le nom [ejb: ..] n'est pas lié dans ce contexte. Impossible de trouver [ejb:].] Avec cause racine javax.naming.NameNotFoundException dans Wildfly
Excuses mais c'est la première fois que j'essaie d'appeler un EJB à distance.
J'ai utilisé les instructions ci-dessous pour appeler des EJB dans Wildfly. Mais, j'ai une erreur en appelant ces EJB et je ne sais pas ce qui ne va pas dans ma configuration.
trace Voir de pile d'erreurs ci-dessous:
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/Project-demo] threw exception [Request processing failed; nested exception is javax.naming.NameNotFoundException: Name [ejb: /ImageService-1.0-SNAPSHOT//GrayscaleImageServiceImpl!com.project.imageservice.ImageManipulateService] is not bound in this Context. Unable to find [ejb: ].] with root cause
javax.naming.NameNotFoundException: Name [ejb: /ImageService-1.0-SNAPSHOT//GrayscaleImageServiceImpl!com.project.imageservice.ImageManipulateService] is not bound in this Context. Unable to find [ejb: ].
at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.sketchy.remote.context.RemoteContext.lookupRemoteGrayscaleService(RemoteContext.java:30)
at com.sketchy.controllers.ServiceController.grayscaleService(ServiceController.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
mon interface à la fois côté serveur et client distant:
public interface ImageManipulateService{
public UploadedImage manipulate(UploadedImage img) throws IOException, Exception;
}
Mon EJB dans le serveur distant (wildfly):
@Service
@Stateless
@Remote(ImageManipulateService.class)
public class GrayscaleImageServiceImpl implements ImageManipulateService{
@Override
public Object manipulate(Object img) throws IOException, Exception {
....
}
}
côté client:
jboss-ejb-client.properties
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host = localhost
remote.connection.default.port = 9090
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
Je dirige mon client dans le serveur tomcat (: 8080) et je suis en train d'invoquer les EJBs sur Wildfly via localhost: 9090. (est-ce correct?)
J'ai aussi le jboss-client.jar inclus dans mes dépendances Maven. I utilisé la version 4.0.2. (jboss-client-4.0.2.jar)
J'ai créé une classe Java qui appelle la recherche de services afin de les appeler facilement.
public class RemoteContext {
public static ImageManipulateService lookupRemoteGrayscaleService() throws NamingException {
Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
Context context = new InitialContext(jndiProperties);
String appName = "";
String moduleName = "ImageService-1.0-SNAPSHOT";
String distinctName = "";
String beanName = "GrayscaleImageServiceImpl";
String viewClassName = "com.project.imageservice.ImageManipulateService";
return (ImageManipulateService) context.lookup("ejb: " + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
}
public static ImageManipulateService lookupRemoteTimestampService() throws NamingException {
Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
Context context = new InitialContext(jndiProperties);
String appName = "";
String moduleName = "ImageService-1.0-SNAPSHOT";
String distinctName = "";
String beanName = "TimestampImageServiceImpl";
String viewClassName = "com.project.imageservice.ImageManipulateService";
return (ImageManipulateService) context.lookup("ejb: " + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
}
}
J'utilise maven et j'inclus l'id d'artefact jboss-client avec la version 4.0.2 puisque je pensais que c'est exactement pareil avec jboss-client qui réside dans le répertoire de wildfly. C'est pour définir mes dépendances uniquement dans Maven. Je vais essayer ceci et vous faire savoir si cela fonctionne. – bpunzalan
** EJBCLIENT000037: Impossible de charger la classe proxy ejb L'erreur com.project.imageservice.ImageManipulateService ** a été affichée. L'erreur ci-dessus n'est pas visible. Des idées? – bpunzalan
Vous devez vous assurer que votre application côté client a accès à la classe 'ImageManipulateService' et à toutes les autres classes qu'elle utilise (par exemple' UploadedImage'). Normalement, je crée un module "API" qui contient toutes les classes dont dépendent le client et le serveur. –