Hi,

We used this technique awhile back when working on a JAX-WS TCK for CXF Fuse :

<httpj:engine-factory bus="cxf">
       <httpj:engine port="@SPRING_CONTAINER_PORT@">
         <httpj:handlers>
           <bean class="org.mortbay.jetty.handler.ResourceHandler">
            <property name="baseResource">
             <bean class="org.mortbay.resource.FileResource">
               <constructor-arg value="file:/@TCK_REPOSITORY@"/>
             </bean>
            </property>
           </bean>
         </httpj:handlers>
      </httpj:engine>
   </httpj:engine-factory>

For whatever it's worth, here's another technique (suggested by Eoghan) whe we use too and which offers more control though it's more complicated :

1. Create your own instance of MessageObserver, eg. :

public class ServletFilterMessageObserver implements MessageObserver  {

       public ServletFilterMessageObserver(MessageObserver observer, Filter 
filter,
                                 QName serviceName, QName portName) {
             ....
      }

   public void onMessage(Message message) {

           HttpServletRequest req =
               
(HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
           HttpServletResponse res =
               
(HttpServletResponse)message.get(AbstractHTTPDestination.HTTP_RESPONSE);
           filter.doFilter(req,  res, new FilterChainImpl(observer, message));
   }

}

This message observer just delegates to a filter chain, or it can chose just write back to HttpServletResponse immediately...Note, the 'observer' passed to the constructor above is the usual ChainMessageObserver used by CXF.

Now, we create the observer like this one  based on certain conditions, here's 
an example :

public class ServletFilterObserverManager implements ServerLifeCycleListener {

   public ServletFilterObserverManager(Bus bus, Map<String, String> filterMap) {
       ServerLifeCycleManager slcm = 
bus.getExtension(ServerLifeCycleManager.class);
       slcm.registerListener(this);
   }

   public void startServer(Server server) {
           // if certain condition is met then....

           MessageObserver observer = 
server.getDestination().getMessageObserver();
           if (observer == null) {
               observer = new ChainInitiationObserver(server.getEndpoint(), 
bus);
           }

           // here's our custom observer
           ServletFilterMessageObserver delegate =
                new ServletFilterMessageObserver(observer, filter, 
serviceQName, portQName);

           server.getDestination().setMessageObserver(delegate);
       }
   }

}

Then register this manager as a bean, ex :

<bean name="ServletFilterObserverManager" 
class="org.apache.cxf.utilities.filters.ServletFilterObserverManager">
           <constructor-arg ref="cxf"/>
           <constructor-arg><map/></constructor-arg>
</bean>


Cheers, Sergey



----- Original Message ----- From: "Willem Jiang" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, July 21, 2008 11:14 AM
Subject: Re: AW: AW: Configure jetty to use static content


Yes, you just need to set the endpoint address with the jetty port that you 
configured.
Such as
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
 <property name="serviceClass" 
value="org.apache.cxf.systest.http_jetty.DummyInterface" />
 <property name="address" value="http://localhost:8808/Dummy"; />
</bean>

Willem
Marcus Redeker wrote:
Willem,

Thanks for that information. If I use the xml-file from svn do I have to do
something else the get the cxf ws-endpoints to work. It looks like the
jetty-engine.xml file only registers ResourceHandlers?

Thanks,
--Marcus

-----Ursprüngliche Nachricht-----
Von: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Im Auftrag von
Willem Jiang
Gesendet: Montag, 21. Juli 2008 03:55
An: [email protected]
Betreff: Re: AW: Configure jetty to use static content

Hi Marcus,

It should work. Here is a unit test[1][2] which shows how to set the
resource handler to the jetty engine.
[1]https://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apa
che/cxf/systest/http_jetty/jetty-engine.xml
[2]https://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apa
che/cxf/systest/http_jetty/EngineLifecycleTest.java

Willem

Marcus Redeker wrote:

Hi Glen,

Thanks for looking at this. When I use Spring the ResourceHandler objekt is created correct from spring and also the setResourceBase() method is called with correct string. It seems the the <httpj:handlers> tag is not evaluated correct because the jetty logging does not say that another handler is registered.

The java code works fine. It does not matter if I create an extra variable or path the string by itself. I don't want to use the java code

anyway.

To avaoid problems with the seperator I am already using the forward

slash.

That no problem and works.

Any idea why the <httpj:handlers> tag might not work?

--Marcus


-----Ursprüngliche Nachricht-----
Von: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Im Auftrag von Glen Mazza
Gesendet: Sonntag, 20. Juli 2008 15:42
An: [email protected]
Betreff: Re: Configure jetty to use static content


Isn't the file divider "\" in Windows--that may be part of the problem.

Also, some debugging appears needed here, from both ends. Perhaps you should System.out.println() what you are passing in via Spring as the resourceBase value--first confirm that indeed the Java code is getting the "d:/temp/" from the config file. Next, factor out that hardcoded

"d:/temp/"

from your Java code into a String variable and then
setResourceBase(myNewVar) --> does that work?

Glen


Marcus Redeker wrote:

All,

I am trying to use the spring configuration to added a ResourceHandler for 
static content to jetty.
It does not work when I use the following spring configuration:

========== Spring config ================
  <httpj:engine-factory bus="cxf">
    <httpj:engine port="9000">
      <httpj:handlers>
        <bean class="org.mortbay.jetty.handler.ResourceHandler">
        <property
name="resourceBase"><value>d:/temp/</value></property>
        </bean>         </httpj:handlers>
    </httpj:engine>
  </httpj:engine-factory>
=========================

But when I use the following java code it does work:

=========== Java code ========================== Bus bus = (Bus)ctx.getBean("cxf"); ServerRegistry sr= bus.getExtension(ServerRegistry.class);
ServerImpl si = (ServerImpl) sr.getServers().get(0); JettyHTTPDestination jhd = 
(JettyHTTPDestination)si.getDestination();
JettyHTTPServerEngine engine = (JettyHTTPServerEngine) jhd.getEngine(); Server server = engine.getServer(); Handler serverHandler = server.getHandler(); ContextHandlerCollection contextHandlerCollection = (ContextHandlerCollection)serverHandler; HandlerList handlerList = new HandlerList(); ResourceHandler resourceHandler = new ResourceHandler(); handlerList.addHandler(resourceHandler);
handlerList.addHandler(contextHandlerCollection);
server.setHandler(handlerList);
handlerList.start();
resourceHandler.setResourceBase("d:/temp/");
========================================

Can you guys help me? I would like to only use spring config and not have to 
have the extra java code.

Thanks,

Marcus




--
View this message in context:
http://www.nabble.com/Configure-jetty-to-use-static-content-tp18554067
p18554
593.html
Sent from the cxf-user mailing list archive at Nabble.com.









----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Reply via email to