2 Replies Latest reply on Jul 20, 2010 8:29 AM by heroicjanitor

    remoting help

    heroicjanitor

      I am using flex with a java back end, my test application is just a button that when i press it displays a string from a java class called HelloSayer. It works fine but when I change it to a different class(and give the remoting-config.xml a new destination) where I want it to return a tweet from a java class it fails and I think it is something to do with my xml, possibly the scope. I'd be grateful if someone could have a look through this since I am very new to flex and remoting.

      Here is the class when it works:

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

         xmlns:s="library://ns.adobe.com/flex/spark"

         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

        

      <fx:Script>

      <![CDATA[

      import mx.controls.Alert;

      import mx.rpc.AsyncToken;

      import mx.rpc.Responder;

      import mx.rpc.events.FaultEvent;

      import mx.rpc.events.ResultEvent;

      import mx.rpc.remoting.RemoteObject;

       

      protected function callJava(event:MouseEvent):void

      {

      var javaObject : RemoteObject = new RemoteObject("hello");

      var token : AsyncToken = javaObject.sayHello();

      token.addResponder(new mx.rpc.Responder(handleResult, handleFault));

      }

                  

      private function handleResult(event : ResultEvent) : void {

      Alert.show(event.result.toString());

      }

      private function handleFault(event : FaultEvent) : void {

      Alert.show(event.fault.message);

      }

      ]]>

      </fx:Script>

           

      <s:Button x="280" y="230" label="Contact Java" click="callJava(event)"/>

      </s:Application>

       

       

       

      And the xml:

       

       

      <?xml version="1.0" encoding="UTF-8"?>

      <service id="remoting-service"

          class="flex.messaging.services.RemotingService">

       

          <adapters>

              <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>

          </adapters>

       

          <default-channels>

              <channel ref="my-amf"/>

          </default-channels>

       

      <destination id="hello">

                 <properties>

                     <source>test.HelloSayer</source>

                     <scope>application</scope>

                 </properties>

           </destination>

       

      </service>

       

       

      but when i change callJava to this:

       

       

      protected function callJava(event:MouseEvent):void

      {

      var javaObject : RemoteObject = new RemoteObject("tweets");

      javaObject.setTweets(username, password); // tells java the username/password so it can make a list of tweets

      var token : AsyncToken = javaObject.getTweets(2); // This just returns the second tweet in the list as a string

      token.addResponder(new mx.rpc.Responder(handleResult, handleFault));

      }

       

       

      And add a destination in the xml like this:

       

       

      <destination id="tweets">

                 <properties>

                     <source>twitter.Tweets</source>

                     <scope>application</scope>

                 </properties>

           </destination>

       

      It gives me loads of errors.

      When I click the button it says:

      faultCode:Client.Error.MessageSend faultString:'Send failed' faultDetail:'Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 404: url: 'http://localhost/TestCombo/messagebroker/amf''

       

      And when I look in the console window it says

       

       

      [BlazeDS]Error instantiating application scoped instance of type 'twitter.Tweets' for destination 'tweets'.

      java.lang.NoClassDefFoundError: twitter4j/TwitterException

      at java.lang.Class.forName0(Native Method)

      at java.lang.Class.forName(Unknown Source)

      at flex.messaging.util.ClassUtil.createClass(ClassUtil.java:61)

      at flex.messaging.factories.JavaFactoryInstance.getInstanceClass(JavaFactoryInstance.java:11 0)

      at flex.messaging.factories.JavaFactoryInstance.createInstance(JavaFactoryInstance.java:96)

      at flex.messaging.factories.JavaFactory.createFactoryInstance(JavaFactory.java:114)

      at flex.messaging.FactoryDestination.createFactoryInstance(FactoryDestination.java:252)

      at flex.messaging.FactoryDestination.getFactoryInstance(FactoryDestination.java:235)

      at flex.messaging.FactoryDestination.getFactoryInstance(FactoryDestination.java:223)

      at flex.messaging.services.remoting.adapters.JavaAdapter.validateInstanceSettings(JavaAdapte r.java:549)

      at flex.messaging.services.remoting.adapters.JavaAdapter.start(JavaAdapter.java:360)

      at flex.messaging.Destination.start(Destination.java:256)

      at flex.messaging.services.AbstractService.startDestinations(AbstractService.java:650)

      at flex.messaging.services.AbstractService.start(AbstractService.java:173)

      at flex.messaging.MessageBroker.startServices(MessageBroker.java:1426)

      at flex.messaging.MessageBroker.start(MessageBroker.java:353)

      at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:146)

      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)

      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)

      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)

      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)

      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)

      at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)

      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)

      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)

      at org.apache.catalina.core.StandardService.start(StandardService.java:516)

      at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)

      at org.apache.catalina.startup.Catalina.start(Catalina.java:578)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

      at java.lang.reflect.Method.invoke(Unknown Source)

      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)

      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

      Caused by: java.lang.ClassNotFoundException: twitter4j.TwitterException

      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)

      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)

      ... 34 more

       

      [BlazeDS]MessageBroker failed to start:   Exception: flex.messaging.config.ConfigurationException: Error instantiating application scoped instance of type 'twitter.Tweets' for destination 'tweets'.

      at flex.messaging.factories.JavaFactory.createFactoryInstance(JavaFactory.java:144)

      at flex.messaging.FactoryDestination.createFactoryInstance(FactoryDestination.java:252)

      at flex.messaging.FactoryDestination.getFactoryInstance(FactoryDestination.java:235)

      at flex.messaging.FactoryDestination.getFactoryInstance(FactoryDestination.java:223)

      at flex.messaging.services.remoting.adapters.JavaAdapter.validateInstanceSettings(JavaAdapte r.java:549)

      at flex.messaging.services.remoting.adapters.JavaAdapter.start(JavaAdapter.java:360)

      at flex.messaging.Destination.start(Destination.java:256)

      at flex.messaging.services.AbstractService.startDestinations(AbstractService.java:650)

      at flex.messaging.services.AbstractService.start(AbstractService.java:173)

      at flex.messaging.MessageBroker.startServices(MessageBroker.java:1426)

      at flex.messaging.MessageBroker.start(MessageBroker.java:353)

      at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:146)

      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)

      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)

      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)

      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)

      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)

      at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)

      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)

      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)

      at org.apache.catalina.core.StandardService.start(StandardService.java:516)

      at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)

      at org.apache.catalina.startup.Catalina.start(Catalina.java:578)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

      at java.lang.reflect.Method.invoke(Unknown Source)

      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)

      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

      Caused by: java.lang.NoClassDefFoundError: twitter4j/TwitterException

      at java.lang.Class.forName0(Native Method)

      at java.lang.Class.forName(Unknown Source)

      at flex.messaging.util.ClassUtil.createClass(ClassUtil.java:61)

      at flex.messaging.factories.JavaFactoryInstance.getInstanceClass(JavaFactoryInstance.java:11 0)

      at flex.messaging.factories.JavaFactoryInstance.createInstance(JavaFactoryInstance.java:96)

      at flex.messaging.factories.JavaFactory.createFactoryInstance(JavaFactory.java:114)

      ... 28 more

      Caused by: java.lang.ClassNotFoundException: twitter4j.TwitterException

      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)

      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)

      ... 34 more

       

      **** MessageBrokerServlet failed to initialize due to runtime exception:   Exception: java.lang.RuntimeException: Error instantiating application scoped instance of type 'twitter.Tweets' for destination 'tweets'.

      at flex.messaging.MessageBroker.start(MessageBroker.java:365)

      at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:146)

      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)

      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)

      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)

      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)

      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)

      at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)

      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)

      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)

      at org.apache.catalina.core.StandardService.start(StandardService.java:516)

      at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)

      at org.apache.catalina.startup.Catalina.start(Catalina.java:578)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

      at java.lang.reflect.Method.invoke(Unknown Source)

      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)

      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

      Caused by: flex.messaging.config.ConfigurationException: Error instantiating application scoped instance of type 'twitter.Tweets' for destination 'tweets'.

      at flex.messaging.factories.JavaFactory.createFactoryInstance(JavaFactory.java:144)

      at flex.messaging.FactoryDestination.createFactoryInstance(FactoryDestination.java:252)

      at flex.messaging.FactoryDestination.getFactoryInstance(FactoryDestination.java:235)

      at flex.messaging.FactoryDestination.getFactoryInstance(FactoryDestination.java:223)

      at flex.messaging.services.remoting.adapters.JavaAdapter.validateInstanceSettings(JavaAdapte r.java:549)

      at flex.messaging.services.remoting.adapters.JavaAdapter.start(JavaAdapter.java:360)

      at flex.messaging.Destination.start(Destination.java:256)

      at flex.messaging.services.AbstractService.startDestinations(AbstractService.java:650)

      at flex.messaging.services.AbstractService.start(AbstractService.java:173)

      at flex.messaging.MessageBroker.startServices(MessageBroker.java:1426)

      at flex.messaging.MessageBroker.start(MessageBroker.java:353)

      ... 18 more

      Caused by: java.lang.NoClassDefFoundError: twitter4j/TwitterException

      at java.lang.Class.forName0(Native Method)

      at java.lang.Class.forName(Unknown Source)

      at flex.messaging.util.ClassUtil.createClass(ClassUtil.java:61)

      at flex.messaging.factories.JavaFactoryInstance.getInstanceClass(JavaFactoryInstance.java:11 0)

      at flex.messaging.factories.JavaFactoryInstance.createInstance(JavaFactoryInstance.java:96)

      at flex.messaging.factories.JavaFactory.createFactoryInstance(JavaFactory.java:114)

      ... 28 more

      Caused by: java.lang.ClassNotFoundException: twitter4j.TwitterException

      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)

      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)

      ... 34 more

       

      20-Jul-2010 13:33:53 org.apache.catalina.core.ApplicationContext log

      INFO: Marking servlet MessageBrokerServlet as unavailable

      20-Jul-2010 13:33:53 org.apache.catalina.core.StandardContext loadOnStartup

      SEVERE: Servlet /TestCombo threw load() exception

      javax.servlet.UnavailableException: Error instantiating application scoped instance of type 'twitter.Tweets' for destination 'tweets'.

      at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:170)

      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)

      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)

      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)

      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)

      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)

      at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)

      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)

      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)

      at org.apache.catalina.core.StandardService.start(StandardService.java:516)

      at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)

      at org.apache.catalina.startup.Catalina.start(Catalina.java:578)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

      at java.lang.reflect.Method.invoke(Unknown Source)

      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)

      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

       

       

       

      If there is anything else anyone needs to see just ask because this is really confusing me