I have a Web Service which I am trying to Autowire a variable into. Here is the class:
package com.xetius.isales.pr7.service;
import java.util.Arrays;
import java.util.List;
import javax.jws.WebService;
import org.springframework.beans.factory.annotation.Autowired;
import com.xetius.isales.pr7.domain.PR7Product;
import com.xetius.isales.pr7.domain.PR7Upgrade;
import com.xetius.isales.pr7.logic.UpgradeControllerInterface;
#WebService(serviceName="ProductRulesService",
portName="ProductRulesPort",
endpointInterface="com.xetius.isales.pr7.service.ProductRulesWebService",
targetNamespace="http://pr7.isales.xetius.com")
public class ProductRulesWebService implements ProductRulesWebServiceInterface {
#Autowired
private UpgradeControllerInterface upgradeController;
#Override
public List<PR7Product> getProducts() {
if (upgradeController == null) {
return Arrays.asList(new PR7Product("Fail"));
}
return upgradeController.getProducts();
}
#Override
public List<PR7Upgrade> getUpgrades() {
if (upgradeController == null) {
return Arrays.asList(new PR7Upgrade("Fail"));
}
return upgradeController.getUpgrades();
}
#Override
public List<PR7Product> getProductsForUpgradeWithName(String upgradeName) {
if (upgradeController == null) {
return Arrays.asList(new PR7Product("Fail"));
}
return getProductsForUpgradeWithName(upgradeName);
}
}
However, when I try to access the web service I am getting the Fail version returned, meaning that upgradeController is not being autowired. Here is my applicationContext:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.xetius.isales.pr7" />
<context:annotation-config />
<bean id="upgradeController" class="com.xetius.isales.pr7.logic.UpgradeController" />
</beans>
How do I make it so that the #WebService class is spring aware and autowiring happens
If you want autowiring to happen, ProductRulesWebService needs to extend SpringBeanAutowiringSupport
Extending that class will allow UpgradeController to be autowired
Use a stack like CXF, which supports Spring natively, then you can essentially do something like this:
<bean id="aService" class="com.xetius.isales.pr7.service.ProductRulesWebService " />
<jaxws:endpoint id="aServiceEndpoint" implementor="#aService" address="/aService" />
Depending on container version or even the Spring, hereinafter you will have an easy solution to expose your WSDL, use:
#PostConstruct
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
Related
I am writing (NUnit) unit tests that target a component of type MyService. Example:
public class MyService : IMyService
{
private readonly IMyRepo _myRepo;
public MyService (IMyRepo myRepo)
{
_myRepo = myRepo;
}
public MyService ()
{
_myRepo = new MyRepo();
}
...
}
I am trying to use AutoFixture as a factory that will generate my test target. I am also trying to have it (AutoFixture) populate my target with mock dependencies (using Moq).
Here's my attempt at doing this:
[Test, AutoMoqData]
public void MyTest(MyService target)
{
...
}
The [AutoMoqData] attribute (based on #ploeh's blog post) extends AutoFixture's [AutoData] attribute with AutoFixture's AutoMoqCustomization feature:
public class AutoMoqDataAttribute : AutoDataAttribute
{
public AutoMoqDataAttribute()
: base(new Fixture()
.Customize(new AutoMoqCustomization()))
{
}
}
When I run unit tests based on the above, I would like to get a real instance of MyService with a Mock<IMyRepo> dependency inside it.
Instead I'm getting a concrete instance of MyRepo.
It seems that AutoMoqCustomization opts to invoke the simplest constructor - the one with no arguments. How can I configure AutoMoqCustomizationto ignore it and instead instantiate the second constructor?
PS - Here is a list of the relevant nuget packages in use:
<package id="AutoFixture" version="3.50.2" targetFramework="net452" />
<package id="AutoFixture.AutoMoq" version="3.50.2" targetFramework="net452" />
<package id="AutoFixture.NUnit3" version="3.50.2" targetFramework="net452" />
<package id="Moq" version="4.5.29" targetFramework="net452" />
<package id="NUnit" version="3.5.0" targetFramework="net452" />
You can try to define a greedy constructor selection algorithm for AutoFixture, but really, the best solution is to remove the parameterless constructor:
public class MyService : IMyService
{
private readonly IMyRepo _myRepo;
public MyService (IMyRepo myRepo)
{
_myRepo = myRepo;
}
}
Having a parameterless constructor is a code smell called Bastard Injection. In most cases, there's no good reason for it.
In my opinion, the best option is to apply the GOOS principle of listening to your tests. When the test becomes difficult to write, it's time to reconsider the design of the System Under Test (SUT). AutoFixture tends to amplify this effect. That's what's happening here.
I am migrating an old NETCF 2.0 Application which uses webservices to NETCF 3.5. The webservice of the foreign server remains the same without changes. Also I newly generated Reference.cs using VS 2008 Command Prompt - and was excited to see the same result as using VS 2005.
My question relates to namespace definition at the root tag by a class which is defined by webservice. The java webservice serializes it with xmlns attribute and XmlSerializer.Deserialize() of NETCF 3.5 blames about this attribute throwing an InvalidOperationException. Using this XML and XmlSerializer.Deserialize() with NETCF 2.0 works as expected. The Object gets deserialized to memory.
Let a few code snippets make things clear.
Exception
InvalidOperationException-There is an error in XML document (2, 2).
InnerException: InvalidOperationException-<InstallDirective xmlns='java:my.foreign.namespace'> was not expected.
at System.Xml.Serialization.XmlSerializer.resolveDeserializingType(XmlReader reader, XmlSerializationReader serialReader, Boolean soap12)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)
at My.Neat.Software.Bug.Test()
generated Reference.cs (excerpt)
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="java:my.foreign.namespace")]
public partial class InstallDirective {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public System.Nullable<System.DateTime> Date;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public JustAnotherThing JustAnotherThing;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public System.Nullable<short> Oid;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public string Filename;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public string Version;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public string Dir;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public string Instructions;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Scripts", IsNullable=true)]
public Script[] Scripts;
}
the XML from webservice
<?xml version="1.0" encoding="utf-8"?>
<InstallDirective xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="java:my.foreign.namespace">
<Date>2014-02-11T13:31:49.238+01:00</Date>
<JustAnotherThing>
<FileName>MyFunnyFile.txt</CabFileName>
<Checksum>e759af8bd5787e3f8d62245a7d6aa73d</Checksum>
<FileExists xsi:nil="true" />
<Name>MyFunnyFile</Name>
<Version>1.2</Version>
<Path xsi:nil="true" />
<DependsOn xsi:nil="true" />
<RegistryPath xsi:nil="true" />
</JustAnotherThing>
<Oid>1</Oid>
<Filename>MyFunnyFile.txt</Filename>
<Version>1.2</Version>
<Dir>\My\Path\To\Files</Dir>
<Instructions xsi:nil="true" />
<Scripts xsi:nil="true" />
</InstallDirective>
the code snippet which throws the exception
FileInfo directiveFile = new FileInfo(#"\tmp\install\funnyInstallDirective.xml");
XmlSerializer xmlSerializer = new XmlSerializer(typeof(InstallDirective));
TextReader reader = new StreamReader(directiveFile.OpenRead());
InstallDirective installDirective = (InstallDirective)xmlSerializer.Deserialize(reader); // BAM!
Thanks for your help!
Indeed the XmlSerializer implementation of .Net Compact Framework 2.0 and 3.5 differs. The solution to this "new" behaviour is easy as well. Because the XmlSerializer which - in my case - serializes XML as a "fragment", we need to declare the XmlRootAttribute. This is due to missing XmlRootAttribute annotation of the type to be serialized within the Reference.cs.
To be backward compatible with XML serialized by NETCF 2.0 implementation, we need to add the namespace by definition of InstallDirective (Reference.cs). Unfortunately I found no programmatically way to get this.
Before:
XmlSerializer xmlSerializer = new XmlSerializer(typeof(InstallDirective));
FileStream file = File.Create(#"\tmp\install\funnyInstallDirective.xml");
TextWriter writer = new StreamWriter(file);
xmlSerializer.Serialize(writer, installDirective);
After:
XmlRootAttribute att = new XmlRootAttribute(typeof(InstallDirective).Name);
att.Namespace = "java:my.foreign.namespace";
XmlSerializer xmlSerializer = new XmlSerializer(typeof(InstallDirective), att);
FileStream file = File.Create(#"\tmp\install\funnyInstallDirective.xml");
TextWriter writer = new StreamWriter(file);
xmlSerializer.Serialize(writer, installDirective);
Credits to ta.speot.is who answered the question here.
[UPDATE]
Of course you can beautify it by using the annotated XmlTypeAttribute of the web service type. It will look this way.
XmlTypeAttribute ta = (XmlTypeAttribute)Attribute.GetCustomAttribute(typeof(InstallDirective), typeof(XmlTypeAttribute));
XmlRootAttribute att = new XmlRootAttribute(typeof(InstallDirective).Name);
att.Namespace = ta.Namespace;
XmlSerializer xmlSerializer = new XmlSerializer(typeof(InstallDirective), att);
I am working in a JAXWS/JAXB web service environment. JAXWS out of the box uses uses the JAXB to marshal/unmarshaler the web service payloads.
I also have a requirement to audit all request and response payloads.
I want a compact and concise marshaled representation of the payload for the audit (as a irrelevant side note - I am auditing using a java.util.concurrent.BlockingQueue and some consumer threads to put batches of audit data in the audit datasource).
I have binary content(mtom) included on some web service response payloads but I DO NOT want to marshal audit these because the serialized base64 would be too large.
So my need is to create a marshaller (exclusively for auditng) that in all cases will scrub binary content but then NOT scrub for the prime purpose of marshalling web service response payloads. I do XSD to Java xjc. I need to use the same XSD/JAXB namespace for both contexts/marshallers.
Java type converter:
<jxb:javaType name=""
parseMethod="com.xxx.xxx.ws.converter.XXXLongConverter.parseXXXLong"
printMethod="com.xxx.xxx.ws.converter.XXXLongConverter.printXXXLong" />
is will not work because 1. I would need to unregister the adapter http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/Marshaller.html#setAdapter%28java.lang.Class,%20A%29
for the marshaller and I don't THINK I have a hook into that for JAXWS. 2. I can't be guaranteed the class name that JAXB will decide to create in order to unregister it.
I created my own XMLAdapter and used the annox jaxb plugin
but that didn't really work for the same reasons the above didn't work.
Update: I now tried manually and reflectively walking through payload(to be audited) prior to marshalling to scrub the binary data but that got to be too much pain for what it was worth.
I should also mention that for brevity of the audit I am using jersey JSON serialization supporting JAXB
but I don't think that takes away or adds to my base problem:
How can I scrub data in one marshaller/unmarshaller but not another but both whose origin is the same JAXB context?
UPDATE: Never figured out an elegate way to do this. Not really possible at this point with the frameworks as they are. UPDATE: Not true. Extending AttachmentMarshaller (I like this a lot and will use it) or creating a "need-aware" XmlAdapter would work for the audit specific marshaller as #Blaise answers below.
UPDATE: If I may take this a step further to round out my use case...I mentioned above that for brevity of the audit I'd like to do Json Serialization of the JSONJAXBContext using jersey apis, specifically using the JSONMarshaller but the interface does not define setAdapter and setAttachmentMarshaller. Coming out of JSONJAXBContext.createJSONMarshaller() is a JSONMarshallerImpl implementation which do define these this methods. I will grudgingly cast to impl so I can set my custom attachment marshaller.
How can I scrub data in one marshaller/unmarshaller but not another
but both whose origin is the same JAXB context?
You could set your own implementation of AttachemntMarshaller and set it on the Marshaller that you are using for auditing.
Root
Below is a sample domain object with a byte[] property that by default will be represented as an element of type base64Binary.
package forum8914008;
import javax.xml.bind.annotation.*;
#XmlRootElement
#XmlAccessorType(XmlAccessType.FIELD)
public class Root {
byte[] bytes;
}
Demo
The demo code below first marshals the object to XML, and then marshals it a second time with a custom impplementation of AttachmentMarshaller set.
package forum8914008;
import javax.activation.DataHandler;
import javax.xml.bind.*;
import javax.xml.bind.attachment.AttachmentMarshaller;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Root.class);
Root root = new Root();
root.bytes = "Hello World".getBytes();
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(root, System.out);
marshaller.setAttachmentMarshaller(new AttachmentMarshaller() {
#Override
public boolean isXOPPackage() {
return true;
}
#Override
public String addMtomAttachment(DataHandler arg0, String arg1,
String arg2) {
return "fake";
}
#Override
public String addMtomAttachment(byte[] arg0, int arg1, int arg2,
String arg3, String arg4, String arg5) {
return "fake";
}
#Override
public String addSwaRefAttachment(DataHandler arg0) {
return "fake";
}
});
marshaller.marshal(root, System.out);
}
}
Output
Below is the output from running the demo code. The first XML document could grow to be quite large if the byte[] was big. The second XML document would stay the same size.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<bytes>SGVsbG8gV29ybGQ=</bytes>
</root>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<bytes>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="fake"/>
</bytes>
</root>
How can I scrub data in one marshaller/unmarshaller but not another
but both whose origin is the same JAXB context?
You could support this use case with an XmlAdapter.
XmlAdapter (ByteArrayAdapter)
The following XmlAdapter is used to convert a byte[] to a byte[]. In its default state it will return the original byte[], it also has a audit state where it will return an empty byte[].
package forum8914008;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class ByteArrayAdapter extends XmlAdapter<byte[], byte[]> {
private boolean audit;
public ByteArrayAdapter() {
this(false);
}
public ByteArrayAdapter(boolean audit) {
this.audit = audit;
}
#Override
public byte[] marshal(byte[] bytes) throws Exception {
if(audit) {
return new byte[0];
}
return bytes;
}
#Override
public byte[] unmarshal(byte[] bytes) throws Exception {
return bytes;
}
}
package-info
The #XmlJavaTypeAdapter annotation is used tp register the XmlAdapter. When used at the package level it will apply to all properties of the specified type in that package (see: http://blog.bdoughan.com/2012/02/jaxb-and-package-level-xmladapters.html).
#XmlJavaTypeAdapter(value=ByteArrayAdapter.class, type=byte[].class)
package forum8914008;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
Root
Below is a sample domain object with a byte[] property that by default will be represented as an element of type base64Binary.
package forum8914008;
import javax.xml.bind.annotation.*;
#XmlRootElement
#XmlAccessorType(XmlAccessType.FIELD)
public class Root {
byte[] bytes;
}
Demo
The demo code below first marshals the object with the default state of the ByteArrayAdapter which will return the real byte[] and the marshals the object a second time with a stateful ByteArrayAdapter set which will convert all byte[] values to an empty byte[].
package forum8914008;
import javax.xml.bind.*;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Root.class);
Root root = new Root();
root.bytes = "Hello World".getBytes();
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(root, System.out);
marshaller.setAdapter(new ByteArrayAdapter(true));
marshaller.marshal(root, System.out);
}
}
Output
Below is the output from running the demo code. The XmlAdapter would apply to all mapped fields/properties of type byte[].
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<bytes>SGVsbG8gV29ybGQ=</bytes>
</root>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<bytes></bytes>
</root>
I have written sample program which uses XSLT to generate HTML response. Check below files.
welcome.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://xml.apache.org/xalan/java" version="1.0">
<xsl:output method="html" indent="yes" />
<xsl:variable name="myResource" select="java:java.util.ResourceBundle.getBundle('com.carbonrider.web.xslt.AppResources')" />
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="first">
<h2>
<xsl:value-of select="java:getString($myResource,'hi')" />
</h2>
</xsl:template>
</xsl:stylesheet>
PageTransformer.java
package curiousmind.web.xslt;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
public class PageTransformer extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
TransformerFactory transFactory = TransformerFactory.newInstance();
try {
DOMSource domSource = createDOMSource();
Transformer transformer = transFactory.newTransformer(new StreamSource(this.getClass().getResourceAsStream("welcome.xsl")));
Result result = new javax.xml.transform.stream.StreamResult(response.getWriter());
transformer.transform(domSource, result);
} catch (Exception e) {
throw new ServletException(e);
}
}
private DOMSource createDOMSource() throws Exception {
String xmlString = "<?xml version=\"1.0\" ?>\n<first><second>Hello World</second></first>";
byte[] buf = xmlString.getBytes("UTF-8");
BufferedInputStream is = new BufferedInputStream(new ByteArrayInputStream(buf));
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
Document dom = domBuilder.parse(is);
DOMSource domSource = new DOMSource(dom);
is.close();
return domSource;
}
}
When I run above code, I get following error message in console
ERROR [STDERR] SystemId Unknown; Line #7; Column #95; java.util.MissingResourceException: Can't find bundle for base name curiousmind.web.xslt.AppResources, locale en_US
Here is the properties file kept inside curiousmind.web.xslt
AppResources.properties
hi=Hello World
Can anyone please tell me what could be the problem?
I tried to access the resource bundle from same servlet "PageTransformer" by instantiating java.util.ResourceBundle and it worked. This lead to more confusion as why transformer instantiated from same class is not able to get the ResourceBundle instance.
I added xalan.jar file, but it gave same result.
Finally I thought of enabling "-verbose" mode for jboss as to find out, what could be the actual cause. This gave me hint that, when the servlet is getting invoked and it is instantiating Transformer, it is loading xalan.jar file from JBOSS_DIR/lib/endorsed/xalan.jar. I had to finally remove "xalan.jar" and "serializer.jar" file from jboss and my page worked well.
Though this solved problem, I think better approach would be to use "jboss-classloading.xml" to customize the classloading behavior. But couldn't get appropriate configuration for that.
I have this FlexMobile Project that retrieves a cart array from a http web service. If the cart has no items in it, the json returned is empty, thus causing a parse error
Here is the JSON response:
{ "cart": [ ] }
Here is the error:
Error: Error while Parsing
at com.adobe.serializers.json::JSONDecoder/parseValue()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONDecoder.as:249]
at com.adobe.serializers.json::JSONDecoder/parseArray()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONDecoder.as:431]
at com.adobe.serializers.json::JSONDecoder/parseValue()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONDecoder.as:222]
at com.adobe.serializers.json::JSONDecoder/parseObject()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONDecoder.as:339]
at com.adobe.serializers.json::JSONDecoder/parseValue()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONDecoder.as:217]
at com.adobe.serializers.json::JSONDecoder/decode()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONDecoder.as:178]
at com.adobe.serializers.json::JSONSerializationFilter/deserializeResult()[C:\opt\sb\ide_trunk\ide_builder\com.adobe.flexbuilder.dcrad\serializers\src\com\adobe\serializers\json\JSONSerializationFilter.as:78]
at mx.rpc.http::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::processResult()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\http\AbstractOperation.as:967]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:313]
at mx.rpc::Responder/result()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\Responder.as:56]
at mx.rpc::AsyncRequest/acknowledge()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84]
at DirectHTTPMessageResponder/completeHandler()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:451]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Here is the code I am using. This is my first attempt at a flex application, so expect newbie methods etc...
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:rincomobile="services.rincomobile.*"
title="view_cart">
<fx:Script>
<![CDATA[
import com.adobe.serializers.utility.TypeUtility;
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
private function onFault( event : FaultEvent ) : void
{
trace(event.fault.message.toString());
}
protected function list_creationCompleteHandler(event:FlexEvent):void {
getCartResult.token = rincoMobile.getCart("getCart");
getCartTotalResult.token = rincoMobile.getCartTotal("getCartTotal");
}
protected function getCartTotal(fuseaction:String):void {
getCartTotalResult.token = rincoMobile.getCartTotal(fuseaction);
}
protected function getCartResult_faultHandler(event:FaultEvent):void
{
// TODO Auto-generated method stub
trace("something happened");
}
]]>
</fx:Script>
<fx:Declarations>
<s:CallResponder id="getCartResult" fault="onFault(event)" />
<rincomobile:RincoMobile id="rincoMobile" />
<s:CallResponder id="getCartTotalResult"/>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:List id="list" left="0" right="0" top="0" bottom="176" borderVisible="false"
creationComplete="list_creationCompleteHandler(event)"
itemRenderer="renderers.cartRenderer" labelField="item_code">
<s:AsyncListView list="{TypeUtility.convertToCollection(getCartResult.lastResult.cart)}"/>
</s:List>
<s:Button id="btn_checkout" bottom="93" width="90%" label="${getCartTotalResult.lastResult.cart[0].total} Checkout" chromeColor="#091A33" horizontalCenter="0"/>
<s:Button bottom="10" width="90%" label="Continue Shopping" chromeColor="#091A33"
horizontalCenter="0"/>
</s:View>
The empty array is a know issue with Flex JSON serializer decoder. Supposedly it will be fixed in flex4.5. See the following link:
http://forums.adobe.com/thread/605070