Java EE 7 and Wildfly 10.1.0 - IllegalStateException: EJBCLIENT000025 - ejb

I created following EJB-Module:
1) My Remote interface
package calculator.beans;
import javax.ejb.Remote;
#Remote
public interface CalculatorRemote {
public int addNum(int num1, int num2);
}
2) A bean which implements the interface
package calculator.beans;
import javax.ejb.Stateless;
#Stateless
public class CalculatorBean implements CalculatorRemote {
#Override
public int addNum(int num1, int num2) {
return num1 + num2;
}
}
3) Next I created a property-file '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 = 8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=appuser
remote.connection.default.password=apppassword
After the deployment to wildfly everything was fine. I get following Information:
INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-4) WFLYEJB0473: JNDI bindings for session bean named 'CalculatorBean' in deployment unit 'deployment "CalculatorEJB.jar"' are as follows:
java:global/CalculatorEJB/CalculatorBean!calculator.beans.CalculatorRemote
java:app/CalculatorEJB/CalculatorBean!calculator.beans.CalculatorRemote
java:module/CalculatorBean!calculator.beans.CalculatorRemote
java:jboss/exported/CalculatorEJB/CalculatorBean!calculator.beans.CalculatorRemote
java:global/CalculatorEJB/CalculatorBean
java:app/CalculatorEJB/CalculatorBean
java:module/CalculatorBean
4) Then I created my Java Client
package calculator.client;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import calculator.beans.CalculatorRemote;
public class RemoteRechnerClient {
public static void main(String[] args) {
try {
final Hashtable<String, String> jndiProperties = new Hashtable<>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context ctx = new InitialContext(jndiProperties);
String crName = CalculatorRemote.class.getName();
CalculatorRemote cr = (CalculatorRemote) ctx.lookup("ejb:CalculatorEJB/beans/CalculatorBean!" + crName);
System.out.println("Result: " + cr.addNum(5, 4));
} catch (NamingException ex) {
ex.printStackTrace();
}
}
}
The code is simple enough. But if I run the Client I get following Error-Message:
Apr 06, 2017 3:30:26 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.0.1.Final
Apr 06, 2017 3:30:26 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.0.Final
Apr 06, 2017 3:30:26 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.0.Final
Apr 06, 2017 3:30:26 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.6.Final
Apr 06, 2017 3:30:27 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
Apr 06, 2017 3:30:27 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext#3c0f93f1, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection#31dc339b,channel=jboss.ejb,nodename=john-waynes-macbook-pro]} on channel Channel ID b98547a5 (outbound) of Remoting connection 0c84e8ba to /127.0.0.1:8080
Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:CalculatorEJB, moduleName:beans, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext#2758fe70
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:749)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:253)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:198)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
at com.sun.proxy.$Proxy0.addNum(Unknown Source)
at calculator.client.RemoteRechnerClient.main(RemoteRechnerClient.java:27)
/Users/manhthangd/Library/Caches/NetBeans/8.2/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 3 seconds)
I am using Netbeans 8.2, Java EE 7 and Wildfly 10.1.0-Final.
What can I do to solve the problem?

Your JNDI lookup name is incorrect.
You need to use the highlighted portion of:
java:jboss/exported/CalculatorEJB/CalculatorBean!calculator.beans.CalculatorRemote
ie.
CalculatorRemote cr = (CalculatorRemote) ctx.lookup("ejb:CalculatorEJB/CalculatorBean!" + crName);
Where did you get "ejb:CalculatorEJB/beans/CalculatorBean!" from?

Related

How to Allocate a Private IP address and Port with Ghostdriver

I wrote a Ghostdriver Maven Java project where I call many instances of the jar file using a shell script in Ubuntu 14.04 64bit.
Each line in my shell script calls a new instance of my jar file.
The format of each line:
screen -dmS name java -jar /path/name.jar arg1 arg2 arg3
Currently I have 1 network interface (eth0) split up into multiple network aliases (eth0:1, eth0:2, etc), each alias points to a private IP which in turns points to a public IP.
I am trying to find the best way to allocate a private IP and possibly port number to each instance of my java program. Currently I call Ghostdriver inside my program.
The way I call ghost driver within my program:
public class className {
PhantomJSDriver driver;
public static final File PHANTOMJS_EXE = new File("//home/username/phantomjs/bin/phantomjs");
public className() {
callGhostdriver();
driver.quit();
}
private void callGhostdriver() {
{
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("phantomjs.binary.path",
PHANTOMJS_EXE.getAbsolutePath());
driver = new PhantomJSDriver(caps);
driver.manage().window().maximize();
actions = new Actions(driver);
}
}
}
Any help would be greatly appreciated.
***Update****
I tried changing the callGhostdriver method but had no success.
private void callGhostdriver() {
DesiredCapabilities dcaps = new DesiredCapabilities();
dcaps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
PHANTOMJS_EXE.getAbsolutePath());
String[] phantomJsArgs = {"--webdriver=172.16.190.131:6781"};
dcaps.setCapability(
PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
phantomJsArgs);
driver = new PhantomJSDriver(dcaps);
driver.manage().window().maximize();
actions = new Actions(driver);
}
Argument --webdriver=IP:PORT seems to be overridden by a default
--webdriver call.
Output from running jar:
*Apr 12, 2015 5:26:25 PM org.openqa.selenium.phantomjs.PhantomJSDriverService INFO: port: 8651
Apr 12, 2015 5:26:25 PM
org.openqa.selenium.phantomjs.PhantomJSDriverService INFO: arguments:
[--webdriver=172.16.190.131:6781, --webdriver=8651,
--webdriver-logfile=/home/RemovedPath/phantomjsdriver.log] Apr 12, 2015 5:26:25 PM org.openqa.selenium.phantomjs.PhantomJSDriverService
INFO: environment: {} [INFO - 2015-04-12T21:26:26.584Z] GhostDriver -
Main - running on port 8651
Port 6781 with the different private IP should be what it is using but it uses 8651 instead.
I was able to find a hackish way to set the port but still haven't figured out how to set the private ip, I may have to use iptables to route the traffic.
private void loadLightWeightDriverCustom() {
ArrayList<String> cliArgsCap = new ArrayList();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, PHANTOMJS_EXE.getAbsolutePath());
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
driver = new PhantomJSDriver(Configure(cliArgsCap), capabilities);
}
private PhantomJSDriverService Configure(ArrayList<String> cap) {
return new PhantomJSDriverService.Builder().usingPhantomJSExecutable(PHANTOMJS_EXE)
.usingPort(5555)
.usingCommandLineArguments(
(cap.toArray(new String[cap.size()])))
.build();
}
Try this -->
List<String> cliArgsCap = Arrays.asList(
"--webdriver=172.16.190.131:6781");
dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
I was able to find a fix to the --webdriver command, https://github.com/detro/ghostdriver/pull/438, I compiled that jar and loaded it in. Now I am getting
Apr 24, 2015 10:35:04 AM org.openqa.selenium.phantomjs.PhantomJSDriverService
INFO: executable: C:*Removed Path\phantomjs-2.0.0-windows\bin\phantomjs.exe
Apr 24, 2015 10:35:04 AM org.openqa.selenium.phantomjs.PhantomJSDriverService
INFO: port: 41533
Apr 24, 2015 10:35:04 AM org.openqa.selenium.phantomjs.PhantomJSDriverService
INFO: arguments: [--webdriver=127.0.0.1:6666, --webdriver-logfile=C:\Removed Path*\phantomjsdriver.log]
Apr 24, 2015 10:35:04 AM org.openqa.selenium.phantomjs.PhantomJSDriverService
INFO: environment: {}
[INFO - 2015-04-24T14:35:06.222Z] GhostDriver - Main - running on port 6666
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27 09:10:26'
System info: host: 'MBC5708', ip: '167.74.185.13', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_45'
Driver info: driver.version: PhantomJSDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:139)
My method invoking phantomjs is:
ArrayList<String> cliArgsCap = new ArrayList<String>();
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
cliArgsCap.add("--webdriver=6666");
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,PHANTOMJS_EXE.getAbsolutePath());
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
driver = new PhantomJSDriver(capabilities);

SEVERE: Context [/SpringMVCPractice1] startup failed due to previous errors

I am practicing Spring MVC web application (Spring4) using Java config files rather than XML config files. the Tomcat Server is not able to start the web application. during starting Tomcat I've received the following error in the console , but there is not previous message on the console
SEVERE: Context [/SpringMVCPractice1] startup failed due to previous errors
I don't have web.xml file and dispatcher-servlet.xml as it is java file config
here are whole log from console and whole source code
Reference of practice : Spring in Action, 4th Edition: Covers Spring 4
Log:
Mar 05, 2015 4:59:41 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.7.0_80\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\Program Files (x86)\Java\jre7\bin\javaw.exe;C:\apache-maven-3.2.3\bin;.
Mar 05, 2015 4:59:42 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SpringMVCPractice1' did not find a matching property.
Mar 05, 2015 4:59:42 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Mar 05, 2015 4:59:42 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Mar 05, 2015 4:59:42 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1234 ms
Mar 05, 2015 4:59:42 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 05, 2015 4:59:42 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.37
Mar 05, 2015 4:59:46 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/SpringMVCPractice1] startup failed due to previous errors
Mar 05, 2015 4:59:46 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Mar 05, 2015 4:59:46 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Mar 05, 2015 4:59:46 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4073 ms
WebConfig.java :
package spittr.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
#Configuration
#EnableWebMvc
#ComponentScan("spitter.web")
public class WebConfig extends WebMvcConfigurerAdapter{
#Bean
public ViewResolver viewResolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
#Override
public void configureDefaultServletHandling( DefaultServletHandlerConfigurer configurer){
configurer.enable();
}
}
SpittrWebAppInitializer.java :
package spittr.config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer ;
public class SpittrWebAppInitializer
extends AbstractAnnotationConfigDispatcherServletInitializer {
#Override
protected String[] getServletMappings(){
return new String[] { "/" };
}
#Override
protected Class[] getRootConfigClasses() {
return new Class<?>[] { RootConfig.class };
}
#Override
protected Class<?>[] getServletConfigClasses(){
return new Class<?>[] { WebConfig.class };
}
}
RootConfig.java :
package spittr.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
#Configuration
#ComponentScan(basePackages = { "spitter" }, excludeFilters = { #Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class) })
public class RootConfig {
}
HomeController.java :
package spittr.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
import static org.springframework.web.bind.annotation.RequestMethod.*;
#Controller
public class HomeController {
#RequestMapping(value = "/", method = GET)
public String home() {
return "home";
}
}
Under folder ...\WEB-INF\views\
home.jsp :
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page session="false" %>
<html>
<head>
<title>Spittr</title>
<link rel="stylesheet"
type="text/css"
href="<c:url value="/resources/style.css" />" >
</head>
<body>
<h1>Welcome to Spittr</h1>
Spittles |
Register
</body>
</html>

Spring MVC Java Configuration

Hi I am trying to use Spring MVC Java config and Content View resolver.
Files:-
public class WebInitializer implements WebApplicationInitializer {
/*
* (non-Javadoc)
*
* #see
* org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet
* .ServletContext)
*/
#Override
public void onStartup(ServletContext servletContext)
throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(SpringMvcConfig.class);
ctx.setServletContext(servletContext);
ctx.refresh();
Dynamic servlet = servletContext.addServlet("dispatcher",
new DispatcherServlet(ctx));
servlet.addMapping("/");
servlet.setLoadOnStartup(1);
servlet.setAsyncSupported(false);
}
}
#Configuration
#EnableWebMvc
#ComponentScan(basePackages = { "com.sambhav.mvc.controller" })
public class SpringMvcConfig extends WebMvcConfigurerAdapter {
/*
* #Bean public UrlBasedViewResolver setupViewResolver() {
* UrlBasedViewResolver resolver = new UrlBasedViewResolver();
* resolver.setPrefix("/WEB-INF/jsp/"); resolver.setSuffix(".jsp");
* resolver.setViewClass(TilesView.class); return resolver; }
*/
#Bean
public TilesViewResolver getTilesViewResolver() {
TilesViewResolver tilesViewResolver = new TilesViewResolver();
/*
* tilesViewResolver.setPrefix("/WEB-INF/jsp/");
* tilesViewResolver.setSuffix(".jsp");
*/
tilesViewResolver.setViewClass(TilesView.class);
return tilesViewResolver;
}
#Bean
public TilesConfigurer getTilesConfigurer() {
TilesConfigurer tilesConfigurer = new TilesConfigurer();
tilesConfigurer.setCheckRefresh(true);
tilesConfigurer.setDefinitions(new String[] { "/WEB-INF/tiles.xml" });
return tilesConfigurer;
}
#Override
public void configureContentNegotiation(
ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.TEXT_HTML)
.mediaType("json", MediaType.APPLICATION_JSON)
.mediaType("xml", MediaType.APPLICATION_XML)
.favorPathExtension(true); // default is true. just for clarity
}
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/css/*").addResourceLocations(
"/WEB-INF/css/*");
registry.addResourceHandler("/js/*").addResourceLocations(
"/WEB-INF/js/*");
registry.addResourceHandler("/img/*").addResourceLocations(
"/WEB-INF/img/*");
}
}
When trying to run the app, I don't the dispatcher servlet getting registered - no related info logs appear. Running in debug mode with break point in WebInitializer also indicates that its not getting called.
Jul 12, 2013 5:06:57 PM com.springsource.tcserver.serviceability.rmi.JmxSocketListener init
INFO: Started up JMX registry on 127.0.0.1:6969 in 68 ms
Jul 12, 2013 5:06:57 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 573 ms
Jul 12, 2013 5:06:57 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jul 12, 2013 5:06:57 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: VMware vFabric tc Runtime 2.8.2.RELEASE/7.0.35.B.RELEASE
Jul 12, 2013 5:06:57 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor D:\Installations\sts3.2\vfabric-tc-server-developer-2.8.2.RELEASE\base-instance\conf\Catalina\localhost\spring-mvc-config.xml
Jul 12, 2013 5:06:57 PM org.apache.catalina.startup.SetContextPropertiesRule begin
WARNING: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:spring-mvc-config' did not find a matching property.
Jul 12, 2013 5:06:57 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory D:\Installations\sts3.2\vfabric-tc-server-developer-2.8.2.RELEASE\base-instance\webapps\manager
Jul 12, 2013 5:06:57 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory D:\Installations\sts3.2\vfabric-tc-server-developer-2.8.2.RELEASE\base-instance\webapps\ROOT
Jul 12, 2013 5:06:57 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 12, 2013 5:06:57 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 311 ms
This results in 404 at / or any other path.
I am wondering what went wrong here.
Thanks for your help.
I know its old question. With newer Spring Boot, it is now far easier to configure any Spring application. Refer Spring Boot starter project here :-
Spring Boot Blog
Possible reasons:
web.xml. I advice you to delete it at all and use servlet-api with version higher than 3.0.
Incorrect #RequestMapping in controllers. Show them, please.
And finally, here you can find good step-by-step guide for base Spring MVC app with java configuration:
http://www.javacodegeeks.com/2013/03/spring-mvc-creation-of-a-simple-controller-with-java-based-config.html

JBoss 7.1.1.Final - EJB Remote Call - java.lang.IllegalStateException: No EJB receiver available for handling

I do have 2 JBoss stanalon instance running. 1 act as Server and another 1 would client.
SERVER:
Remote Interface
package com.xyz.life.service.ejb;
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.EJB;
import javax.ejb.Remote;
#Remote
public interface QuoteFacade extends Serializable{
public boolean isAlive() throws RemoteException;
}
EJB Impl
package com.xyz.life.common.component.ejb.services;
import java.rmi.RemoteException;
import javax.ejb.Remote;
import javax.ejb.Stateless;
#Stateless(mappedName = "QuoteFacadeEJB")
#Remote(QuoteFacade.class)
public class QuoteFacadeEJB extends CommonSessionBean implements QuoteFacade {
private static final long serialVersionUID = -8788783322280644881L;
#Override
public boolean isAlive() throws RemoteException {
return true;
}
}
server.log
16:40:25,012 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named QuoteFacadeEJB in deployment unit subdeployment "quote.jar" of deployment "quote.ear" are as follows:
java:global/quote/quote.jar/QuoteFacadeEJB!com.xyz.life.service.ejb.QuoteFacade
java:app/quote.jar/QuoteFacadeEJB!com.xyz.life.service.ejb.QuoteFacade
java:module/QuoteFacadeEJB!com.xyz.life.service.ejb.QuoteFacade
java:jboss/exported/quote/quote.jar/QuoteFacadeEJB!com.xyz.life.service.ejb.QuoteFacade
java:global/quote/quote.jar/QuoteFacadeEJB
java:app/quote.jar/QuoteFacadeEJB
java:module/QuoteFacadeEJB
Client
public void testClient() {
try {
Hashtable<String, Object> jndiProps = new Hashtable<String, Object>();
jndiProps.put(Context.URL_PKG_PREFIXES, JNDINames.JBOSS_CLIENT_NAMING_PREFIX);
jndiProps.put("jboss.naming.client.ejb.context", true);
Context ctx = new InitialContext(jndiProps);
String name = "ejb:global/quote/quote.jar/QuoteFacadeEJB!com.ge.life.annuity.service.ejb.QuoteFacade";
/*
"ejb:global/quote/quote.jar/QuoteFacadeEJB!com.ge.life.annuity.service.ejb.QuoteFacade",
"ejb:app/quote.jar/QuoteFacadeEJB!com.ge.life.annuity.service.ejb.QuoteFacade",
"ejb:jboss/exported/quote/quote.jar/QuoteFacadeEJB!com.ge.life.annuity.service.ejb.QuoteFacade"
*/
Object ref = ctx.lookup(name);
QuoteFacade quoteFacade = (QuoteFacade) ref;
LOGGER.debug("isAlive : " + quoteFacade.isAlive());
} catch (Exception e) {
LOGGER.error("Remote Client Exception : ", e);
}
}
No error/log on server side. Client side, it is failing with following error:
java.lang.IllegalStateException: No EJB receiver available for handling [appName:global,modulename:quote,distinctname:quote.jar] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext#200cae
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
at $Proxy10.isAlive(Unknown Source)
I tried without using Properties file:
private static QuoteFacade connectToStatelessBean(String name) throws NamingException {
Properties jndiProperties = new Properties();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProperties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put(javax.naming.Context.PROVIDER_URL, "remote://localhost:4447");
jndiProperties.put(javax.naming.Context.SECURITY_PRINCIPAL, "admin");
jndiProperties.put(javax.naming.Context.SECURITY_CREDENTIALS, "Pass1234");
final Context context = new InitialContext(jndiProperties);
return (QuoteFacade) context.lookup(name);
}
public static void testLocal() {
String[] JNDINAME1 = {
"ejb:global/quote/quote.jar/QuoteFacadeEJB!com.ge.life.annuity.service.ejb.QuoteFacade",
"ejb:app/quote.jar/QuoteFacadeEJB!com.ge.life.annuity.service.ejb.QuoteFacade",
"ejb:module/QuoteFacadeEJB!com.ge.life.annuity.service.ejb.QuoteFacade",
"ejb:jboss/exported/quote/quote.jar/QuoteFacadeEJB!com.ge.life.annuity.service.ejb.QuoteFacade",
"ejb:global/quote/quote.jar/QuoteFacadeEJB",
"ejb:app/quote.jar/QuoteFacadeEJB",
"ejb:module/QuoteFacadeEJB"
};
for(int i=0;i<JNDINAME1.length;i++){
try {
QuoteFacade test1 = connectToStatelessBean(JNDINAME1[i]);
LOGGER.error("DSLKAJDLAS : " + test1.isAlive());
} catch (Exception e) {
LOGGER.error("DSLKAJDLAS : " , e);
}
}
LOGGER.info("Done - SANSSAN!!!!!!!!");
}
This time, different exception :
14.01.2013 17:40:37.627 [ERROR] - EJBClient - DSLKAJDLAS :
javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jboss.naming.remote.client.InitialContextFactory from classloader ModuleClassLoader for Module "deployment.quote.war:main" from Service Module Loader
at org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:64)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:681)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.><init>(InitialContext.java:216)
at com.xyz.life.test.EJBClient.connectToStatelessBean(EJBClient.java:208)
at com.xyz.life.test.EJBClient.testLocal(EJBClient.java:225)
at com.xyz.life.test.EJBClient.test(EJBClient.java:172)
at com.xyz.life.common.web.struts.plugin.FrameworkStartupPlugIn.init(FrameworkStartupPlugIn.java:99)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:1158)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:473)
at javax.servlet.GenericServlet.init(GenericServlet.java:242)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3873)
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Try removing "global" from name:
String name =
"ejb:quote/quote.jar/QuoteFacadeEJB!com.xyz.life.service.ejb.QuoteFacade"
Also, your package name should be com.xyz.life.service.ejb (as seen on server log) and not com.ge.life.annuity.service.ejb.
Anyway, using remote-naming project for remote EJB invocations is discouraged as explained here.
... . So as you can see, we have managed to optimize certain operations by using the EJB client API for EJB lookup/invocation as against using the remote-naming project. There are other EJB client API implementation details (and probably more might be added) which are superior when it is used for remote EJB invocations in client applications as against remote-naming project which doesn't have the intelligence to carry out such optimizations for EJB invocations. That's why the remote-naming project for remote EJB invocations is considered "deprecated". ...
You can check how to do remote EJB invocations using the EJB client API here.
Found it....
The ones I used for Local machines only. Difference JBoss instances, should change the JNDI lookup name...
like
ejb:quote/quote.jar//QuoteFacadeEJB!com.xyz.life.service.ejb.QuoteFacade

Protocol Buffers MIME problem

Help!
Trying to implement Protocol Buffers via Rest (Jersey), but get this exception.
class com.util.ProtobufMessageBodyReader
class com.util.ProtobufMessageBodyWriter
Jul 6, 2010 3:43:37 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-9102
Jul 6, 2010 3:43:37 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 45485 ms
Jul 6, 2010 3:49:00 PM org.apache.catalina.connector.CoyoteAdapter convertURI
SEVERE: Invalid URI encoding; using HTTP default
Jul 6, 2010 3:49:00 PM com.sun.jersey.spi.container.ContainerRequest getEntity
SEVERE: A message body reader for Java type, class com.example.tutorial.ProfileRequestProto$ProfileRequest, and MIME media type, application/x-protobuf, was not found
I loaded ProtobufMessageBodyReader/Writer in the Apache ContextLoader.
From the log above, it seems Tomcat found the class but it apparent it fails when it reads
#Consumes("application/x-protobuf")
Here is ProtobufMessageBodyReader
#Provider
#Component
#Consumes("application/x-protobuf")
public class ProtobufMessageBodyReader implements MessageBodyReader<Message> {
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return Message.class.isAssignableFrom(type);
}
public Message readFrom(Class<Message> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws IOException, WebApplicationException {
try {
Method newBuilder = type.getMethod("newBuilder");
GeneratedMessage.Builder<?> builder = (GeneratedMessage.Builder<?>) newBuilder.invoke(type);
return builder.mergeFrom(entityStream).build();
} catch (Exception e) {
throw new WebApplicationException(e);
}
}
#Override
public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2) {
// TODO Auto-generated method stub
return false;
}
And here is ProtobufMessageBodyWriter
#Provider
#Component
#Produces("application/x-protobuf")
public class ProtobufMessageBodyWriter implements MessageBodyWriter<Message> {
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return Message.class.isAssignableFrom(type);
}
public long getSize(Message m, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return m.getSerializedSize();
}
public void writeTo(Message m, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String,Object> httpHeaders,OutputStream entityStream) throws IOException, WebApplicationException {
entityStream.write(m.toByteArray());
}
Here is the code from client :
URL url = new URL(URL);
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setDoInput(true);
http.setDoOutput(true);
http.setUseCaches(false);
http.setRequestMethod("POST");
http.setRequestProperty("Content-Type","application/x-protobuf");
http.setRequestProperty("Accept", "application/x-protobuf");
DataOutputStream stream = new DataOutputStream(http.getOutputStream ());
if(contentType.equals("application/x-protobuf")) {
ProfileRequest.Builder profile = ProfileRequest.newBuilder();
profile.setName("John");
profile.setId("123");
profile.build().writeTo(http.getOutputStream());
}
stream.flush();
stream.close();
And here is the code from server
#POST
#Consumes("application/x-protobuf")
public byte[] processProtoRequest(ProfileRequest protoRequest) {
byte[] result = null;
ProfileRequest.Builder profile = ProfileRequest.newBuilder();
profile.mergeFrom(protoRequest);
result = getProfileProtoResponse(profile);
}catch(Exception e){
}
return result;
}
I cannot figure out what is the problem.
Is there anything with Jersey config? Or something is wrong when I sent protocol request via HTTP?
Any help will be appreciate it.
Thanks
You mostly nailed the issue yourself already I think:
and MIME media type, application/x-protobuf, was not found
[...]
From the log above, it seems Tomcat found the class but it apparent it fails when it reads
#Consumes("application/x-protobuf")
The media types supported by Jersey (or rather JSR-311/JAX-RS) out of the box are defined in class MediaType. To resolve your issue it might be enough to define an appropriate media type for application/x-protobuf, see thread [Jersey] MediaType-s? for a discussion and samples regarding this.
I just met the same problem on my maven+jersey+protobuf project,and I am using tomcat 6. to me the problems is that the Provider Class the tomcat hasn't found.
After I solve this problem the tomcat 6.0 shows like this :
Deploying configuration descriptor jerseydemo2.xml
一月 26, 2015 11:13:41 上午 com.sun.jersey.api.core.WebAppResourceConfig init
信息: Scanning for root resource and provider classes in the Web app resource paths:
/WEB-INF/lib
/WEB-INF/classes
一月 26, 2015 11:13:41 上午 com.sun.jersey.api.core.ScanningResourceConfig logClasses
信息: Root resource classes found:
class sample.hello.resources.AddressBookResource
一月 26, 2015 11:13:41 上午 com.sun.jersey.api.core.ScanningResourceConfig logClasses
信息: Provider classes found:
class sample.pb.ProtobufMessageBodyReader
class sample.pb.ProtobufMessageBodyWriter
一月 26, 2015 11:13:41 上午 com.sun.jersey.server.impl.application.WebApplicationImpl initiate
信息: Initiating Jersey application, version 'Jersey: 1.2-SNAPSHOT 01/27/2010 01:47 AM'
before it showed the Provider classes not found.
my problems is that the web.xml file has set the specific path for the tomcat to find all the resouces. now I have changed it like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.server.impl.container.servlet.ServletAdaptor</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
hope it helps you !

Resources