FailedToCreateRouteException Deploying Camel-CDI application to Wildfly 8.2 - java

I am developing an application that reads messages from a Kafka queue, and processes them creating an e-mail and sending it.
I was able to get a simple camel route working in a standalone java application, however when I package it up using CDI and Wildfly 8.2 it fails to deploy.
I am following the directions from here:
camel CDI Properties example
I used the example as a template for my application.
I am using Wildfly 8.2.0, Camel 2.18.1, Kafka 0.10.1.1
What am I doing wrong? I don't understand the error "org.apache.camel.FailedToCreateRouteException: Failed to create route Deep-email-notify-route: Route(Deep-email-notify-route)[[From[no uri or ref supplied!... because of Either 'uri' or 'ref' must be specified on: org.apache.camel.impl.DefaultRouteContext#55edcc54"
This is most of my code:
#ApplicationScoped
public class OrderEmailApplication {
/** The logger. */
private static Logger logger =LogManager.getLogger(OrderEmailRoute.class);
public OrderEmailApplication() {}
#ContextName("OrderNotifications")
static class OrderEmailRoute extends RouteBuilder {
#Uri("kafka://{{deep.notify.kafka.server}}?topic={{deep.notify.order.topics}}&groupId={{deep.notify.order.groupId}}&"+
"keyDeserializer=org.apache.kafka.common.serialization.StringDeserializer&" +
"valueDeserializer=org.apache.kafka.common.serialization.StringDeserializer")
Endpoint kafkaEndpoint;
#Uri("file:///home/whomer/tmp/Notify/deadMessages")
private Endpoint deadLetter;
#BeanInject
BulkEmailProcessor bulkEmailProcessor;
#BeanInject
FailedMessageEnrichmentProcessor failedEmailEnrichement;
#Override
public void configure() throws Exception {
errorHandler(defaultErrorHandler().maximumRedeliveries(0));
from(kafkaEndpoint).routeId("Deep-email-notify-route")
.unmarshal().json(JsonLibrary.Jackson, LinkedHashMap.class)
.bean("velocityBean")
.process(bulkEmailProcessor)
.marshal().json(JsonLibrary.Jackson, Map.class)
.to("Log:?level=DEBUG");
from("direct:getTemplate").to("velocity://dummy");
}
}
#Named("velocityBean")
static class VelocityBean {
#Uri("direct:getTemplate")
private ProducerTemplate template;
public void process(Exchange exchange) {
// removed for brevity
}
}
#Produces
#Named("properties")
// "properties" component bean that Camel uses to lookup properties
PropertiesComponent properties(PropertiesParser parser) {
PropertiesComponent component = new PropertiesComponent();
// Use DeltaSpike as configuration source for Camel CDI
component.setPropertiesParser(parser);
return component;
}
// PropertiesParser bean that uses DeltaSpike to resolve properties
static class DeltaSpikeParser extends DefaultPropertiesParser {
#Override
public String parseProperty(String key, String value, Properties properties) {
return ConfigResolver.getPropertyValue(key);
}
}
}
This is the stack trace:
14:51:37,674 INFO [org.apache.camel.cdi.CdiCamelExtension] (MSC service thread 1-4) Camel CDI is starting Camel context [OrderNotifications]
14:51:37,680 INFO [org.apache.camel.impl.DefaultCamelContext] (MSC service thread 1-4) Apache Camel 2.18.1 (CamelContext: OrderNotifications) is starting
14:51:37,682 INFO [org.apache.camel.management.ManagedManagementStrategy] (MSC service thread 1-4) JMX is enabled
14:51:37,821 INFO [org.apache.camel.impl.DefaultRuntimeEndpointRegistry] (MSC service thread 1-4) Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000)
14:51:37,827 INFO [org.apache.camel.impl.DefaultCamelContext] (MSC service thread 1-4) Apache Camel 2.18.1 (CamelContext: OrderNotifications) is shutting down
14:51:37,849 INFO [org.apache.camel.impl.DefaultCamelContext] (MSC service thread 1-4) Apache Camel 2.18.1 (CamelContext: OrderNotifications) uptime 0.169 seconds
14:51:37,849 INFO [org.apache.camel.impl.DefaultCamelContext] (MSC service thread 1-4) Apache Camel 2.18.1 (CamelContext: OrderNotifications) is shutdown in 0.022 seconds
14:51:37,859 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit."NotificationService.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."NotificationService.war".WeldStartService: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_51]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_51]
Caused by: org.jboss.weld.exceptions.DeploymentException: Exception List with 1 exceptions:
Exception 0 :
org.apache.camel.FailedToCreateRouteException: Failed to create route Deep-email-notify-route: Route(Deep-email-notify-route)[[From[no uri or ref supplied!... because of Either 'uri' or 'ref' must be specified on: org.apache.camel.impl.DefaultRouteContext#55edcc54
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:201)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1008)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3397)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3128)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:182)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2957)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2953)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2976)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2953)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2920)
at org.apache.camel.impl.DefaultCamelContext$Proxy$_$$_WeldClientProxy.start(Unknown Source)
at org.apache.camel.cdi.CdiCamelExtension.afterDeploymentValidation(CdiCamelExtension.java:422)
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:497)
at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:90)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:271)
at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:121)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:258)
at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:237)
at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:174)
at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:133)
at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:107)
at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:54)
at org.jboss.weld.bootstrap.events.AbstractDeploymentContainerEvent.fire(AbstractDeploymentContainerEvent.java:35)
at org.jboss.weld.bootstrap.events.AfterDeploymentValidationImpl.fire(AfterDeploymentValidationImpl.java:28)
at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:439)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90)
at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:93)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
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:745)
Caused by: java.lang.IllegalArgumentException: Either 'uri' or 'ref' must be specified on: org.apache.camel.impl.DefaultRouteContext#55edcc54
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:136)
at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:69)
at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:90)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1051)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:196)
... 35 more
at org.jboss.weld.bootstrap.events.AbstractDeploymentContainerEvent.fire(AbstractDeploymentContainerEvent.java:37)
at org.jboss.weld.bootstrap.events.AfterDeploymentValidationImpl.fire(AfterDeploymentValidationImpl.java:28)
at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:439)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90)
at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:93)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
... 3 more

OOPS. Programmer error!
The main issue turned out to be the Endpoint injections.
Instead of
#Uri("kafka:...")
Endpoint fubar;
the injection should have been:
#EndpointInjection(uri = "kafka:...")
Endpoint fubar;

Related

Spring Quartz remote scheduler

I started quartz server instance using spring (as in article), it works good.
But when I try to start another app with quartz client and connect to quartz server, I have an error, please help what I'm doing wrong.
Server config:
#Configuration
public class ServerConfig {
#Bean
public SchedulerFactoryBean schedulerFactoryBean(ApplicationContext applicationContext) {
SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
schedulerFactory.setConfigLocation(new ClassPathResource("quartz.properties"));
schedulerFactory.setSchedulerListeners(...);
schedulerFactory.setJobFactory(...);
schedulerFactory.setTriggers(...);
return schedulerFactory;
}
...
}
Client config:
#Configuration
public class ClientConfig {
#Bean
public SchedulerFactoryBean schedulerFactoryBean() {
SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
schedulerFactory.setConfigLocation(new ClassPathResource("quartz.properties"));
return schedulerFactory;
}
...
}
Server quartz.properties:
org.quartz.scheduler.instanceName=myScheduler
org.quartz.scheduler.rmi.export=true
org.quartz.scheduler.rmi.createRegistry=true
org.quartz.scheduler.rmi.registryHost=localhost
org.quartz.scheduler.rmi.registryPort=1099
org.quartz.scheduler.rmi.serverPort=1100
Client quartz.properties:
org.quartz.scheduler.instanceName=myScheduler
org.quartz.scheduler.rmi.proxy=true
org.quartz.scheduler.rmi.registryHost=localhost
org.quartz.scheduler.rmi.registryPort=1099
Server logs:
[2019-09-03] [10:07:26.171] INFO SchedulerFactoryBean:538 - Loading Quartz config from [class path resource [quartz.properties]]
[2019-09-03] [10:07:26.229] INFO StdSchedulerFactory:1208 - Using default implementation for ThreadExecutor
[2019-09-03] [10:07:26.272] INFO SchedulerSignalerImpl:61 - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
[2019-09-03] [10:07:26.273] INFO QuartzScheduler:229 - Quartz Scheduler v.2.3.0 created.
[2019-09-03] [10:07:26.277] INFO RAMJobStore:155 - RAMJobStore initialized.
[2019-09-03] [10:07:26.338] INFO QuartzScheduler:421 - Scheduler bound to RMI registry under name 'schedulerFactoryBean_$_NON_CLUSTERED'
[2019-09-03] [10:07:26.343] INFO QuartzScheduler:294 - Scheduler meta-data: Quartz Scheduler (v2.3.0) 'schedulerFactoryBean' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - access via RMI.
...
[2019-09-03] [10:07:26.344] INFO StdSchedulerFactory:1362 - Quartz scheduler 'schedulerFactoryBean' initialized from an externally provided properties instance.
[2019-09-03] [10:07:26.345] INFO StdSchedulerFactory:1366 - Quartz scheduler version: 2.3.0
...
[2019-09-03] [10:07:29.12] INFO SchedulerFactoryBean:684 - Starting Quartz Scheduler now
[2019-09-03] [10:07:29.13] INFO QuartzScheduler:547 - Scheduler schedulerFactoryBean_$_NON_CLUSTERED started.
Client logs:
[2019-09-03] [10:11:53.255] INFO SchedulerFactoryBean:538 - Loading Quartz config from [class path resource [quartz.properties]]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schedulerFactoryBean' defined in class path resource [com/mypackage/ClientConfig.class]: Invocation of init method failed; nested exception is org.quartz.SchedulerException: Operation not supported for remote schedulers.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1631)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:73)
... 3 more
Caused by: org.quartz.SchedulerException: Operation not supported for remote schedulers.
at org.quartz.impl.RemoteScheduler.getListenerManager(RemoteScheduler.java:913)
at org.springframework.scheduling.quartz.SchedulerAccessor.registerListeners(SchedulerAccessor.java:340)
at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:476)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1689)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1627)
... 13 more
As you can see, the error is:
org.quartz.SchedulerException: Operation not supported for remote schedulers. and happens while bean initialization. What's wrong with it?
After client fails to start, server shows in logs:
[2019-09-03] [10:11:53.462] INFO QuartzScheduler:666 - Scheduler schedulerFactoryBean_$_NON_CLUSTERED shutting down.
[2019-09-03] [10:11:53.462] INFO QuartzScheduler:585 - Scheduler schedulerFactoryBean_$_NON_CLUSTERED paused.
[2019-09-03] [10:11:53.871] INFO QuartzScheduler:447 - Scheduler un-bound from name 'schedulerFactoryBean_$_NON_CLUSTERED' in RMI registry
[2019-09-03] [10:11:53.872] INFO QuartzScheduler:740 - Scheduler schedulerFactoryBean_$_NON_CLUSTERED shutdown complete.
I have versions of Spring - 4.3.20, Quartz - 2.3.0
Update:
I see registerListeners() call in SchedulerFactoryBean:
#Override
public void afterPropertiesSet() throws Exception {
...
try {
registerListeners();
registerJobsAndTriggers();
}
catch (Exception ex) {
try {
this.scheduler.shutdown(true);
}
catch (Exception ex2) {
logger.debug("Scheduler shutdown exception after registration failure", ex2);
}
throw ex;
}
}
and in registerListeners() we call getScheduler().getListenerManager() which fails with Operation not supported for remote schedulers exception. How to avoid calling registerListeners() for RemoteScheduler?
Finally I get it working the following way:
I refused from using Spring's SchedulerFactoryBean on a client, but instead I directly create an instance of StdSchedulerFactory from quartz library (then it properly creates an instance of RemoteScheduler): new StdSchedulerFactory(). It properly connects to a server quartz instance.
Due to I cannot obtain an instance of StdSchedulerFactory from SchedulerFactoryBean I just pass both to beans where it is needed. So on a client app SchedulerFactoryBean is null, and on a server app StdSchedulerFactory is null.
Job schedule part is the same for both factories as all I do with them is obtain scheduler:
private Scheduler getScheduler() throws SchedulerException {
if (schedulerFactoryBean != null) return schedulerFactoryBean.getScheduler();
if (schedulerFactory != null) return schedulerFactory.getScheduler();
else return null;
}
and then...
Scheduler scheduler = getScheduler();
if (scheduler != null) {
scheduler.scheduleJob(job, trigger);
}

"type" cannot be resolved to a type, while using ejb in jsp

I use eclipse Neon.
I created simple EJB project with follow code:
package com.clientManager;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
/**
* Session Bean implementation class ClientManager
*/
#Stateless
#LocalBean
public class ClientManager {
/**
* Default constructor.
*/
public ClientManager() {
// TODO Auto-generated constructor stub
}
public String test() {
return "test";
}
}
It created automatically and reside in ejbModule folder.
It uses EJB 3.2 and successfully deploying on WildFly server:
11:25:50,360 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0028: Stopped deployment Neoflex.jar (runtime-name: Neoflex.jar) in 9ms
11:25:50,370 WARN [org.jboss.as.controller] (DeploymentScanner-threads - 2) WFLYCTL0357: Notification of type deployment-undeployed is not described for the resource at the address []
11:25:50,370 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0009: Undeployed "Neoflex.jar" (runtime-name: "Neoflex.jar")
11:25:55,380 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found Neoflex.jar in deployment directory. To trigger deployment create a file called Neoflex.jar.dodeploy
11:25:55,380 INFO [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0027: Starting deployment of "Neoflex.jar" (runtime-name: "Neoflex.jar")
11:25:55,400 INFO [org.jboss.weld.deployer] (MSC service thread 1-6) WFLYWELD0003: Processing weld deployment Neoflex.jar
11:25:55,400 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-6) WFLYEJB0473: JNDI bindings for session bean named 'ClientManager' in deployment unit 'deployment "Neoflex.jar"' are as follows:
java:global/Neoflex/ClientManager!com.clientManager.ClientManager
java:app/Neoflex/ClientManager!com.clientManager.ClientManager
java:module/ClientManager!com.clientManager.ClientManager
java:global/Neoflex/ClientManager
java:app/Neoflex/ClientManager
java:module/ClientManager
11:25:55,523 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0010: Deployed "Neoflex.jar" (runtime-name : "Neoflex.jar")
Now I created DynamicWebProject for JSP page which will use the EJB:
<%#page import="com.clientManager.*"%>
<%
ClientManager c = new ClientManager();
%>
<%= c.test() %>
I configured in Build Path of JSP project the EJB project (!)
Please see screenshot.
When I publish JSP and access to the page (main.jsp), I have:
JBWEB004060: An error occurred at line: 3 in the jsp file: /main.jsp
ClientManager cannot be resolved to a type
1: <%#page import="com.clientManager.*"%>
2: <%
3: ClientManager c = new ClientManager();
4: %>
5: <%= c.test() %>
What is wrong?
You shouldn’t directly instantiate the EJB bean rather it lifecycle in managed by the EJB container, the right way of getting the EJB bean handle is via it's look up method.
Make sure you choose the correct look up name, I am using randomly the one from your post
Try changing to something like below.
<%
ClientManager cm;
cm = (ClientManager) ctx.lookup("java:module/ClientManager");
%>

HibernateSearch ClassBridge - sorting and faceting not working with HS 5.5.1

I posted this a while ago in the hibernate search forum and got no response, so trying again in stackoverflow...
Since migrating from HS 4.5.1 to HS 5.5.1 we have problems with sorting and faceting.
All our indexing is done using a class bridge which calls a CDI-Bean to do the actual indexing. In our system the configuration which fields are indexed is dynamic and can change at runtime, so we cannot use HS-annotations.
Sorting: we would like to take advantage of lucene's new sorting features using docvalues. We tried to add interface MetadataProvidingFieldBridge to the class bridge to provide the information which fields are sort fields, but at the time when the class bridge is initalized (when jboss is booting) the CDI-bean is not yet available.
Question 1: Is there a way to re-initialize the HS-SearchIntegrator at a later time, when the CDI-bean is available or when our index configuration has changed?
For the time being HS falls back to using the UninvertingReader for dealing with the sort fields without docvalues.
Question 2: Is this going to be supported in the future? How "bad" is it performancewise to use UninvertingReader?
With faceting we face a similar problem, we cannot use #Facet-annotation because the configuration is dynamic. For the time being we use lucene's faceting API directly.
Question 3: Is there a plan in HS to add faceting-information via a class bridge in the near future, similar to MetadataProvidingFieldBridge? Is the class bridge going to be supported by Hibernate Search in the future?
Code of the ClassBridge:
public class FtiClassBridgeCE implements FieldBridge, MetadataProvidingFieldBridge
{
#Override
public void set(String fieldName, Object value, Document document, LuceneOptions options)
{
if( !(value instanceof ComplexEntity))
return; // ignore
ComplexEntity object = (ComplexEntity)value;
// FtiService does the actual indexing by adding fields to given document
Configuration.service( FtiService.class).setIndexData( object, new FtiDocumentHS( document, options));
}
/*
* This method is called in startup process of JBoss (Wildfly10) when initializing the persistence context. At that
* time the CDI-Beans are not yet available resulting in a NullPointerException.
*
* #see org.hibernate.search.bridge.MetadataProvidingFieldBridge#configureFieldMetadata(java.lang.String,
* org.hibernate.search.bridge.spi.FieldMetadataBuilder)
*/
public void configureFieldMetadata(String name, FieldMetadataBuilder builder)
{
try
{
// FtiService is a CDI bean which is obtained from BeanManager via our Configuration-class
// FtiSearchConfig stores information which fields should be added to lucene index and how they map to
// ComplexEntity's data
for( FtiSearchConfig config : Configuration.service( FtiService.class).getAllConfigurations())
{
for( FtiSearchField ftiSearchField : config.getSortFields())
{
builder.field( ftiSearchField.getNameForSort( null), hsSortType( ftiSearchField.getFieldDataType())).sortable( true);
}
}
}
catch( Exception ex)
{
ex.printStackTrace();
// catch the NPE thrown at JBoss boot time
}
}
private FieldType hsSortType(FtiFieldDataType fieldDataType)
{
switch( fieldDataType)
{
case DATE:
return FieldType.LONG;
case NUMERIC:
return FieldType.INTEGER;
case PRICE:
return FieldType.DOUBLE;
default:
return FieldType.STRING;
}
}
In the #PostConstruct-Method of the CDI-Bean I tried to reinitialized the HS SearchIntegrator like this but it did not call again the method FtiClassBridgeCE.configureFieldMetadata(String name, FieldMetadataBuilder builder).
#PostConstruct
protected void initialize() throws ConfigurationException
{
initSearchConfig();
initializeHSSearch();
}
private void initializeHSSearch()
{
FullTextEntityManager ftEM = ftidx().getFullTextEM();
SearchIntegrator si = ftEM.getSearchFactory().unwrap( SearchIntegrator.class);
SearchIntegratorBuilder sb = new SearchIntegratorBuilder().currentSearchIntegrator( si);
sb.buildSearchIntegrator();
}
Which is the right way to do this or is there no way to reinitialize the SearchIntegrator?
Stacktrace of the Exception that is thrown at JBoss boot time when initializing HS SearchIntegrator:
13:33:12,656 INFO [jpa] (ServerService Thread) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'mc.ear/web.war#mc'
13:33:16,219 INFO [Dialect] (ServerService Thread) HHH000400: Using dialect: mc.core.system.util.db.SQLServerDialect
13:33:16,996 INFO [EnversServiceImpl] (ServerService Thread) Envers integration enabled? : true
13:33:23,864 INFO [UpdateTimestampsCache] (ServerService Thread) HHH000250: Starting update timestamps cache at region: mc.ear/web.war#mc.org.hibernate.cache.spi.UpdateTimestampsCache
13:33:25,675 INFO [StandardQueryCache] (ServerService Thread) HHH000248: Starting query cache at region: mc.ear/web.war#mc.org.hibernate.cache.internal.StandardQueryCache
13:33:27,529 INFO [Version] (ServerService Thread) HSEARCH000034: Hibernate Search 5.5.1.Final
babysitten13:34:45,462 ERROR [stderr] (ServerService Thread) java.lang.NullPointerException
13:34:45,463 ERROR [stderr] (ServerService Thread) at org.jboss.weld.bean.builtin.BeanManagerProxy.<init>(BeanManagerProxy.java:74)
13:34:45,463 ERROR [stderr] (ServerService Thread) at org.jboss.as.weld.WeldProvider$CdiImpl.getBeanManager(WeldProvider.java:95)
13:34:45,463 ERROR [stderr] (ServerService Thread) at org.jboss.as.weld.WeldProvider$CdiImpl.getBeanManager(WeldProvider.java:73)
13:34:45,463 ERROR [stderr] (ServerService Thread) at mc.core.service.configuration.WorkerFactory.lookupBM(WorkerFactory.java:42)
13:34:45,464 ERROR [stderr] (ServerService Thread) at mc.core.service.configuration.WorkerFactory.createService(WorkerFactory.java:28)
13:34:45,464 ERROR [stderr] (ServerService Thread) at mc.core.service.configuration.Configuration.service(Configuration.java:27)
13:34:45,464 ERROR [stderr] (ServerService Thread) at mc.core.service.ftindex.hs.FtiClassBridgeCE.configureFieldMetadata(FtiClassBridgeCE.java:63)
13:34:45,464 ERROR [stderr] (ServerService Thread) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getSortableFieldNames(AnnotationMetadataProvider.java:1751)
13:34:45,464 ERROR [stderr] (ServerService Thread) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.bindClassBridgeAnnotation(AnnotationMetadataProvider.java:621)
13:34:45,464 ERROR [stderr] (ServerService Thread) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.bindClassBridgeAnnotation(AnnotationMetadataProvider.java:593)
13:34:45,465 ERROR [stderr] (ServerService Thread) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClassLevelAnnotations(AnnotationMetadataProvider.java:546)
13:34:45,465 ERROR [stderr] (ServerService Thread) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClass(AnnotationMetadataProvider.java:430)
13:34:45,465 ERROR [stderr] (ServerService Thread) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor(AnnotationMetadataProvider.java:130)
13:34:45,465 ERROR [stderr] (ServerService Thread) at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:373)
13:34:45,466 ERROR [stderr] (ServerService Thread) at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:199)
13:34:45,466 ERROR [stderr] (ServerService Thread) at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:117)
13:34:45,467 ERROR [stderr] (ServerService Thread) at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:75)
13:34:45,473 ERROR [stderr] (ServerService Thread) at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35)
13:34:45,473 ERROR [stderr] (ServerService Thread) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:530)
13:34:45,473 ERROR [stderr] (ServerService Thread) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.__build(SessionFactoryBuilderImpl.java:444)
13:34:45,474 ERROR [stderr] (ServerService Thread) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java)
13:34:45,474 ERROR [stderr] (ServerService Thread) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
13:34:45,474 ERROR [stderr] (ServerService Thread) at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.__build(TwoPhaseBootstrapImpl.java:44)
13:34:45,474 ERROR [stderr] (ServerService Thread) at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java)
13:34:45,474 ERROR [stderr] (ServerService Thread) at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)

Jboss AS 7.1.1 Final Local JNDI EJB Invocation

Using Jboss AS 7.1.1 Final, I'm trying to invoke a Local EJB(3.1) through JNDI.
My Local EJB is:
#Stateless(mappedName = "Services")
#LocalBean
public class Services implements ServicesLocal {
.....// scary stuffs here
}
My Interface Services is:
#Local
public interface ServicesLocal {
.... // Some powerfull stuffs here
}
I'm trying to invoke this EJB above like this:
private ServicesLocal getLocalEJB() throws NamingException {
log.info("\n\n\n\n\n\n\n\n ################## Getting the ServicesLocal");
InitialContext context = new InitialContext();
return (ServicesLocal) context.lookup("ejb:/global/docs/docs-ejb-0.1/Services!com.mycompany.docs.local.ServicesLocal");
}
This is the error I'm getting when invoking this code above:
############ Getting the ServicesLocal
15:36:10,437 INFO [org.jboss.ejb.client] (http-localhost-127.0.0.1-8080-1) JBoss EJB Client version 1.0.5.Final
15:36:10,456
ERROR [stderr] (http-localhost-127.0.0.1-8080-1) java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:global,distinctname:docs] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext#396f6a24
15:36:10,457
ERROR [stderr] (http-localhost-127.0.0.1-8080-1) ^Iat org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
And this is the JNDI log when the Jboss 7.1.1 Final boot. Having the EJB that I want to invoke:
15:07:07,975 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named Services in deployment unit subdeployment "docs-ejb-0.1.jar" of deployment "docs.ear" are as follows:
java:global/docs/docs-ejb-0.1/Services!com.mycompany.docs.local.ServicesLocal
java:app/docs-ejb-0.1/Services!com.mycompany.docs.local.ServicesLocal
java:module/Services!com.mycompany.docs.local.ServicesLocal
java:global/docs/docs-ejb-0.1/Services!com.mycompany.docs.services.Services
java:app/docs-ejb-0.1/Services!com.mycompany.docs.services.Services
java:module/Services!com.mycompany.docs.services.Services
I think my context.lookup("ejb:/global/docs/docs-ejb-0.1/Services!com.mycompany.docs.local.ServicesLocal") is wrong. What I can do to fix that and invoke my Local EJB with JNDI?
Have you tried to use what JBoss tells you?
context.lookup("java:global/docs/docs-ejb-0.1/Services!com.mycompany.docs.local.ServicesLocal")
Your EJB is stored in java namespace, not in ejb one.

log4j configuration with jboss7 issue

java code
public static synchronized void init(String log4jXMLPath) //throws ServletException
{
try
{
if (!initialized) // set the global RepositorySelector
{
defaultRepository = LogManager.getLoggerRepository();
RepositorySelector theSelector = new AppRepositorySelector();
**LogManager.setRepositorySelector(theSelector, guard);**
initialized = true;
}
Hierarchy hierarchy = new Hierarchy(new RootLogger(Level.DEBUG));
//loadLog4JConfig(servletContext, hierarchy);
loadLog4JConfig(hierarchy, log4jXMLPath);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
repositories.put(loader, hierarchy);
}
catch (Exception e)
{
e.printStackTrace();
}
}
LogManager.setRepositorySelector(theSelector, guard); this line in java code throwing an error
stacktrace
18:17:11,189 ERROR [stderr] (MSC service thread 1-2) java.lang.IllegalArgumentException: Attempted to reset the LoggerFactory without possessing the guard.
18:17:11,190 ERROR [stderr] (MSC service thread 1-2) at org.apache.log4j.LogManager.setRepositorySelector(LogManager.java:164)
18:17:11,191 ERROR [stderr] (MSC service thread 1-2) at com.mportal.logger.api.AppRepositorySelector.init(AppRepositorySelector.java:73)
18:17:11,192 ERROR [stderr] (MSC service thread 1-2) at com.mportal.logger.api.MPLoggerImpl.loadLogInstance(MPLoggerImpl.java:64)
18:17:11,192 ERROR [stderr] (MSC service thread 1-2) at com.mportal.logger.api.MPLoggerImpl.<init>(MPLoggerImpl.java:38)
18:17:11,192 ERROR [stderr] (MSC service thread 1-2) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
18:17:11,193 ERROR [stderr] (MSC service thread 1-2) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
18:17:11,194 ERROR [stderr] (MSC service thread 1-2) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
18:17:11,194 ERROR [stderr] (MSC service thread 1-2) at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
How to solve this one? Please give solutions.
LogManager.setRepositorySelector(theSelector, guard);
You can only use one guard, using different guard objects will result in the observerd error:
java.lang.IllegalArgumentException: Attempted to reset the LoggerFactory without possessing the guard.
It should be possible to pass null as a parameter to the function. Or simply hold a reference to the initial set guard.
The documentation states:
Initally the guard is null. If the guard is null, then invoking this method sets the logger factory and the guard. Following invocations will throw a IllegalArgumentException, unless the previously set guard is passed as the second parameter.

Categories