Thanks you two for helping me! I've managed to do it.

My ErrorHandler class is like:
-----------------------------------------------------------------------
public class ProvaHandler extends ErrorHandler{

    @Override
    public void handle(String target, Request request1, HttpServletRequest
request, HttpServletResponse response) throws IOException {
            Request base_request = request1;

            if(base_request.getRequestURI().startsWith("/helloWorld"))
                base_request.setHandled(false);
            else{
                base_request.setHandled(true);
                response.setContentType("text/html");
                response.setStatus(HttpServletResponse.SC_OK);
                response.getWriter().println("<h1>Address not
permitted</h1>");
            }
    }
}
-------------------------------------------------------
do you think it's a good/smart way to handle pages out of my WS uri (my
service is register as "helloWorld")? Are there any cleaner ways?

Thanks
Matteo


On 21 December 2010 01:16, Freeman Fang <[email protected]> wrote:

> Hi,
>
> You can easily use the option 3 "Custom error handle class" with cxf
> embeded jetty, register your customer error handler to jetty engine,
>
> If you are using spring configuration way, it should be like
>
>
>  <httpj:engine-factory bus="cxf">
>      .....
>      <httpj:handlers>
>        <beans:bean class="your_error_handler_class"/>
>      </httpj:handlers>
>  </httpj:engine-factory>
>  </beans>
> more details take a look at [1]
>
> If you are using java code, you can do something like
>
>
> System.out.println("Starting Server");
> HelloWorldImpl implementor = new HelloWorldImpl();
> String address = "http://localhost:9000/helloWorld";;
> org.apache.cxf.jaxws.EndpointImpl endpoint =
> (org.apache.cxf.jaxws.EndpointImpl)Endpoint.publish(address, implementor);
> if (endpoint.getServer().getDestination() instanceof JettyHTTPDestination)
> {
>            JettyHTTPDestination jettyDest = (JettyHTTPDestination)
> endpoint.getServer.getDestination();
>            JettyHTTPServerEngine jettyEng = (JettyHTTPServerEngine)
> jettyDest.getEngine();
>            List<Handler> handlers = jettyEng.getHandlers();
>            if (handlers == null) {
>                handlers = new ArrayList<Handler>();
>                jettyEng.setHandlers(handlers);
>            }
>            handlers.add(new YourErrorHandler(());
>        }
>
>
> Hope this helps.
>
> [1]http://cxf.apache.org/docs/jetty-configuration.html
>
> Freeman
>
>
>
> On 2010-12-21, at 上午12:00, Matteo Bertamini wrote:
>
>  Hi everyone!
>> I'm new to CXF but I'm finding very well with it. I'm using it to create
>> a web service with the JAX-WS frontend and the default embedded Jetty:
>>
>> ---------------------------
>> System.out.println("Starting Server");
>> HelloWorldImpl implementor = new HelloWorldImpl();
>> String address = "http://localhost:9000/helloWorld";;
>> Endpoint e = Endpoint.publish(address, implementor);
>> ---------------------------
>>
>> everything is working fine in my example, but I would like to handle the
>> HTTP errors like "404 not found", just to personalize my service in case
>> someone points to my server address to see what happens.
>>
>> I've found this page for personalizing what I want in Jetty:
>> http://docs.codehaus.org/display/JETTY/How+to+Create+Custom+Error+Pages
>>
>> but I really don't know how to associate this configuration to my
>> default Jetty CXF server. I'm also using an cxf.xml configuration file
>> to personalize the Jetty threads:
>> ----------------------------------------
>> <beans xmlns="http://www.springframework.org/schema/beans";
>>      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>>        xmlns:httpj="
>> http://cxf.apache.org/transports/http-jetty/configuration";
>>        xsi:schemaLocation="http://www.springframework.org/schema/beans
>> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
>>
>> http://cxf.apache.org/transports/http-jetty/configuration
>> http://cxf.apache.org/schemas/configuration/http-jetty.xsd";>
>> <httpj:engine-factory bus="cxf">
>> <!-- You can specify a value of 0 for the port attribute. Any threading
>> properties specified in an httpj:engine element with its port attribute
>> set to 0 are used as the configuration for all Jetty listeners that are
>> not explicitly configured. -->
>>   <httpj:engine port="0">
>>     <httpj:threadingParameters minThreads="5"
>>                                maxThreads="15" />
>>   </httpj:engine>
>>  </httpj:engine-factory>
>>
>>
>> </beans>
>> ----------------------------------------
>>
>> but I don't know if I can put some configuration I need here because I
>> haven't found any info about it.
>>
>> Does someone know a little more about it? Any piece of suggestion?
>>
>> Thanks :-)
>> Matteo
>>
>>
>
> --
> Freeman Fang
>
> ------------------------
>
> FuseSource: http://fusesource.com
> blog: http://freemanfang.blogspot.com
> twitter: http://twitter.com/freemanfang
> Apache Servicemix:http://servicemix.apache.org
> Apache Cxf: http://cxf.apache.org
> Apache Karaf: http://karaf.apache.org
> Apache Felix: http://felix.apache.org
>
>

Reply via email to