I have a requirement where i am supposed to upload a gzip file to wso2 EI server.
I have a file(gzip) in a system(running java). I need to send this file to a API hosted in wso2ei, which will store this. Since file can be HUGE, I need the API to support multi part file upload. I want to write an API in wso2 EI which will support multipart and will take this file and store on some location on EI server itself.
I do not want to use VFS.
Below is the code that i tried but not working. Its creating a corrupted zip file. If i am giving a huge file , then i am getting out of memory error too. Though while using multipart, i was not expecting out of memory error(irrespective the size of file).
Note: I tried without decoding the body. With application/zip content type as well.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/upload" name="MultiPartAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST" >
<inSequence>
<property expression="json-eval($)" name="inputPayLoad" scope="default" type="STRING"/>
<property name="messageType" scope="axis2" type="STRING" value="multipart/form-data"/>
<property name="ContentType" scope="axis2" type="STRING" value="multipart/form-data"/>
<property expression="//mediate/data/text()" name="payload" scope="default" type="STRING"/>
<property expression="//mediate/data/#filename" name="fileName" scope="default" type="STRING"/>
<log level="custom">
<property name="===========" value="================="/>
<property expression="$ctx:fileName" name="fileName"/>
</log>
<property expression="base64Decode(get-property('payload'))" name="DecodeBody" scope="default" type="STRING"/>
<property description="File full path" expression="fn:concat('\home\files\gzip\',$ctx:fileName)" name="fileFullPath" scope="default" type="STRING"/>
<property name="messageType" scope="axis2" type="STRING" value="application/octet-stream"/>
<property name="ContentType" scope="axis2" type="STRING" value="application/octet-stream"/>
<fileconnector.create>
<source>{$ctx:fileFullPath}</source>
<inputContent>{$ctx:DecodeBody}</inputContent>
</fileconnector.create>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
BR//
Vipin Nirwal
This give the details of above requirement.
Related
I'm using wso2 integration studio (version 7.2). I'm trying to post a JSON payload factory to an endpoint. This JSON message has a JSON array with a square bracket but wso2 keeps removing that before sending it out. The receiver API doesn't accept it in this format.
See my code below:
<api context="/test" name="testAPi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="setCharacterEncoding" value="false" scope="axis2"/>
<payloadFactory media-type="json">
<format>{"field1": 5,"field2": 2022,"field3": "22","contacts": [{"id":1014,"surname": "N"}],"applicants": [{"nameId": 111111}]}
</format>
<args/>
</payloadFactory>
<header name="Content-Type" scope="transport" value="application/json"/>
<property name="contentType" scope="axis2" type="STRING" value="application/json"/>
<log level="full"/>
<header name="Accept" scope="transport" value="*/*"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<header name="Connection" scope="transport" value="keep-alive"/>
<header name="Accept-Encoding" scope="transport" value="gzip, deflate, br"/>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<log level="full"/>
<call blocking="true">
<endpoint key="tcpmon"/>
</call>
<log level="full"/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
I used the tcpmon to see what is sending out. and I can see wso2 just remove the [] from the message and send it out.
Do you know how can I fix this?
I am new to wso2 and I want to log all the properties in the incoming request except one property
here's my code:
<log level="full"/>
<propertyGroup>
<property expression="json-eval($.username)" name="Username" scope="default" type="STRING"/>
<property expression="json-eval($.password)" name="Password" scope="default" type="STRING"/>
<property expression="json-eval($.objectStore)" name="ObjectStore" scope="default" type="STRING"/>
<property expression="json-eval($.documentClass)" name="DocumentClass" scope="default" type="STRING"/>
<property expression="json-eval($.fileName)" name="FileName" scope="default" type="STRING"/>
<property expression="json-eval($.fileData)" name="FileData" scope="default" type="STRING"/>
<property expression="json-eval($.contentType)" name="ContentType" scope="default" type="STRING"/>
</propertyGroup>
I want to exclude the fileData property from log because it's base64
is there's any solution other than a custom log that has only the properties that I want to log ?
Its not posible by default i think. You can write your custom mediator for logging necessary attributes and properties
By default, the <log level="full"/> won't log your property - it is logging standard headers (i.e. To, From, WSAction, SOAPAction, ReplyTo, and MessageID) and the full payload of the message. And as i see in your example - json-eval($.fileData) is part of the JSON payload.
So, there is no other option than using a custom logger.
We have a very simple EI API. We receive an XML payload, we then extract a destination code from the XML document and, based on the destination code, we forward the payload to the appropriate endpoint.
One of our clients have made a spelling mistake in their payload and we want to correct it before we send it to the new endpoint. We want to replace the word 'Principle' with 'Principal'.
How can we replace a string in the request body with another string?
Here is our current implementation:
<inSequence>
<property expression="//MyXML/Destination" name="Destination" scope="default" type="STRING"/>
<log level="custom">
<property expression="//MyXML/Transaction/Destination" name="Destination"/>
</log>
<property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
<property description="vendorId" expression="concat('gov:/integration/endpoints/myendpoints/', get-property('uri.var.vendorId'), '_EP')" name="vendorId" scope="default" type="STRING"/>
<log category="DEBUG" description="request_log" level="full">
<property expression="get-property('vendorId')" name="Vendor ID"/>
</log>
<log description="request_log" level="custom">
<property expression="get-property('vendorId')" name="Vendor ID"/>
</log>
<send>
<endpoint key-expression="get-property('vendorId')"/>
</send>
</inSequence>
I created proxy service in WSO EI 6.4.0, which send email. In the flow I use properties: AttachmentFile, transport.mail.bodyWhenAttached, senderAddress and Subject. How to create custom wsdl with input parameters sender_address, subject, mail_text, attachment_file. or what other solution can you use?
I want to call this proxy server via API and send the parameters.
<inSequence xmlns="http://ws.apache.org/ns/synapse">
<property name="transport.mail.Format" scope="axis2" type="STRING" value="Attachment"/>
<property name="AttachmentFile" scope="axis2" type="STRING" value="attachment.csv"/>
<property name="ContentType" scope="axis2" type="STRING" value="text/html"/>
<property name="messageType" scope="axis2" type="STRING" value="text/html"/>
<property expression="Some body text" name="transport.mail.bodyWhenAttached"
scope="axis2" type="STRING"/>
<property name="senderAddress" scope="default" type="STRING" value="test#test.com"/>
<property name="Subject" scope="transport" type="STRING" value="WSO Email Test"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<log level="full"/>
<header
expression="fn:concat('mailto:', get-property('senderAddress'))"
name="To" scope="default"/>
<call>
<endpoint>
<default/>
</endpoint>
</call>
</inSequence>
Save the below file with the name sendEmailProxy.xml under the location
//repository/deployment/server/synapse-configs/default/proxy-services
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="sendEmailProxy"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<property name="transport.mail.Format"
scope="axis2"
type="STRING"
value="Attachment"/>
<property name="AttachmentFile"
scope="axis2"
type="STRING"
value="attachment.csv"/>
<property name="ContentType"
scope="axis2"
type="STRING"
value="text/html"/>
<property name="messageType"
scope="axis2"
type="STRING"
value="text/html"/>
<property name="senderAddress"
scope="default"
type="STRING"
value="test#test.com"/>
<property name="Subject"
scope="transport"
type="STRING"
value="WSO Email Test"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED"
scope="axis2"
type="STRING"
value="true"/>
<log level="full"/>
<header expression="fn:concat('mailto:', get-property('senderAddress'))"
name="To"
scope="default"/>
<call>
<endpoint>
<default/>
</endpoint>
</call>
<respond/>
</inSequence>
</target>
<parameter name="useOriginalwsdl">true</parameter>
<description/>
</proxy>
Once it is saved start wso2 EI/ESB instance , log into the instance, then click on service which is on left hand side of screen below services you wil find the proxy, You will have two options wsdl1.1 wsdl2.0 click on which ever you prefer , this would provide the wsdl file for you proxy
If you are already having a custom wsdl and want wso2 to pick up that wsdl then you need to add the below parameter
<parameter name="useOriginalwsdl">true</parameter>
This would accept your custom wsdl and wso2 will not generate it's own wsdl
I am working on the WSO2 ESB Proxy service, which involves exposing the internal RESTful service via SOAP endpoint on the ESB.
My RESTful service requires Content-type = "application/rdf+xml". I tried setting it using all 3 properties mentioned in the documentation: messageType, ContentType and CONTENT_TYPE. However, the request Content-type still remains "application/xml".
Here is an excerpt from my sequence that calls REST service:
<property xmlns:ns="http://org.apache.synapse/xsd" name="REST_URL_POSTFIX" value="/record/12345" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="PUT" scope="axis2" type="STRING"/>
<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="CONTENT_TYPE" value="application/rdf+xml" scope="axis2" type="STRING"/>
<send>
<endpoint name="CQ">
<address uri="http://my_url" format="pox">
</address>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Basic ', base64Encode('username:password'))" scope="transport"/>
<property name="OSLC-Core-Version" value="2.0" scope="transport"/>
<property name="Accept" value="application/rdf+xml" scope="transport"/>
</endpoint>
</send>
I tested it with TCPMon and no matter what Content-type property I use, request still contains "application/xml".
Please advice.
Can you try WSO2 ESB 4.7.0 with following configuration? Note that, I have changed the address format from "pox" to "rest"
<property xmlns:ns="http://org.apache.synapse/xsd" name="REST_URL_POSTFIX" value="/record/12345" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="PUT" scope="axis2" type="STRING"/>
<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="CONTENT_TYPE" value="application/rdf+xml" scope="axis2" type="STRING"/>
<send>
<endpoint name="CQ">
<address uri="http://my_url" format="rest">
</address>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Basic ', base64Encode('username:password'))" scope="transport"/>
<property name="OSLC-Core-Version" value="2.0" scope="transport"/>
<property name="Accept" value="application/rdf+xml" scope="transport"/>
</endpoint>
</send>
These are the http headers sent now (captured from tcpmon)
PUT /record/12345 HTTP/1.1
Cookie: region1_configure_menu=none; region3_registry_menu=none; region4_monitor_menu=none; region5_tools_menu=none; JSESSIONID=54D2911FCD5559C6B2F723E7C6FA9B44; requestedURI="../../carbon/service-mgt/index.jsp?region=region1&item=services_list_menu"; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23
Authorization: null
OSLC-Core-Version: 2.0
Content-Type: application/rdf+xml
Accept: application/rdf+xml
Transfer-Encoding: chunked
Host: www.foo.com:8080
Connection: Keep-Alive
User-Agent: Synapse-PT-HttpComponents-NIO
In the configuration you have attached, you have specified the format of the address uri as "pox" .
<address uri="http://my_url" format="pox">
This will be the reason that you are getting content-type as application/xml always. Please remove this attribute and try. It should be
<address uri="http://my_url">
If you still see the issue, then try to switch to the NHTTP transport as suggested by RaviU. For that, you can first backup the axis2.xml (ESB_HOME/repository/conf/axis2/axis2.xml) as axis2_back.xml and then rename the axis2_nhttp.xml file (same location) as axis2.xml.
Can you set the content type property like this;
<property name="Content-Type” value="application/rdf+xml" scope="transport"/>
Please remove other content-type properties..
If you define like this;
[1]<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/>
[2]<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/>
[1] for, to select messageformatter
[2]for, to select message builders
Edit;
try like this
<inSequence>
<log level="custom">
<property name="in seq --------------of proxy" expression="$trp:Content-Type"/>
</log>
<property name="messageType"
value="application/json"
scope="axis2"
type="STRING"/>
<property name="Content-Type"
value="application/json"
scope="transport"
type="STRING"/>
<log level="custom">
<property name="in seq --------------of proxy" expression="$trp:Content-Type"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:5555/com"/>
</endpoint>
</send>
Sometimes, you have to enable those message formatters in axis2.xml before using them.
Check this article out. It may help if you haven't done so yet.
http://wso2.com/library/articles/axis2-configuration-part2-learning-axis2-xml#mf