Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Beginner. Please help (Part 2. Result)

*Message imported, originaly posted: Wed, 08 Feb 2012 14:34:20 .
So we where able to pass parameters to a service through Mule. Next step is to actually get data back. I am trying to figure out how to get the result as a string containing XML and as a FundStatementResult
object

This is what I tried to far. I changed between xml-to-object-transformer
and object-to-xml-transformer
I tried giving the transformer a returnClass
I tried using the automatic transfomer with a returnClass
I tried without any transformer
I tried adding JAXB annotations into the value object returned by the service
I tried casting to FundStatementResultI tried casting to String
I tried without casting
The exceptions I usually get:
java.lang.ClassCastException: org.mule.transport.http.ReleasingInputStream cannot be cast to za.co.discoveryinvest.objectmodel.notificationcontrol.FundStatementResultjava.lang.ClassCastException: org.mule.transport.http.ReleasingInputStream cannot be cast to java.lang.String

I used this example to find that I am supposed to cast the results from the payload
http://www.mulesoft.org/documentation...

MuleClient client = new MuleClient(muleContext);
Date from = new GregorianCalendar(2011, 10, 1).getTime();
Date to = new GregorianCalendar(2011, 11, 1).getTime();

Object] args = new Object[{"8550000053", "1031276775", from, to, "D"};
MuleMessage result = client.send("http://localhost:3883/retrieveFundSta..., args, null, 100000);
System.out.println((FundStatementResult) result.getPayload());
<byte-array-to-object-transformer name="ByteArrayToObject" />
<xm:xml-to-object-transformer name="XmlToObject"/>
<flow name="main">
<composite-source>
<http:inbound-endpoint
transformer-refs="ByteArrayToObject"
host="localhost" port="3883"
path="retrieveFundStatementProc"
exchange-pattern="request-response">
</http:inbound-endpoint>

<vm:inbound-endpoint path="retrieveFundStatementProc" exchange-pattern="request-response"/>
</composite-source>

<!-- TODO add your service component here. This can also be a Spring bean using <spring-object bean="name"/> -->
<pooled-component>
<spring-object bean="retrieveFundStatementProc"/>
</pooled-component>
<vm:outbound-endpoint path="out"/>
<http:outbound-endpoint transformer-refs="XmlToObject" host="localhost" port="3883"/>
</flow>





1 person has
this question
+1
Reply
  • *Message imported, originaly posted: Fri, 03 Dec 2010 11:58:45 .
    You do not need outbound endpoints to get data back: your inbound endpoints
    are request-response ones so the response will get back through them.

    So you can remove the outbound endpoints and add a response transformer on
    the inbound HTTP endpoint. This response transformer would usually be the
    alter ego of the inbound transformer (say: xml-to-object-transformer for the
    inbound transformer and object-to-xml-transformer for the response
    transformer).

    HTH
    D.
    On Fri, Dec 3, 2010 at 5:12 AM, Kobus du Toit <
    mule dot user dot relay at mulesource dot com> wrote:

    So we where able to pass parameters to a service through Mule. Next step
    is to actually get data back. I am trying to figure out how to get the
    result as a string containing XML and as a FundStatementResult
    object
    This is what I tried to far. I changed between xml-to-object-transformer
    and object-to-xml-transformer
    I tried giving the transformer a returnClass
    I tried using the automatic transfomer with a returnClass
    I tried without any transformer
    I tried adding JAXB annotations into the value object returned by the
    service
    I tried casting to FundStatementResultI tried casting to String
    I tried without casting




    The exceptions I usually get:
    java.lang.ClassCastException: org.mule.transport.http.ReleasingInputStream
    cannot be cast to
    za.co.discoveryinvest.objectmodel.notificationcontrol.FundStatementResultjava.lang.ClassCastException:
    org.mule.transport.http.ReleasingInputStream cannot be cast to
    java.lang.String


    I used this example to find that I am supposed to cast the results from the
    payload


    http://www.mulesoft.org/documentation/display/MULE2USER/Using+the+Mule+Client


    MuleClient client = new MuleClient(muleContext);
    Date from = new GregorianCalendar(2011, 10, 1).getTime();
    Date to = new GregorianCalendar(2011, 11, 1).getTime();


    Object] args = new Object[{"8550000053", "1031276775", from, to,
    "D"};
    MuleMessage result = client.send("
    http://localhost:3883/retrieveFundStatementProc", args, null, 100000);
    System.out.println((FundStatementResult) result.getPayload());




    <byte-array-to-object-transformer name="ByteArrayToObject" />
    <xm:xml-to-object-transformer name="XmlToObject"/>




    <flow name="main">
    <composite-source>
    <http:inbound-endpoint
    transformer-refs="ByteArrayToObject"
    host="localhost" port="3883"
    path="retrieveFundStatementProc"
    exchange-pattern="request-response">
    </http:inbound-endpoint>


    <vm:inbound-endpoint path="retrieveFundStatementProc"
    exchange-pattern="request-response"/>
    </composite-source>


    <!-- TODO add your service component here. This can also be a
    Spring bean using <spring-object bean="name"/> -->
    <pooled-component>
    <spring-object bean="retrieveFundStatementProc"/>
    </pooled-component>
    <vm:outbound-endpoint path="out"/>
    <http:outbound-endpoint transformer-refs="XmlToObject"
    host="localhost" port="3883"/>
    </flow>















  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • *Message imported, originaly posted: Fri, 03 Dec 2010 15:05:54 .
    Cool. Will try Monday. Didn't make sense that I needed an extra outbound decleration
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • *Message imported, originaly posted: Mon, 06 Dec 2010 08:38:02 .
    I tried:
    • XmlToObject, ObjectToXml transformers on the return
    • Casting to String
    • Casting to FundStatementResult
    • Adding JAXB annotation to the value object

    The Java code
    MuleMessage result = client.send("http://localhost:3883/retrieveFundSta..., args, null, 100000);
    System.out.println((FundStatementResult) result.getPayload());

    I get (depending on the cast)- org.mule.transport.http.ReleasingInputStream cannot be cast to java.lang.Stringor
    java.lang.ClassCastException: org.mule.transport.http.ReleasingInputStream cannot be cast to za.co.discoveryinvest.objectmodel.notificationcontrol.FundStatementResult

    <xm:object-to-xml-transformer name="ObjectToXml"/>
    <xm:xml-to-object-transformer name="XmlToObject"/>
    <flow name="main">
    <composite-source>
    <http:inbound-endpoint
    transformer-refs="ByteArrayToObject"
    responseTransformer-refs="XmlToObject"
    host="localhost" port="3883"
    path="retrieveFundStatementProc"
    exchange-pattern="request-response">
    </http:inbound-endpoint>

    <vm:inbound-endpoint path="retrieveFundStatementProc" exchange-pattern="request-response"/>
    </composite-source>

    <!-- TODO add your service component here. This can also be a Spring bean using <spring-object bean="name"/> -->
    <pooled-component>
    <spring-object bean="retrieveFundStatementProc"/>
    </pooled-component>
    <vm:outbound-endpoint path="out"/>
    </flow>

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • *Message imported, originaly posted: Mon, 06 Dec 2010 11:07:15 .
    You're receiving an input stream as payload back from client.send so you
    can't cast it like that. You can use one of the helper methods on
    MuleMessage to get the payload under another form (byte[], string) depending
    on what you're expecting.

    D.

    PS. In your XML config, you use XmlToObject for inbound and ByteArrayToObject
    for response, is it really what you want?
    PPS. You still have an outbound VM endpoint.
    On Mon, Dec 6, 2010 at 6:38 AM, Kobus du Toit <
    mule dot user dot relay at mulesource dot com> wrote:

    I tried:
    • XmlToObject, ObjectToXml transformers on the return
    • Casting to String
    • Casting to FundStatementResult
    • Adding JAXB annotation to the value object
    The Java code
    MuleMessage result = client.send("
    http://localhost:3883/retrieveFundStatementProc", args, null, 100000);
    System.out.println((FundStatementResult) result.getPayload());


    I get (depending on the cast)- org.mule.transport.http.ReleasingInputStream
    cannot be cast to java.lang.Stringor
    java.lang.ClassCastException: org.mule.transport.http.ReleasingInputStream
    cannot be cast to
    za.co.discoveryinvest.objectmodel.notificationcontrol.FundStatementResult


    <xm:object-to-xml-transformer name="ObjectToXml"/>
    <xm:xml-to-object-transformer name="XmlToObject"/>




    <flow name="main">
    <composite-source>
    <http:inbound-endpoint
    transformer-refs="ByteArrayToObject"
    responseTransformer-refs="XmlToObject"
    host="localhost" port="3883"
    path="retrieveFundStatementProc"
    exchange-pattern="request-response">
    </http:inbound-endpoint>


    <vm:inbound-endpoint path="retrieveFundStatementProc"
    exchange-pattern="request-response"/>
    </composite-source>


    <!-- TODO add your service component here. This can also be a
    Spring bean using <spring-object bean="name"/> -->
    <pooled-component>
    <spring-object bean="retrieveFundStatementProc"/>
    </pooled-component>
    <vm:outbound-endpoint path="out"/>
    </flow>

















  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • *Message imported, originaly posted: Mon, 06 Dec 2010 22:59:26 .
    By George You've Done It :)
    I am able to pass in an array of parameters and receive the return result as XML (without needing JAXB annotations, as you said :)) and I can get the object back itself
    I tried different transformers now. The reason why I am passing in an array of values is because the MuleClient is executing old code that accepts a couple parameters. I don't want to change the old code to accept a single object. From my experience, working with the guys here, if you have a parameter value object they use it everywhere, because they are too lazy to create a new one for a new method so you end up with a parameter object with 100 properties, but only 5 get used by a specific method. That is the one reason. The other reason is now I can let other teams execute my service without giving them a client jar containing my value objects. Being able to return XML from the service allows them to parse the XML and do with it what they want, e.g. the Oracle developers have their own way of working with XML. They don't compile Java into their procs, nobody here knows how to do it and the DBA's don't like to manage it.
    Is it possible to pass in XML and convert it to the parameters I require? I can't imagine how. I will most likely have to add a method that accepts a parameter object. Maybe pass in the values on the URL? How will I do that?
    In case someone finds this post and they want an example, here is some of my code.
    I would recommend updating the examples on the website to have services with multiple parameters and a result of a complex object
    Example of what I am trying to stop
    public class FundSearchCriteriaBean extends SearchCriteriaBean implements Serializable
    {
    private static final long serialVersionUID = -2479646730982303396L;

    private static Method[] methods;

    private String fundTypeCd;
    private String fundManagementCompanyCd;
    private String fundCd;
    private String jseFundCd;
    private String fundIndice;
    private String fundIndex;
    private String aciSector;
    private String aciSectorGroup;
    private String fundRisk;
    private String perfTypeCd;
    private String benchmarkCd;
    private Date measurementDate;
    private Date periodStartDate;
    private Date periodEndDate;
    private String portfolioId;
    private HistoricRisk historicalRisk;
    private HistoricReturn historicalReturn;
    private String riskProfileCd;
    private String indicatorCd;
    private List<String> fundCds;
    private List<String> indCds;
    private Boolean latestMarketSectorAlloc;
    private BigDecimal startAmt;
    private Boolean discoveryFund;
    private LogInDisplay loggedIn;
    private Boolean princClass;
    private String fundName;
    private Boolean cumGrowthCompare;
    private FundCumGrowthCallType fundCumGrowthCallType;
    private Boolean includeNullPageLayout;
    private Boolean sortByPdfOrder;
    private Long trustNumber;
    Return an object
    MuleClient client = new MuleClient(muleContext);
    Date from = new GregorianCalendar(2011, 10, 1).getTime();
    Date to = new GregorianCalendar(2011, 11, 1).getTime();

    Object] args = new Object[{"8550000053", "1031276775", from, to, "D"};
    MuleMessage result = client.send("http://localhost:3883/retrieveFundSta..., args, null, 0);

    FundStatementResult fundStatementResult =
    (FundStatementResult) new ObjectInputStream(new ByteArrayInputStream(result.getPayloadAsBytes())).readObject();
    System.out.println(fundStatementResult);
    <byte-array-to-object-transformer name="ByteArrayToObject" />
    <object-to-byte-array-transformer name="ObjectToByteArray"/>
    <xm:object-to-xml-transformer name="ObjectToXml"/>
    <xm:xml-to-object-transformer name="XmlToObject"/>
    <flow name="main">
    <composite-source>
    <http:inbound-endpoint
    transformer-refs="ByteArrayToObject"
    responseTransformer-refs="ObjectToByteArray"
    host="localhost" port="3883"
    path="retrieveFundStatementProc"
    exchange-pattern="request-response"
    responseTimeout="0">
    </http:inbound-endpoint>

    <vm:inbound-endpoint path="retrieveFundStatementProc" exchange-pattern="request-response"/>
    </composite-source>

    <!-- TODO add your service component here. This can also be a Spring bean using <spring-object bean="name"/> -->
    <pooled-component>
    <spring-object bean="retrieveFundStatementProc"/>
    </pooled-component>
    </flow>
    Return XML
    MuleClient client = new MuleClient(muleContext);
    Date from = new GregorianCalendar(2011, 10, 1).getTime();
    Date to = new GregorianCalendar(2011, 11, 1).getTime();

    Object] args = new Object[{"8550000053", "1031276775", from, to, "D"};
    MuleMessage result = client.send("http://localhost:3883/retrieveFundSta..., args, null, 0);
    System.out.println(result.getPayloadAsString());
    <byte-array-to-object-transformer name="ByteArrayToObject" />
    <object-to-byte-array-transformer name="ObjectToByteArray"/>
    <xm:object-to-xml-transformer name="ObjectToXml"/>
    <xm:xml-to-object-transformer name="XmlToObject"/>
    <flow name="main">
    <composite-source>
    <http:inbound-endpoint
    transformer-refs="ByteArrayToObject"
    responseTransformer-refs="ObjectToXml"
    host="localhost" port="3883"
    path="retrieveFundStatementProc"
    exchange-pattern="request-response"
    responseTimeout="0">
    </http:inbound-endpoint>

    <vm:inbound-endpoint path="retrieveFundStatementProc" exchange-pattern="request-response"/>
    </composite-source>

    <!-- TODO add your service component here. This can also be a Spring bean using <spring-object bean="name"/> -->
    <pooled-component>
    <spring-object bean="retrieveFundStatementProc"/>
    </pooled-component>
    </flow>

    Edited by: Kobus du Toit on Dec 6, 2010 9:00 PM

























































  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • *Message imported, originaly posted: Mon, 06 Dec 2010 23:35:04 .
    I moved it to a new question

    Edited by: Kobus du Toit on Dec 7, 2010 12:35 AM
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated