Example usage for javax.xml.ws.handler PortInfo getPortName

List of usage examples for javax.xml.ws.handler PortInfo getPortName

Introduction

In this page you can find the example usage for javax.xml.ws.handler PortInfo getPortName.

Prototype

public QName getPortName();

Source Link

Document

Gets the qualified name of the WSDL port being accessed.

Usage

From source file:org.apache.axis2.jaxws.handler.HandlerResolverImpl.java

public List<Handler> getHandlerChain(PortInfo portInfo) {
    List<Class> handlerClasses = getHandlerClasses(portInfo);

    if (handlerClasses.size() == 0) {
        return new ArrayList<Handler>();
    }//from  w  w w .ja v  a 2  s  .c o  m

    ArrayList<Handler> handlers = new ArrayList<Handler>();
    // Create temporary MessageContext to pass information to HandlerLifecycleManager
    MessageContext ctx = new MessageContext();
    ctx.setEndpointDescription(serviceDesc.getEndpointDescription(portInfo.getPortName()));

    HandlerLifecycleManager hlm = createHandlerlifecycleManager();

    for (Iterator<Class> iterator = handlerClasses.iterator(); iterator.hasNext();) {
        Class aClass = iterator.next();
        //  instantiate portHandler class 
        try {
            handlers.add(hlm.createHandlerInstance(ctx, aClass));
        } catch (Exception e) {
            // TODO: should we just ignore this problem?
            throw ExceptionFactory.makeWebServiceException(e);
        }
        if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) {
            log.debug("Successfully instantiated the class: " + aClass);
        }

    }
    return handlers;
}

From source file:org.apache.axis2.jaxws.handler.HandlerResolverImpl.java

/**
 * Resolve the handlers and roles for the given port.  This will process the handler configuration
 * information, which can be specified either in a file on a HandlerChain annotaiton or via a
 * deployment descriptor.  The handler classes and the SOAP roles played will be resolved and
 * returned./*from   w  ww. j  a v a  2s  .  co  m*/
 * 
 * @param portinfo  Information describing the port for which the handlers and roles are to be
 *     resolved
 * @param handlerRoles  OUTPUT PARAMETER!  The List that is passed in will be updated with the
 *     roles relevant to the specfied port.
 * @return List of handler classes relevant to the specified port.
 * @throws WebServiceException
 */
private ArrayList<Class> resolveHandlers(PortInfo portinfo, List<String> handlerRoles)
        throws WebServiceException {
    /*
    A sample XML file for the handler-chains:
            
    <jws:handler-chains xmlns:jws="http://java.sun.com/xml/ns/javaee">
        <jws:handler-chain>
            <jws:protocol-bindings>##XML_HTTP</jws:protocol-bindings>
            <jws:handler>
                <jws:handler-name>MyHandler</jws:handler-name>
                <jws:handler-class>org.apache.axis2.jaxws.MyHandler</jws:handler-class>
            </jws:handler>
        </jws:handler-chain>
        <jws:handler-chain>
            <jws:port-name-pattern>jws:Foo*</jws:port-name-pattern>
            <jws:handler>
                <jws:handler-name>MyHandler</jws:handler-name>
                <jws:handler-class>org.apache.axis2.jaxws.MyHandler</jws:handler-class>
                <jws:soap-role>http://org/apache/axis2/jaxws/MyRole</jws:soap-role>
            </jws:handler>
        </jws:handler-chain>
        <jws:handler-chain>
            <jws:service-name-pattern>jws:Bar</jws:service-name-pattern>
            <jws:handler>
                <jws:handler-name>MyHandler</jws:handler-name>
                <jws:handler-class>org.apache.axis2.jaxws.MyHandler</jws:handler-class>
            </jws:handler>
        </jws:handler-chain>
    </jws:handler-chains>
            
    Couple of things I'm not sure about...
    1)  if the protocol-binding, port-name-pattern, and service-name-pattern all
        match the PortInfo object, does MyHandler get added three times?  Probably would get added 3 times.
    2)  I assume the asterisk "*" is a wildcard.  Can the asterisk only occur on the local part of the qname?
    3)  Can there be more than one service-name-pattern or port-name-pattern, just like for protocol-bindings?
    4)  How many protocol-bindings are there?  ##XML_HTTP ##SOAP11_HTTP ##SOAP12_HTTP ##SOAP11_HTTP_MTOM ##SOAP12_HTTP_MTOM
        They are separated by spaces
     */

    // our implementation already has a reference to the EndpointDescription,
    // which is where one might get the portinfo object.  We still have the 
    // passed-in variable, however, due to the spec

    ArrayList<Class> handlers = new ArrayList<Class>();

    /*
     * TODO: do a better job checking that the return value matches up
     * with the PortInfo object before we add it to the chain.
     */

    // The HandlerChain annotation can be specified on:
    // - a service implementation (per JSR-181) which is on the service-provider side
    // - an SEI (per JSR-181), which can be on both the service-provider and 
    //   service-requester sides
    // - a generated Service (per JSR-224), which is on the service-requester side
    //
    // The order of precedence here is a bit counter intuitive if the HandlerChain annotation
    // is present on more than one class.  
    // - For the service-provider, JSR-181 [p. 25, Section 4.6.1]
    //   states that the service implementation's HandlerChain takes is used if it is present
    //   on both the implementation and the SEI.
    // - Following that same pattern, we conclude that a generated service HandlerChain should
    //   take precedence if the annotation is on both the Service and the SEI.
    //
    // The reasoning for this is (probably) that the SEI can be used by multiple endpoints 
    // and / or multiple Service requesters, so the endpoint implementation and the Service
    // should have the final say in what handlers are run, rather than the SEI.
    //
    // Adding Deployment Descriptors complicates this further.  A DD should have the absolute 
    // final say (such as a JSR-109 client DD).  Given that, on a service-requester if the
    // Service has a HandlerChain and the SEI has a HandlerChain and the DD specifies a 
    // HandlerChain for a port, then the DD should win.  Since DDs are implented as information
    // in a sparse composite, then that means the sparse composite wins.

    // Get the HandlerChains specified on the Endpoint (service-provider) or on the Service
    // (service-requester).
    handlerChainsType = serviceDesc.getHandlerChain(getServiceDelegateKey());

    // HandlerChains apply to specific Port Compoments (service-provider) or Ports (
    // (service-requesters) so find the appropriate one.
    EndpointDescription ed = null;
    if (portinfo != null) {
        ed = serviceDesc.getEndpointDescription(portinfo.getPortName());
    }

    // Get the HandlerChain information, if any, off the SEI (service-provider or 
    // service-requster) and check for any DD overrides.
    if (ed != null) {
        // If there was no handler chains information specifed on the endpoint (service-
        // provider) or the Service (service-requester)
        // -- OR -- 
        // If the handler chains associated with a particular instance of a service delegate
        // DOES NOT match the handler chains across all service delegates, then there was
        // sparse composite information specified for this service delegate.  Sparse composite
        // information is how Deployment Descriptor information is specified, and that 
        // overrides the annotations as described in the long-winded comment above.
        // -- THEN --
        // Use this handler chains information
        HandlerChainsType hct_includingComposite = ed.getHandlerChain(getServiceDelegateKey());
        HandlerChainsType hct_noComposite = ed.getHandlerChain();
        if (handlerChainsType == null || (hct_includingComposite != hct_noComposite)) {
            handlerChainsType = hct_includingComposite;
        }
    } else {
        // There is no EndpointDescription that matches the portInfo specified so 
        // return the empty list of handlers since there are no ports that match
        if (log.isDebugEnabled()) {
            QName qName = (portinfo == null) ? null : portinfo.getPortName();
            log.debug("The PortInfo object did not match any ports; returning an empty list of handlers."
                    + "  PortInfo QName: " + qName);
        }
        return handlers;
    }

    Iterator it = handlerChainsType == null ? null : handlerChainsType.getHandlerChain().iterator();

    while ((it != null) && (it.hasNext())) {
        HandlerChainType handlerChainType = ((HandlerChainType) it.next());

        // if !match, continue (to next chain)
        if (!(chainResolvesToPort(handlerChainType, portinfo)))
            continue;

        List<HandlerType> handlerTypeList = handlerChainType.getHandler();
        Iterator ht = handlerTypeList.iterator();
        while (ht.hasNext()) {
            HandlerType handlerType = (HandlerType) ht.next();
            // TODO must do better job comparing the handlerType with the PortInfo param
            // to see if the current iterator handler is intended for this service.
            // TODO review: need to check for null getHandlerClass() return?
            // or will schema not allow it?
            String portHandler = handlerType.getHandlerClass().getValue();
            Class aClass;
            try {
                aClass = loadClass(portHandler);
            } catch (Exception e) {
                // TODO: should we just ignore this problem?
                throw ExceptionFactory.makeWebServiceException(e);
            }

            // 9.2.1.2 sort them by Logical, then SOAP
            if (LogicalHandler.class.isAssignableFrom(aClass))
                handlers.add(aClass);
            else if (SOAPHandler.class.isAssignableFrom(aClass))
                // instanceof ProtocolHandler
                handlers.add(aClass);
            else if (Handler.class.isAssignableFrom(aClass)) {
                throw ExceptionFactory
                        .makeWebServiceException(Messages.getMessage("handlerChainErr1", aClass.getName()));
            } else {
                throw ExceptionFactory
                        .makeWebServiceException(Messages.getMessage("handlerChainErr2", aClass.getName()));
            }
            // If a role was specified, add it to the roles played
            if (handlerRoles != null) {
                List<org.apache.axis2.jaxws.description.xml.handler.String> soapRolesList = handlerType
                        .getSoapRole();
                Iterator<org.apache.axis2.jaxws.description.xml.handler.String> soapRolesIterator = soapRolesList
                        .iterator();
                while (soapRolesIterator.hasNext()) {
                    org.apache.axis2.jaxws.description.xml.handler.String soapRoleElement = soapRolesIterator
                            .next();
                    String addSoapRole = soapRoleElement.getValue();
                    handlerRoles.add(addSoapRole);
                    if (log.isDebugEnabled()) {
                        log.debug("Adding soap role " + addSoapRole);
                    }
                }
            }
        }
    }

    return handlers;
}

From source file:org.apache.axis2.jaxws.spi.handler.BaseHandlerResolver.java

protected static boolean chainResolvesToPort(HandlerChainType hct, PortInfo portinfo) {

    List<String> protocolBindings = hct.getProtocolBindings();
    if (protocolBindings != null) {
        boolean match = true;
        for (Iterator<String> it = protocolBindings.iterator(); it.hasNext();) {
            match = false; // default to false in the protocol bindings until we find a match
            String protocolBinding = it.next();
            protocolBinding = protocolBinding.startsWith("##") ? protocolBindingsMap.get(protocolBinding)
                    : protocolBinding;/*from   ww  w.ja  va 2  s .  c  om*/
            // if the protocolBindingsMap returns null, it would mean someone has some nonsense ##binding
            if ((protocolBinding != null) && (protocolBinding.equals(portinfo.getBindingID()))) {
                match = true;
                break;
            }
        }
        if (match == false) {
            // we've checked all the protocolBindings, but didn't find a match, no need to continue
            return match;
        }
    }

    /*
     * need to figure out how to get the namespace declaration out of the port-name-pattern and service-name-pattern
     */

    if (!doesPatternMatch(portinfo.getPortName(), hct.getPortNamePattern())) {
        // we've checked the port-name-pattern, and didn't find a match, no need to continue
        return false;
    }

    if (!doesPatternMatch(portinfo.getServiceName(), hct.getServiceNamePattern())) {
        // we've checked the service-name-pattern, and didn't find a match, no need to continue
        return false;
    }

    return true;
}