Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

No Format
EndpointReferenceType create(int val) {
   synchronized (this) {
     if (!servicePublished) {
        publishSingleInstanceServant(SERVICE_QNAME);
        servicePublished = true;
     }
   }
   String state = String.valueOf(val);
   String portName = null; // unless there are multiple ports in the service 
   return EndpointReferenceUtils.getEndpointReferenceWithId(SERVICE_QNAME, 
              portName, state, BusFactory.getDefaultBus()); 
 }

Here is the skeleton implementation of Number.isEven():

No Format
 

    @Resource
    protected WebServiceContext wsContext;
    
    public boolean isEven() {

        MessageContext messageContext = wsContext.getMessageContext();
        String state = EndpointReferenceUtils
            .getCurrentEndpointReferenceId(messageContext);
        
        int val = Integer.parseInt(state);
        return valIsEven(val);
    }
How does it Work

The API uses WS-Addressing(WS-A) reference parameters to embed the users state in an EndpointReference. The reference parameters are part of the EPR that is returned to the caller. WS-A interceptors are used to propagate the reference parameters as a soap header on subsequent invocations using the returned EPR. On the receiving side, the current WS-A MEPs are queried to extract the state from the reference parameters.

...

The multiplexWithAddress property for HTTP is enabled by adding the following to cxf.xml

No Format
 <bean name="<port name>.http-destination" abstract="true">
   <property name="multiplexWithAddress" value="true"/>
 </bean>

 <!-- or for all http ports (using a wildcard) -->
 <bean name="*" abstract="true" class="org.apache.cxf.transport.http_jetty.JettyHTTPDestination">
   <property name="multiplexWithAddress" value="true"/>
 </bean>
Using EndpointRefernces with a JAX-WS Service

...

Sample JAX-WS client code would do the following to access a Number instance using an EPR -

No Format
 

    NumberFactoryService service = new NumberFactoryService();
    NumberFactory factory = service.getNumberFactoryPort();
        
    EndpointReferenceType epr = factory.create("20");
    NumberService numService = new NumberService();
    ServiceImpl serviceImpl = ServiceDelegateAccessor.get(numService);                   
    Number num = (Number)serviceImpl.getPort(epr, Number.class);
    ...