I have a WSDL file with defines a java.io.Exception:
<xsd:schema xmlns:tns="http://io.java" xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://io.java">
<xsd:complexType name="IOException">
<xsd:sequence/>
</xsd:complexType>
</xsd:schema>
When generating Java classes using the Apache CXf wsdl2java task, it generates a class like this (which causes compile errors, as it is not a valid java.io.IoException):
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "IOException")
public class IOException {
}
Is there a way to prevent CXF from generating JDK classes?
Thx! :)
You definitely need to change your namespace.
targetNamespace="http://io.java"
xmlns:tns="http://io.java"
If you have such namespace and the complex type named IOException of course there will a problem. And why in the world you named the namespace like this http://io.java?
Change the namespace for e.g.:
targetNamespace="http://yourcompany.com/yourservice"
xmlns:tns="http://yourcompany.com/yourservice"
You you'll be good.
Related
First I have generated pojo class using jsonschema2pojo plugin using WSDL file.
My WSDL file contains Header and Body.
Body Root Pojo looks like this:
public class SubmitCustomerOrderRequest {
#XmlElement(required = true)
protected List<Order> order;
}
Header looks like this:
public class MessageHeader {
.....
}
Now in a process class of camel i am putting SubmitCustomerOrderRequest (Here this pojo only consider body not header) into body like this:
submitCustomerOrderRequest.setOrder(orderList);
exchange.getIn().setBody(submitCustomerOrderRequest);
Now in the route i am marshalling using this concept
SoapJaxbDataFormat soapDF = new SoapJaxbDataFormat("org.com.model",
new ServiceInterfaceStrategy(order.class, true));
And marshalling into xml like this:
.marshal(soapDF)
Now here the problem here is, its generating xml but without header, how to include header also in the process class so that while converting into xml, its generates header also with body
Its generating like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Envelope xmlns:ns2="org.com" xmlns:ns3="org.com.something">
<ns2:Body>
<ns3:submitCustomerOrderV3Request>
</ns3:submitCustomerOrderV3Request>
</ns2:Body>
</ns2:Envelope>
whereas i need like this with header:
<SOAP-ENV:Envelope xmlns:SOAP-ENV=org.com>
<SOAP-ENV:Header>
<messageHeader xmlns=org.om>
</messageHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns2:submitCustomerOrderV3Request xmlns:ns2=org.com>
</ns2:submitCustomerOrderV3Request>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Any help would be appreciable.
I'm new to Apache Camel. I'm trying to send an exchange from a java method to a route but it gives me "Caused by: org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint" error. I want to understand what exactly this error is and when do we get this?
#EndpointInject(uri = "direct:reportRoute")
private ProducerTemplate templatereportRoute;
public void saveDataFromExchange(Map<String, Object> DataMap){
List<Map<String, Object>> paramList = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> rows = templatereportRoute.requestBody("direct:reportReport", DataMap, List.class);
<from uri="direct:reportRoute"/>
<log message=" - ${body}" loggingLevel="INFO"/>
<setProperty propertyName="DataMap">
<simple>${body}</simple>
</setProperty>
The error you encounter means that you are sending to a direct endpoint that does not exist in the Camel Context.
Since you posted an XML fragment that defines the route in question there are two possible problems (as already commented by #claus-ibsen):
The XML you posted is not in use. You are starting a Camel Context but it does not use your XML code. Are you using Spring? Then you can define your Camel routes in Spring XML.
Your setup is fine but your Java code sends the message too early, i.e. before the direct endpoint is up and running. You can put this code in a Test class and run it after the Camel context is started and ready.
Try put in public class from routerBuilder implemention the anotation #Component from Spring context
Ex:
#Component //<<<<---- This
public class RouterClass extends RouteBuilder {
#Override
public void configure() throws Exception {
}
}//class closure
I am using Camel in Karaf with blueprint xml and I want to create a bean with the class coming from a different bundle.
<blueprint>
...
<bean id="token-validation" class="com.xxx.security.JwtTokenValidator" init-method="init" >
<property name="realm" value="${auth.realm}"/>
</bean>
...
<camelContext>
<route id="route.EventsNotify" routePolicyRef="token-validation">
...
</camelContext>
</blueprint>
JwtTokenValidator class is located in another bundle, that extends the Camel's RoutePolicySupport, that's why it is applied in route route.EventsNotify.
public class JwtTokenValidator extends RoutePolicySupport {
#Override
public void onExchangeBegin(Route route, Exchange exchange) {
super.onExchangeBegin(route, exchange);
checkAuthorizationHeader(exchange);
}
...
}
This bundle has some dependencies and classes like the aforementioned one, in order to be used in many projects. Write once and applied in many projects instead of coping the same code again and again.
Unfortunately this is not working, I am getting the following error in stacktrace
Caused by: java.lang.ClassCastException: Cannot cast com.xxx.security.JwtTokenValidator to org.apache.camel.spi.RoutePolicy
I cannot understand why, because the class is extending RoutePolicySupport which in terms implements the desired RoutePolicy interface.
If I move the class to the same bundle it is working, but I need to have it in a seperate bundle for the reasons that I explained before.
Could someone tells me where I am wrong?
Thanks a lot!
Try to import all required Classes (org.apache.camel.spi.RoutePolicy, ...) to current Bundle's classLoader. If you are building your bundle with maven-bundle plugin, you can do it like this:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
...
<configuration>
<instructions>
...
<Import-Package>
...,
org.apache.camel.spi*;version=[min_version, max_version),
...
</Import-Package>
</instructions>
</configuration>
</plugin>
I have the following scenario:
I have an OSGI bundle that has a service reference defined in the blueprint XML that references an interface in a remote bundle, and a bean that uses one of the impl's methods to populate a Properties object.
Relevant snippet from Bundle #1's XML (the consumer):
...
<!-- other bean definitions, namespace stuff, etc -->
<!-- reference to the fetching service -->
<reference id="fetchingService" interface="company.path.to.fetching.bundle.FetchingService" />
<!-- bean to hold the actual Properties object: the getConfigProperties method is one of the overridden interface methods -->
<bean id="fetchedProperties" class="java.util.Properties" factory-ref="fetchingService" factory-method="getProperties" />
<camelContext id="contextThatNeedsProperties" xmlns="http://camel.apache.org/schema/blueprint">
<propertyPlaceholder id="properties" location="ref:fetchedProperties" />
...
<!-- the rest of the context stuff - routes and so on -->
</camelContext>
Remote Bundle's blueprint.xml:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<cm:property-placeholder id="config-properties" persistent-id="company.path.configfetcher" />
<bean id="fetchingService" class="company.path.to.fetching.bundle.impl.FetchingServiceImpl" scope="singleton" init-method="createLoader" depends-on="config-properties">
<property name="environment" value="${environment}" />
<property name="pathToRestService" value="${restPath}" />
</bean>
<service ref="fetchingService" interface="company.path.to.fetching.bundle.FetchingService" />
<!-- END TESTING -->
</blueprint>
From Impl Class:
public synchronized Properties getProperties() {
if(!IS_RUNNING) {
// timer task that regularly calls the REST api to check for updates
timer.schedule(updateTimerTask, 0, pollInterval);
IS_RUNNING = true;
}
//Map<String, Properties> to return matching object if it's there
if(PROPERTIES_BY_KEY.containsKey(environment)) {
return PROPERTIES_BY_KEY.get(environment);
}
/* if nothing, return an empty Properties object - if this is the case, then whatever bundle is relying on these
* properties is going to fail and we'll see it in the logs
*/
return new Properties();
}
The issue:
I have a test class (extending CamelBlueprintTestSupport) and there are a lot of moving parts such that I can't really change the order of things. Unfortunately, the properties bean method gets called before the CamelContext is started. Not that big a deal because in the test environment there is no config file to read the necessary properties from so the retrieval fails and we get back an empty properties object [note: we're overriding the properties component with fakes since it's not that class being tested], but in a perfect world, I'd like to be able to do two things:
1) replace the service with a new Impl()
2) intercept calls to the getProperties method OR tie the bean to the new service so that the calls return the properties from the fake impl
Thoughts?
Edit #1:
Here's one of the things I'm doing as a workaround right now:
try {
ServiceReference sr = this.getBundleContext().getServiceReference(FetchingService.class);
if(sr != null) {
((FetchingServiceImpl)this.getBundleContext().getService(sr)).setEnvironment(env);
((FetchingServiceImpl)this.getBundleContext().getService(sr)).setPath(path);
}
} catch(Exception e) {
log.error("Error getting Fetching service: {}", e.getMessage());
}
The biggest problem here is that I have to wait until the createCamelContext is called for a BundleContext to exist; therefore, the getProperties call has already happened once. As I said, since in the testing environment no config for the FetchingService class exists to provide the environment and path strings, that first call will fail (resulting in an empty Properties object). The second time around, the code above has set the properties in the impl class and we're off to the races. This is not a question about something that isn't working. Rather, it is about a better, more elegant solution that can be applied in other scenarios.
Oh, and for clarification before anyone asks, the point of this service is so that we don't have to have a .cfg file for every OSGI bundle deployed to our Servicemix instance - this central service will go and fetch the configs that the other bundles need and the only .cfg file that need exist is for the Fetcher.
Other pertinent details:
Camel 2.13.2 - wish it was 2.14 because they've added more property-placeholder tools to that version that would probably make this easier
Servicemix - 5.3.1
Have you tried overriding CamelBlueprintTestSupport's addServicesOnStartup in your test (see "Adding services on startup" http://camel.apache.org/blueprint-testing.html)?
In your case something like:
#Override
protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) {
services.put(FetchingService.class.getName(), asService(new FetchServiceImpl(), null));
}
I experience something rather strange and I would like to know if other people have experienced the same...
I am currently working on a project using jboss fuse (previously fuse esb) and we are using blueprint for our configuration files.
We use property place holders and have the following files under src/main/resources/OSGI-INF/blueprint:
blueprint.xml
properties.xml
In blueprint.xml we have something like this:
<bean id="myBean" class="com.test.MyClass">
<property name="prop1" value="${my.prop}" />
<∕bean>
Then in properties.xml I have this:
<cm:property-placeholder persistent-id="my.properties" update-strategy="reload">
<cm:default-properties>
<cm:property name="my.prop" value="true" />
</cm:default-properties>
</cm:property-placeholder>
And I obviously have a setter for prop1 (which is a String) in MyClass.
But what I see is that when I deploy this, prop1 is set to "${my.prop}" instead of "true", i.e the variable never gets replaced with its defined value!
But now if I call the properties file aaa_properties.xml, it works!!
Is this a bug in the blueprint container?
Did any one else experience the same behaviour?
Thanks for your feedback :)
JM.
I found some information about Blueprint Configuration in Fuse ESB
It states:
If you need to place your blueprint configuration files in a non-standard location (that is, somewhere other than OSGI-INF/blueprint/*.xml), you can specify a comma-separated list of alternative locations in the Bundle-Blueprint header in the manifest
For Example:
Bundle-Blueprint: lib/account.xml, security.bp, cnf/*.xml
I suggest, can you please give this a try, and specify your xml files here, naturally in the correct ordering.