I am new to the WSO2 ESB. I want to create an API in which I want to add an endpoint URL following the documentation(i know that there are more easy methods but this is that I want to test to follow because the others I already test them):
https://docs.wso2.com/display/EI6xx/Injecting+Parameters+using+a+file
I follow step by step the documentation...but the error is the following:
ERROR - ClientUtils The system cannot infer the transport information from the $FILE:test URL.
ERROR - Axis2Sender Unexpected error during sending the message out
org.apache.axis2.AxisFault: The system cannot infer the transport information from the $FILE:test URL.
[code for call ep]:
<call blocking="true">
<endpoint key="test-ep"/>
</call>
[code ep]:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="test-ep" xmlns="http://ws.apache.org/ns/synapse">
<address uri="$FILE:test">
<enableSec/>
<timeout>
<duration>600000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>`enter code here`
</markForSuspension>
</address>
</endpoint>
[file.properties in carbon home and set in integrator.bat how documentation]:
test=http://localhost:8280/services/document
whenever you start the run integrator.bat, you can pass that location.
Eg:integrator.bat -Dproperties.file.path=yourlocation(Eg:D:\env_variables)\file.properties
once deploy the .car file automatically it will replace the keyword with respective value
Related
I am trying to call a rest api that returns a maximum of 1000 data in wso2 integration studio and list its results in the script mediator. It does not work when the limit parameter is set to a value close to 1000. I can fetch 500 pieces of data. But I can't fetch more. How can I get this to work when there is too much data?
The error I got:
The script engine returned an Exception executing the external js script : null function mediate java.lang.IllegalArgumentException: out of range index
Here is my sample work:
<resource methods="GET" url-mapping="/GetTotalBuildingCountAndArea">
<inSequence>
<call>
<endpoint>
<http method="get" uri-template="http://localhost/entities?type=Building&limit=800">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<script language="js"><![CDATA[
var buildings = mc.getPayloadJSON();
mc.setPayloadJSON(JSON.stringify(buildings));
]]></script>
<property name="messageType" scope="axis2" type="STRING"
value="application/json"/>
<jsontransform description="Json Convert">
<property name="synapse.commons.json.output.autoPrimitive" value="true"/>
<property name="synapse.commons.enableXmlNullForEmptyElement"
value="false"/>
</jsontransform>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
This is a limitation of Script Mediator. The documentation has this to say.
The Micro Integrator uses Rhino engine to execute JavaScripts. Rhino
engine converts the script to a method inside a Java class. Therefore,
when processing large JSON data volumes, the code length must be less
than 65536 characters, since the Script mediator converts the payload
into a Java object. However, you can use the following alternative
options to process large JSON data volumes.
Achieve the same functionality via a Class mediator .
If the original message consists of repetitive sections, you can use the Iterate mediator to generate a relatively small payload using
those repetitive sections. This will then allow you to use the Script
mediator.
The Script Mediator supports using Nashorn to execute JavaScripts, in addition to its default Rhino engine.
It's best to handle this in such a way you altogether avoid the issue. But you can try the third option mentioned above as well. In the Script mediator try changing the language to nashornJS.
<script language="nashornJS">
.
.
.
Endpoints can have three timeout configurations. Never timeout, discard, or fault. I desperately need to continue the flow after a timeout. Is there a way to achieve this? Fault handler (onError sequence) is not a desired solution for this issue. Imagine orchestration with eight call mediators, I would have to create eight sequences and set each other as fault. This would very quickly bloat carbon apps, make code unreadable and increase deployment time.
Basically,at any given time, the state of the endpoint can be one of the following.
Active
Timeout
Suspend
OFF
When an endpoint is in the "Timeout" state, it will continue to attempt to receive messages until one message succeeds or the maximum retry setting has been reached. If the maximum is reached at which point the endpoint is marked as "Suspended." If one message succeeds, the endpoint is marked as "Active."
If you need to continue the mediation flow when you get an endpoint timeout as per the endpoint timeout configuration, you can use the fault option in responseAction.
Then, whenever the endpoint is timeout, the fault sequence (custom fault sequence if you have defined it already, otherwise the default fault sequence) will be hit. If you need to continue the mediation flow and as per the existing implementation, you can define the required mediation logic in a custom sequence and call that sequence in the fault sequence as follows.
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="customFaultSequence" xmlns="http://ws.apache.org/ns/synapse">
<!-- Log the message at the full log level with the ERROR_MESSAGE and the ERROR_CODE-->
<log level="full">
<property name="MESSAGE" value="Executing default 'fault' sequence"/>
<property expression="get-property('ERROR_CODE')" name="ERROR_CODE" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="get-property('ERROR_MESSAGE')" name="ERROR_MESSAGE" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<sequence key="afterTimeoutEndpointSequence"/>
</sequence>
Sample proxy service:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestProxy" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
<target faultSequence="customFaultSequence">
<inSequence>
<endpoint>
<address uri="http://run.mocky.io/v3/51c11e65-55a7-47e5-ba38-1d86e8e5d7ea?mocky-delay=45000ms">
<timeout>
<duration>2</duration>
<responseAction>fault</responseAction>
</timeout>
</address>
</endpoint>
<respond/>
</inSequence>
<description/>
</proxy>
Is there a way to read the properties from file in wso2 using property mediator?
I'm injecting an address uri from the file.properties, and passing the file path as -Dproperties.file.path argument to the startup script, it is able to resolve the varibale only within the address endpoint's uri attribute using the syntax $FILE:variableName as below:
<call>
<endpoint>
<address uri="$FILE:uploadPath">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</address>
</endpoint>
</call>
But I also have the need to use the same property, do a minor transformation and pass it to a class mediator,
I've tried the below approaches and none of them are working.
<log level="custom">
<property expression="$FILE:uploadPath" name="file-path-1"/>
<property expression="$ctx:uploadPath" name="file-path-2"/>
<property expression="$axis2:uploadPath" name="file-path-3"/>
<property expression="$trp:uploadPath" name="file-path-4"/>
<property expression="$axis2:POST_TO_URI" name="POST_TO_URI"/>
</log>
Below are the versions of OS and tools that I'm using.
OS: Mac os catalina,
WSO2: micro-integrator 1.2.0, Integration sutdio - 7.1.0
Some time ago, i was struggling with similar issue, to try using $FILE: in dockered microintegrator . After checking sourcecode i realized that there is no implemented reading in property mediator, and that works only in endpoints... I belive that is because of security reason?
But, there is some workaround, which I'm not a big fan. You could use Property and ScriptMediator:
<property xmlns:ns="http://org.apache.synapse/xsd" name="propPath" expression="get-property('system','properties.file.path')" scope="default" type="STRING"/>
<script language="js"><![CDATA[
var path = java.nio.file.Paths.get(mc.getProperty('propPath'));
var fromFile = java.nio.file.Files.readAllLines(path, java.nio.charset.StandardCharsets.UTF_8);
mc.setProperty('line1',fromFile.get(0).toString());
mc.setProperty('line2',fromFile.get(1).toString());
]]></script>
Of course you got full line, but if you tweak this ScriptMediator, you can have what you want in separate properties.
Trying to make workable solution for guaranteed delivery In memory.
Create InMemoryStore InMemMessageStore, create and point InsertInvoice
create API so code looking like this :
Sequence:
<?xml version="1.0" encoding="UTF-8"?> <sequence name="InMMSsequence" xmlns="http://ws.apache.org/ns/synapse">
<log level="custom">
<property name="STATE" value="message is sent to InMemMessageStore"/>
</log>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="True"/>
<axis2ns12:store messageStore="InMemMessageStore" xmlns:axis2ns12="http://ws.apache.org/ns/synapse"/> </sequence>
my API looks like :
<resource methods="POST" uri-template="/sendMessage">
<inSequence>
<sequence key="InMMSsequence"/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
Message Processor :
<messageProcessor name="MySMessageProcessor" class="org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor" targetEndpoint="InsertInvoice" messageStore="InMemMessageStore" xmlns="http://ws.apache.org/ns/synapse">
<parameter name="interval">1000</parameter>
<parameter name="client.retry.interval">1000</parameter>
<parameter name="max.delivery.attempts">4</parameter>
<parameter name="is.active">true</parameter>
<parameter name="max.delivery.drop">Disabled</parameter>
<parameter name="member.count">1</parameter>
</messageProcessor>
And point :
<endpoint xmlns="http://ws.apache.org/ns/synapse"
name="InsertInvoice">
<http uri-template="http://xxxx.xxx.xxx.xxx/InsertInvoiceVehicleList"
method="post">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension> </http> </endpoint>
PROBLEMS:
over PostMan I'm sending the request in JSON format but when I open InMemMessageStore message is in XML ?!? Why?
Endpoint expecting message in JSON format. Probably this is the reason of failure BUT on log I see something like
Failed to send the message through the fault sequence. Sequence name does not Exist.
Is the fault sequence mandatory or it is complaining because I don't have any default error sequence defines at all ?
also
Unable to sendViaPost to url[http://xxx.xxx.xx.xx/InsertInvoiceVehicleList/sendMessage]
Why the 'sendMessage' (This is uritemplate that is defined in API is added on endpoint url ?!?!)
so : Biggest issue here is how to keep message in JSON format and how to keep endpoint url intact ...
I found the problem and I wanted to share it with others ...
1. call end point from API adds postfix on end gives the error
By default, URI template 'sendMessage' will get appended to the target URL when sending messages out. You need to use following property in your sequence to remove URI template from target URL
<property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>.
2. message processor fails to send message to end point
My end point was api .net web service and issue was with HTTP 1.1 chunking,had to disable it since .NET service doesn’t support it.
This setting is in axis2_blocking_client.xml and axis2_client.xml
<parameter name="Transfer-Encoding">chunked</parameter>
3. message processor fails to send message to end point
my seccond End point was servicestack web service and I used end point like
http://xxxx.xxx.xxx.xxx/TMSALSvc/UpdateStatus
but problem was that I needed to specify the reponce format. Once when I put a EndPoint delaration like
http://xxx.xxx.xxx.xx/TMSALSvc/json/reply/UpdateStatus
everything forked
I hope that this can same some times for other facing the same issues
When I create proxy with send mediator with Rest service Post HTTP Method in HTTP endpoint url. Selected the endpoint as HTTP endpoint on proxy and post the request xml without soap envelop, this perfectly works and get the response in the response window.
But when I use the call mediator with the same HTTP end point url configuration, this does not works. I would like to know can we use call mediator for Post HTTP method? When I use Call mediator for the GET HTTP method which require only query parameters and does not require any request xml this works absolutely fine.
Here is the further information:
However issue is resloved by using the address endpoint in callmediator. When I Invoke the proxy from external Restt client ot Soap UI, it does works. If I use the Try this Service option in wso2 ESB will fail with the results 1. When Soap12 endpoint is selected and 2 when HTTP end point is selected as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="postIDMPCall"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<organizationList xmlns="">
<xml content>
</organizationList>
</format>
<args/>
</payloadFactory>
<header name="_user" scope="transport" value="username"/>
<header name="_password" scope="transport" value="Password"/>
<call blocking="true">
<endpoint>
<address uri="http://<ip-address>:<port>/<resource-path>/UpdateOrganization"
format="rest"/>
</endpoint>
</call>
</inSequence>
</target>
</proxy>
Output: When soap12 endpoint is selected
Though posted the correct xml service does not recorgonize the correct xml format for soap12 endpoint.
FAILURE
Record is not processed successfully. Please Provide valid Request XML
When Http end point is selected
[2016-04-21 12:07:50,179] INFO - HTTPSender Unable to sendViaPost to url[http://://UpdateOrganization/mediate]
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
I think we can't use call mediator for this purpose because call mediator is context unaware mediator.
Your call should already perform a post out the box.
Did you try to set format="pox" if you expect simple xml as a response