mule - Xml to Json Custom Transformer Not responding -


i trying convert xml response json per below flow

<?xml version="1.0" encoding="utf-8"?>  <mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"     xmlns:spring="http://www.springframework.org/schema/beans" version="ee-3.4.1"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">     <data-mapper:config name="json_to_xml" transformationgraphpath="json_to_xml.grf" doc:name="json_to_xml"/>     <custom-transformer class="org.hhmi.transformer.xmltojson" name="xmltojson" doc:name="java" mimetype="application/json"/>     <flow name="sumtotalflow1" doc:name="sumtotalflow1">         <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="9119" doc:name="http"/>         <logger level="info" doc:name="logger"/>         <data-mapper:transform config-ref="json_to_xml" doc:name="json xml"/>         <logger level="debug" doc:name="logger" message="#[message.payload]"/>         <https:outbound-endpoint exchange-pattern="request-response" host="stage.sumtotalsystems.com" port="443" path="webservice/services/wfm3service" method="post" doc:name="http" contenttype="text/xml"/>         <logger message="soap resonse sumtotal #[message.payload]" level="debug" doc:name="logger"/>         <mulexml:xslt-transformer mimetype="text/xml" maxidletransformers="2" maxactivetransformers="5" xsl-file="xmlresponse.xsl" doc:name="xslt"/>         <object-to-string-transformer mimetype="text/xml" doc:name="object string"/>      <transformer ref="xmltojson" doc:name="xmltojson"/>     </flow> </mule> 

the flow working till object string transformer. below custom transformer xmltojson conversion. seems hang @ xmlsearlizer.read(xml) line .

import net.sf.json.json; import net.sf.json.xml.xmlserializer;  import org.apache.log4j.logger; import org.mule.api.transformer.transformerexception; import org.mule.transformer.abstracttransformer;  public class xmltojson extends abstracttransformer {     public static logger logger = logger.getlogger(xmltojson.class);      @override     protected object dotransform(object src, string enc)             throws transformerexception {          // string xml = (string) src;         logger.debug("xmltojson payload " + src.tostring());         system.out.println("xmltojson payload " + src.tostring());         xmlserializer xmlserializer = new xmlserializer();         xmlserializer.setskipnamespaces(true);         xmlserializer.settrimspaces(true);         xmlserializer.setremovenamespaceprefixfromelements(true);         json json = xmlserializer.read(src.tostring());         system.out.println("xmltojson json.tostring() " + json.tostring());         return json.tostring();     } } 

any appreciated. thanks.

if use xmlserializer net.sf.json-lib have bring optional xom dependency otherwise execution fail.

use:

    <dependency>         <groupid>net.sf.json-lib</groupid>         <artifactid>json-lib</artifactid>         <version>2.4</version>         <classifier>jdk15</classifier>     </dependency>     <dependency>         <groupid>xom</groupid>         <artifactid>xom</artifactid>         <version>1.1</version>     </dependency> 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -