Hi,
Thanks for the replies. I was able to get error message removing JsonObject
element using following enrich mediator block.

<enrich>
                   <source clone="true" xpath="$body//jsonObject//error"/>
                   <target type="body"/>
 </enrich>

On Tue, Nov 4, 2014 at 5:07 AM, Dilan Udara Ariyaratne <[email protected]>
wrote:

> Hi Asanka,
>
> If I understood your requirement correctly, you can try this out.
>
> In your code, figure out a way to access the xml based or json based
> custom error response that you generate, so that you can easily assign that
> value to an OMNode or a JSONObject.
> Once that is done, using the way we generally access an OMNode or
> JSONObject, you can simply extract the error message and display the
> content.
>
> Hope this may help.
>
> Thanks.
>
>
>
> *Dilan U. Ariyaratne*
> Software Engineer
> WSO2 Inc. <http://wso2.com/>
> Mobile: +94775149066
> lean . enterprise . middleware
>
> On Tue, Nov 4, 2014 at 12:22 PM, Senduran Balasubramaniyam <
> [email protected]> wrote:
>
>> Hi Asanka,
>>
>> Is your requirement to get the final output as json or xml ?
>> If it is xml then you can change the payload factory media-type to "xml"
>>
>> Thanks
>> Senduran
>>
>> On Tue, Nov 4, 2014 at 10:09 AM, Asanka Vithanage <[email protected]>
>> wrote:
>>
>>> Hi,
>>>
>>> I customized API manager main sequence to change the default error
>>> message according to below format.so now i am getting the error messages as
>>> below.
>>>
>>> *PayloadFactory:*
>>>
>>> <property name="ERROR_DETAIL" value="Unsupported Transport. The
>>> requested resource  is not available."/>
>>> <property name="ERROR_URL_POSTFIX" expression="$axis2:REST_URL_POSTFIX"/>
>>> <property name="ERROR_FORMAT_LINK" value="
>>> http://errors.api.wso2.com/wso2/"/>
>>>  <property name="ERROR_CODE" value="403"/>
>>>
>>> <payloadFactory media-type="json">
>>>                  <format>
>>>         {
>>>                         "message":"$1",
>>>
>>>   "_links":{
>>>                                         "about":{
>>>                                                 "href": "$2"
>>>                                         },
>>>
>>>                                         "help":{
>>>                                                 "href": "$3$4"
>>>                                         }
>>>
>>>                                 }
>>>
>>>         }
>>>                 </format>
>>>                 <args>
>>>                 <arg xmlns:soapenv="
>>> http://www.w3.org/2003/05/soap-envelope"; xmlns:ns3="
>>> http://org.apache.synapse/xsd"; evaluator="xml"
>>> expression="$ctx:ERROR_DETAIL"/>
>>>                 <arg xmlns:soapenv="
>>> http://www.w3.org/2003/05/soap-envelope"; xmlns:ns3="
>>> http://org.apache.synapse/xsd"; evaluator="xml"
>>> expression="$ctx:ERROR_URL_POSTFIX"/>
>>>                 <arg xmlns:soapenv="
>>> http://www.w3.org/2003/05/soap-envelope"; xmlns:ns3="
>>> http://org.apache.synapse/xsd"; evaluator="xml"
>>> expression="$ctx:ERROR_FORMAT_LINK"/>
>>>                 <arg xmlns:soapenv="
>>> http://www.w3.org/2003/05/soap-envelope"; xmlns:ns3="
>>> http://org.apache.synapse/xsd"; evaluator="xml"
>>> expression="$ctx:ERROR_CODE"/>
>>>                 </args>
>>>        </payloadFactory>
>>>
>>>
>>> *Error Results:*
>>>
>>> XML:
>>>
>>> <jsonObject><error><message>The requested resource is not 
>>> available.</message><_links><about><href>HelloService1/1.0.0/greet?name=Hi</href></about><help><href>http://errors.api.wso2.com/wso2/404
>>>  
>>> <http://errors.api.aligntech.com/wso2/404></href></help></_links></error></jsonObject>
>>>
>>> Json:
>>>
>>> {"jsonObject":{"error":{"message":"The requested resource is not 
>>> available.","_links":{"about":{"href":"HelloService1\/1.0.0\/greet?name=Hi"},"help":{"href":"http:\/\/errors.api.wso2.com
>>>  <http://errors.api.aligntech.com>\/wso2\/404"}}}}}
>>>
>>>
>>> Here my requirement is to remove the <jsonObject> element from the
>>> response and display only the error message. Is there any way to do this?
>>> Appreciate if anyone can provide some help on this.
>>>
>>> --
>>> Asanka Vithanage
>>> Senior Software Engineer -QA
>>> Mobile: +94 0716286708
>>> Email: [email protected]
>>> WSO2 Inc. www.wso2.com
>>>
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> [email protected]
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>> *Senduran *
>> Software Engineer,
>> WSO2, Inc.;  http://wso2.com/ <http://wso2.com/>
>> Mobile: +94 77 952 6548
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>


-- 
Asanka Vithanage
Senior Software Engineer -QA
Mobile: +94 0716286708
Email: [email protected]
WSO2 Inc. www.wso2.com
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to