tags:

views:

345

answers:

2
+1  Q: 

Mule/Jetty Setup

I have a working Mule application that I want to setup Jetty on to respond to http requests. The following config:

<jetty:endpoint address="http://localhost:8080" 
                name="jettyEndpoint" 
                host="localhost" 
                port="8080" path="/" 
                synchronous="true" /> 

<service name="jettyUMO">
  <inbound>
    <jetty:inbound-endpoint ref="jettyEndpoint" /> 
  </inbound>
  <test:component appendString="Received" /> 
</service>

...works when I start the application, and point browser of choice to http://localhost:8080 - all that gets displayed is "Received", per the test:component.

What I want to do is update this so that instead of seeing "Received", I want to go to where I defined an index.html file. My assumption is that I have to change the test:component out for an outbound endpoint - is this correct? Where would I specify the path (relative or absolute)?

A: 

I had to add a jetty:connector instance:

<jetty:connector name="httpConnector" 
                 configFile="conf/jettyConfig.xml" 
                 useContinuations="true" />

Here's the contents of the jettyConfig.xml because the simple example has errors:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"&gt;

<Configure id="Server" class="org.mortbay.jetty.Server">
  <Call name="addConnector">
    <Arg>
      <New class="org.mortbay.jetty.nio.SelectChannelConnector">
        <Set name="port">8080</Set>
      </New>
    </Arg>
  </Call>

  <Set name="handler">
    <New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection">
      <Set name="handlers">
        <Array type="org.mortbay.jetty.Handler">
          <Item>
            <New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"/>
          </Item>
          <Item>
            <New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/>
          </Item>
        </Array>
      </Set>
    </New>
  </Set>

  <Call name="addLifeCycle">
    <Arg>
      <New class="org.mortbay.jetty.deployer.WebAppDeployer">
        <Set name="contexts"><Ref id="Contexts"/></Set>
        <Set name="webAppDir">path/webapps</Set>
      </New>
    </Arg>
  </Call>
</Configure>
OMG Ponies
A: 

This did not work for me.

> [04-22 17:25:22] WARN  log [main]:
> failed [email protected]:8080
> java.net.BindException: Address already in use
>         at sun.nio.ch.Net.bind(Native Method)

I think, what happens is that one instance is being created on port defined in jettyConfig and then another through Mule. Changing the port in jettyConfig yields two identically behaving instances on two different ports.

The simplest solution is to remove the addConnector Call from jettyConfig.xml and let Mule assign the port.

It is also not needed to specify host and port on the endpoint. This suffices:

<jetty:endpoint address="http://localhost:8080" name="serverEndpoint" path="services/Foo" synchronous="false" />
dmossakowski