0
votes

I have the following code to configure a Jersey service at "http://localhost:8080/alpha":

*** my mule config ***

<flow name="flow1">
    <inbound-endpoint address="http://localhost:8080/" exchange-pattern="request-response"    />
<jersey:resources>
    <component>
        <singleton-object class="com.address.Flow1Resource"/>
    </component>
</jersey:resources>
</flow>

*** Flow1Resource.java ***

@Path("/alpha")
public class Flow1Resource {...}

I want to add a new inbound-endpoint that handles all the addresses under "http://localhost:8080" except "http://localhost:8080/alpha" (e.g. "http://localhost:8080/beta"). These new addresses need a single jersey resource. For example:

*** my mule config ***

<flow name="flow1">
    <inbound-endpoint address="http://localhost:8080/" exchange-pattern="request-response"    />
<jersey:resources>
    <component>
        <singleton-object class="com.address.Flow1Resource"/>
    </component>
</jersey:resources>
</flow>

<flow name="flow2">
    <inbound-endpoint address="http://localhost:8080/*" exchange-pattern="request-response"    />
<jersey:resources>
    <component>
        <singleton-object class="com.address.Flow2Resource"/>
    </component>
</jersey:resources>
</flow>

*** Flow1Resource.java ***

@Path("/alpha")
public class Flow1Resource {...}

*** Flow2Resource.java ***

@Path("/")
public class Flow2Resource {
    @Path("beta")
    public void beta() {...}
    @Path("gamma")
    public void gamma() {...}
    ...
}

How do I set up the mule inbound-endpoint to capture all the addresses (i.e. beta & gamma), except for a specific url (i.e. alpha).

I know that I can hardcode the paths in the mule config, but this would result in duplication because each address (i.e. beta & gamma) would need its own flow and resource code, which are similar.

Please note that I used "http://localhost:8080/*" in the code above as an conceptual example. It does not work.

--- Update ---

I forgot to mention that the beta and gamma uri's also have security associated with them using:

<http:inbound-endpoint ...>
    <spring-security:http-security-filter realm="mule-realm"/>
</http:inbound-endpoint>

I tried adding a 'choice' element to the endpoint, but it complained that spring-security was invalid inside the choice decision structure.

A solution would also need to accommodate this feature.

1
What do you mean by adding the spring-security to the choice router? Do you need only either alpha or beta to be authenticated?genjosanzo

1 Answers

0
votes

An easy way to achieve your goal is to combine your flows into one and use the choice router. In this configuration your flow will look like the following:

<flow name="stackoverflowFlow1" doc:name="stackoverflowFlow1">
    <http:inbound-endpoint exchange-pattern="request-response"
        host="localhost" port="8081" doc:name="HTTP" />
    <logger level="ERROR" />
    <choice doc:name="Choice">
        <when expression="#[message.inboundProperties['http.request'] == '/']">
            <processor-chain>
                <logger message="/ invoked " level="ERROR" />
                <jersey:resources doc:name="REST">
                    <component class="Resource" />
                </jersey:resources>
            </processor-chain>
        </when>
        <otherwise>
            <processor-chain>
                <logger message="otherwise invoked " level="ERROR" />

                <jersey:resources doc:name="REST">
                    <component class="ApplicationsResource" />
                </jersey:resources>
            </processor-chain>
        </otherwise>
    </choice>
</flow>

As you can imagine you can take decision on the path or on top of any other http header.

You can find this router documentation here and a list of the most common http properties you can use to make your choices here