|
next
|
Subject: Problems posting multipart form via http-post Author: Ivan Pedruzzi Date: 06 Oct 2023 04:11 PM
|
You should not try to handle authentication manually, ddtek:http functions support and user/password for BASIC and DIGEST
Mime type it is also managed automatically.
<request username="..." password="...">
<header name="Environment" value="TEST"/>
<header name="Company" value="PT501234569"/>
<header name="Id" value="4587"/>
</request>
Make sure to pass the element "request" to the function and not element "Marosa" as in your example
<Marosa>
<WS URLInvoiceCreditNote="(https)://sii.marosavat.com/api/private/portugal/invoice-sender-feedback___"/>
....
</Marosa>
Try the above first, if the multi-part is really a requirement. you may need to use a different function.
Here is an example of extension function HTTP.VERB available from XPS build 150 or greater, which was designed to be compatible with ddtek:http option and response.
Element "parameter" you can point to a local file using local path.
Attribute "type" supports 3 values: file, base64, text
When type is base64 or text you need to place the value directly as text, see second example.
declare namespace xps_http = 'ddtekjava:com.ivitechnologies.pipeline.ext.net.HTTP';\n";
declare function xps_http:VERB($verb as xs:string, $url, $options as document-node()?, $payload as document-node()?) external;\n";
declare variable $options :=
<request username="..." password="...">
<header name="Environment" value="TEST"/>
<header name="Company" value="PT501234569"/>
<header name="Id" value="4587"/>
<parameters>
<parameter name="file" type="file">c:\temp\image.png</parameter>
<parameters>
</request>
xps_http:VERB('POST', url, $options, ())
You can also simulate a browser FORM POST, here an example
<request username="..." password="...">
<header name="Environment" value="TEST"/>
<header name="Company" value="PT501234569"/>
<header name="Id" value="4587"/>
<form>
<parameters>
<parameter name="first" type="text">Ivan</parameter>
<parameter name="last" type="text">Pedruzzi</parameter>
<parameters>
</form>
</request>
xps_http:VERB('POST', url, $options, ())
Ivan Pedruzzi
Stylus Studio Team
|
next
|
Subject: Problems posting multipart form via http-post Author: Bruce Cantor Date: 09 Oct 2023 11:00 AM Originally Posted: 09 Oct 2023 08:36 AM
|
Hi Ivan,
Thank you for your input.
I looks like as if it needs to be a form, so I tried this approach:
import module namespace Marosa = "Marosa:library" at "Marosa_lib.xqm";
declare namespace xps_http = "ddtekjava:com.ivitechnologies.pipeline.ext.net.HTTP";
declare function xps_http:VERB($verb as xs:string, $url, $options as document-node()?, $payload as document-node()?) external;
declare variable $request := /;
(: Load transactionlogdir from global environment file :)
declare variable $logFileDir := doc(resolve-uri("../../environment/environment.xml", fn:static-base-uri()))/Params/TransactionLogDir;
declare variable $origFileName := string(processing-instruction(Original-FileName));
declare variable $endpoints := doc(resolve-uri("../Config/config.xml", fn:static-base-uri()))/config/Marosa/WS;
declare variable $LogFileFullPath := concat('file:////', $logFileDir, $origFileName, '.log');
declare option ddtek:serialize "indent=yes";
let $options := <request username="***" password="*********">
<request-header>
<form>
<parameters>
<parameter name="file" type="text">{Marosa:CreateInvoiceCSV(/)}</parameter>
</parameters>
</form>
<!--<header name="Content-Type" value="undefined"/>-->
<!-- additional required header values-->
<header name="Environment" value="TEST"/>
<header name="Company" value="PT50284474"/>
<header name="Id" value="5587"/>
</request-header>
</request>
return xps_http:VERB('POST', $endpoints/@URLInvoiceCreditNote, document { $options }, ())
But this result in an error:
[DataDirect][XQuery]Error at line 33, column 87. Static error during resolving of external Java function. No matching Java external function found for 'com.ivitechnologies.pipeline.ext.net.HTTP:VERB(xs:string, attribute(URLInvoiceCreditNote, xs:untypedAtomic)*, document-node()?, document-node()?)'. [Call stack: xps_http:VERB@33.8]
javax.xml.xquery.XQQueryException: [DataDirect][XQuery]Error at line 33, column 87. Static error during resolving of external Java function. No matching Java external function found for 'com.ivitechnologies.pipeline.ext.net.HTTP:VERB(xs:string, attribute(URLInvoiceCreditNote, xs:untypedAtomic)*, document-node()?, document-node()?)'. [Call stack: xps_http:VERB@33.8]
at com.ddtek.xquery.xqj.Util.createXQQueryException(Util.java:341)
at com.ddtek.xquery.xqj.Util.createXQException(Util.java:241)
at com.ddtek.xquery.xqj.DDXQAbstractExpression.createOrGetExecutionContext(DDXQAbstractExpression.java:519)
at com.ddtek.xquery.xqj.DDXQAbstractExpression.createOrGetExecutionContext(DDXQAbstractExpression.java:481)
at com.ddtek.xquery.xqj.DDXQPreparedExpression.<init>(DDXQPreparedExpression.java:37)
at com.ddtek.xquery.xqj.DDXQConnection.prepareExpression(DDXQConnection.java:243)
Caused by: com.ddtek.xquery.typing.TypeVisitor$TypeVisitorException: [EJF0002][DataDirect][XQuery]Static error during resolving of external Java function. No matching Java external function found for 'com.ivitechnologies.pipeline.ext.net.HTTP:VERB(xs:string, attribute(URLInvoiceCreditNote, xs:untypedAtomic)*, document-node()?, document-node()?)'. [Call stack: xps_http:VERB@33.8]
at com.ddtek.xquery.typing.TypeVisitor.createException(TypeVisitor.java:5111)
at com.ddtek.xquery.typing.TypeVisitor.getExternalJavaFunction(TypeVisitor.java:7775)
at com.ddtek.xquery.typing.TypeVisitor.visit(TypeVisitor.java:2980)
at com.ddtek.xquery.expr.FunctionCall.accept(FunctionCall.java:224)
at com.ddtek.xquery.typing.TypeVisitor.visit(TypeVisitor.java:2794)
at com.ddtek.xquery.expr.FLWORExpr.accept(FLWORExpr.java:204)
at com.ddtek.xquery.expr.AllExpressionVisitor.visit(AllExpressionVisitor.java:455)
at com.ddtek.xquery.typing.TypeVisitor.visit(TypeVisitor.java:3450)
at com.ddtek.xquery.expr.MainModule.accept(MainModule.java:57)
at com.ddtek.xquery.typing.TypeVisitor.typeExpression(TypeVisitor.java:740)
at com.ddtek.xquery.mediator.ContextFactory$MediatorTypeVisitor.typeExpression(ContextFactory.java:581)
at com.ddtek.xquery.mediator.ContextFactory.prepareQuery(ContextFactory.java:254)
at com.ddtek.xquery.xqj.DDXQAbstractExpression.createOrGetExecutionContext(DDXQAbstractExpression.java:512)
... 3 more
In the classpath I am refering to the latest xmlpipelineserver.jar that I copied from the pipeline server. (MD-5: 0x99C067E7B4C8DC6264C1B2CC1F62B050).
What am I missing??
|
next
|
Subject: Problems posting multipart form via http-post Author: Ivan Pedruzzi Date: 09 Oct 2023 07:51 PM Originally Posted: 09 Oct 2023 04:16 PM
|
Try the following.
You may also need to add additional XPS libraries in your Stylus Studio project's classpath:
httpmime-4.5.3.jar
httpcore-4.4.6.jar
httpclient-4.5.3.jar
xmlpipelineserver.jar
commons-logging-1.2.jar
commons-codec-1.9.jar
import module namespace Marosa = "Marosa:library" at "Marosa_lib.xqm";
declare namespace xps_http = "ddtekjava:com.ivitechnologies.pipeline.ext.net.HTTP";
declare function xps_http:VERB(
$verb as xs:string,
$url as xs:string,
$options as document-node()?,
$payload as document-node()?) external;
declare variable $request := /;
(: Load transactionlogdir from global environment file :)
declare variable $logFileDir := doc(resolve-uri("../../environment/environment.xml", fn:static-base-uri()))/Params/TransactionLogDir;
declare variable $origFileName := string(processing-instruction(Original-FileName));
declare variable $endpoints := doc(resolve-uri("../Config/config.xml", fn:static-base-uri()))/config/Marosa/WS;
declare variable $LogFileFullPath := concat('file:////', $logFileDir, $origFileName, '.log');
declare option ddtek:serialize "indent=yes";
declare variable $VERB_OPTIONS_POST :=
document{
<options username="*****" password="*****">
<request-header>
<header name="Content-Type" value="application/x-www-form-urlencoded"/>
<header name="Environment" value="TEST"/>
<header name="Company" value="PT50284474"/>
<header name="Id" value="5587"/>
</request-header>
</options>
};
declare variable $payload :=
document{
<request>
<form>
<parameters>
<parameter name="file" type="text">{Marosa:CreateInvoiceCSV(/)}</parameter>
</parameters>
</form>
</request>
};
xps_http:VERB(
'POST',
xs:string($endpoints/@URLInvoiceCreditNote),
$VERB_OPTIONS_POST,
$payload)
|
|
|
|