XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Bruce CantorSubject: xquery and try - catch
Author: Bruce Cantor
Date: 30 Jul 2021 01:55 PM
Hi

Any help appreciated here :-)

I need to be able to deliver a log file back to my backend when finishing a file transfer with sftp.

Until now I have been delivering using the sftp option in the pipeline binding file, but I cannot see how I can use this when there is a specific requirement for the log file name. The log file name must follow the name of the input file.

So, I turned to xquery, knowing that I should be able to have access to the input file name.

My problem is I cannot make any try - catch statement work if I use the Datadirect xquery processor. I get errors like this:

DataDirect][XQuery][err:XPST0003]Error at line 2, column 5. Unexpected token "{" beyond end of query.

If I run a script with the Saxon processor I can use try - catch statements, but then I do not have access to the functions that I need to send the file. e.g. sftp:sendFile()

Is it possible to do exception handling in xquery wile using the Datadirect Xquery processor?

script:
xquery version "1.1";

declare namespace xps_sftp = "ddtekjava:com.ivitechnologies.pipeline.ext.net.SFTP";

(: declare variable $ediData as xs:string external;:)

declare variable $config := <root host='ftp.test.com' port='22' path='/Upload' user='*******' password='*******'/>;

declare variable $input as document-node(element(*, xs:untyped)) external;



declare function xps_sftp:sendString($element as element(), $data as xs:string, $targetPath as xs:string) as xs:boolean external;

declare function xps_sftp:sendFile($element as element(), $uriLocalFile as xs:string, $targetPath as xs:string) as xs:boolean external;



let $now := ddtek:format-dateTime(fn:current-dateTime(),'[Y0001][M01][D01][H01][m01][s01]') , $fileName := concat("Dispatch.",$now,'.xml')
return

try {

xps_sftp:sendFile($config,base-uri(/*), $fileName)
}

catch * {
(: write log file here, with error result :)

}


Kind regards
Bruce

Postnext
Ivan PedruzziSubject: xquery and try - catch
Author: Ivan Pedruzzi
Date: 30 Jul 2021 08:52 PM
Originally Posted: 30 Jul 2021 08:47 PM
DataDirect XQuery supports the following specifications:

XQuery 1.0 An XML Query Language
XQuery 1.0 and XPath 2.0 Data Model (XDM)
XQuery 1.0 and XPath 2.0 Functions and Operators
XQuery 1.0 and XPath 2.0 Formal Semantics
XQuery 1.1 W3C Working Draft 3

Currently XML Pipeline Server does not allow to use any either XQuery Processor.

One possibility is adding new built-in (S)FTP functions that wrap runtime exceptions and return an XML fragment instead of a Boolean.

something like

<status>
<steps>
<step name="login" status="ok"/>
<step name="cwdir" status="ok"/>
<step name="upload" status="failed"/>
</steps>
<error>
<message>access denied</message>
</error>
</status>

-Ivan

Posttop
Bruce CantorSubject: xquery and try - catch
Author: Bruce Cantor
Date: 02 Aug 2021 07:53 AM
That sounds like a good idea.

FTP connections are not stable, the server may be busy or unavailable, we even experience that IP's are sometimes blocked or accounts are changed without warned, I do not think these kind of problems should result in runtime errors. My opinion is that runtime errors are errors that no one really could predict, and this is a type of error that will happen once in a while.


I like the idea of an XML result with status of the different steps.

The status attribute also makes it possible for me to parse the result of the upload as Success or Failed.


 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.