Expand my Community achievements bar.

RemoteObject Java -> http failled

Avatar

Former Community Member
Hi, I have an application with flex 2.0, flex data services
and java and I want to access methods of my JAVA classes. So I use
the remoteObject.



Here is the code :



Test.java



package beans;



public class Test {



public Test()

{

System.out.println("-= Test start =-");

}



public String doTest()

{

return "-= This is a test =-";

}



}



remoting-config.xml



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

<service id="remoting-service"

class="flex.messaging.services.RemotingService"

messageTypes="flex.messaging.messages.RemotingMessage">



<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="test">

<properties>

<source>beans.Test</source>

<scope>application</scope>

</properties>

</destination>



</service>



index.mxml



<?xml version="1.0"?>



<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"

initialize="applicationInit()"

layout="absolute"

backgroundGradientColors="[#ffffff, #808080]"

viewSourceURL="srcview/index.html"

creationComplete="doTest()">



<mx:Script>

<![CDATA[

import mx.controls.Alert;

import mx.rpc.events.FaultEvent;

import mx.collections.ArrayCollection;

import flash.events.MouseEvent;

import mx.rpc.AsyncToken;

import mx.data.*;

import mx.managers.*;



[Bindable]



private function doTest():void

{

test.doTest();

}



]]>

</mx:Script>



<mx:RemoteObject id="test" destination="test">

<mx:method name="createTest"/>

</mx:RemoteObject>



When I launch the server " -= Test start =-" is printed on
tomcat so the remoteObject is good initialized but after there is
an error due to the method createTest.



Here is the final message when i launch the application :



[RPC Fault faultString="Send failed"
faultCode="Client.Error.MessageSend"
faultDetail="Channel.Connect.Failed error
NetConnection.Call.Failed: HTTP: Failed"]

at mx.rpc::AbstractInvoker/
http://www.adobe.com/2006/flex/mx/internal::faultHandler()

at mx.rpc::Responder/fault()

at mx.rpc::AsyncRequest/fault()

at mx.messaging::ChannelSet/::faultPendingSends()

at mx.messaging::ChannelSet/channelFaultHandler()

at
flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at
mx.messaging::Channel/mx.messaging:Channel::connectFailed()

at
mx.messaging.channels::PollingChannel/mx.messaging.channels:PollingChannel::connectFailed()

at
mx.messaging.channels::AMFChannel/mx.messaging.channels:AMFChannel::statusHandler()





Please help me.
3 Replies

Avatar

Level 2
what purpose does the lin <mx:method
name="createTest"/> serve? I'd remove that first off and try it
again.



Also add a System.out.println to your doTest function so
you'll see when it actually gets called... that will help a bit.



Just my 2cents.

Avatar

Level 3
2 things



1) your method should be doTest not createTest for your
remote object

2) you need to add an endpoint to your remote object

Avatar

Level 2
My understanding is that you really only need the
<mx:method/> if the method being called requires arguments
passed to it. Likewise, if you are not returning any values (i.e.
private function doTest():void) you don't really need to supply a
resultHandler - at least you don't need one to see if the code is
calling your method correctly. If you want to see the string it's
supposed to pass back then yes you will need to handle the result.



I use this format and it lets me call any function in my
com.abc.Security java class.

<mx:RemoteObject

id="authenticationService"

destination="com.abc.Security"

result="event.token.resultHandler(event)" />