Re: Namespace list - blueprint - xpath

2013-11-01 Thread Nurali Techie
Thanks Aki for your thoughts ..

Yes, I should call setNamespaces() .. but I need namespace Map which I can pass 
to ..
So, my question remain same .. is there any API or service .. which I can use 
to get Namespace Map ..
And I hv Camel Exchange and Camel Endpoint object with me ..

Parsing blueprint beans.xml and to extract Namespace from blueprint tag; 
looks hack and dirty way ..
Also, I don't know how can I get beans.xml InputStream to parse for .. 

I also debugged and found that .. for standard xpath tag having namespace 
xpath in beans.xml .. the blueprint container do magic to pass all namespace 
while creating xpath expression object.  It means; namespace list is with 
blueprint container .. but I don't know how I can reached to there when I only 
have Camel Exchange and Endpoint object with me.

Thanks,
Nurali



On Thursday, October 31, 2013 9:24 PM, Aki Yoshida elak...@gmail.com wrote:
 
for the first part of the question, maybe you forgot the set the
namespace context (the prefix-nsuri map) in the expression?

setNamespaces(MapString,String namespaces)

for the second part, you probably need to parse the file that will
scan all the namespaces declared and you will see them in the
corresponding namespace declaration handler.


2013/10/31 Nurali Techie nurali.tec...@yahoo.com:
 Hi Friends,

 I want to execute xpath in my code.  It means; I have xpath expression, I 
 have exchange object with In Message.

 Using 'XPathExpression' and 'XPathBuilder' classes; I succeed to do so.  
 Below is the code snippet.

         XPathExpression xpathExprObj = new 
XPathExpression(/userResponse/User/id);
         xpathExprObj.setResultType(String.class);

         Object result = xpathExprObj.evaluate(exchange, Object.class);

 But, if I have xpath with namespace (i.e xpath = /ns0:userResponse/User/id).. 
 above code throwing exception .. saying - Prefix must resolve to a namespace: 
 ns0

 Part of Exception:

 org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath: 
 /ns0:userResponse/User/id. Reason: javax.xml.xpath.XPathExpressionException
 at 
 org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:767) 
 ~[bundlefile:2.11.2-sap-02]
 at org.apache.camel.builder.xml.XPathBuilder.evaluate(XPathBuilder.java:748) 
 ~[bundlefile:2.11.2-sap-02]
 at org.apache.camel.builder.xml.XPathBuilder.evaluate(XPathBuilder.java:168) 
 ~[bundlefile:2.11.2-sap-02]
 at *** My project code calling from here ..
 ..
 ---
 Caused by: 
 com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: Prefix 
 must resolve to a namespace: ns0
 at 
 com.sun.org.apache.xpath.internal.compiler.XPathParser.errorForDOM3(XPathParser.java:653)
  ~[na:1.6.0_33]
 at 
 com.sun.org.apache.xpath.internal.compiler.Lexer.mapNSTokens(Lexer.java:638) 
 ~[na:1.6.0_33]
 at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:265) 
 ~[na:1.6.0_33]
 at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:96) 
 ~[na:1.6.0_33]
 at 
 com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:110)
  ~[na:1.6.0_33]
 at com.sun.org.apache.xpath.internal.XPath.init(XPath.java:176) 
 ~[na:1.6.0_33]
 at com.sun.org.apache.xpath.internal.XPath.init(XPath.java:264) 
 ~[na:1.6.0_33]
 at 
 com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:385) 
 ~[na:1.6.0_33]

 Upon digging; I found that .. I need to set namespaces to XPathExpression 
 object .. So, I need list of all namespace.
 I am using blueprint beans.xml .. so I need list of all namespaces defined 
 with blueprint tag in beans.xml.

 I have camel exchange and camel endpoint object with me.
 I want programmatic solution.

 Thanks,
 Nurali

Re: Namespace list - blueprint - xpath

2013-11-01 Thread Nurali Techie
Hi All,

I have got the solution .. :)

I have used xpath expression to get all namespace.  Here is the part of code:

        String searchAllNamespacesXpathExpr = //namespace::*;    // xpath 
expr to search all namespace
        XPathExpression nsXpath = new 
XPathExpression(searchAllNamespacesXpathExpr);
        nsXpath.setResultType(NodeList.class);
        NodeList nsNodeList = (NodeList) nsXpath.evaluate(exchange, 
Object.class);  // this NodeList contains all namespaces

From NodeList object, I prepare namespace Map which I set to XpathExpression 
object.

        XPathExpression xpathExprObj = new 
XPathExpression(/ns0:userResponse/User/id));
        xpathExprObj.setNamespaces(namespaceMap);     // set namespace Map 
which was prepared from NodeList
        xpathExprObj.setResultType(String.class);
        Object result = xpathExprObj.evaluate(exchange, Object.class);


Now, xpath with namespace (i.e /ns0:userResponse/User/id) will be evaluated 
correctly.

Thanks Aki and All for you help.

Let me know; in case you see any flaw in above way.

Cheers,
Nurali



On Friday, November 1, 2013 2:50 PM, Nurali Techie nurali.tec...@yahoo.com 
wrote:
 
Thanks Aki for your thoughts ..

Yes, I should call setNamespaces() .. but I need namespace Map which I can pass 
to ..
So, my question remain same .. is there any API or service .. which I can use 
to get Namespace Map ..
And I hv Camel Exchange and Camel Endpoint object with me ..

Parsing blueprint beans.xml and to extract Namespace from blueprint tag; 
looks hack and dirty way ..
Also, I don't know how can I get beans.xml InputStream to parse for .. 

I also debugged and found that .. for standard xpath tag having namespace 
xpath in beans.xml .. the blueprint container do magic to pass all namespace 
while creating xpath expression object.  It means; namespace list is with 
blueprint container .. but I don't know how I can reached to there when I only 
have Camel Exchange and Endpoint object with me.

Thanks,
Nurali




On Thursday, October 31, 2013 9:24 PM, Aki Yoshida elak...@gmail.com wrote:

for the first part of the question, maybe you forgot the set the
namespace context (the prefix-nsuri map) in the expression?

setNamespaces(MapString,String namespaces)

for the second part, you probably need to parse the file that will
scan all the namespaces declared and you will see them in the
corresponding namespace declaration handler.


2013/10/31 Nurali Techie nurali.tec...@yahoo.com:
 Hi Friends,

 I want to execute xpath in my code.  It means; I have xpath expression, I 
 have exchange object with In Message.

 Using 'XPathExpression' and 'XPathBuilder' classes; I succeed to do so.  
 Below is the code snippet.

         XPathExpression xpathExprObj = new 
XPathExpression(/userResponse/User/id);
         xpathExprObj.setResultType(String.class);

         Object result = xpathExprObj.evaluate(exchange, Object.class);

 But, if I have xpath with namespace (i.e xpath = /ns0:userResponse/User/id).. 
 above code throwing exception .. saying - Prefix must resolve to a namespace: 
 ns0

 Part of Exception:

 org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath: 
 /ns0:userResponse/User/id. Reason: javax.xml.xpath.XPathExpressionException
 at 
 org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:767) 
 ~[bundlefile:2.11.2-sap-02]
 at org.apache.camel.builder.xml.XPathBuilder.evaluate(XPathBuilder.java:748) 
 ~[bundlefile:2.11.2-sap-02]
 at org.apache.camel.builder.xml.XPathBuilder.evaluate(XPathBuilder.java:168) 
 ~[bundlefile:2.11.2-sap-02]
 at *** My project code calling from here ..
 ..
 ---
 Caused by: 
 com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: Prefix 
 must resolve to a namespace: ns0
 at 
 com.sun.org.apache.xpath.internal.compiler.XPathParser.errorForDOM3(XPathParser.java:653)
  ~[na:1.6.0_33]
 at 
 com.sun.org.apache.xpath.internal.compiler.Lexer.mapNSTokens(Lexer.java:638) 
 ~[na:1.6.0_33]
 at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:265) 
 ~[na:1.6.0_33]
 at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:96) 
 ~[na:1.6.0_33]
 at 
 com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:110)
  ~[na:1.6.0_33]
 at com.sun.org.apache.xpath.internal.XPath.init(XPath.java:176) 
 ~[na:1.6.0_33]
 at com.sun.org.apache.xpath.internal.XPath.init(XPath.java:264) 
 ~[na:1.6.0_33]
 at 
 com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:385) 
 ~[na:1.6.0_33]

 Upon digging; I found that .. I need to set namespaces to XPathExpression 
 object .. So, I need list of all namespace.
 I am using blueprint beans.xml .. so I need list of all namespaces defined 
 with blueprint tag in beans.xml.

 I have camel exchange and camel endpoint object with me.
 I want programmatic solution.

 Thanks,
 Nurali

Namespace list - blueprint - xpath

2013-10-31 Thread Nurali Techie
Hi Friends,

I want to execute xpath in my code.  It means; I have xpath expression, I have 
exchange object with In Message.

Using 'XPathExpression' and 'XPathBuilder' classes; I succeed to do so.  Below 
is the code snippet.

        XPathExpression xpathExprObj = new 
XPathExpression(/userResponse/User/id);
        xpathExprObj.setResultType(String.class);

        Object result = xpathExprObj.evaluate(exchange, Object.class);
        
But, if I have xpath with namespace (i.e xpath = /ns0:userResponse/User/id).. 
above code throwing exception .. saying - Prefix must resolve to a namespace: 
ns0

Part of Exception:

org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath: 
/ns0:userResponse/User/id. Reason: javax.xml.xpath.XPathExpressionException
at org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:767) 
~[bundlefile:2.11.2-sap-02]
at org.apache.camel.builder.xml.XPathBuilder.evaluate(XPathBuilder.java:748) 
~[bundlefile:2.11.2-sap-02]
at org.apache.camel.builder.xml.XPathBuilder.evaluate(XPathBuilder.java:168) 
~[bundlefile:2.11.2-sap-02]
at *** My project code calling from here ..
..
---
Caused by: 
com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: Prefix 
must resolve to a namespace: ns0
at 
com.sun.org.apache.xpath.internal.compiler.XPathParser.errorForDOM3(XPathParser.java:653)
 ~[na:1.6.0_33]
at com.sun.org.apache.xpath.internal.compiler.Lexer.mapNSTokens(Lexer.java:638) 
~[na:1.6.0_33]
at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:265) 
~[na:1.6.0_33]
at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:96) 
~[na:1.6.0_33]
at 
com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:110)
 ~[na:1.6.0_33]
at com.sun.org.apache.xpath.internal.XPath.init(XPath.java:176) ~[na:1.6.0_33]
at com.sun.org.apache.xpath.internal.XPath.init(XPath.java:264) ~[na:1.6.0_33]
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:385) 
~[na:1.6.0_33]

Upon digging; I found that .. I need to set namespaces to XPathExpression 
object .. So, I need list of all namespace.
I am using blueprint beans.xml .. so I need list of all namespaces defined with 
blueprint tag in beans.xml.

I have camel exchange and camel endpoint object with me.
I want programmatic solution.

Thanks,
Nurali 


Re: Memory leak - when an exception is thrown during the scheduling phase

2013-10-06 Thread Nurali Techie
Thanks James for the response .. I have created Jira issue.
https://issues.apache.org/jira/browse/CAMEL-6832 


Yes, I know which code causing this issue and how to fix that.  But I don't 
know other usecases (around the code where the fix needed).  I will spend some 
time and will update my finding/fix in Jira issue.

@All, Please follow Jira issue for further details.

Thanks,
Nurali


 From: James Carman ja...@carmanconsulting.com
To: users@camel.apache.org users@camel.apache.org; Nurali Techie 
nurali.tec...@yahoo.com 
Sent: Friday, October 4, 2013 4:32 PM
Subject: Re: Memory leak - when an exception is thrown during the scheduling 
phase
 


Create a JIRA.  Looks like you may have a patch in mind?  Do you have test 
cases?

On Friday, October 4, 2013, Nurali Techie  wrote:

Hello,



I have observed a memory leak for Quartz worker thread in case an exception is 
thrown during the scheduling phase when schedule is set to past time.
I have observed this issue with camel-quart 2.10.4, 2.11.0, 2.11.2 versions.

For ex, assuming today is 4-Oct; If a schedule is provided for yesterday (i.e 
3-Oct) then below sequence happen:

1. Quartz create worker thread for new schedule [generally TEN Threads with 
name 'DefaultQuartzScheduler']
2. Camel-quartz increment jobCounter for scheduler context [using 
QuartzComponent.incrementJobCounter()]
3. Camel-quartz tries to create new schedule [using Scheduler.scheduleJob()]
4. scheduleJob() throws SchedulerException with the message - 'Based on 
configured schedule, the given trigger will never fire'
5. Camel-quartz does NOT decrement the job counter and jobCounter value 
remains '1'
6. Later Camel-Quartz stops the route and call QuartzComponent.doStop()
7. In doStop(), Scheduler.shutdown() supposed to be called so that those TEN 
threads are removed but to call shutdown() the pre-condition is that the 
jobCounter should be '0'.  In this case jobCounter is '1' and 
Scheduler.shutdown() will NOT be called and those TEN threads are NOT removed. 
 This is memory leak.

Please find the stack trace [with Camel-Quartz 2.11.2 and 
org.apache.servicemix.bundles.quartz-1.8.6_1 which wrapped Quartz Scheduler as 
OSGi bundle] when SchedulerException is thrown at step 4 in above sequence.

Let me know if you want me to create JIRA issue.

Thanks,
Nurali

** Stack Trace:

15:55:22.432 ERROR [Blueprint Extender: 1] o.a.c.b.BlueprintCamelContext 
[BlueprintCamelContext.java:139] - Error occurred during starting Camel: 
CamelContext(sfsftest35) due Based on configured schedule, the given trigger 
will never fire.
org.quartz.SchedulerException: Based on configured schedule, the given trigger 
will never fire.
at org.quartz.core.QuartzScheduler.scheduleJob(QuartzScheduler.java:793) 
~[na:na]
at org.quartz.impl.StdScheduler.scheduleJob(StdScheduler.java:243) ~[na:na]
at 
org.apache.camel.component.quartz.QuartzComponent.doAddJob(QuartzComponent.java:232)
 ~[na:na]
at 
org.apache.camel.component.quartz.QuartzComponent.addJob(QuartzComponent.java:222)
 ~[na:na]
at 
org.apache.camel.component.quartz.QuartzEndpoint.addTrigger(QuartzEndpoint.java:81)
 ~[na:na]
at 
org.apache.camel.component.quartz.QuartzEndpoint.consumerStarted(QuartzEndpoint.java:213)
 ~[na:na]
at 
org.apache.camel.component.quartz.QuartzConsumer.doStart(QuartzConsumer.java:39)
 ~[na:na]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) 
~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:1819)
 ~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(DefaultCamelContext.java:2113)
 ~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers(DefaultCamelContext.java:2049)
 ~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:1979)
 ~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:1758)
 ~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1633)
 ~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1500)
 ~[na:na]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) 
~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1468) 
~[na:na]
at 
org.apache.camel.blueprint.BlueprintCamelContext.start(BlueprintCamelContext.java:167)
 [bundlefile:2.11.2]
at 
org.apache.camel.blueprint.BlueprintCamelContext.maybeStart(BlueprintCamelContext.java:199)
 [bundlefile:2.11.2]
at 
org.apache.camel.blueprint.BlueprintCamelContext.serviceChanged(BlueprintCamelContext.java:137)
 [bundlefile:2.11.2]
at 
org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107)
 [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na]
at 
org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861

Memory leak - when an exception is thrown during the scheduling phase

2013-10-04 Thread Nurali Techie
Hello,



I have observed a memory leak for Quartz worker thread in case an exception is 
thrown during the scheduling phase when schedule is set to past time.
I have observed this issue with camel-quart 2.10.4, 2.11.0, 2.11.2 versions.

For ex, assuming today is 4-Oct; If a schedule is provided for yesterday (i.e 
3-Oct) then below sequence happen:

1. Quartz create worker thread for new schedule [generally TEN Threads with 
name 'DefaultQuartzScheduler']
2. Camel-quartz increment jobCounter for scheduler context [using 
QuartzComponent.incrementJobCounter()]
3. Camel-quartz tries to create new schedule [using Scheduler.scheduleJob()]
4. scheduleJob() throws SchedulerException with the message - 'Based on 
configured schedule, the given trigger will never fire'
5. Camel-quartz does NOT decrement the job counter and jobCounter value remains 
'1'
6. Later Camel-Quartz stops the route and call QuartzComponent.doStop()
7. In doStop(), Scheduler.shutdown() supposed to be called so that those TEN 
threads are removed but to call shutdown() the pre-condition is that the 
jobCounter should be '0'.  In this case jobCounter is '1' and 
Scheduler.shutdown() will NOT be called and those TEN threads are NOT removed.  
This is memory leak.

Please find the stack trace [with Camel-Quartz 2.11.2 and 
org.apache.servicemix.bundles.quartz-1.8.6_1 which wrapped Quartz Scheduler as 
OSGi bundle] when SchedulerException is thrown at step 4 in above sequence.

Let me know if you want me to create JIRA issue.

Thanks,
Nurali

** Stack Trace:

15:55:22.432 ERROR [Blueprint Extender: 1] o.a.c.b.BlueprintCamelContext 
[BlueprintCamelContext.java:139] - Error occurred during starting Camel: 
CamelContext(sfsftest35) due Based on configured schedule, the given trigger 
will never fire.
org.quartz.SchedulerException: Based on configured schedule, the given trigger 
will never fire.
at org.quartz.core.QuartzScheduler.scheduleJob(QuartzScheduler.java:793) 
~[na:na]
at org.quartz.impl.StdScheduler.scheduleJob(StdScheduler.java:243) ~[na:na]
at 
org.apache.camel.component.quartz.QuartzComponent.doAddJob(QuartzComponent.java:232)
 ~[na:na]
at 
org.apache.camel.component.quartz.QuartzComponent.addJob(QuartzComponent.java:222)
 ~[na:na]
at 
org.apache.camel.component.quartz.QuartzEndpoint.addTrigger(QuartzEndpoint.java:81)
 ~[na:na]
at 
org.apache.camel.component.quartz.QuartzEndpoint.consumerStarted(QuartzEndpoint.java:213)
 ~[na:na]
at 
org.apache.camel.component.quartz.QuartzConsumer.doStart(QuartzConsumer.java:39)
 ~[na:na]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) 
~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:1819)
 ~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(DefaultCamelContext.java:2113)
 ~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers(DefaultCamelContext.java:2049)
 ~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:1979)
 ~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:1758)
 ~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1633)
 ~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1500)
 ~[na:na]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) 
~[na:na]
at 
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1468) 
~[na:na]
at 
org.apache.camel.blueprint.BlueprintCamelContext.start(BlueprintCamelContext.java:167)
 [bundlefile:2.11.2]
at 
org.apache.camel.blueprint.BlueprintCamelContext.maybeStart(BlueprintCamelContext.java:199)
 [bundlefile:2.11.2]
at 
org.apache.camel.blueprint.BlueprintCamelContext.serviceChanged(BlueprintCamelContext.java:137)
 [bundlefile:2.11.2]
at 
org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107)
 [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na]
at 
org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861)
 [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na]
at 
org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
 [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na]
at 
org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
 [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na]
at 
org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:819)
 [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na]
at 
org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:771)
 [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na]
at