[Dev] Custom Mediator File

2015-02-12 Thread Maz Lakadia
I am trying to include a custom mediator. I have created a .java file which 
extends the AbstractMediator class as needed, with a Mediate() method. However, 
when I try to compile the file it fails (probably because it doesn't know where 
the Abstract Mediator files are). How do I compile the file properly to include 
it in the project?

Thanks.   ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] Custom Mediator for JSON Payload Mediation

2015-02-02 Thread Maz Lakadia
Hi,

I am attempting to write a Custom Mediator using http://wso2.com/library/2898/ 
and http://wso2.com/library/2936/. However, these examples are for XML 
payloads. I am unsure how I could access the message payload within the 
mediate() method when the payload the JSON. Are there any available solutions 
which do not involve changing my JSON to XML and back (I cannot do that as my 
payload may be invalid XML, but it will always be valid JSON).

Thank you, 

Maz   ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] JSON Payloads with Spaces in Attribute Names

2015-01-14 Thread Maz Lakadia
I am having some trouble with WSO2AM-1.7. When I try to GET a resource such as:

{  "hello there" : "world"}

The mediation step does not work, because of the space in "hello there". I know 
XML element types cannot contain spaces in their names, and the error I'm 
getting suggests that's precisely what the program is trying to do. This must 
mean that the data is implicitly changed to XML, even though all my data is 
supposed to stay in JSON. 
I am using the messagebuilder and formatters:


Is there another message builder or formatter I should be using instead?

Thanks,

Maz   ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] getPayloadJSON returning an empty object

2015-01-12 Thread Maz Lakadia
Just in case someone has the same issue, I managed to get mine working.

I had to do a workaround method:

1. Use property mediator before the script mediator to set a property:  

2. Within the script mediator, get the payload (as a string) by doing this: 
 var pl_string = mc.getProperty("JSONPayload");
3. Now have to convert the string into a JS object: var pl = 
JSON.parse(pl_string);
4. Manipulate the payload as if you'd obtained it using getPayloadJSON().

I know it's a hacked together method, but none of the other ways were working 
for me so I tried this one. 

Some information in case anyone wants to debug it: 

I'm using API Manager 1.7. 

I set the message builders and formatters to these:Builder class= 
"org.apache.synapse.commons.json.JsonStreamBuilder" 
Formatter class  = "org.apache.synapse.commons.json.JsonStreamFormatter"

Hope this helps, 

Maz
From: mlaka...@hotmail.com
To: mal...@wso2.com; dev@wso2.org
Date: Mon, 12 Jan 2015 08:54:09 +1300
Subject: Re: [Dev] getPayloadJSON returning an empty object




I'm using the ESB that comes with WSO2 API Manager 1.7.0. 

The Formatter is:  class="org.apache.axis2.json.JSONMessageFormatter" The 
Builder is: class="org.apache.axis2.json.JSONBuilder"

Date: Fri, 9 Jan 2015 09:25:53 +0530
From: mal...@wso2.com
To: dev@wso2.org
Subject: Re: [Dev] getPayloadJSON returning an empty object

Also specify what is the ESB version used? 4.9.0 M4 or 4.8.1?
On Fri, Jan 9, 2015 at 7:54 AM, Asanka Dissanayake  wrote:
Hi Maz,
What is the JSON builder and formatter you are using? You can find them in 
/repository/conf/axis2/axis2.xml under Formatters and Builders.

Thanks,
Asanka

On Thu, Jan 8, 2015 at 8:14 PM, Bhathiya Jayasekara  wrote:
Hi Maz,
I quickly tried out your config and it worked fine for me. I'm copying my full 
config here for your reference. 
http://ws.apache.org/ns/synapse"; name="jsonTest" context="/json">   
 
   var older = 
mc.getPayloadJSON(); var newer=older; 
mc.setPayloadJSON(newer);  
   
 
Request:curl -X POST -d "{\"origin\":\"202.37.75.130\"}" -H "Content-Type: 
application/json" http://10.113.56.222:8281/json

Response:{"origin":"202.37.75.130"}

Hope this helps.
Thanks,Bhathiya
On Fri, Jan 9, 2015 at 3:55 AM, Maz Lakadia  wrote:



I am doing some very simple script mediation as a test to see if I can change 
the payload being returned by my server.My unmediated payload comes out 
as:{"origin":"202.37.75.130"}
Then I try doing a very simple check to see whether get and set work for 
payloads:
var older = mc.getPayloadJSON(); 
var newer=older; 
mc.setPayloadJSON(newer);   
 
My result from this is:{"jsonObject":""}
I have done testing that shows that setPayloadJSON() works, which means that my 
getPayloadJSON must be returning an empty object.Looking at the log file shows 
this:ERROR {org.apache.synapse.mediators.bsf.ScriptMessageContext} -  JSON 
object is null. {org.apache.synapse.mediators.bsf.ScriptMessageContext}
Is there anyone else having this error? Is this happening because the Payload 
is actually a Java object rather than a JSON object?
Thanks,
Maz   

___

Dev mailing list

Dev@wso2.org

http://wso2.org/cgi-bin/mailman/listinfo/dev




-- 
Bhathiya JayasekaraSoftware Engineer,WSO2 inc., http://wso2.com
Phone: +94715478185LinkedIn: http://www.linkedin.com/in/bhathiyajTwitter: 
https://twitter.com/bhathiyaxBlog: http://movingaheadblog.blogspot.com


___

Dev mailing list

Dev@wso2.org

http://wso2.org/cgi-bin/mailman/listinfo/dev




-- 

Asanka Dissanayake
Software EngineerWSO2 Inc. - lean . enterprise . middleware |  wso2.com

email: asan...@wso2.com,   blog: cyberwaadiya.blogspot.com, 
asankastechtalks.wordpress.com  mobile: +94 71 8373821


___

Dev mailing list

Dev@wso2.org

http://wso2.org/cgi-bin/mailman/listinfo/dev




-- 

Best Regards,
Malaka Silva
Senior Tech Lead
M: +94 777 219 791Tel : 94 11 214 5345
Fax :94 11 2145300 Skype : malaka.sampath.silvaLinkedIn : 
http://www.linkedin.com/pub/malaka-silva/6/33/77Blog : 
http://mrmalakasilva.blogspot.com/

WSO2, Inc. lean . enterprise . middleware 
http://www.wso2.com/
http://www.wso2.com/about/team/malaka-silva/

Save a tree -Conserve nature & Save the world for your future. Print this email 
only if it is absolutely necessary.



___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev
  

___

Re: [Dev] getPayloadJSON returning an empty object

2015-01-11 Thread Maz Lakadia
I'm using the ESB that comes with WSO2 API Manager 1.7.0. 

The Formatter is:  class="org.apache.axis2.json.JSONMessageFormatter" The 
Builder is: class="org.apache.axis2.json.JSONBuilder"Date: Fri, 9 Jan 2015 
09:25:53 +0530
From: mal...@wso2.com
To: dev@wso2.org
Subject: Re: [Dev] getPayloadJSON returning an empty object

Also specify what is the ESB version used? 4.9.0 M4 or 4.8.1?
On Fri, Jan 9, 2015 at 7:54 AM, Asanka Dissanayake  wrote:
Hi Maz,
What is the JSON builder and formatter you are using? You can find them in 
/repository/conf/axis2/axis2.xml under Formatters and Builders.

Thanks,
Asanka

On Thu, Jan 8, 2015 at 8:14 PM, Bhathiya Jayasekara  wrote:
Hi Maz,
I quickly tried out your config and it worked fine for me. I'm copying my full 
config here for your reference. 
http://ws.apache.org/ns/synapse"; name="jsonTest" context="/json">   
 
   var older = 
mc.getPayloadJSON(); var newer=older; 
mc.setPayloadJSON(newer);  
   
 
Request:curl -X POST -d "{\"origin\":\"202.37.75.130\"}" -H "Content-Type: 
application/json" http://10.113.56.222:8281/json

Response:{"origin":"202.37.75.130"}

Hope this helps.
Thanks,Bhathiya
On Fri, Jan 9, 2015 at 3:55 AM, Maz Lakadia  wrote:



I am doing some very simple script mediation as a test to see if I can change 
the payload being returned by my server.My unmediated payload comes out 
as:{"origin":"202.37.75.130"}
Then I try doing a very simple check to see whether get and set work for 
payloads:
var older = mc.getPayloadJSON(); 
var newer=older; 
mc.setPayloadJSON(newer);   
 
My result from this is:{"jsonObject":""}
I have done testing that shows that setPayloadJSON() works, which means that my 
getPayloadJSON must be returning an empty object.Looking at the log file shows 
this:ERROR {org.apache.synapse.mediators.bsf.ScriptMessageContext} -  JSON 
object is null. {org.apache.synapse.mediators.bsf.ScriptMessageContext}
Is there anyone else having this error? Is this happening because the Payload 
is actually a Java object rather than a JSON object?
Thanks,
Maz   

___

Dev mailing list

Dev@wso2.org

http://wso2.org/cgi-bin/mailman/listinfo/dev




-- 
Bhathiya JayasekaraSoftware Engineer,WSO2 inc., http://wso2.com
Phone: +94715478185LinkedIn: http://www.linkedin.com/in/bhathiyajTwitter: 
https://twitter.com/bhathiyaxBlog: http://movingaheadblog.blogspot.com


___

Dev mailing list

Dev@wso2.org

http://wso2.org/cgi-bin/mailman/listinfo/dev




-- 

Asanka Dissanayake
Software EngineerWSO2 Inc. - lean . enterprise . middleware |  wso2.com

email: asan...@wso2.com,   blog: cyberwaadiya.blogspot.com, 
asankastechtalks.wordpress.com  mobile: +94 71 8373821


___

Dev mailing list

Dev@wso2.org

http://wso2.org/cgi-bin/mailman/listinfo/dev




-- 

Best Regards,
Malaka Silva
Senior Tech Lead
M: +94 777 219 791Tel : 94 11 214 5345
Fax :94 11 2145300 Skype : malaka.sampath.silvaLinkedIn : 
http://www.linkedin.com/pub/malaka-silva/6/33/77Blog : 
http://mrmalakasilva.blogspot.com/

WSO2, Inc. lean . enterprise . middleware 
http://www.wso2.com/
http://www.wso2.com/about/team/malaka-silva/

Save a tree -Conserve nature & Save the world for your future. Print this email 
only if it is absolutely necessary.



___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev
  ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] getPayloadJSON returning an empty object

2015-01-08 Thread Maz Lakadia
I am doing some very simple script mediation as a test to see if I can change 
the payload being returned by my server.My unmediated payload comes out 
as:{"origin":"202.37.75.130"}
Then I try doing a very simple check to see whether get and set work for 
payloads:
var older = mc.getPayloadJSON(); 
var newer=older; 
mc.setPayloadJSON(newer);   
 
My result from this is:{"jsonObject":""}
I have done testing that shows that setPayloadJSON() works, which means that my 
getPayloadJSON must be returning an empty object.Looking at the log file shows 
this:ERROR {org.apache.synapse.mediators.bsf.ScriptMessageContext} -  JSON 
object is null. {org.apache.synapse.mediators.bsf.ScriptMessageContext}
Is there anyone else having this error? Is this happening because the Payload 
is actually a Java object rather than a JSON object?
Thanks,
Maz   ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] Conditional Payload Factory Mediator configurations

2015-01-07 Thread Maz Lakadia
Hi,

I am trying to use Payload Factory Mediator to change server responses. Suppose 
I have 2 sorts of JSON objects my server can respond with: ball and bat. Now 
for the ball case, my response could look something like:
{"ball":{"weight": 152},{"radius": 46},{"colour":"white"}}

If the case of "ball" I want to change the response to something like:
{"baseball":{"colour":"white"},{"mass":152},}
I know how to mediate a single resource like that. i.e. given the server 
response is "ball" object, I can change it to what I want. The difficulty 
arises if now I have a 2nd possible response from the server (a "bat" object). 
I wish to perform a similar mediation on it, but it would have different fields 
that need to be filled. Therefore my Payload Factory code from the "ball" case 
will no longer work. How could I write the configuration files such that for 
different resources ("bat","ball",etc) a different template is used to fill in 
the data? Is it easier to use a Script Mediator or some other sort of mediator 
for this purpose? 

Thanks,
Maz   ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] Payload mediation of JSON message using Script Mediator

2015-01-07 Thread Maz Lakadia
I will be mapping resources that are in a particular format into another 
format. This means I will have a lot of template mappings that I could load 
into script mediator and let it use the appropriate one for the task. I am 
unsure of how I could do that will payload factory mediator. Do you have any 
clues?Date: Wed, 7 Jan 2015 09:07:13 +0530
Subject: Re: [Dev] Payload mediation of JSON message using Script Mediator
From: va...@wso2.com
To: awanth...@wso2.com
CC: mlaka...@hotmail.com; dev@wso2.org

What is the real motivation you to use script mediator instead of payload 
factory?
You can easly construct jaon payload with payload factory 

On Wednesday, January 7, 2015, Awanthika Senarath  wrote:
Hi Maz,
Can you follow the format at [1] and see whether it works? This explains the 
sample 351 in ESB. 
[1] 
https://docs.wso2.com/display/ESB480/Sample+351%3A+Inline+script+mediation+with+JavaScript
On Wed, Jan 7, 2015 at 4:03 AM, Maz Lakadia  wrote:



Hi, I'm using script mediator to mediate the response payload from my server. 
The unmediated response is:
{"origin":"202.37.75.130"}
I then add in a mediator via source code, that should change "origin" to 
"IP_Address":
   <![CDATA[ old_payload = 
mc.getPayloadJSON();  payload["IP_Address"] 
= old_payload["origin"];  
mc.setPayloadJSON(payload); ]]>
   
   
 
 
  
However, my response remains unchanged (same as the unmediated response). I do 
not know how I can fix this. Is there an error I am making?

Thanks,
Maz   

___

Dev mailing list

Dev@wso2.org

http://wso2.org/cgi-bin/mailman/listinfo/dev




-- 
Awanthika Senarath
Software Engineer, WSO2 Inc.


Mobile: +94717681791





-- 
Sent from Gmail Mobile
  ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] Payload mediation of JSON message using Script Mediator

2015-01-06 Thread Maz Lakadia
Hi, I'm using script mediator to mediate the response payload from my server. 
The unmediated response is:
{"origin":"202.37.75.130"}
I then add in a mediator via source code, that should change "origin" to 
"IP_Address":
   
   
   
 
 
  
However, my response remains unchanged (same as the unmediated response). I do 
not know how I can fix this. Is there an error I am making?

Thanks,
Maz   ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] Payload Factory sending back object wrapped in "jsonObject"

2015-01-06 Thread Maz Lakadia
Hi, I am mediating a message using Payload Factory Mediator. The unmediated 
message is:

{ "origin": "202.68.75.242"}

My mediated payload is meant to be:
{ "ip_address": "202.68.75.242"}

Instead it gives me back:

{  "jsonObject" :{ "ip_address": "202.68.75.242"}
}

How can I get rid of the "jsonObject" wrapper?  
  ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] Empty Response from Server when using Payload Factory Mediator

2015-01-05 Thread Maz Lakadia
I'm modifying a response sent by a server. To do this I've set up a test API 
that is meant to just send back the IP, in a format like this:{
  "origin": "202.37.75.130"
}
My unmodified code gives me back what I want.What I wish to do as a test is to 
change the name of "origin" to "IP Address", hopefully getting a response like 
this:{
  "IP Address": "202.37.75.130"
}
To do this I've modified my outSequence section of the code, to be this (all 
I've added is the PayloadFactoryMediator section, the filter was there before):

  
{
  "IP Address" : {
  "$1"
  }
  }


  

  
  

  
  

  
  

However, when I curl to the API as before I get a response:curl: (52) Empty 
reply from serverCan anybody tell me what I may have done wrong?
Thanks,
Maz   ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] Meaning of XML Tags

2015-01-05 Thread Maz Lakadia
Hi, I'm trying to modify some given source code to try and add in a Mediator of 
my own. I'm trying to understand the code, and am having a hard time with some 
tags. Is there documentation specifically for the tags available? 
Thanks,
Maz   ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] Mediating a Server Response

2015-01-04 Thread Maz Lakadia
Thanks for your reply.

My data is JSON format, does that change your opinion about what I should use? 
Also, is Script Mediator recommended for this task?Date: Mon, 5 Jan 2015 
07:19:26 +0530
Subject: Re: [Dev] Mediating a Server Response
From: chana...@wso2.com
To: mlaka...@hotmail.com
CC: dev@wso2.org

Hi Maz,

WSO2 ESB provides the following mediators which you can use to transform a 
message.

1) Enrich mediator - For simple transformations like enriching a field to a 
message

2) PayloadFactory mediator - Somewhat advanced transformations. You can use 
this for changing the elements of an xml message and create a completely new 
message. This is the best option for your case

3) XSLT mediator - You can write XSLT tranformation code to transform the 
message.

4) XQuery mediator - You can write XQuery code to transform the message.


Here is the documentation for ESB mediators.

https://docs.wso2.com/display/ESB481/Mediators


Thanks,
Chanaka


On Mon, Jan 5, 2015 at 3:39 AM, Maz Lakadia  wrote:



Hi,

I would like to mediate a response from my server. This mediation would be 
changing something like:

{   "Quote":{  "Current":{ "High":-61.53602401623976, 
"Last":62.32682938796667  },  "Code":"WSO2",  
"Price":62.32682938796667   },   "Status":"NOT-OK"}

into 
{   "Estimate":{  "Now":{ "Max":-61.53602401623976  },  
"Company_Name":"WSO2",  "Worth":62.32682938796667   },   "Status":"Not 
Good"}
What I need is to change the name of some fields, delete others, possibly 
modify the values of some fields and add some fields.

What mediator(s) would you suggest I use for such a task. 

Thanks, 

Maz   

___

Dev mailing list

Dev@wso2.org

http://wso2.org/cgi-bin/mailman/listinfo/dev




-- 
--
Chanaka Fernando
Technical Lead
WSO2, Inc.; http://wso2.com


lean.enterprise.middleware

mobile: +94 773337238
Blog : http://soatutorials.blogspot.com
LinkedIn:http://www.linkedin.com/pub/chanaka-fernando/19/a20/5b0Twitter:https://twitter.com/chanakaudayaWordpress:http://chanakaudaya.wordpress.com




  ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] Mediating a Server Response

2015-01-04 Thread Maz Lakadia
Hi,

I would like to mediate a response from my server. This mediation would be 
changing something like:

{   "Quote":{  "Current":{ "High":-61.53602401623976, 
"Last":62.32682938796667  },  "Code":"WSO2",  
"Price":62.32682938796667   },   "Status":"NOT-OK"}

into 
{   "Estimate":{  "Now":{ "Max":-61.53602401623976  },  
"Company_Name":"WSO2",  "Worth":62.32682938796667   },   "Status":"Not 
Good"}
What I need is to change the name of some fields, delete others, possibly 
modify the values of some fields and add some fields.

What mediator(s) would you suggest I use for such a task. 

Thanks, 

Maz   ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] Modifying Samples for Testing

2014-12-28 Thread Maz Lakadia
Sorry, I did not word my question well.

I mean instead of sending requests to 
"http://localhost:9000/services/SimpleStockQuoteService";, I want to send 
requests to "httpbin.org" for testing purposes.Date: Mon, 29 Dec 2014 07:58:54 
+0530
Subject: Re: [Dev] Modifying Samples for Testing
From: mal...@wso2.com
To: mlaka...@hotmail.com
CC: dev@wso2.org

Hi,

You need to change the uri [1] from the synapse configuration.

To update sequences, etc. in ESB, you can either use the ESB management console 
or copy the XML configuration to the source view. You can find the source view 
under menu Manage > Service Bus > Source View in the left navigation pane of 
the WSO2 ESB management console.

[1] http://localhost:9000/services/SimpleStockQuoteService"/>

On Mon, Dec 29, 2014 at 3:11 AM, Maz Lakadia  wrote:



Hi, 

I am currently using Sample 350 and playing around with it to see what I can do 
with script mediator. However, I'd like to change the address that I send 
requests to. Is there a way I can change the URL that I send requests to?

Thank you for your time,

Maz   

___

Dev mailing list

Dev@wso2.org

http://wso2.org/cgi-bin/mailman/listinfo/dev




-- 

Best Regards,
Malaka Silva
Senior Tech Lead
M: +94 777 219 791Tel : 94 11 214 5345
Fax :94 11 2145300 Skype : malaka.sampath.silvaLinkedIn : 
http://www.linkedin.com/pub/malaka-silva/6/33/77Blog : 
http://mrmalakasilva.blogspot.com/

WSO2, Inc. lean . enterprise . middleware 
http://www.wso2.com/
http://www.wso2.com/about/team/malaka-silva/

Save a tree -Conserve nature & Save the world for your future. Print this email 
only if it is absolutely necessary.

  ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] Modifying Samples for Testing

2014-12-28 Thread Maz Lakadia
Hi, 

I am currently using Sample 350 and playing around with it to see what I can do 
with script mediator. However, I'd like to change the address that I send 
requests to. Is there a way I can change the URL that I send requests to?

Thank you for your time,

Maz   ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] Script Mediator for JSON

2014-12-22 Thread Maz Lakadia
I am trying to use Script Mediator to convert a message Payload. However, 
Samples are all using a method called getPayloadXML. My Payload will be in JSON 
form; is there a JSON equivalent of this? I could transform the Payload to XML 
for my mediations, but that's a last resort. 

Thank you,

Maz   ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] Transforming Message Content

2014-12-21 Thread Maz Lakadia
Hello,I am currently trying to create an application that will help to output 
data in a specific format for a user to view on a website. The way I am 
thinking about doing this is by using WSO2 Payload Factory Mediator to modify 
the client request to be what the server database expects. Then I can modify 
the server's response to output in the form expected by the client. My database 
is JSON, not XML. I had a look at Sample 17 
(https://docs.wso2.com/pages/viewpage.action?pageId=33136018) on the WSO2 
website for ESB. However, that is an XML example. I was wondering if there was 
a similar example, but for JSON. Even if the method used does not utilise 
Payload Factory Mediator I would be open to using it. Thank you for your 
time,Maz ___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev