Issue with Apache Camel with CXF SOAP service - cxf

Flow is not going to the implementation class at all. How should get the flow to Implementation class?
I wonder if it doesn't matter that Impl class implements the service class. But it raises another question what if more than one impl classes are implementing the serviceClass interface. Where the flow will go?
Do I need to declare some annotations on Impl class? Or there is no way to recognize Impl class, I just have to treat it as another bean and add it to my webservice route.
Here is the setup.
applicationContext.xml
<cxf:cxfEndpoint id="tryWebService" address="http://localhost:15080/PORTAL/webservices/tryWebService"
serviceClass="webservice.TryWebServiceImpl"
/>
<route>
<from uri="cxf:bean:tryWebService"/>
<to uri="stream:out"/>
</route>
Interface
#WebService
public interface TryWebService {
public void acceptRequest(String xmlString);
}
Implementation
public class ACORDWebServiceImpl implements ACORDWebService
{
public void acceptTXLife(String xmlString)
{
try
{
dosomething

Service class in cxf is only an interface. You d'ont need implementation. Parameters of the method called ( ie: "acceptRequest") are set in the body of your route. So you can get them in the route with a processor for example between your from and to instructions.

Related

the difference between the Calling Object and the Target Object?

I'm learning Spring AOP and there are some termonolgies of this concept like Advice , PointCut , JoinPoint .. One of them is AOP Proxy and I found that a proxy is an intermediary object, introduced by the AOP framework, between the calling object and the target object. So my question is what is the difference between the Calling Object and the Target Object ?
Plese go through the reference document section : Understanding AOP Proxies
Following image depicts the concept of a proxy.
Consider a class TestService with method run() and a class Pojo with method foo(). Also consider Spring framework creates a proxy for Pojo .
#Component
public class TestService{
#Autowired
Pojo pojo;
public void run(){
pojo.foo()
}
}
Here the instance of TestService is the Calling Object and instance of Pojo is the Target object.

Instantiate one Routebuilder from inside a route in another RouteBuilder in Camel

I am relatively new to Camel. I have a use case where I need to instantiate a RouteBuilder only when it receives get an exchange to kickstart the process from an Orchestration module. I am trying to do this mainly because, the exchange carries information required to instantiate the new RouteBuilder. Is there a way where I could instantiate this new RouteBuilderB from inside a route in the existing RouteBuilderA.
public class RouteBuilderA extends RouteBuilder {
public void configure(){
//So, something like this?
from("direct:A")
.process(//new RouteBuilderB())
.to("direct:B")
}
Is there a way to accomplish this?
Yes its just Java code, so write a Processor that creates the RoutBuilder instance you want, and do any configuration with setter/getter etc. And then you can add that as routes to CamelContext using the addRoutes method.

Mocking XMPP endpoints

I'm trying to verify my Camel routes I need to prevent the endpoints from starting, the XMPP in particular as it contains concrete host information in their URI. Unfortunately I don't seem to figure out how.
My test class is as follows:
#RunWith(CamelSpringJUnit4ClassRunner.class)
#ContextConfiguration(
classes = {
ApplicationConfig.class
},
loader = CamelSpringDelegatingTestContextLoader.class)
#UseAdviceWith
#MockEndpointsAndSkip
public class XMPPRouteBuilderTest {
#Autowired
ApplicationContext applicationContext;
#Autowired
CamelContext camelContext;
#Test
public void testConfigure() throws Exception {
camelContext.start();
Collection<Endpoint> endpoints = camelContext.getEndpoints();
}
}
Whenever I call start() the actual endpoints are started which causes the XMPP routes to fail with host not found exceptions; I was expecting the mocks to replace the real ones.
Can anyone suggest what am I doing wrong?
Best,
Edoardo
#MockEndpointsAndSkip is only for producers (eg not consumers) so all the route from endpoints is not mocked.
You can use the replaceFromWith with the advice-with builder. See the section Replace from with another endpoint in the official Camel documentation for an example:
http://camel.apache.org/advicewith.html

#Autowired custom ReloadableResourceBundleMessageSource in #Controller

I've built an application composed of angularJs for the client side and spring MVC for the backend side. My purpose is to expose my language properties to the client side, so that I can use them in my JS files. To do that, I've used the library angular-translate.min.js and followed thoses instructions:
(https://gist.github.com/rvillars/6422287).
Basically the idea is to create a custom class which extends from ReloadableResourceBundleMessageSource, and override getAllProperties(Locale locale) method. Then, injecting that custom class in a #controller, which will return the list of properties in a Json format to the client.
So far my issue is that I haven't been able to autowired my custom class extending ReloadableResourceBundleMessageSource, in my #controller. My app always crashing during the deployment phase with "No qualifying bean of type CustomResourceBundleMessageSource".
My environment:
Spring MVC 3.2.3
Angular JS
Please find the code:
Controller class:
#Controller
#RequestMapping("/messageBundle")
public class SerializableMessageBundleController {
#Autowired
private CustomResourceBundleMessageSource messageSource;
#RequestMapping(method = RequestMethod.GET)
#ResponseBody
public Properties list(#RequestParam String lang) {
return messageSource.getAllProperties(new Locale(lang));
}
Custom message source:
public class CustomResourceBundleMessageSource extends ReloadableResourceBundleMessageSource {
public Properties getAllProperties(Locale locale) {
clearCacheIncludingAncestors();
PropertiesHolder propertiesHolder = getMergedProperties(locale);
Properties properties = propertiesHolder.getProperties();
return properties;
}
}
}
ApplicationContext.xml:
<bean id="messageSource" class="com.contgo.CustomResourceBundleMessageSource">
<qualifier value="messageSource"/>
<property name="basename" value="LanguageResources"/>
</bean>
I've tried to add #qualifier("messageSource") as well but doesn't work.
Also try #Resource and #Inject, doesn't work either.
Has anyone ever managed to do that?
I had the same problem, and finally got it working as follows.
The class extending ReloadableResourceBundleMessageSource is correct.
All you need to do is configure it properly in your applicationContext file.
You leave the original ReloadableResourceBundleMessageSource configuration alone:
<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource">
<property name="basename" value="LanguageResources"/>
</bean>
Then you add the following below it, using the 'parent' attribute to refer to the original config:
<bean class="com.contgo.CustomResourceBundleMessageSource" id="myCustomMessageSource" parent="messageSource"/>
Then finally, in your controller you can autowire it like this:
#Autowired
CustomResourceBundleMessageSource myCustomMessageSource;

What are the pros/cons when defining an Endpoint as a URI over defining it programatically?

Consider the following:
public class MyRouteBuilder extends RouteBuilder {
#Override
public void configure() throws Exception {
FileEndpoint dropLocation = new FileEndpoint();
dropLocation.setCamelContext(getContext());
dropLocation.setFile(new File("/data"));
dropLocation.setRecursive(true);
dropLocation.setPreMove(".polled");
dropLocation.setNoop(true);
dropLocation.setMaxMessagesPerPoll(1);
from(dropLocation).to(...
versus
public class MyBuilder extends RouteBuilder {
#Override
public void configure() throws Exception {
from("file://data?recursive=true&preMove=.polled&noop=true&maxMessagesPerPoll=1").to(...
Programatically I get code completion and the like, whereas with the URI everything is in a single line. Are these the only pros/cons or are there others to consider?
Pretty much all the examples I see utilise the URI method - is there a strong reason for this?
generally you rely on the Component to create the Endpoint instance (via route definitions), but it can be done programmatically if there is a desire to integrate with legacy code, create Endpoints through class structures/instances, etc.
overall, a major benefit of Camel is to leverage it's concise DSL route capabilities to describe processes/interactions all in one place (a route). the more programmatic the route definitions are, the more verbose/spread out these definitions become...
overall, I prefer the URI approach because its more concise, easier to follow and nice to manipulate route parameters all in one place...otherwise, its entirely a preference/style decision.

Resources