2
votes

I am trying to set up a scenario where a Flex application would be able to use resources written in two different web application implementing BlazeDS.

I originally tried to do it by specifying a channel set in my mxml code and then setting this as the channel set of the service in mxml. However, although this worked, I was getting duplicate session errors.

It was suggested in one of the answers to my question linked to above that I could/should see about setting up channels with different endpoints. I guess this means that the Flex app will only be connecting to one service as it sees it but that the service will actually be delivering this service from another location as well.

I tried doing the following in my services-config.xml:

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

        <channel-definition id="my-amf2" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://localhost:7001/dataservice1/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>

But I get the following errors in my weblogic console when trying to start up my server.

Could not register endpoint 'my-amf' because its URL, '/messagebroker/amf', is already used by endpoint 'my-amf2'

and

"MessageBrokerServlet" failed to preload on startup in Web application: "/dataservice2". flex.messaging.config.ConfigurationException: Could not register endpoint 'my-amf' because its URL, '/messagebroker/amf', is already used by endpoint 'my-amf2'

and

Unable to set the activation state to true for the application '_appsdir_DataService2_dir'. weblogic.application.ModuleException: [HTTP:101216]Servlet: "MessageBrokerServlet" failed to preload on startup in Web application: "/dataservice2".

I'm guessing that this is because you can only have one channel of class mx.messaging.channels.AMFChannel. Is this correct?

In general, is there a way around any of the problems I'm experiencing? I'm open to different solutions.

I've googled and read for hours and hours but can't find anything about this.

We want to have a common functionality service that is shared amongst all applications and an application specific service that provides services specific to that application.

2
I think, as the error message says, you should simply provide a different endpoint URL for my-amf2. You'll have to set up the servlet in web.xml of course.RIAstar
You'll have to excuse my ignorance: As far as I know, the URL is different already in that it has a different port. I'm not really sure what to do. Could you elaborate please? It would be much appreciated.the_new_mr
Are you certain it is different? From what I can see the {server.port} token could well be replaced with the same port. You could use FireBug or Charles to monitor exactly at what address it's trying to connect.RIAstar
I'm 100% certain. The server that dataservice2 is being started on is on port 7002 and the other service (dataservice1) is on port 7001. I would not be able to get as far as checking with FireBug because the server won't even start up properly.the_new_mr
I don't think so: there already are different channels with different endpoints (my-amf, my-polling-amf, my-streaming-amf,...). But I've been re-reading that error message and it would seem that BlazeDS just uses the '/messagebroker/amf' to verify if the endpoint was already registered. In that case you might be able to fix the issue by changing the servlet name (to '/messagebroker/amf2' for instance) or creating . For this you'll just have to change the endpoint url, because I think it will automatically map to MessageBrokerServlet. The '/messagebroker/' part is required though.RIAstar

2 Answers

1
votes

I'll just summarize what we've been discussing so that other readers might benefit.

Let's look closely at the error message:

Could not register endpoint 'my-amf' because its URL, '/messagebroker/amf', is already used by endpoint 'my-amf2'

It speaks of '/messagebroker/amf' and doesn't mention the part of the URL before this, i.e. the part with the port number. From this we can derive that BlazeDS simply ignores this first part when it ascertains that two endpoints are identical or not. As such http://localhost:7001/dataservice1/messagebroker/amf and http://localhost:7002/dataservice2/messagebroker/amf would be considered identical even though they point to a different instance.

quick fix

A simple fix for this issue would be to simply rename the second endpoint after the last forward slash. For instance http://localhost:7001/dataservice1/messagebroker/amf2 should already do the trick. I don't think there is anything else you need to worry about since the MessageBroker servlet has a mapping with a wildcard after this last slash (/messagebroker/*) which will route any address formatted like this to the right servlet.

but why?

Perhaps you should reconsider why you're trying to do this. The reason that BlazeDS only checks the last part is that the developers probably simply didn't think of the fact that someone would actually try to point an endpoint to a different instance. Furthermore in your setup this other instance already has the same channel definition. You could simply connect to that channel so there is no need for this routing from the first instance. I have no idea what you're trying to achieve so all I can tell you is that you're probably approaching it from the wrong angle.

0
votes

A bit out of topic but did you consider using GraniteDS? It would give you much better real-time messaging performance/scalability with its support of WebLogic's asynchronous servlets (see here and here). Connecting to two different webapps shouldn't be a problem as well, since the two messaging contexts (channel definitions, etc.) would be saved in separate servlet contexts.