cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Grzegorz Grzybek (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-5388) Can't register two similar callbacks to different services
Date Tue, 19 Nov 2013 13:49:23 GMT

    [ https://issues.apache.org/jira/browse/CXF-5388?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13826518#comment-13826518
] 

Grzegorz Grzybek commented on CXF-5388:
---------------------------------------

After some research (thank you Jürgen for help!), Here's the solution.

First - there *is* a need to be able to create more than one Server (and underneath: POA,
Servant, CorbaDestination) for the same set of inputs:
* WSDL (with single {{wsdl:service/wsdl:port}})
* implementation class (the instances are different)
* service name
* endpoint (port) name

The goal is to be able to publish different Corba objects (different IORs) wrapped inside
W3CEndpointReference.

The existing code:
{code:java}
            poaName = CorbaUtils.getUniquePOAName(getEndPointInfo()
                    .getService().getName(), getEndPointInfo().getName()
                    .getLocalPart(), poaName).replace('.', '_');
{code}

doesn't have anything to distinguish between consecutive invocations. Anything except initial
{{poaName}} - which may be customized by {{corba:policy}} extension of {{wsdl:service/wsdl:port}}.

So my solution is to create a listener which would allow to dynamically add the {{org.apache.cxf.binding.corba.wsdl.PolicyType}}
to just created endpoint:

1. The listener (not thread safe!)

{code:java}
    private static final class PoaNameCustomizer implements FactoryBeanListener {
        private String poaName;

        @Override
        public void handleEvent(Event ev, AbstractServiceFactoryBean factory, Object ... args)
{
            switch (ev) {
                case ENDPOINT_CREATED: {
                    EndpointInfo ei = (EndpointInfo)args[0];
                    PolicyType pt = new PolicyType();
                    pt.setPoaname(this.poaName);
                    ei.addExtensor(pt);
                    break;
                }
                default:
                    //do nothing
            }
        }

        public void setPoaName(String poaName) {
            this.poaName = poaName;
        }
    }
{code}

2. Bus configuration (before any service creation)

{code:java}
        Bus bus = BusFactory.getDefaultBus();
        FactoryBeanListenerManager m = bus.getExtension(FactoryBeanListenerManager.class);
        PoaNameCustomizer poaNameCustomizer = new PoaNameCustomizer();
        m.addListener(poaNameCustomizer);
{code}

3. Now, after creating JaxWsServerFactoryBean, a little bit of customization (setting customized
bus):

{code:java}
        svrFactory.setBus(bus);
{code}

4. And just before svrFactory.create(); A configuration of the bus' Poa Name listener:

{code:java}
            ...
            svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
            poaNameCustomizer.setPoaName("poa1"); // different value for next service creation
            Server s = svrFactory.create();
{code}

After this, Jürgen's code works fine.

regards
Grzegorz Grzybek

> Can't register two similar callbacks to different services
> ----------------------------------------------------------
>
>                 Key: CXF-5388
>                 URL: https://issues.apache.org/jira/browse/CXF-5388
>             Project: CXF
>          Issue Type: Bug
>          Components: CORBA Binding
>    Affects Versions: 2.7.8
>         Environment: Windows / JAVA 7/ CXF 2.7.8-SNAPSHOT
>            Reporter: Jürgen Bockhorn
>            Priority: Blocker
>
> Hi,
> our client application we need to register multiple similar callbacks to different similar
services.
> This is done by using this code:
> {code}
> 		    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
> 		    svrFactory.setServiceClass(CallbackImpl.class);
> 		    
> 		    //Attention: It is necessary that thre is at least one character after the IOR:.
Doesn't matter which character(s). 
>                     //Whithout this it's not a legal URL
> 		    svrFactory.setAddress("IOR:callback");
> 		    svrFactory.setEndpointName( new QName( http://zst.heuboe.de", 
> 		            "CallbackCORBAPort" ) );
> 		    svrFactory.setServiceName(  new QName( "http://zst.heuboe.de", 
> 		            "CallbackCORBAService" ) ); 
> 		    svrFactory.setServiceBean(new CallbackImpl());
> 		    svrFactory.setWsdlLocation("classpath:guiService.wsdl");
> 		    svrFactory.getInInterceptors().add(new LoggingInInterceptor());
> 		    svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
> 		    Server s = svrFactory.create();
> 		    EndpointReferenceType epr = s.getDestination().getAddress();
> 		    Source src = EndpointReferenceUtils.convertToXML(epr);
> 		    W3CEndpointReference ref = new W3CEndpointReference(src);
> {code}
> If you call this code a second time you get an exception in CorbaDestination at this
point:
> {code:title=CorbaDestination-Snipplet}
>             // When using object references, we can run into a situation where
>             // we are implementing
>             // multiple instances of the same port type such that we would end
>             // up using the same
>             // poaname for each when persistance is used. Handle this case by
>             // not throwing an
>             // exception at this point during the activation, we should see an
>             // exception if we try
>             // an activate two objects with the same servant ID instead.
>             if (bindingPOA != null && !isPersistent && serviceId == null)
{
>                 throw new CorbaBindingException(
>                         "Corba Port activation failed because the poa "
>                                 + poaName + " already exists");
>             } else if (bindingPOA == null) {
>                 bindingPOA = createPOA(poaName, rootPOA, poaManager);
>             }
> {code}
> In my opinion it should be possible to register multiple callbacks of the same 'type'.
> Thx
> Jürgen



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message