I used WSO2 ESB schedule task to fetch data from external system, the task call my proxy service every 5 seconds. In my proxy service, I used a property name "startTime" and "endTime", it means I want to fetch data from "startTime" to "endTime". "startTime" and "endTime" should be increase 5 seconds every task call.
But it seems ESB cannot store these properties(startTime and endTime) between every task call. I try to use the script to write the "startTime" :
importPackage(Packages.org.apache.synapse.config);
var id = mc.getProperty("id");
var res = "conf/data_task/"+id ;
var startTimeInReg = mc.getProperty("_endTime");
mc.getConfiguration().getRegistry().updateResource(res+"/startTime", startTimeInReg.toString());
and get it
<property expression="get-property('registry', fn:concat('conf/data_task/',get-property('id'),'/startTime'))"
name="startTimeInReg" scope="default" type="STRING"/>
I can get the "startTime", but it remain the same value , and I found that after 2 or 3 times schedule task call ( maybe elaps more than 15s ), the value of startTime change.
I think this maybe caused by ESB caching , how I can commit the changing of the startTime value immediately after updateResource method called. Or how can solve this issue.
Try to save your value in the governance registry :
mc.getConfiguration().getRegistry().newResource("gov:/trunk/test/MyCounter.txt",false); // create the resource the 1st time, does nothing the others
mc.getConfiguration().getRegistry().updateResource("gov:/trunk/test/MyCounter.txt", startTimeInReg.toString());
An other solution, have a look at this sample that create a "global" counter (lost when the ESB is restarted) :
<script language="js"><![CDATA[
var curValue = mc.getEnvironment().getServerContextInformation().getProperty("MyCounter");
if (curValue == null) {
curValue = 0;
} else {
curValue++;
}
mc.getEnvironment().getServerContextInformation().addProperty("MyCounter",curValue);
mc.setProperty("MyCounter",curValue);
]]></script>
Related
I'm trying to retrieve a property set inside a script mediator for later use, however it seems to be blank. This is my code:
<script language="js"><![CDATA[var log = mc.getServiceLog();
var payload = mc.getPayloadXML();
var numDevices5GHz = payload["Device.WiFi.AccessPoint.10101.AssociatedDeviceNumberOfEntries"];
log.info("numDevices5GHz :"+numDevices5GHz);
var devices5GHz = new Array(numDevices5GHz);
//formats 5GHz associated devices parameters
for(i = 0; i<numDevices5GHz; i++){
var device = new Object();
device.name="nome"+i;
device.value=i;
devices5GHz[i] = device;
}
mc.setProperty("devices5GHz",devices5GHz);
]]></script>
<log>
<property expression="get-property('devices5GHz')" name="DEVICES 5GHz"/>
</log>
and this is the result:
[2020-03-31 12:11:30,223] [EI-Core] INFO - CommonScriptMessageContext numDevices5GHz :1
[2020-03-31 12:11:30,224] [EI-Core] INFO - CommonScriptMessageContext name: nome0, value: 0
[2020-03-31 12:11:30,224] [EI-Core] INFO - LogMediator To: , WSAction: , SOAPAction: , MessageID: urn:uuid:44561262-94fa-4d92-99f0-d5a25e0d28bd, Direction: response, DEVICES 5GHz =
So, I can see that inside the script the devices5GHz Array has one member (this will later be populated with real data), but when I try to retrieve it outside the script it's empty. What am I doing wrong here?
Thanks.
This is because the javascript array object you are assigning inside the Script mediator, cannot be read by the Property mediator. If you can create an appropriate string inside the Script mediator and assign, then it would become accessible outside the Script mediator.
i'm new to all the hot graphql/apollo stuff.
I have a subscription which gets a search result:
export const SEARCH_RESULTS_SUBSCRIPTION = gql`
subscription onSearchResultsRetrieved($sid: String!) {
searchResultsRetrieved(sid: $sid) {
status
clusteredOffers {
id
}
}
}
`;
Is it possible to query the "status" field from client cache if i need it inside another component? Or do i have to use an additional ?
In the apollo dev-tools i can see that there is a cache entry under "ROOT_SUBSCRIPTION" not "ROOT_QUERY". What does that mean?
....thanks
I found out that subscribeToMore is my friend to solve this.
At first i wrote a normal query for the data i want to subscribe to have cached data, then the cache will be updated by the subscription.
<3 apollo
I need to catch the url parameters parsing in a get request by script mediator. I uses WSO2 esb 4.8.1. and I tried with the following js code. but it gives an error saying window is not defined.
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
var requestNew="<m:ViW xmlns:m=\"wom\">
<m:request>
<RequestHeader>
<RemoteIP>dummyIp</RemoteIP>
<AppName>dummyAppName</AppName>
<AppPassword>dummyPassword</AppPassword>
<UserName>dummyUserName</UserName>
</RequestHeader>
<OrderId>23</OrderId>
<AccountNo>23</AccountNo>
<Cir>23</Cir>
<DocketNo>23</DocketNo>
<Status>23</Status>
<RequestType>23</RequestType>
<RequestedFrom>2016-04-19T22:47:37.000Z</RequestedFrom>";
requestNew=requestNew+"
<RequestedTo>"+getUrlVars()['RequestedTo']+"</RequestedTo>
</m:request>
</m:ViW>";
mc.setPayloadXML(new XML(requestNew));
So how can I access url parameter values in the wso2 esb script mediator?
Following blog will tell you how to do it. Its written targetting WSO2 API Cloud. But since synapse is used in both ESB and API Manager, its valid for your question as well. In summary,
To retrieve path parameters
var id = mc.getProperty('uri.var.id');
To retrieve query parameters
var mask = mc.getProperty('query.param.mask');
I created a web service and was able to send requests to it from a serverside Jaggery.js script with no problem. Then I created a WSDL Proxy Service inside WSO2 ESB and tested it using the "Try it!" feature.
After I redirected my serverside script from the original web service to its proxy inside ESB, I got the error in System Logs:
The endpoint reference (EPR) for the Operation not found is /services/BpmAdderProcessProxy.BpmAdderProcessProxyHttpSoap11Endpoint and the WSA Action = urn:anonOutInOpResponse. If this EPR was previously reachable, please contact the server administrator.
To see in detail what was happening I activated the "SOAP Message Tracer" of the ESB. Suddenly my serverside script could access the webservice via my ESB proxy. Then I deactivated the "SOAP Message Tracer" and the error message was back again. Is my serverside script correct? Or does the debugging tool modify behavior of debugged code?
I'm a JavaScript developer. Actually Jaggery and UES are targeted at people like me. I'm not supposed to look inside Java code, am I? Is there a forum where JavaScript developers discuss WSO2 UES and Jaggery?
My serverside code is as follows:
<%
var x = request.getParameter("x");
var y = request.getParameter("y");
//var sum = parseInt(x) + parseInt(y);
var sum = add(parseInt(x), parseInt(y));
response.content = {
success: true,
data: {
result: sum
}
};
function add(x, y) {
var ws = require('ws');
var stub = new ws.WSStub("http://02-128:8280/services/BpmAdderProcessProxy?wsdl");
var process = stub.services["BpmAdderProcessProxy"].operations["process"];
var payloadTemplate = process.payloadXML();
var payload = replaceQuestionMarks(payloadTemplate, arguments);
var resultXml = process.request(payload);
var resultValue = resultXml.children().text();
return parseInt(resultValue);
}
function replaceQuestionMarks(template, values) {
var i = 0;
return template.replace(
/\?/g,
function() {
return values[i++];
}
);
}
%>
In ESB v4.8.1, pass-through transport is enabled by default and it does not support SOAP body based dispatching (it does not build the message so it can't acces the body's first element to find the operation)
You can append the operation name to the endpoint url : http://host:8280/services/BpmAdderProcessProxy/OperationName
You can add this parameter in your proxy conf (BpmAdderProcessProxy) in WSO2 ESB : <parameter name="disableOperationValidation" locked="false">true</parameter>
You can edit wso2esb/repository/conf/axis2/axis2.xml and replace <handler class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher" name="SOAPMessageBodyBasedDispatcher"/>
with
<handler class="org.apache.synapse.core.axis2.SynapseSOAPMessageBodyBasedDispatcher" name="SOAPMessageBodyBasedDispatcher"/>
The code to get connected to my WebService (Lotus Notes Database) is created by the Flash Builder over "Data/Connect with WebService...". All works fine, but I have a problem to increase the request timeout. The API says that you can set the request timeout like this:
_serviceControl.requestTimeout = 300;
On a iOS (iPad) it seems to be work all fine. But if I run my app on desktop or on an android smartphone this only works if I set up the request timeout lower than ~30 seconds. If I don't set up the request timeout or higher than 30 and my app needs longer than 30 seconds to wait for an answer/result the "_serviceControl" fires an FaultEvent with the message:
body = ""
clientId = "DirectHTTPChannel0"
correlationId = "CDED773E-34E5-56F8-D521-4FFC393D7565"
destination = ""
extendedData = (null)
faultCode = "Server.Error.Request"
faultDetail = "Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: "http://...?OpenWebService" errorID=2032]. URL: "http://...?OpenWebService"
faultString = "HTTP request error"
headers = (Object)#1
DSStatusCode = 0
messageId = "91D11378-49D4-EDF7-CE7A-4FFCB09EBC47"
rootCause = (flash.events::IOErrorEvent)#2
bubbles = false
cancelable = false
currentTarget = (flash.net::URLLoader)#3
bytesLoaded = 0
bytesTotal = 0
data = ""
dataFormat = "text"
errorID = 2032
eventPhase = 2
target = (flash.net::URLLoader)#3
text = "Error #2032: Stream Error. URL: "http://...?OpenWebService"
type = "ioError"
timestamp = 0
timeToLive = 0
Any idea why this happens?
I had the same problem, requestTimeout didn't work.
If someone is looking for an answer, this configuration works fine for me :
import flash.net.URLRequestDefaults;
URLRequestDefaults.idleTimeout = 120000; //note this value represents milliseconds (120 secs)
Have a look here for more details : Flex HTTPService times out anyway
Though it seems to be assumed that requestTimeout doesn't work. It actually does... the 1st time.
After the 1st request, the requestTimeout is set in
HTTPService.channelSet.currentChannel.requestTimeout
If you have to change the timeout, you will want to do it there.
To see the specific offending code, see AbstractOperation.getDirectChannelSet(). Even for different instances of HTTPService, it pulls from:
private static var _directChannelSet:ChannelSet;
_directChannelSet is only instantiated once, and the requestTimeout on it is only set on creation, so even if you change the requestTimeout on HTTPService, it won't reflect in the request.