Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mule/Jetty Setup

Tags:

java

jetty

mule

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)?

like image 365
OMG Ponies Avatar asked Jan 01 '26 16:01

OMG Ponies


2 Answers

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">

<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>
like image 116
OMG Ponies Avatar answered Jan 03 '26 05:01

OMG Ponies


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" />
like image 39
dmossakowski Avatar answered Jan 03 '26 05:01

dmossakowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!