EJB2.1 lookup issue in JBoss EAP 7.2.8 - jboss7.x

We have migrated our application from Weblogic to JBoss EAP 7.2.8 and now we are facing issue in JNDI lookup of remote interface.
Configuration in ejb-jar.xml:
<session>
<ejb-name>BeanSL</ejb-name>
<home>com.project.ejb.BeanSLHome</home>
<remote>com.project.ejb.BeanSLIF</remote>
<ejb-class>com.project.ejb.BeanSL</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
server.log entry in Jboss for EJB registration of above mentioned class:
java:global/ear/jarWithEJB/BeanSL!com.project.ejb.BeanSLIF
java:app/dbdocejb/BeanSL!com.project.ejb.BeanSLIF
java:module/BeanSL!com.project.ejb.BeanSLIF
java:jboss/exported/ear/jarWithEJB/BeanSL!com.project.ejb.BeanSLIF
java:global/ear/jarWithEJB/BeanSL!com.project.ejb.BeanSLHome
java:app/dbdocejb/BeanSL!com.project.ejb.BeanSLHome
java:module/BeanSL!com.project.ejb.BeanSLHome
java:jboss/exported/ear/jarWithEJB/BeanSL!com.project.ejb.BeanSLHome
Remote Interface: BeanSLIF
Home Interface: BeanSLHome
Class implementing Remote Interface: BeanSL
BeanSLIF beanSLIf = null ;
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, “org.wildfly.naming.client.WildFlyInitialContextFactory”);
p.put( Context.PROVIDER_URL, “http-remoting://localhost:8090” );
p.put(Context.SECURITY_PRINCIPAL, “jbossUser”);
p.put(Context.SECURITY_CREDENTIALS, “jbossPassword”);
p.put("jboss.naming.client.ejb.context", "true");
ctx = new InitialContext( p );
beanSLIf = (BeanSLIF) ctx.lookup(“ejb:/ear/jarWithEJB/BeanSL!com.project.ejb.BeanSLIF”);
On inspecting the above lookup code(cx.lookup(ejb:/...) code I am getting below ‘Proxy’:
Proxy for remote EJB StatelessEJBLocator for "/ear/jarWithEJB/BeanSL", view is interface com.project.ejb.BeanSLIF, affinity is None
And this further leads to:
com.sun.proxy.$Proxy39 cannot be cast to com.project.ejb.BeanSLIF
Any help would be really appreciated. Thanks in advance.

Related

TomEE Embedded: Resource defined in resources.xml not available within webapp

I'm currently trying to run a simple webapp on TomEE Embedded (TomEE Version 7.0.5).
According to the docs, I can start the TomEE and deploy the classpath as a webapp like this. I've set the document base to src/main/webapp.
try (final Container container = new Container(new Configuration())
.deployClasspathAsWebApp("", new File("src/main/webapp"))) {
container.await();
}
I have defined a datasource in WEB-INF/resources.xml which looks like this:
<Resource id="myDataSource" type="javax.sql.DataSource">
JdbcDriver org.hsqldb.jdbcDriver
JdbcUrl jdbc:hsqldb:file:hsqldb
UserName sa
Password
</Resource>
And I've setup a reference in the web.xml:
<resource-ref>
<res-ref-name>myDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
</resource-ref>
Then I try to lookup this datasource in my Servlet via JNDI.
#Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
Context initCtx = new InitialContext();
DataSource ds = (DataSource) initCtx.lookup("java:comp/env/myDataSource");
Connection connection = ds.getConnection();
...
}
When the TomEE starts, it seems like my DataSource is created (at least there is some output about that in the logs). However when I try to lookup the DataSource in my servlet, I get an unconfigured dbcp2 connection pool as a DataSource which throws the following exception when ds.getConnection() is called:
java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2186)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2066)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1525)
at TestServlet.doGet(TestServlet.java:32)
...
The same configuration works fine on a standalone TomEE (I tried TomEE Webprofile) or when using the TomEE Maven Plugin. Is there anything I'm missing to get it running also for Embedded TomEE?
Thanks in advance
Tomee embedded does not bind a custom webapp classloader by default so does not have comp/ always bound. You can pass properties to the context to force it to be openejb one or use openejb:Resource/myDataSource or java:openejb/Resource/myDataSource naming.

Regiser JacksonJsonProvider in Websphere liberty profile

I am trying to call a REST service from an EJB hoping to utilize Jackson's
#JsonIgnoreProperties(ignoreUnknown = true)
The following does the trick in wlp v8.5.5.9
Client client = ClientBuilder.newClient().register(JacksonJsonProvider.class);
The same code produces a NullPointerException in the wlp v16.0.0.2
Caused by: java.lang.NullPointerException
at org.apache.cxf.jaxrs.impl.tl.ThreadLocalProviders.getContextResolver(ThreadLocalProviders.java:50)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.locateMapper(JacksonJsonProvider.java:634)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:413)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1356)
at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:438)
... 98 more
I have found a discussions triggered by the same problems in v8.5.5.9, but I am not sure how it could help me. As I noted I have no troubles with the code in the v8.5.5.9
Another discussion was related to the Jackson v2.x. Initially I used Jackson v1.9.13, but I have tried to switch to the newest Jeckson 2.8.0 version and apply the offered solution. The same outcome: application works in wlp 8.5.5.9 and produces the same error in v16.0.0.2.
Any ideas?
Update:
the problem could be avoided by extending the JacksonJsonProvider class and explicitly providing object mapper
public class MyJacksonJsonProvider extends JacksonJsonProvider {
public MyJacksonJsonProvider() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibilityChecker(objectMapper.getVisibilityChecker().withFieldVisibility(JsonAutoDetect.Visibility.ANY));
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
setMapper(objectMapper);
}
}
and then registering it in the client
Client client = ClientBuilder.newClient().register(MyJacksonJsonProvider.class);
However it would be nice to understand if it is a bug or a feature.

ProxyServlet stop working after migration from jetty 8 to jetty 9

I have an eclipse plugin which uses jetty server with ProxyServlet. Basically, the implementation is the following:
ServletHolder proxyServletHolder = new ServletHolder(new SubClassOfProxyServlet());
proxyServletHolder.setAsyncSupported(true);
ServletHandler proxyServletHandler = new ServletHandler();
proxyServletHandler.addServletWithMapping(proxyServletHolder, "/mapping/url");
After that I add proxy handler to the handler list and set this list to the server:
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] {
. // Other Handlers
.
proxyServletHandler,
.
.
.
new DefaultHandler()
});
server.setHandler(handlers);
Everything worked like a charm against jetty 8 but after migration to jetty 9 I get the following error:
Caused by: java.lang.IllegalStateException: No server executor for proxy
at org.eclipse.jetty.proxy.ProxyServlet.createHttpClient(ProxyServlet.java:279)
at org.eclipse.jetty.proxy.ProxyServlet.init(ProxyServlet.java:123)
... 24 more
Has the mechanism of working with ProxyServer changed? Am I missing something?
You need to update your SubClassOfProxyServlet class to include the various configurations that are now being passed from the Server to the Proxy which are then in turn used by the internal HttpClient
The particular error means you are not passing along the Executor properly.
You have 2 choices for the Executor specific piece (there might be more things for you to configure after this is addressed)
Set the init-parameter maxThreads to a valid integer value.
or Create an Executor, and set it in the servlet context attributes at ServletContext.setAttribute("org.eclipse.jetty.server.Executor", myExecutor) on application deployment / startup. - You could probably do this as well in your SubClassOfProxyServlet.init(ServletConfig config) method.
I was able to get it working via the maxThreads method mentioned above, setting it on creation. Applying this to the original example would result in this:
ServletHolder proxyServletHolder = new ServletHolder(new SubClassOfProxyServlet());
proxyServletHolder.setAsyncSupported(true);
proxyServletHolder.setInitParameter("maxThreads", "2");
ServletHandler proxyServletHandler = new ServletHandler();
proxyServletHandler.addServletWithMapping(proxyServletHolder, "/mapping/url");
Here is an example of how you can add a servlet to a list of handlers:
private void addWebApp(String contextPath, String resourceBase, Server server) {
WebAppContext webAppContext = new WebAppContext();
// webAppContext.setDescriptor(webapp + "/WEB-INF/web.xml");
webAppContext.setResourceBase(resourceBase);
webAppContext.setContextPath(contextPath);
webAppContext.setParentLoaderPriority(true);
webAppContext.setWelcomeFiles(new String[] {"index.html"});
webAppContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
webAppContext.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
final ServletHolder servletHolder =new ServletHolder();
servletHolder.setAsyncSupported(ContentBasedProxyServlet.class);
servletHolder.setAsyncSupported(true);
webAppContext.addServlet(servletHolder, "/*");
HandlerList handlers = (HandlerList) server.getHandler();
handlers.addHandler(webAppContext);
}
In addition you can put maxThreads to web.xml as well:
<servlet>
<servlet-name>proxy</servlet-name>
<servlet-class>example.MyProxyServlet</servlet-class>
<init-param>
<param-name>maxThreads</param-name>
<param-value>5</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>

Fail to connect to Rabbitmq using Spring 4.0 webstocket stomp api

I tried to make STOMP connection to RabbitMQ using Spring 4.0 WebSocketMessageBrokerConfigurer class, but failed ?
Snap of code is here.
#Configuration
#EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
#Override
public void configureMessageBroker(MessageBrokerRegistry config) {
StompBrokerRelayRegistration StompBrokerRelayRegistration = config.enableStompBrokerRelay("/");
StompBrokerRelayRegistration.setApplicationLogin("guest");
StompBrokerRelayRegistration.setApplicationPasscode("guest");
StompBrokerRelayRegistration.setAutoStartup(true);
StompBrokerRelayRegistration.setRelayHost("localhost");
StompBrokerRelayRegistration.setRelayPort(15674);
Note that
I am using spring boot to run application. In fact I am changing the existing spring example "gs-messaging-stomp-websocket". and changing class WebSocketConfig.
Rabbitmq is locally installed with STOMP plugin enabled.
Added all the maven dependency like spring-rabbitmq.
Do I need to do any thing else ?
Thanks,
Rafiq
Ok got the issue
StompBrokerRelayRegistration StompBrokerRelayRegistration = config.enableStompBrokerRelay("/");
We need to pass the stomp supported "uri" instead of "/" vhost.
StompBrokerRelayRegistration StompBrokerRelayRegistration = config.enableStompBrokerRelay("/topic", "/queue", "/amq/");

Authentication in Remote Connection to JBoss 4.2.3

I'm trying to connect to a JBoss MBean, but am getting blocked due to authentication failures.
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "jnp://"+testIP+":"+testPort);
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "admin");
InitialContext ic = new InitialContext(env);
RMIAdaptor server = (RMIAdaptor) ic.lookup("jmx/invoker/RMIAdaptor");
// Get the MBeanInfo for the JNDIView MBean
ObjectName name = new ObjectName("my.service:service=MyBean");
MBeanInfo info = server.getMBeanInfo(name);
Everything seems to behave fine in terms of connection until the last line when I get:
java.lang.SecurityException: Failed to authenticate principal=null, securityDomain=jmx-console
at org.jboss.jmx.connector.invoker.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:97)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.invocation.jrmp.server.JRMPProxyFactory.invoke(JRMPProxyFactory.java:179)
:
:
The security domain is configured to use JAAS (in the jmx-invoker-service.xml):
<interceptor code="org.jboss.jmx.connector.invoker.AuthenticationInterceptor"
securityDomain="java:/jaas/jmx-console"/>
And the user is defined in jmx-console-users.properties properly.
It appears to me that the principal is simply not being read properly. Does JBoss use something other than Context.SECURITY_PRINCIPAL/CREDENTIALS? It appears from Their Naming Documentation that they do not, but why is this failing then?
Many Thanks,
-C
Try setting you initial context factory like this:
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.LoginInitialContextFactory");