Search in sources :

Example 26 with StringRefAddr

use of javax.naming.StringRefAddr in project tomcat70 by apache.

the class NamingContextListener method addEjb.

/**
 * Set the specified EJBs in the naming context.
 */
public void addEjb(ContextEjb ejb) {
    // Create a reference to the EJB.
    Reference ref = new EjbRef(ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
    // Adding the additional parameters, if any
    Iterator<String> params = ejb.listProperties();
    while (params.hasNext()) {
        String paramName = params.next();
        String paramValue = (String) ejb.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        createSubcontexts(envCtx, ejb.getName());
        envCtx.bind(ejb.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) EjbRef(org.apache.naming.EjbRef) NamingException(javax.naming.NamingException)

Example 27 with StringRefAddr

use of javax.naming.StringRefAddr in project tomcat70 by apache.

the class NamingContextListener method addResourceLink.

/**
 * Set the specified resource link in the naming context.
 */
public void addResourceLink(ContextResourceLink resourceLink) {
    // Create a reference to the resource.
    Reference ref = new ResourceLinkRef(resourceLink.getType(), resourceLink.getGlobal(), resourceLink.getFactory(), null);
    Iterator<String> i = resourceLink.listProperties();
    while (i.hasNext()) {
        String key = i.next();
        Object val = resourceLink.getProperty(key);
        if (val != null) {
            StringRefAddr refAddr = new StringRefAddr(key, val.toString());
            ref.add(refAddr);
        }
    }
    javax.naming.Context ctx = "UserTransaction".equals(resourceLink.getName()) ? compCtx : envCtx;
    try {
        if (logger.isDebugEnabled())
            log.debug("  Adding resource link " + resourceLink.getName());
        createSubcontexts(envCtx, resourceLink.getName());
        ctx.bind(resourceLink.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }
    ResourceLinkFactory.registerGlobalResourceAccess(getGlobalNamingContext(), resourceLink.getName(), resourceLink.getGlobal());
}
Also used : ResourceLinkRef(org.apache.naming.ResourceLinkRef) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException)

Example 28 with StringRefAddr

use of javax.naming.StringRefAddr in project tomcat70 by apache.

the class NamingContextListener method addResource.

/**
 * Set the specified resources in the naming context.
 */
public void addResource(ContextResource resource) {
    // Create a reference to the resource.
    Reference ref = new ResourceRef(resource.getType(), resource.getDescription(), resource.getScope(), resource.getAuth(), resource.getSingleton());
    // Adding the additional parameters, if any
    Iterator<String> params = resource.listProperties();
    while (params.hasNext()) {
        String paramName = params.next();
        String paramValue = (String) resource.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("  Adding resource ref " + resource.getName() + "  " + ref);
        }
        createSubcontexts(envCtx, resource.getName());
        envCtx.bind(resource.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }
    if ("javax.sql.DataSource".equals(ref.getClassName()) && resource.getSingleton()) {
        try {
            ObjectName on = createObjectName(resource);
            Object actualResource = envCtx.lookup(resource.getName());
            Registry.getRegistry(null, null).registerComponent(actualResource, on, null);
            objectNames.put(resource.getName(), on);
        } catch (Exception e) {
            logger.warn(sm.getString("naming.jmxRegistrationFailed", e));
        }
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) ResourceRef(org.apache.naming.ResourceRef) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MalformedURLException(java.net.MalformedURLException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) ObjectName(javax.management.ObjectName)

Example 29 with StringRefAddr

use of javax.naming.StringRefAddr in project tomcat by apache.

the class NamingContextListener method addService.

/**
 * Set the specified web service in the naming context.
 *
 * @param service the web service descriptor
 */
public void addService(ContextService service) {
    Reference ref = lookForLookupRef(service);
    if (ref == null) {
        if (service.getWsdlfile() != null) {
            URL wsdlURL = null;
            try {
                wsdlURL = new URL(service.getWsdlfile());
            } catch (MalformedURLException e) {
            // Ignore and carry on
            }
            if (wsdlURL == null) {
                try {
                    wsdlURL = ((Context) container).getServletContext().getResource(service.getWsdlfile());
                } catch (MalformedURLException e) {
                // Ignore and carry on
                }
            }
            if (wsdlURL == null) {
                try {
                    wsdlURL = ((Context) container).getServletContext().getResource("/" + service.getWsdlfile());
                    log.debug("  Changing service ref wsdl file for /" + service.getWsdlfile());
                } catch (MalformedURLException e) {
                    log.error(sm.getString("naming.wsdlFailed", e));
                }
            }
            if (wsdlURL == null) {
                service.setWsdlfile(null);
            } else {
                service.setWsdlfile(wsdlURL.toString());
            }
        }
        if (service.getJaxrpcmappingfile() != null) {
            URL jaxrpcURL = null;
            try {
                jaxrpcURL = new URL(service.getJaxrpcmappingfile());
            } catch (MalformedURLException e) {
            // Ignore and carry on
            }
            if (jaxrpcURL == null) {
                try {
                    jaxrpcURL = ((Context) container).getServletContext().getResource(service.getJaxrpcmappingfile());
                } catch (MalformedURLException e) {
                // Ignore and carry on
                }
            }
            if (jaxrpcURL == null) {
                try {
                    jaxrpcURL = ((Context) container).getServletContext().getResource("/" + service.getJaxrpcmappingfile());
                    log.debug("  Changing service ref jaxrpc file for /" + service.getJaxrpcmappingfile());
                } catch (MalformedURLException e) {
                    log.error(sm.getString("naming.wsdlFailed", e));
                }
            }
            if (jaxrpcURL == null) {
                service.setJaxrpcmappingfile(null);
            } else {
                service.setJaxrpcmappingfile(jaxrpcURL.toString());
            }
        }
        // Create a reference to the resource.
        ref = new ServiceRef(service.getName(), service.getInterface(), service.getServiceqname(), service.getWsdlfile(), service.getJaxrpcmappingfile());
        // Adding the additional port-component-ref, if any
        Iterator<String> portcomponent = service.getServiceendpoints();
        while (portcomponent.hasNext()) {
            String serviceendpoint = portcomponent.next();
            StringRefAddr refAddr = new StringRefAddr(ServiceRef.SERVICEENDPOINTINTERFACE, serviceendpoint);
            ref.add(refAddr);
            String portlink = service.getPortlink(serviceendpoint);
            refAddr = new StringRefAddr(ServiceRef.PORTCOMPONENTLINK, portlink);
            ref.add(refAddr);
        }
        // Adding the additional parameters, if any
        Iterator<String> handlers = service.getHandlers();
        while (handlers.hasNext()) {
            String handlername = handlers.next();
            ContextHandler handler = service.getHandler(handlername);
            HandlerRef handlerRef = new HandlerRef(handlername, handler.getHandlerclass());
            Iterator<String> localParts = handler.getLocalparts();
            while (localParts.hasNext()) {
                String localPart = localParts.next();
                String namespaceURI = handler.getNamespaceuri(localPart);
                handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_LOCALPART, localPart));
                handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_NAMESPACE, namespaceURI));
            }
            Iterator<String> params = handler.listProperties();
            while (params.hasNext()) {
                String paramName = params.next();
                String paramValue = (String) handler.getProperty(paramName);
                handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PARAMNAME, paramName));
                handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PARAMVALUE, paramValue));
            }
            for (int i = 0; i < handler.getSoapRolesSize(); i++) {
                handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_SOAPROLE, handler.getSoapRole(i)));
            }
            for (int i = 0; i < handler.getPortNamesSize(); i++) {
                handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PORTNAME, handler.getPortName(i)));
            }
            ((ServiceRef) ref).addHandler(handlerRef);
        }
    }
    try {
        if (log.isDebugEnabled()) {
            log.debug("  Adding service ref " + service.getName() + "  " + ref);
        }
        createSubcontexts(envCtx, service.getName());
        envCtx.bind(service.getName(), ref);
    } catch (NamingException e) {
        log.error(sm.getString("naming.bindFailed", e));
    }
}
Also used : NamingContext(org.apache.naming.NamingContext) Context(org.apache.catalina.Context) ContextHandler(org.apache.tomcat.util.descriptor.web.ContextHandler) MalformedURLException(java.net.MalformedURLException) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) ServiceRef(org.apache.naming.ServiceRef) URL(java.net.URL) HandlerRef(org.apache.naming.HandlerRef)

Example 30 with StringRefAddr

use of javax.naming.StringRefAddr in project tomcat by apache.

the class NamingContextListener method addEjb.

/**
 * Set the specified EJBs in the naming context.
 *
 * @param ejb the EJB descriptor
 */
public void addEjb(ContextEjb ejb) {
    Reference ref = lookForLookupRef(ejb);
    if (ref == null) {
        // Create a reference to the EJB.
        ref = new EjbRef(ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
        // Adding the additional parameters, if any
        Iterator<String> params = ejb.listProperties();
        while (params.hasNext()) {
            String paramName = params.next();
            String paramValue = (String) ejb.getProperty(paramName);
            StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
            ref.add(refAddr);
        }
    }
    try {
        createSubcontexts(envCtx, ejb.getName());
        envCtx.bind(ejb.getName(), ref);
    } catch (NamingException e) {
        log.error(sm.getString("naming.bindFailed", e));
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) EjbRef(org.apache.naming.EjbRef) NamingException(javax.naming.NamingException)

Aggregations

StringRefAddr (javax.naming.StringRefAddr)67 Reference (javax.naming.Reference)51 NamingException (javax.naming.NamingException)18 RefAddr (javax.naming.RefAddr)9 Test (org.junit.Test)8 Name (javax.naming.Name)7 Properties (java.util.Properties)6 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 CompositeName (javax.naming.CompositeName)5 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)5 ObjectFactory (javax.naming.spi.ObjectFactory)5 MalformedURLException (java.net.MalformedURLException)4 Enumeration (java.util.Enumeration)4 Hashtable (java.util.Hashtable)4 Map (java.util.Map)4 Context (javax.naming.Context)4 NameNotFoundException (javax.naming.NameNotFoundException)3 Context (org.apache.catalina.Context)3 NamingContext (org.apache.naming.NamingContext)3