Hi

On Fri, Jan 31, 2014 at 7:56 PM, Rasika Hettige <[email protected]> wrote:

> Hi,
>
> Please find the below queries which are currently en-counted.
>
> 1. Java Connector - parsing JSON as XML
> We found the following method in the Twitter connector to parse JSON as
> XML:
> private static OMElement parseJsonToXml(String sb) throws JSONException,
> XMLStreamException,
>                                               IOException {
>         OMElement elm = JsonBuilder.toXml(new
> ByteArrayInputStream(sb.getBytes()), false);
>         return elm;
>     }
>
> The JsonBuilder.toXml method seems to be deprecated. Is there an
> alternative
> for this?


  We did major refactoring to JSON by moving from Jettison to Staxon,
please refer org.apache.synapse.commons.json.JsonUtil under synapse commons.

>
> 2. To handle exceptions thrown within a Class mediator, we are using the
> following method as specified in Google Spreadsheets and Twitter ESB
> connectors:
> public static void storeErrorResponseStatus(MessageContext ctxt, Exception
> e) {
>         ctxt.setProperty(SynapseConstants.ERROR_EXCEPTION, e);
>         ctxt.setProperty(SynapseConstants.ERROR_MESSAGE, e.getMessage());
>     }
>
> Is this type of error handling sufficient? Or do we need to have a fault
> sequence within each synapse template?
>

  throwing exception there is nothing to re-invent, look at simple inbuilt
mediators, such as Iterator, Payload etc.. see how exceptions are handled..

catch (AxisFault af) {
            handleException("Error creating an iterated copy of the
message", af, synCtx);
        }


/**
     * Perform an error log message to all logs @ ERROR. Writes to the
general log, the service log
     * and the trace log (of trace is on) and throws a SynapseException
     * @param msg the log message
     * @param e an Exception encountered
     * @param msgContext the message context
     */
    protected void handleException(String msg, Exception e, MessageContext
msgContext) {
        log.error(msg, e);
        if (msgContext.getServiceLog() != null) {
            msgContext.getServiceLog().error(msg, e);
        }
        if (shouldTrace(msgContext.getTracingState())) {
            trace.error(msg, e);
        }
        throw new SynapseException(msg, e);
    }

>
>
> Thanks & Regards
>
>
>
>
> --
> View this message in context:
> http://wso2-oxygen-tank.10903.n7.nabble.com/Parsing-JSON-as-XML-and-handling-exceptions-tp91557.html
> Sent from the WSO2 Development mailing list archive at Nabble.com.
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>



-- 
Dushan Abeyruwan | Associate Tech Lead
Integration Technologies Team
PMC Member Apache Synpase
WSO2 Inc. http://wso2.com/
Blog:http://dushansview.blogspot.com/
Mobile:(0094)713942042
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to