PDA

View Full Version : Configuring the flex app



jettro
Dec 23rd, 2008, 02:52 AM
Hi,
I am trying to convert a sample of mine but I think I am missing something. The docs are talking about the configuration of the services in services-config.xml and remoting-config.xml. The remoting.xml can be pretty much left with some defaults. You do not have to configure the destinations.

In the log files I can see this going for the server side. I see that the configured classes are used. However, I am having some problems at the client. There I cannot find the destinations. Am I doing something wrong? Should I now configure the client differently from the server?

Following my code for the configuration, the commented part is the bean now exposed using the spring integration.


<service id="remoting-service"
class="flex.messaging.services.RemotingService">

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

<default-channels>
<channel ref="my-amf"/>
</default-channels>

<!--<destination id="bookManager">-->
<!--<properties>-->
<!--<factory>spring</factory>-->
<!--<source>bookManager</source>-->
<!--</properties>-->
<!--</destination>-->

<destination id="authenticationHelper">
<properties>
<source>nl.gridshore.samples.books.web.security.Authentica tionHelper</source>
</properties>
</destination>

</service>


If I change this for the client into:


<?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.JavaAdap ter"
default="true"/>
</adapters>

<default-channels>
<channel ref="my-amf"/>
</default-channels>

<destination id="remoteBookManager"/>

<destination id="authenticationHelper">
<properties>
<source>nl.gridshore.samples.books.web.security.Authentica tionHelper</source>
</properties>
</destination>

</service>


Than it all seems to work, no I have the problem I cannot share config files, Allthough I like it that I only need to define the destinations without any hassle of factories etc. I still need to know the name of the bean that is exposed. It feels like something that cannot be overcome by the spring blazeds library.

Am I right?

Jettro

jeremyg484
Dec 23rd, 2008, 03:01 PM
However, I am having some problems at the client. There I cannot find the destinations.

What do you mean exactly? I'm assuming you mean when referencing the services at runtime with a RemoteObject?

It should definitely work without having to add


<destination id="remoteBookManager"/>

for the client.

Are you perhaps not accessing the destination by the correct identifier? The dynamic destination is configured such that by default the id is the same as the bean id of the exporter, though that is configurable via the serviceId property of the exporter.

jettro
Dec 23rd, 2008, 03:17 PM
Yes I mean from code, I do create the services programmatically. I did manage to get it working with a custom build channelset. It seems the client does not know how to connect to the destination because the client does not know it.



public class BookService extends RemoteService {
public function BookService(channelSet:ChannelSet) {
super("bookService", "remoteBookManager",channelSet);
}
}

public class RemoteService {
protected var remoteObject:RemoteObject;

public function RemoteService(id:String, destination:String, channelSet:ChannelSet) {
this.remoteObject = new RemoteObject(id);
this.remoteObject.destination = destination;
this.remoteObject.channelSet = channelSet;
this.remoteObject.addEventListener(FaultEvent.FAUL T,onRemoteException);
}
}


With the config file I cannot make this work.

I'll do some more experimentation to nail this one doen


What do you mean exactly? I'm assuming you mean when referencing the services at runtime with a RemoteObject?

It should definitely work without having to add


<destination id="remoteBookManager"/>

for the client.

Are you perhaps not accessing the destination by the correct identifier? The dynamic destination is configured such that by default the id is the same as the bean id of the exporter, though that is configurable via the serviceId property of the exporter.

jeremyg484
Dec 23rd, 2008, 03:36 PM
Ahh, okay I see. Yes, I do think assigning the ChannelSet to the RemoteObject is the key there. I don't think there's any getting around that when using dynamic destinations.

See here:
http://livedocs.adobe.com/blazeds/1/blazeds_devguide/runtimeconfig_1.html

Though I believe if you have "my-amf" set up as an application-wide default, it would work without needing to explicitly specify the ChannelSet.

For example, from the services-config.xml in the BlazeDS sample:



<services>

<service class="flex.samples.DatabaseCheckService" id="hsqldb" />

<service-include file-path="remoting-config.xml" />
<service-include file-path="proxy-config.xml" />
<service-include file-path="messaging-config.xml" />

<service class="flex.samples.runtimeconfig.EmployeeRuntimeRemoting Destination" id="runtime-employee-ro" />

<!--
Application level default channels. Application level default channels are
necessary when a dynamic destination is being used by a service component
and no ChannelSet has been defined for the service component. In that case,
application level default channels will be used to contact the destination.
-->
<default-channels>
<channel ref="my-amf"/>
</default-channels>

</services>

k.v.ahuja
Jan 1st, 2009, 02:50 PM
I have a similar issue here. I have configured the server as suggested. But, when i make a call from the client i get the following error:


message='Destination 'loginService' either does not exist or the destination has no channels defined


remoting-service



<?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.JavaAdap ter" default="true"/>
</adapters>

<default-channels>
<channel ref="my-amf"/>
</default-channels>

</service>



services-config.xml


<channels>
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http : / / {server.name}:{server.port}/{context.root}/spring/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
</channel-definition>




Spring beans


<bean id="loginServiceController" class="org.phoenix.core.LoginService" />


<bean id="loginService" class="org.springframework.flex.messaging.remoting.FlexRe motingServiceExporter">
<property name="service" ref="loginServiceController"/>
<property name="messageBroker" ref="messageBrokerFactory"/>
</bean>


What am i missing?

pHk
Jan 2nd, 2009, 08:17 AM
Not sure whether they're typos or not, but it's supposed to be remoting-config.xml (not remoting-service) and there are some spaces in the endpoint URL in the services-config.xml which may cause some unexpected behaviour.

k.v.ahuja
Jan 3rd, 2009, 01:45 AM
Not sure whether they're typos or not, but it's supposed to be remoting-config.xml (not remoting-service) The remoting-service is defined in the Services-config file. The only thing that you have to worry about is to ensure that file name matches the one provided in services-config.xml


some spaces in endpoint URL - I did this because i was not allowed to post URL possibly because of being a new user.

jettro
Jan 5th, 2009, 04:41 AM
I have a sample that I have been using for a while and I have re-written it with the blazeds spring integration. I still have the same problem as mentioned in this thread. It only works when I add an empty destination to the client side configuration. If someone has the time to try it out:

http://code.google.com/p/gridshore/source/browse/#svn/trunk/books-overview

It is all maven, so you can build it using maven, do make sure you have the M1 of the integration in you repository.

You can start the application using jetty integrated with maven:
cd books-web
mvn clean jetty:run-war

Open the link
http://localhost:8080:/books-web

k.v.ahuja
Jan 5th, 2009, 04:57 AM
While i try the application...!!



It only works when I add an empty destination to the client side configuration. I am surprised that this works for you, because when I compile my application with an entry in remoting-service, I get an error on my web server, which says that I have the service exposed twice one in remoting-service and other in the spring-bean configuration.

However, I tried by creating a channel in my code-behind and assigned that channel to my remote service. It worked.

jettro
Jan 5th, 2009, 06:17 AM
While i try the application...!!


I am surprised that this works for you, because when I compile my application with an entry in remoting-service, I get an error on my web server, which says that I have the service exposed twice one in remoting-service and other in the spring-bean configuration.

However, I tried by creating a channel in my code-behind and assigned that channel to my remote service. It worked.

I only added the destination to the client, so I duplicated the files. Yes I know that is not clean, but for the time being it does work. As for the Channels in code, yes I did that as well and for me it worked also. I am planning on using the other spring-flex module. The action script integration. There was some example code for configuring a channel using the xml config.

jeremyg484
Jan 5th, 2009, 08:55 AM
I am planning on using the other spring-flex module. The action script integration. There was some example code for configuring a channel using the xml config.

I would definitely recommend this, as it externalizes and decouples things nicely. Using this approach you ultimately don't have to compile your Flex app against services-config.xml at all and can potentially deploy the back end and Flex front end as separate modules.

For those who haven't seen it yet, check out Christophe Herreman's blog on the matter:
http://www.herrodius.com/blog/158

k.v.ahuja
Jan 5th, 2009, 11:02 AM
I am planning on using the other spring-flex module. The action script integration. There was some example code for configuring a channel using the xml config.

I am almost ready to write a XML based configuration. If you have this available as a source already, can you point me to that?

jettro
Jan 5th, 2009, 11:10 AM
I am almost ready to write a XML based configuration. If you have this available as a source already, can you point me to that?
I meant the blog that Jeremy already pointed to in the previous comment

jettro
Jan 6th, 2009, 03:16 AM
If you are looking for an example of a client using the Spring ActionScript library to connect to endpoints you can have a look at my latest blog post:
http://www.gridshore.nl/2009/01/06/creating-the-flex-client-using-spring-actionscript/

This is a start, not necessarily the best way.

greetz Jettro

jcarter
Jan 13th, 2009, 08:57 PM
Just to be pedantic. Here is an example to address the "message='Destination 'loginService' either does not exist or the destination has no channels defined" error in the M1 build.


// Define a ChannelSet object.
private var cs:ChannelSet;

// Replace 'server.mydomain.com' and 'myproject' with appropriate identifiers for your environment.
private function createChannelSet():ChannelSet {
if (cs == null) {
cs = new ChannelSet();
var ac:AMFChannel = new AMFChannel("sketchThree","http://server.mydomain.com:8080/myproject/messagebroker/amf");
cs.addChannel(ac);
}
return cs;
}

// Pass the ChannelSet explicitly to the RemoteObject call.

itsmeprash
Jan 15th, 2009, 10:35 AM
I had configured the Flex-Spring-BlazeDS using the SpringFactory using

<factories>
<factory id="spring" class="flex.samples.factories.SpringFactory"/>
</factories>

Now i wanted to try the Spring BlazeDS Integration 1.0.0.M1. I changed my configuration similar to how it was suggested in the BlazeDS sample. Initially i got the same error as everybody else.

----------------------------------------------------------------------
No destination 'distributorService' found or channel not defined.
----------------------------------------------------------------------

<bean id="distributorService" class="com.csc.zyxyz.businesslogic.services.DistributorSe rviceImpl"/>

<!-- Expose the distributorService bean for BlazeDS remoting -->
<bean id="distributor" class="org.springframework.flex.messaging.remoting.FlexRe motingServiceExporter">
<property name="messageBroker" ref="mySpringManagedMessageBroker"/>
<property name="service" ref="distributorService"/>
</bean>

Insted for passing "distributor" to the RemoteService, i was passing the distributorService

/**
* Constructor
*/
public function DistributorService() {
super("distributor", "distributor");
}

Instead i had misconfigured

/**
* Constructor
*/
public function DistributorService() {
super("distributorService", "distributorService");
}

Once i corrected it, all was fine.

I am looking forward for the REST implementation and how easy it will be to change from AMF to REST or even JSON if requried.

Does anybody know of a AMF viewer so i can test the response before consuming it as the flex end?.

Great job

Thank you
Prashanth Sukumaran

azanux
Jan 29th, 2009, 04:08 PM
Hi !


I'm also newbeez in flex blazeds spring and i have the same problem.

message='Destination 'testService' either does not exist or the destination has no channels defined


How can i solve this probleme, i read this topic but i don't understand how to correct this problem

what do you mean with
Insted for passing "distributor" to the RemoteService, i was passing the distributorService ?

can anybody give me some information ?

thanks !

sorry for my bad english ,i'm french

jcarter
Jan 30th, 2009, 12:03 PM
Here's a simple recipe. In the BlazeDS, define the appropriate channel. Then in the application, pass in a channel set which points to the specific channel of interest.


[flex/services-config.xml]

...
<channels>

<channel-definition id="my-amf"
class="mx.messaging.channels.AMFChannel">
<endpoint url="http://example.com:8080/appName/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
...

[BasicApp.mxml]

<mx:Script><![CDATA[
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;

// Define a ChannelSet object.
private var cs:ChannelSet;

private function createChannelSet():ChannelSet {
if (cs == null) {
cs = new ChannelSet();
var ac:AMFChannel = new AMFChannel("my-AMF","http://example.com:8080/appName/messagebroker/amf");
cs.addChannel(ac);
}
return cs;
}
]]></mx:Script>

....

<mx:RemoteObject id="ro" destination="specimen" channelSet="{createChannelSet()}"/>

djo.mos
Feb 19th, 2009, 09:20 AM
Thanks jcarter, it worked like a charm :D

I guess that the reason of this error is that the swf file is trying to access the remote service at host:port/context/messagebroker/amf, whereas the actual address should rather be host:port/context/dipatcherServletMapping/messagebroker/amf.

Still, this solution is not perfect as the host and port are harde coded in the compiled swf file :(

bh5k
Feb 19th, 2009, 10:20 AM
Why aren't you guys doing it like the examples that show you doing the configuration in xml? http://forum.springframework.org/showthread.php?t=66542

BTW, the Spring Factory is NOT the same thing, but I think/hope you realize that.

Durden
Feb 24th, 2009, 09:26 AM
I am having similar problems with my application. Client doesn`t find it`s destination, although it has been configured correctly. I do not create channels programmatically.

Is this issue a known bug or just a lack of configuration dokumentation in SpringBlazeDS reference? I don`t think it`s some wrong configuration in my code. For some reason, the client just does not find it`s destination.

Or should I always define programmatically channelsets? Is this the only solution?

jcarter
Feb 24th, 2009, 02:06 PM
As far as I know, explicit creation of the ChannelSet is necessary in M1. The comments from bh5k suggest an XML route, but even Christophe Coenraets AIR example follows this approach.

It looks like one of the issues (http://jira.springframework.org/browse/FLEX-15) for M2 could fix this.