Hello, big brother! Recently, a problem has troubled me for a long time. I used payara-embedded embedded server and the deployed EJB service was successfully deployed. But as a java client, an error is reported when calling? Is there something wrong? Please give me some guidance, thank you! what happened?
ERRO MESSAGE:
javax.naming.NamingException: Invoker V0 not found at http://172.20.0.161:9081/ejb-invoker/ejb/: Not Found
at fish.payara.ejb.http.client.LookupDiscoveryServiceImpl.discoverV0(LookupDiscoveryServiceImpl.java:111)
at fish.payara.ejb.http.client.LookupDiscoveryServiceImpl.createDiscovery(LookupDiscoveryServiceImpl.java:94)
at fish.payara.ejb.http.client.LookupDiscoveryServiceImpl.discover(LookupDiscoveryServiceImpl.java:80)
at fish.payara.ejb.http.client.RemoteEJBContext.determineLookup(RemoteEJBContext.java:172)
at fish.payara.ejb.http.client.RemoteEJBContext.lookup(RemoteEJBContext.java:160)
at fish.payara.ejb.http.client.RemoteEJBContext.lookup(RemoteEJBContext.java:144)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at eb.ClientPayara.main(ClientPayara.java:40)
服务调用失败…:Invoker V0 not found at http://172.20.0.161:9081/ejb-invoker/ejb/: Not Found
The server code is as follows:
package micro.service;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.glassfish.admin.amx.util.FileUtils;
import org.glassfish.embeddable.GlassFish;
import org.glassfish.embeddable.GlassFishException;
import org.glassfish.embeddable.GlassFishProperties;
import org.glassfish.embeddable.GlassFishRuntime;
public class MicroMain {
public InputStream getPath(String name) {
// String url=MicroMain.class.getResource(name).getPath();
// String f = MicroMain.class.getResource("micro/service/microprofile-1.0-SNAPSHOT.war").getPath();
InputStream is = this.getClass().getResourceAsStream("microprofile-1.0-SNAPSHOT.war");
// String f2 = MicroMain.class.getClassLoader().getResource("/microprofile-1.0-SNAPSHOT.war").getPath();
// System.out.print(f2);
// String url=MicroMain.class.getClassLoader().getResource("./microprofile-1.0-SNAPSHOT.war").getPath();
// System.out.print(f);
return is;
}
// public static void main(String args) {
// String path = new MicroMain().getPath(“./microprofile-1.0-SNAPSHOT.war”);
// }
public static void main(String[] args) {
try {
GlassFishRuntime runtime = GlassFishRuntime.bootstrap();
GlassFishProperties glassfishProperties = new GlassFishProperties();
glassfishProperties.setPort("http-listener", 9080);
glassfishProperties.setPort("https-listener", 9845);
GlassFish glassfish = runtime.newGlassFish(glassfishProperties);
glassfish.start();
//String path = new MicroMain().getPath("microprofile-1.0-SNAPSHOT.war");
//glassfish.getDeployer().deploy(new MicroMain().getPath("microprofile-1.0-SNAPSHOT.war"));
InputStream is =new MicroMain().getPath("microprofile-1.0-SNAPSHOT.war");
//File file= StreamUtil.stream2file(is);
glassfish.getDeployer().deploy(is,"--name", "microprofile");
//glassfish.getDeployer().deploy(new File("E:\\microprofile-1.0-SNAPSHOT.war"));
} catch (GlassFishException ex) {
System.out.println(ex.getMessage());
}
}
}
client code:
package eb;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.tian.bean.ShoppBookRemote;
import cm_.Cmt;
public class ClientPayara {
public static Context getinitContext() {
Context ctx = null;
try {
Properties propers = new Properties();
propers.put(Context.INITIAL_CONTEXT_FACTORY, "fish.payara.ejb.rest.client.RemoteEJBContextFactory");
propers.put(Context.PROVIDER_URL, "http://172.20.0.161:9081/ejb-invoker");
// propers.put(Context.SECURITY_PRINCIPAL, “u1”);
// propers.put(Context.SECURITY_CREDENTIALS, “p1”);
ctx = new InitialContext(propers);
} catch (NamingException e) {
System.out.println(“服务器链接失败…:” + e.getMessage());
e.printStackTrace();
}
return ctx;
}
public static void main(String[] args) {
//jakarta.ws.rs.client.ClientBuilder
Context ctx = getinitContext();
try {
// ShoppBookRemote shop = (ShoppBookRemote) ctx
// .lookup(“java:global/mi/look/ShoppBookBean!com.tian.bean.ShoppBookRemote”);
//
// System.out.println(shop.queryBookList());
Cmt cmt=(Cmt) ctx.lookup("java:global/microprofile/CmtBean");
System.out.println(cmt.findByName("甜"));
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("服务调用失败.....:" + e.getMessage());
}
}
}