mule 2 template-endpoint-router

View: New views
6 Messages — Rating Filter:   Alert me  

mule 2 template-endpoint-router

by rotten :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The current documentation is missing an example for the "template-endpoint-router".
Can someone point me to how it actually should be used?

Re: mule 2 template-endpoint-router

by rotten :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

To explain more about what I need to do:

I need to take some data out of my message and construct a URL (to a cgi-like interface) to make a call over http.

ie,

inbound message contains:  "myparameter" in the payload

I need to then call:
http://somehost:someport/mycgi?dothis=myparameter

In mule 1.4.x we wrote a component that makes the http call.  I found this architecture confusing.  You have this inbound message that gets fed to a component, and then disappears.  It is like it fell through a trap door while you weren't looking.

I'd rather use an actual outbound router to deliver the message.

I was hoping the template-endpoint-router could do this trick.

--

service:

<inbound>
  <inbound-endpoint xxx />
</inbound>

<component>
  extract myparameter somehow
</component>

<outbound>
   <template-endpoint-router theparameter="myparameter">
       <template outbound endpoint>
   </template-endpoint-router>
</outbound>

--

1) Once I've found "myparameter" with the component, how do I feed it into the template-endpoint-router?  Do I replace the payload with it?  Put it on the message headers somehow?

2) How do I configure the http endpoint to accept "myparameter" at the proper place in the url?

... Maybe this isn't possible, and the only way to get out of Mule 2.0.2 with the URL I need, will have to be through the component.

 
rotten wrote:
The current documentation is missing an example for the "template-endpoint-router".
Can someone point me to how it actually should be used?

RE: mule 2 template-endpoint-router

by antoine.borg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Why don't you create an outbound router that builds its own endpoints (just
like the RecipientListRouter does) and creates the endpoint based upon the
message payload and a configured endpoint.

So your router will be configured like this:

<my-outbound-router>
        <spring:property name="endpointStub">
       
<spring:value>http://somehost:someport/mycgi?dothis=</spring:value>
        </spring:property>
</my-outbound-router>

Regards

Antoine Borg, Senior Consultant | Tel: +32 28 504 696
ricston Ltd., BP 2, 1180 Uccle, Brussels, BELGIUM
email: antoine.borg@... | blog: blog.ricston.com | web: ricston.com

-----Original Message-----
From: rotten [mailto:rickotten@...]
Sent: Thursday, August 28, 2008 8:58 PM
To: user@...
Subject: Re: [mule-user] mule 2 template-endpoint-router


To explain more about what I need to do:

I need to take some data out of my message and construct a URL (to a
cgi-like interface) to make a call over http.

ie,

inbound message contains:  "myparameter" in the payload

I need to then call:
http://somehost:someport/mycgi?dothis=myparameter

In mule 1.4.x we wrote a component that makes the http call.  I found this
architecture confusing.  You have this inbound message that gets fed to a
component, and then disappears.  It is like it fell through a trap door
while you weren't looking.

I'd rather use an actual outbound router to deliver the message.

I was hoping the template-endpoint-router could do this trick.

--

service:

<inbound>
  <inbound-endpoint xxx />
</inbound>

<component>
  extract myparameter somehow
</component>

<outbound>
   <template-endpoint-router theparameter="myparameter">
       <template outbound endpoint>
   </template-endpoint-router>
</outbound>

--

1) Once I've found "myparameter" with the component, how do I feed it into
the template-endpoint-router?  Do I replace the payload with it?  Put it on
the message headers somehow?

2) How do I configure the http endpoint to accept "myparameter" at the
proper place in the url?

... Maybe this isn't possible, and the only way to get out of Mule 2.0.2
with the URL I need, will have to be through the component.

 

rotten wrote:
>
> The current documentation is missing an example for the
> "template-endpoint-router".
> Can someone point me to how it actually should be used?
>
>

--
View this message in context:
http://www.nabble.com/mule-2-template-endpoint-router-tp19170359p19206956.ht
ml
Sent from the Mule - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: mule 2 template-endpoint-router

by Dimitar Dimitrov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've had the same requirement and I've implemented our custom router based on the TemplateEndpointRouter.

See the patch attached to this issue.

http://www.mulesource.org/jira/browse/MULE-3580

(and don't forget to vote ;-)

Re: mule 2 template-endpoint-router

by rotten :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks D.

I wrote simple transformer to extract the stuff I wanted to append the end of the URL out of the message.  Then I chose to implement a simple extension of the Exception Router.  it seems to work.

I still think the Template Router is could probably do what I want, but I couldn't figure out how to use it.

-- Configured like this --

<custom-outbound-router class="org.my.custom.mule.urlAppendRouter">

    <http:outbound-endpoint host="${primary.host}"
                                       port="${primary.port}"
                                       path="/some/path/doSomething?myparameter="
                                       synchronous="true"
                                       contentType="text/plain" />
   
    <http:outbound-endpoint host="${backup.host}"
                                       port="${backup.port}"
                                       path="/some/path/doSomething?myparameter="
                                       synchronous="true"
                                       contentType="text/plain" />

</custom-outbound-router>

-- My implementation - urlAppendRouter.java --

package org.my.custom.mule;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.mule.api.MuleMessage;
import org.mule.api.endpoint.EndpointException;
import org.mule.api.endpoint.EndpointURI;
import org.mule.api.endpoint.OutboundEndpoint;
import org.mule.api.routing.CouldNotRouteOutboundMessageException;
import org.mule.config.i18n.CoreMessages;
import org.mule.endpoint.DynamicURIOutboundEndpoint;
import org.mule.endpoint.MuleEndpointURI;
import org.mule.routing.outbound.ExceptionBasedRouter;

import org.my.custom.log.*;

//
// This custom router appends whatever is left in the Message to
//    the end of the URL stub provided to router when it is invoked.
// It tries the primary, if it can't get through, it'll try the "backup".
//
// Configuration syntax is essentially the same as the Exception based Router.
//
// It still puts the message in the body of the POST, but that is ignored in our application.
//

public class urlAppendRouter extends ExceptionBasedRouter {

    //
    // Override the routine that pulls the endpoint out of the configuration.
    // (We aren't worried about supporting templates in this override...)
    //

    public OutboundEndpoint getEndpoint(int index, MuleMessage message) throws CouldNotRouteOutboundMessageException {

        // get the relevant endpoint (stub) from the config file
        OutboundEndpoint ep = (OutboundEndpoint)endpoints.get(index);

        String uri_stub = ep.getEndpointURI().toString();

        Log.debug("Found URI Stub: " + uri_stub, getClass());

        String newUriString = uri_stub + (String)message.getPayload();

        Log.debug("Appended (full) URI: " + newUriString, getClass());

        try {
            EndpointURI newUri = new MuleEndpointURI(newUriString);
            if (!newUri.getScheme().equalsIgnoreCase(ep.getEndpointURI().getScheme())) {
                throw new CouldNotRouteOutboundMessageException(CoreMessages.schemeCannotChangeForRouter(ep
                        .getEndpointURI().getScheme(), newUri.getScheme()), message, ep);
            }

            return new DynamicURIOutboundEndpoint(ep, newUri);
        }
        catch (EndpointException e) {
            throw new CouldNotRouteOutboundMessageException(CoreMessages.templateCausedMalformedEndpoint(uri_stub,
                    newUriString), message, ep, e);
        }

    }
}


:-)  Thanks again for the pointers.  I've got something working, so I can move on to the next problem.


Re: mule 2 template-endpoint-router

by Dimitar Dimitrov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Just for the record, the regular endpoint template router is configured like this:

<endpoint-template-router address="foobar://server:1234/path/path/path?param1=[header1]¶m2=[header2]"/>

Where the header1 and 2 are substituted with the actual values from the current message. Also, the params can be used only in the query string as the square brackets are not valid characters for the authority and path URI components.

My modification is similar, but it allows you to use evaluator expressions anywhere in the URI:

<endpoint-template-router-x address="foobar://server:1234/$(header:SERVICE)/$(jxpath:/entity/id)?version=$(jxpath:/entity/version)"/>