No bean named 'CamelBeanParameterMappingStrategy' available - apache-camel

I have a Springboot camel application. Below error is seen in dynatrace.
No bean named 'CamelBeanParameterMappingStrategy' available

Within the BeanInfo class of Apache Camel the ParameterMappingStrategy is resolved by looking in the registry (see below)
Registry registry = camelContext.getRegistry();
ParameterMappingStrategy answer = registry.lookupByNameAndType(BeanConstants.BEAN_PARAMETER_MAPPING_STRATEGY, ParameterMappingStrategy.class);
So yes, you can create your own version and add it to the registry

Related

Exception in FluentProducerTemplate in Apache Camel after upgrade to 3.7.2

I've the following dependency to 3.7.2:
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-dependencies</artifactId>
<version>3.7.2</version>
I've this in the code:
fluentProducerTemplate.to("direct:myenpoint");
fluentProducerTemplate.send();
This code was working until the upgrade, but now it throws:
java.lang.IllegalArgumentException: No endpoint configured on FluentProducerTemplate. You can configure an endpoint with to(uri)`
Now I'm not able to figure why it's complaining about configuring endpoint as endpoint is clearly set in to(endpoint) call. I couldn't find anything in their documentation.
It's a fluent builder, so you should use it in a style like this:
template.to("xxx").send()
I found that endpoint has to be set at fluentProducerTemplate.setDefaultEndpoint(startingEndpoint);
The error message was misleading. And, I am not sure why to (endpoint) is still there.

Loading properties file while running camel blueprint test

I am using property-placeholder tag to load a properties as follows:
<cm:property-placeholder id="myblueprint.test" persistent-id="camel.blueprint"/>
While deploying my project on JBOSS Fuse, it will load camel.blueprint.cfg from /etc/ directory of FUSE, and when I deploy project on a fabric profile, it will read from properties file created in profile.
But, when I run camel blueprint test, how can I configure it to load properties file from a particular location?
After browsing the documentation for property-placeholder, I got the solution. We can set the location for properties file in test case file as follows:
#Override
protected String[] loadConfigAdminConfigurationFile() {
// String[0] = tell Camel the path of the .cfg file to use for OSGi ConfigAdmin in the blueprint XML file
// String[1] = tell Camel the persistence-id of the cm:property-placeholder in the blueprint XML file
return new String[]{"src/test/resources/etc/stuff.cfg", "stuff"};
}
Please ensure that, property file is having extension .cfg. otherwise it will be ignored.

Apache Camel reference property files with and without OSGI

I understand that if you deploy your Camel project to an OSGI environment like Karaf you can simply write:
<cm:property-placeholder id="INT001_********_Properties" persistent-id="INT001_SelfServiceMachine" />
<camelContext xmlns="http://camel.apache.org/schema/blueprint"
id="INT001_SelfServiceMachine" useMDCLogging="true">
<propertyPlaceholder id="properties" location="blueprint:INT001_*********_Properties"/>
And this works when the project is deployed to Karaf and the property file is located there in the etc folder.
But how can you configure it when Karaf is not available?
I used this bean before:
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="classpath:some.properties"
/> </bean>
But is there a single way to refer to property files regardless of when you are in Karaf or when you are in your e.g. Eclipse environment and your property file is in your /src/resources folder and the bean above works? For instance, when you use Jenkins and and want to run tests and build the bundle, you may not have Karaf available.
Thanks for any input on this.
You can maybe implement your own PropertiesResolver which know how to resolve your properties according to the runtime environment. If OSGi is detected, then it can use ConfigurationAdmin, else it can use a static properties file.
Personally, I use something more simple thanks to Spring DM: my beans/configurations are dispatched in multiples files, and all the configuration related to OSGi is regrouped in one file. In Karaf, Spring DM load all XML in META-INF/spring. Outside of Karaf, I filter the XML to exclude the OSGi configuration.
There is a blueprint noosgi bundle around, that one can be used to have the blueprint capabilities outside of the osgi container. With this you're able to stick to your blueprint xml, though you need to change from configuration admin service for property lookup to native blueprint property replacement.

How can I configure the JAX-RS base path in TomEE+?

I have a WAR with some JAX-RS services, deployed into TomEE Plus. Given a service annotated with #Path("myservice"), TomEE+ publishes it to localhost:8080/mywebapp/myservice.
However, that also makes accessing a JSP at localhost:8080/mywebapp/index.jsp impossible - JAXRSInInterceptor complains that No root resource matching request path has been found, Relative Path: /index.jsp.
So I would like to configure a path prefix api to all services, which changes the myservice URL to localhost:8080/mywebapp/api/myservice. Doing so would be trivial if I had configured CXF on my own (with or without Spring), because I could simply change the URL pattern of the CXF Servlet - but I am relying on the default settings where I don't configure anything besides the annotations. So how do I do that in this case?
Note that I don't want to alter the #Path annotations to include the prefix, because that does not fix the issue with the JSP.
Create an extension of javax.ws.rs.core.Application and annotate it with #ApplicationPath where value would be api in your case:
#ApplicationPath("/api")
public class MyApplication extends Application {
#Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<Class<?>>();
// register root resource
classes.add(MyServiceResource.class);
return classes;
}
}
This way a Servlet 3 container would find your application and map your resource to /mywebapp/api/myservice while making your web resources (.jsp) available at /mywebapp.
TomEE trunk supports these configurations: cxf.jaxrs.staticSubresourceResolution & cxf.jaxrs.static-resources-list
but the #ApplicationPath is the more relevant solution IMO
Using -Dopenejb.webservice.old-deployment=true can help too in some cases

Getting problems in adding cutom JAAS Login module in Servicemix

I am using Servicemix 4.2 for my osgi based webservice application.
My webservice application is exposed using the CXF stack provided with the Servicemix.
Now we have to integrate the application with a separately developed Authentication api. The third party api is using JAAS as the mean to authenticate.
I embedded the third party jars in my application bundle. I exported the LoginModule implementation class using export-package instruction.
When I tried to use the third party provided jaas module, it gave error
Cannot create Login Context.No LoginModules configured for LoginModule
The third party jaas provider finds the location of jaas.config file using the system property
java.security.auth.login.config
The content of jaas.config file is as follows
LoginModule {
com.altair.aaservice.windowsauthn.hwec.WindowsAuthentication required;
};
After doing googling, I found that servicemix out of box provides two System bundles for jaas
Apache Felix Karaf :: JAAS Modules (1.4.0)
Apache Felix Karaf :: JAAS Config (1.4.0)
And you need to modify etc/users.properties file and some other things to implement jaas. But as we need to integrate with a third party jaas provider, i can not look into these ways. Also most of the documentation provided with servicemix insist you to use the servicemix way to implement jaas hence I did not get much success in finding any solution.
I manually uninstalled the two system bundles, after that I got following error
javax.security.auth.login.LoginException: unable to find LoginModule class: com.altair.aaservice.windowsauthn.hwec.WindowsAuthentication not found from bundle [org.apache.cxf.bundle]
As my webservice is CXF based, it may be looking in this bundle.
Is there any convenient way to integrate servicemix with custom jaas implementation. Please tell if there is any.
There is an example of writing a custom JAAS LoginModule here.

Resources