Exception when registering the JMX bean MessageHistory from Spring Integration into a Spring XD Module - spring-integration

If I try to use the Message History bean from Spring Integration "int:message-history" when developing a Spring XD module, it fails when try to export the JMX bean.
I've seen that the naming strategy used is org.springframework.xd.dirt.module.jmx.ModuleObjectNamingStrategy
I already open a ticket for that https://jira.spring.io/browse/XD-3748
Is there any workaround for that? Like explicitly use another MBeanExporter and add a different name for the bean?

It's a bug in the ModuleObjectNamingStrategy; I'll see if I can come up with a work-around.

Thanks Gary, for now I have implemented other class like the ModuleObjectNamingStrategy and changed the mbean-exporters.xml to use that one if the bean is the messageHistoryConfigurer I create the ObjectName instance like:
String name = domain +":name=messageHistoryConfigurer";
ObjectName originalName = new ObjectName(name);

Related

Can you spy on the Vert.x event bus in Quarkus tests?

Does anyone know of a way to spy on the Vert.x event bus in Quarkus tests? Ideally I'd like to assert that during a method in the service layer we are sending an event to the correct address, but does anyone know if this is possible?
If I just try to use #InjectMock I get the following error
io.vertx.core.eventbus.impl.EventBusImpl#5769679b is not a normal scoped CDI bean, make sure the bean is a normal scope like #ApplicationScoped or #RequestScoped
I solved this Problem, by creating an ApplicationScoped Delegate around the EventBus. This Delegate can be mocked and inspected as a normal bean in Quarkus. All the Beans which were using the EventBus directly need to use the EventBusDelegate instead. In your test you can use the #InjectMock annotation to inject the EventBusDelegate mocked.
As suggested here https://github.com/quarkusio/quarkus/issues/8983
#InjectMock(convertScopes = true)
should solve your problem. If convertScopes is true, then Quarkus will change Singleton to ApplicationScoped to make the bean mockable.
NOTE: the documentation states that this is an advanced setting and should only be used if you don't rely on the differences between Singleton and ApplicationScoped beans

How to access class of a spring-integration project?

I have a project based on spring-integration . I want to use some of its class in other project ,i added reference to spring-integration based project class in other project all autowired object become null , as i am using new operator to create the object , how can i access the object using applicationContext from other project ?
You can't autowire beans that you create yourself (with new); you have to add them to a spring application context. Perhaps if you show your configuration and what you are trying to do, someone can help.

Read web.xml file from an ejb bean

I want to know the authentication type if it is ldap realm or jdbc realm
I am not getting any solution in this problem
So i proposed to read the web.xml file from the jsf project
What i want is to read this file in the ejb project by an ejb bean
Is there any other solution other than my proposal
If you know the name of the realm you can get an instance of it and check the type with instanceof like this:
import com.sun.enterprise.security.auth.realm.Realm;
//...
Realm realm = Realm.getInstance("realmName");
if (realm instanceof JDBCRealm) {
// do something
}
If you don't have the name you may try your solution but I can't say if it will work because I think it will be difficult to get access to the ServletContext inside an EJB.

Sending custom objects across portlets in liferay

I'm having serious issues trying to send share custom objects between portlets in liferay. I have a Hook Plugin, with a servlet filter, which loads an object of Type MyCustomClass and inserts it into the request object as a parameter.
When i try to read this object in a portlet's render() i get a ClassCastException, though i am casting the object to the same class.
I understand that liferay plugins have different contexts, and i already tried to change the classloader before loading the object in the bean and portlet like this:
ClassLoader portalcl = PortalClassLoaderUtil.getClassLoader();
ClassLoader currentcl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(portalcl);
//do my stuff
Thread.currentThread().setContextClassLoader(currentcl);
however, it did not solved the problem, and the only way i found to solve the problem is to serialize the object into a json string, and deserialize it whenever i need it.
Isn't this kinda lame ? Does anyone know a better solution ?
Regards, DS
It sounds like the main problem you're seeing is that two different class loaders are loading the class which techncally makes them different classes (which it seems like you've already determined).
I haven't used LifeRay much but this has been a problem I've seen on other platforms as well. We were using WebSphere and solved this problem by putting the common MyCustomClass into a shared library that was on the server classpath. This way the server will load the class and make it available to all applications on the server through the server's single classloader. If you let each application load the class then you'll keep seeing this exception.

adding custom methods in Hook environment?

i am adding a new method into CalEventLocalServiceImpl using hook...
my code is ..
public class MyCalendarLocalServiceImpl extends CalEventLocalServiceWrapper {
public MyCalendarLocalServiceImpl(CalEventLocalService calEventLocalService) {
super(calEventLocalService);
// TODO Auto-generated constructor stub
}
public List getUserData(long userId) throws SystemException{
DynamicQuery query=DynamicQueryFactoryUtil.forClass(CalEvent.class)
.add(PropertyFactoryUtil.forName("userId").eq(userId));
List deatils=CalEventLocalServiceUtil.dynamicQuery(query);
return deatils;
}
}
liferay-hook.xml:
<service>
<service-type>
com.liferay.portlet.calendar.service.CalEventLocalService
</service-type>
<service-impl>
com.liferay.portlet.calendar.service.impl.MyCalendarLocalServiceImpl
</service-impl>
</service>
my question is how to use getUserData from jsp file.
Can anybody help me out....
i think u didn't gt my question...i want list of events based on USERID from Calendar ...to achieve this task what i need to do??
I assume getUserData() is not overridden but a new method (can't look up currently). This is not what you can do when overriding a service. Instead you'd have to add a new Service and make it available to the portal.
Remember that a customized ("hooked") jsp is running in the portal classloader, while your overloaded service is running in the hook's classloader. Thus, if you create a new service and make the service.jar available to Liferay (e.g. on the global classpath) you can call it from JSPs. The interface of Liferay services can not be extended through an overloaded service.
In case getUserData() is already in the interface (as I said I can't look up currently), you just need to call the CalendarLocalServiceUtil from your jsp and it will be delegated to your wrapper.
Just to add to Olaf's answer and comments...
if you you want to extend CalEventLocalService service with just "getUsetData" and use it in one jsp than building your own service might be overkill. Simply put your code from "getUserData" in jsp. Otherwise follow Olaf's suggestions.

Resources