Hi,

I've dug into this a bit further. The problem is that <<Endpoint jaxwsEp = 
Endpoint.publish(address, service)>> fails with a ServiceConstructionException 
("org.apache.cxf.service.factory.ServiceConstructionException: Failed to create 
service"). Might there be a problem with the service passed? The class is 
called like this: 

    public ChildOfJaxWsNotificationBroker(String name,
            ConnectionFactory connectionFactory, EndpointManager epManager) {
        //Original call:
        //super(name, connectionFactory, epManager);
        //New call copied from JaxwsNotificationBroker(String name, 
ConnectionFactory connectionFactory, EndpointManager epManager)
        super(name, connectionFactory);
        if (epManager == null) {
            manager = new MyWsnEndpointManager();
        } else {
            manager = epManager;
        }
    }

The original version still works fine; there's some bug in my 
MyWsnEndpointManager which I can't identify.

Thank you for any pointers
Anne

-----Ursprüngliche Nachricht-----
Von: Diefenbach, Anne <anne.diefenb...@fkie.fraunhofer.de> 
Gesendet: Freitag, 17. Mai 2019 17:48
An: users@cxf.apache.org
Cc: cohei...@apache.org
Betreff: AW: Adding interceptors to Notification Broker

Hi Colm,

thank you very much for the help! It's taken me a while, but I've overridden 
the JaxwsEndpointManager as suggested. Unfortunately, my interceptors still 
aren't picked up as far as I can tell - I can find their log entries from where 
I've used them in another component, but not from the Notification Broker. Do 
you have any idea why that might be? Code below.

Thank you so much!
Anne


import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Endpoint;

import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.wsn.AbstractEndpoint;
import org.apache.cxf.wsn.EndpointManager;
import org.apache.cxf.wsn.services.JaxwsEndpointManager;
import org.apache.cxf.wsn.EndpointRegistrationException;
import org.apache.cxf.wsn.util.WSNHelper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyWsnEndpointManager extends JaxwsEndpointManager {
    private Logger log = LoggerFactory.getLogger(MyWsnEndpointManager.class);

        public Endpoint register(String address, Object service, URL 
wsdlLocation) throws EndpointRegistrationException {

                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                try {
                    if (WSNHelper.getInstance().setClassLoader()) {
                
Thread.currentThread().setContextClassLoader(JaxwsEndpointManager.class.getClassLoader());
                    }

                    Endpoint jaxwsEp = Endpoint.publish(address, service);

                    if (wsdlLocation != null) {
                try {
                    if (jaxwsEp.getProperties() == null) {
                    jaxwsEp.setProperties(new HashMap<String, Object>());
                    }
                    
jaxwsEp.getProperties().put("javax.xml.ws.wsdl.description", 
wsdlLocation.toExternalForm());
                    List<Source> mt = new ArrayList<>();
                    StreamSource src = new 
StreamSource(wsdlLocation.openStream(), wsdlLocation.toExternalForm());
                    mt.add(src);
                    jaxwsEp.setMetadata(mt);
                } catch (IOException e) {
                    //ignore, no wsdl really needed
                }
                    }

                    EndpointImpl epi = (EndpointImpl) jaxwsEp;
            try {
                org.apache.cxf.endpoint.Endpoint cxfEp = 
epi.getServer().getEndpoint();
                cxfEp.getInInterceptors().add(new MyInInterceptor());
                cxfEp.getOutInterceptors().add(new myOutInterceptor());
            } catch (Exception ex) {
                log.warn(ex.toString());
            }
            try {
                if (super.mbeanServer != null
                    && service instanceof AbstractEndpoint) {
                    ObjectName on = ((AbstractEndpoint)service).getMBeanName();
                    if (on != null) {
                    super.mbeanServer.registerMBean(service, on);
                    }
                }
            } catch (Exception ex) {
            //ignore for now
            }
            return jaxwsEp;
                } finally {
                    Thread.currentThread().setContextClassLoader(cl);
                }
        }       
}

-----Ursprüngliche Nachricht-----
Von: Colm O hEigeartaigh <cohei...@apache.org>
Gesendet: Mittwoch, 1. Mai 2019 10:54
An: users@cxf.apache.org
Betreff: Re: Adding interceptors to Notification Broker

Hi Anne,

The WS-Notification broker uses the standard JAX-WS APIs to create the services 
(and so uses CXF under the hood). What you need to do is to customise the 
JaxwsEndpointManager. For example, instead of:

Endpoint.create(bindingId, service);

you could add a CXF Feature via:

Endpoint.create(bindingId, service, new LoggingFeature());

You can add CXF interceptors via something like:

EndpointImpl ep = (EndpointImpl) Endpoint.publish("http://localhost/service";,
implementor);
ep.getServer().getEndpoint().getInInterceptors().add(new
LoggingInInterceptor());

I've merged a tiny update to the JaxwsEndpointManager to make it easier to 
override the creation of the Endpoint and so add CXF Feature/interceptors:

https://github.com/apache/cxf/commit/cc0f12533d407baabc29c2a1131520012db97662

Colm.


On Tue, Apr 30, 2019 at 1:56 PM Diefenbach, Anne < 
anne.diefenb...@fkie.fraunhofer.de> wrote:

> Hi,
>
> does anyone have any ideas on this? Does the Notification Broker 
> shipped with CXF even use the CXF bus so interceptors can hook into 
> it? I thought that the interface probably is provided via CXF, but as 
> I said, I can't find any point where I could add the interceptors.
>
> Thank you for any pointers
> Anne
>
> -----Ursprüngliche Nachricht-----
> Von: Diefenbach, Anne <anne.diefenb...@fkie.fraunhofer.de>
> Gesendet: Mittwoch, 17. April 2019 10:54
> An: users@cxf.apache.org
> Betreff: Adding interceptors to Notification Broker
>
> Hi,
>
> we've extended the JaxwsNotificationBroker in a previous project, 
> inheriting all its methods in our NotificationBroker and adding a new 
> Starter class which (as far as I can tell) replaces Service.java. Now 
> I want to add some interceptors to log incoming and outgoing messages.
> How do I do that? Placing a beans.xml in our resources/META-INF does 
> nothing. I have no idea how to access a Server object to add the 
> interceptors programmatically - the only object I have access to is 
> the JaxwsNotificationBroker instance. SEI and service class are 
> generated from WSDL, so I can't edit them. Does anyone have any tips 
> how I can get my interceptors in there?
>
> Thank you very much for any help!
> Anne
>
>

--
Colm O hEigeartaigh

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

Reply via email to