You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sergey Beryozkin <sb...@gmail.com> on 2012/02/08 22:25:14 UTC

Re: serve static content through jetty

Hi

On 08/02/12 17:10, matteo rulli wrote:
> Dear all,
>
> I publish some soap-WS through CXF (v. 2.5.0 - bundled into OSGi equinox) on
> the following URI:
>
>
>
> http://10.0.2.243:8160/Persistence
>
>
>
> The problem is that when a Silverlight client tries to consume my WS, a
> "get" request for a resource called clientaccesspolicy.xml is generated,
> namely
>
> http:// 10.0.2.243:8160/clientaccesspolicy.xml
> <http://%2010.0.2.243:8160/clientaccesspolicy.xml>

where exactly is this file located/created ? Is it available before the 
bundle is even started for the very first time ?

Cheers, Sergey


>
>
>
> Is there a way to configure Jetty to serve this file? I should perform this
> programmatically. I tried with something like (sorry for that, I know it is
> a very awkward attempt of mine to reproduce the
> <http://cxf.apache.org/docs/standalone-http-transport.html>
> http://cxf.apache.org/docs/standalone-http-transport.html example):
>
>
>
> String address = "http:// 10.0.2.243:8160";
>
> Bus _defaultBUS = BusFactory.getDefaultBus();
>
> JettyHTTPServerEngineFactory jettyFactory =
>
>
> _defaultBUS.getExtension(JettyHTTPServerEngineFactory.class);
>
> // get the jetty server form the destination
>
> EndpointInfo ei = new EndpointInfo();
>
> ei.setAddress(address);
>
> DestinationFactoryManager dfm =
>
> _defaultBUS.getExtension(DestinationFactoryManager.class);
>
> DestinationFactory df = dfm.getDestinationFactoryForUri(address);
>
> JettyHTTPDestination destination =
>
>          (JettyHTTPDestination) df.getDestination(ei);
>
>
>
> JettyHTTPDestination jettyDestination = (JettyHTTPDestination) destination;
>
> ServerEngine engine = jettyDestination.getEngine();
>
> Handler handler = engine.getServant(new URL(address));
>
> org.eclipse.jetty.server.Server server = handler.getServer(); // The Server
>
>
>
> // We have to create a HandlerList structure that includes both a
> ResourceHandler for the static
>
> // content as well as the ContextHandlerCollection created by CXF (which we
> retrieve as serverHandler).
>
> Handler serverHandler = server.getHandler();
>
> HandlerList handlerList = new HandlerList();
>
> ResourceHandler resourceHandler = new ResourceHandler();
>
> handlerList.addHandler(resourceHandler);
>
> handlerList.addHandler(serverHandler);
>
>
>
> // replace the CXF servlet connect collection with the list.
>
> server.setHandler(handlerList);
>
> // and tell the handler list that it is alive.
>
> handlerList.start();
>
>
>
> // setup the resource handler
>
> File staticContentFile = new File(staticContentPath); // ordinary pathname.
>
> URL targetURL = new URL("file://" + staticContentFile.getCanonicalPath());
>
> FileResource fileResource = new FileResource(targetURL);
>
> resourceHandler.setBaseResource(fileResource);
>
>
>
> But unfortunately it does not work and it spoils my endpoint.
>
>
>
> Could you suggest an alternative java-based approach to serve the
> clientaccesspolicy.xml file?
>
>
>
> Thank you very much.
>
>
>
> Matteo Rulli
>
>
>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: Fwd: serve static content through jetty

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 09/02/12 05:21, Matteo Rulli wrote:
> The file is on the classpath. More precisely is in a folder which is specified in xbootclasspath option with append option. This usually works well with wss4j configuration files, so I thought it could work also for jetty.
>

I guess there are few options there, one is to rely on the pax-web 
configuration, see this advice from Sven:
http://cxf.547215.n5.nabble.com/Distributed-OSGi-Maximum-number-of-parallel-requests-24-tp5463221p5467123.html

Most of it will apply to any OSGI application which relies on OSGI 
HttpService.

Perhaps a more involved option is to get hold of HttpService and 
register a filter with it which will serve the static content. I think 
there must be few higher-level utility libraries out there which follow 
this approach...

Actually, possibly a much simpler option to try (assuming you rely on 
CXF Http Transport OSGI support) is to set this OSGI property:
"org.apache.cxf.servlet.static-resources-list", (the persistend-id of 
the CXF OSGI properties is "org.apache.cxf.osgi"). For example, set it 
to '*.xml'. CXF Servlet may be able to fetch this resource given that on 
the class path...

Give it a go and let us know which option may work for you :-)
Sergey


> Matteo Rulli
>
> Begin forwarded message:
>
>> From: Sergey Beryozkin<sb...@gmail.com>
>> Date: February 8, 2012 22:25:14 GMT+01:00
>> To: users@cxf.apache.org
>> Subject: Re: serve static content through jetty
>> Reply-To: users@cxf.apache.org
>>
>> Hi
>>
>> On 08/02/12 17:10, matteo rulli wrote:
>>> Dear all,
>>>
>>> I publish some soap-WS through CXF (v. 2.5.0 - bundled into OSGi equinox) on
>>> the following URI:
>>>
>>>
>>>
>>> http://10.0.2.243:8160/Persistence
>>>
>>>
>>>
>>> The problem is that when a Silverlight client tries to consume my WS, a
>>> "get" request for a resource called clientaccesspolicy.xml is generated,
>>> namely
>>>
>>> http:// 10.0.2.243:8160/clientaccesspolicy.xml
>>> <http://%2010.0.2.243:8160/clientaccesspolicy.xml>
>>
>> where exactly is this file located/created ? Is it available before the bundle is even started for the very first time ?
>>
>> Cheers, Sergey
>>
>>
>>>
>>>
>>>
>>> Is there a way to configure Jetty to serve this file? I should perform this
>>> programmatically. I tried with something like (sorry for that, I know it is
>>> a very awkward attempt of mine to reproduce the
>>> <http://cxf.apache.org/docs/standalone-http-transport.html>
>>> http://cxf.apache.org/docs/standalone-http-transport.html example):
>>>
>>>
>>>
>>> String address = "http:// 10.0.2.243:8160";
>>>
>>> Bus _defaultBUS = BusFactory.getDefaultBus();
>>>
>>> JettyHTTPServerEngineFactory jettyFactory =
>>>
>>>
>>> _defaultBUS.getExtension(JettyHTTPServerEngineFactory.class);
>>>
>>> // get the jetty server form the destination
>>>
>>> EndpointInfo ei = new EndpointInfo();
>>>
>>> ei.setAddress(address);
>>>
>>> DestinationFactoryManager dfm =
>>>
>>> _defaultBUS.getExtension(DestinationFactoryManager.class);
>>>
>>> DestinationFactory df = dfm.getDestinationFactoryForUri(address);
>>>
>>> JettyHTTPDestination destination =
>>>
>>>          (JettyHTTPDestination) df.getDestination(ei);
>>>
>>>
>>>
>>> JettyHTTPDestination jettyDestination = (JettyHTTPDestination) destination;
>>>
>>> ServerEngine engine = jettyDestination.getEngine();
>>>
>>> Handler handler = engine.getServant(new URL(address));
>>>
>>> org.eclipse.jetty.server.Server server = handler.getServer(); // The Server
>>>
>>>
>>>
>>> // We have to create a HandlerList structure that includes both a
>>> ResourceHandler for the static
>>>
>>> // content as well as the ContextHandlerCollection created by CXF (which we
>>> retrieve as serverHandler).
>>>
>>> Handler serverHandler = server.getHandler();
>>>
>>> HandlerList handlerList = new HandlerList();
>>>
>>> ResourceHandler resourceHandler = new ResourceHandler();
>>>
>>> handlerList.addHandler(resourceHandler);
>>>
>>> handlerList.addHandler(serverHandler);
>>>
>>>
>>>
>>> // replace the CXF servlet connect collection with the list.
>>>
>>> server.setHandler(handlerList);
>>>
>>> // and tell the handler list that it is alive.
>>>
>>> handlerList.start();
>>>
>>>
>>>
>>> // setup the resource handler
>>>
>>> File staticContentFile = new File(staticContentPath); // ordinary pathname.
>>>
>>> URL targetURL = new URL("file://" + staticContentFile.getCanonicalPath());
>>>
>>> FileResource fileResource = new FileResource(targetURL);
>>>
>>> resourceHandler.setBaseResource(fileResource);
>>>
>>>
>>>
>>> But unfortunately it does not work and it spoils my endpoint.
>>>
>>>
>>>
>>> Could you suggest an alternative java-based approach to serve the
>>> clientaccesspolicy.xml file?
>>>
>>>
>>>
>>> Thank you very much.
>>>
>>>
>>>
>>> Matteo Rulli
>>>
>>>
>>>
>>>
>>
>>
>> --
>> Sergey Beryozkin
>>
>> Talend Community Coders
>> http://coders.talend.com/
>>
>> Blog: http://sberyozkin.blogspot.com
>>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Fwd: serve static content through jetty

Posted by Matteo Rulli <ab...@abodata.com>.
The file is on the classpath. More precisely is in a folder which is specified in xbootclasspath option with append option. This usually works well with wss4j configuration files, so I thought it could work also for jetty. 

Matteo Rulli

Begin forwarded message:

> From: Sergey Beryozkin <sb...@gmail.com>
> Date: February 8, 2012 22:25:14 GMT+01:00
> To: users@cxf.apache.org
> Subject: Re: serve static content through jetty
> Reply-To: users@cxf.apache.org
> 
> Hi
> 
> On 08/02/12 17:10, matteo rulli wrote:
>> Dear all,
>> 
>> I publish some soap-WS through CXF (v. 2.5.0 - bundled into OSGi equinox) on
>> the following URI:
>> 
>>  
>> 
>> http://10.0.2.243:8160/Persistence
>> 
>> 
>> 
>> The problem is that when a Silverlight client tries to consume my WS, a
>> "get" request for a resource called clientaccesspolicy.xml is generated,
>> namely
>> 
>> http:// 10.0.2.243:8160/clientaccesspolicy.xml
>> <http://%2010.0.2.243:8160/clientaccesspolicy.xml>
> 
> where exactly is this file located/created ? Is it available before the bundle is even started for the very first time ?
> 
> Cheers, Sergey
> 
> 
>> 
>> 
>> 
>> Is there a way to configure Jetty to serve this file? I should perform this
>> programmatically. I tried with something like (sorry for that, I know it is
>> a very awkward attempt of mine to reproduce the
>> <http://cxf.apache.org/docs/standalone-http-transport.html>
>> http://cxf.apache.org/docs/standalone-http-transport.html example):
>> 
>> 
>> 
>> String address = "http:// 10.0.2.243:8160";
>> 
>> Bus _defaultBUS = BusFactory.getDefaultBus();
>> 
>> JettyHTTPServerEngineFactory jettyFactory =
>> 
>> 
>> _defaultBUS.getExtension(JettyHTTPServerEngineFactory.class);
>> 
>> // get the jetty server form the destination
>> 
>> EndpointInfo ei = new EndpointInfo();
>> 
>> ei.setAddress(address);
>> 
>> DestinationFactoryManager dfm =
>> 
>> _defaultBUS.getExtension(DestinationFactoryManager.class);
>> 
>> DestinationFactory df = dfm.getDestinationFactoryForUri(address);
>> 
>> JettyHTTPDestination destination =
>> 
>>         (JettyHTTPDestination) df.getDestination(ei);
>> 
>> 
>> 
>> JettyHTTPDestination jettyDestination = (JettyHTTPDestination) destination;
>> 
>> ServerEngine engine = jettyDestination.getEngine();
>> 
>> Handler handler = engine.getServant(new URL(address));
>> 
>> org.eclipse.jetty.server.Server server = handler.getServer(); // The Server
>> 
>> 
>> 
>> // We have to create a HandlerList structure that includes both a
>> ResourceHandler for the static
>> 
>> // content as well as the ContextHandlerCollection created by CXF (which we
>> retrieve as serverHandler).
>> 
>> Handler serverHandler = server.getHandler();
>> 
>> HandlerList handlerList = new HandlerList();
>> 
>> ResourceHandler resourceHandler = new ResourceHandler();
>> 
>> handlerList.addHandler(resourceHandler);
>> 
>> handlerList.addHandler(serverHandler);
>> 
>> 
>> 
>> // replace the CXF servlet connect collection with the list.
>> 
>> server.setHandler(handlerList);
>> 
>> // and tell the handler list that it is alive.
>> 
>> handlerList.start();
>> 
>> 
>> 
>> // setup the resource handler
>> 
>> File staticContentFile = new File(staticContentPath); // ordinary pathname.
>> 
>> URL targetURL = new URL("file://" + staticContentFile.getCanonicalPath());
>> 
>> FileResource fileResource = new FileResource(targetURL);
>> 
>> resourceHandler.setBaseResource(fileResource);
>> 
>> 
>> 
>> But unfortunately it does not work and it spoils my endpoint.
>> 
>> 
>> 
>> Could you suggest an alternative java-based approach to serve the
>> clientaccesspolicy.xml file?
>> 
>> 
>> 
>> Thank you very much.
>> 
>> 
>> 
>> Matteo Rulli
>> 
>> 
>> 
>> 
> 
> 
> -- 
> Sergey Beryozkin
> 
> Talend Community Coders
> http://coders.talend.com/
> 
> Blog: http://sberyozkin.blogspot.com
> 

R: serve static content through jetty

Posted by matteo rulli <ma...@abodata.com>.
The file is on the classpath. More precisely, I put its path in a
-Xbootclasspath jvm argument with append option. This usually works well
with wss4j property files, so I thought it could work also with jetty...


-----Messaggio originale-----
Da: Sergey Beryozkin [mailto:sberyozkin@gmail.com] 
Inviato: mercoledì 8 febbraio 2012 22:25
A: users@cxf.apache.org
Oggetto: Re: serve static content through jetty

Hi

On 08/02/12 17:10, matteo rulli wrote:
> Dear all,
>
> I publish some soap-WS through CXF (v. 2.5.0 - bundled into OSGi equinox)
on
> the following URI:
>
>
>
> http://10.0.2.243:8160/Persistence
>
>
>
> The problem is that when a Silverlight client tries to consume my WS, a
> "get" request for a resource called clientaccesspolicy.xml is generated,
> namely
>
> http:// 10.0.2.243:8160/clientaccesspolicy.xml
> <http://%2010.0.2.243:8160/clientaccesspolicy.xml>

where exactly is this file located/created ? Is it available before the 
bundle is even started for the very first time ?

Cheers, Sergey


>
>
>
> Is there a way to configure Jetty to serve this file? I should perform
this
> programmatically. I tried with something like (sorry for that, I know it
is
> a very awkward attempt of mine to reproduce the
> <http://cxf.apache.org/docs/standalone-http-transport.html>
> http://cxf.apache.org/docs/standalone-http-transport.html example):
>
>
>
> String address = "http:// 10.0.2.243:8160";
>
> Bus _defaultBUS = BusFactory.getDefaultBus();
>
> JettyHTTPServerEngineFactory jettyFactory =
>
>
> _defaultBUS.getExtension(JettyHTTPServerEngineFactory.class);
>
> // get the jetty server form the destination
>
> EndpointInfo ei = new EndpointInfo();
>
> ei.setAddress(address);
>
> DestinationFactoryManager dfm =
>
> _defaultBUS.getExtension(DestinationFactoryManager.class);
>
> DestinationFactory df = dfm.getDestinationFactoryForUri(address);
>
> JettyHTTPDestination destination =
>
>          (JettyHTTPDestination) df.getDestination(ei);
>
>
>
> JettyHTTPDestination jettyDestination = (JettyHTTPDestination)
destination;
>
> ServerEngine engine = jettyDestination.getEngine();
>
> Handler handler = engine.getServant(new URL(address));
>
> org.eclipse.jetty.server.Server server = handler.getServer(); // The
Server
>
>
>
> // We have to create a HandlerList structure that includes both a
> ResourceHandler for the static
>
> // content as well as the ContextHandlerCollection created by CXF (which
we
> retrieve as serverHandler).
>
> Handler serverHandler = server.getHandler();
>
> HandlerList handlerList = new HandlerList();
>
> ResourceHandler resourceHandler = new ResourceHandler();
>
> handlerList.addHandler(resourceHandler);
>
> handlerList.addHandler(serverHandler);
>
>
>
> // replace the CXF servlet connect collection with the list.
>
> server.setHandler(handlerList);
>
> // and tell the handler list that it is alive.
>
> handlerList.start();
>
>
>
> // setup the resource handler
>
> File staticContentFile = new File(staticContentPath); // ordinary
pathname.
>
> URL targetURL = new URL("file://" + staticContentFile.getCanonicalPath());
>
> FileResource fileResource = new FileResource(targetURL);
>
> resourceHandler.setBaseResource(fileResource);
>
>
>
> But unfortunately it does not work and it spoils my endpoint.
>
>
>
> Could you suggest an alternative java-based approach to serve the
> clientaccesspolicy.xml file?
>
>
>
> Thank you very much.
>
>
>
> Matteo Rulli
>
>
>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com