camel-karaf icon indicating copy to clipboard operation
camel-karaf copied to clipboard

unmarshal hangs camel process if using true/false on int field

Open dbrmantech opened this issue 1 year ago • 1 comments

Recently upgraded to karaf 4.4.6 and camel 4.7.

We found out the hard way that we had some bugs in our XSLT. It was generating XML like this:

<ITAsset (snip)>
	<vulnerability>
		<exploitAvailable>false</exploitAvailable>
	</vulnerability>
</ITAsset>

exploitAvailable in the vuln bean is an int. Oops.

We unmarshal to our java objects like this in our XML blueprints:

	<unmarshal>
		<jaxb prettyPrint="false" contextPath="foo.model"/>
	</unmarshal>

With true or false, It just hangs silently, never returns. If we pass an int, all is well.

Is this a known issue? Is there a work around or some config we could set so if we goof again, it gives us some error message instead of a silent hang?

dbrmantech avatar Sep 25 '24 16:09 dbrmantech

Found another case where it hangs during the unmarshal. If we pass an empty tag in the XML for a Date field in the bean, then it hangs during the unmarshal. For example:

XML snippet:

<ITAsset ...>
   ...
   <assetDiscovery>
      <lastCollectionDateTime/>
   </assetDiscovery>

Unmarshalling from XML Camel blueprint as shown in initial post above to this property in the bean, with public getters and setters:

	@XmlElement(name="lastCollectionDateTime")
	private Date lastCollectionDateTime;

Hangs during the unmarshal with empty tag but works when we put value in tag:

<lastCollectionDateTime>2024-10-02T11:03:00.728-04:00</lastCollectionDateTime>

The hung records just hang out inside Karaf until we shutdown the process, and then get messages like this when stopping the Route:

ShutdownTask | DefaultShutdownStrategy          | 56 - camel-base-engine - 4.7.0 | Waiting as there are still 747 inflight and pending exchanges to complete, timeout in 10 seconds. Inflights per route: [process-record = 747]
9
8
7
...

dbrmantech avatar Oct 02 '24 15:10 dbrmantech

Hello, and thanks for sharing.

I couldn’t reproduce the issue on my end. Am I missing something?

Route in blueprint file:

<route id="jaxb-route">
			
   <from uri="timer://foo?period=10000"/>
			
      <log message="START route"/>
		
      <setBody>
          <constant>
              <![CDATA[
                  <MyData>
                      <randomField>Johnny</randomField>
                      <name/>
                      <nikname>Johnny</nikname>
                      <age>30</age>
                      <asset>
                          <name>Car</name>
                          <inherited>1</inherited>
                          <age>true</age>
                      </asset>
                    </MyData>
                ]]>
            </constant>
        </setBody>
            
        <log message="Will unmarshal: ${body}"/>
           
        <unmarshal>
                <jaxb prettyPrint="false" contextPath="org.apache.karaf.camel.test"/>
        </unmarshal>
            
        <log message="Unmarshalled: ${body}"/>	
			
	<log message="FINISH route"/>
</route>

logs in my console:

21:26:31.009 INFO [Camel (camel-1) thread #1 - timer://foo] START route
21:26:31.010 INFO [Camel (camel-1) thread #1 - timer://foo] Will unmarshal: <MyData>
                      <randomField>Johnny</randomField>
                      <name/>
                      <nikname>Johnny</nikname>
                      <age>30</age>
                      <asset>
                          <name>Car</name>
                          <inherited>1</inherited>
                          <age>true</age>
                      </asset>
                    </MyData>
21:26:31.012 INFO [Camel (camel-1) thread #1 - timer://foo] Unmarshalled: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MyData>
    <asset>
        <age>0</age>
        <inherited>true</inherited>
        <name>Car</name>
    </asset>
    <age>30</age>
    <name></name>
</MyData>

21:26:31.014 INFO [Camel (camel-1) thread #1 - timer://foo] FINISH route

MyData class

package org.apache.karaf.camel.test;

import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "MyData")
public class MyData {

    private String name;
    private int age;
    @XmlElement(name="asset")
    private Asset asset;
    
    // getters and setters  ...  (except getter for asset)   
}

Asset class

package org.apache.karaf.camel.test;

public class Asset {

    private String name;
    private boolean inherited;
    private int age;
    
    // getters and setters ...
}

ObjectFactory class

package org.apache.karaf.camel.test;

import jakarta.xml.bind.annotation.XmlRegistry;

@XmlRegistry
public class ObjectFactory {

    public ObjectFactory() {
    }

    public MyData create() {
        return new MyData();
    }
}

I placed two files inside karaf's deploy folder:

  • a xml blueprint file with the route I shared.
  • a jar file that is a bundle exporting the package org.apache.karaf.camel.test, containing the three classes I shared.

In my setup, I've noticed the blueprint bundle hangs when deploying and undeploying the JAR file. However, I assume that in your scenario, you have a bundle containing both the blueprint and the target package with the classes.

Could you share more information ? 🙏

stataru8 avatar Oct 08 '24 19:10 stataru8

Thanks for trying to reproduce. I've also noticed that there must be something else going on in addition to what I mentioned above. The second hang about dates stopped hanging the next day.

I've also noticed my blueprint hangs on deployment sometimes. I just kill the karaf service with task manager on windows, and restart the service and then it and everything else starts deploying ok again. Just to muddy the waters, I noticed this would start happening after I uninstalled and re-installed the karaf windows service.

We'll try and nail it down more precisely soon. I'm not exactly sure how to answer your question about our bundle, I'll ask a teammate and edit response...

dbrmantech avatar Oct 10 '24 15:10 dbrmantech

We deploy our Java classes before our blueprints, and then deploy/redeploy our blueprints.

But we can no longer reproduce this hang in the unmarshall either. The hang was consistently happening for everyone on the team, but after uninstalling the karaf service and doing fresh installs of the karaf service and our camel blueprints, the unmarshall hangs seem to have disappeared.

Thanks again, and sorry for wasting time here.

dbrmantech avatar Oct 11 '24 17:10 dbrmantech