FileDocCategorySizeDatePackage
JBIAdapterBuilder.javaAPI DocGlassfish v2 API7410Wed Jul 18 22:04:04 BST 2007com.sun.enterprise.jbi.serviceengine.bridge

JBIAdapterBuilder

public class JBIAdapterBuilder extends Object
A Builder class to create JBIAdapters. JBIAdapters are created from WSEndpoints using the webservice container code.
author
Vikas Awasthi

Fields Summary
private com.sun.enterprise.jbi.serviceengine.core.EndpointRegistry
endpointRegistry
private final Logger
logger
Constructors Summary
JBIAdapterBuilder()

    
     
    
Methods Summary
public com.sun.enterprise.jbi.serviceengine.bridge.transport.JBIAdaptercreateAdapter(javax.xml.namespace.QName service, java.lang.String endpointName, javax.jbi.messaging.MessageExchange me)

        ServiceEngineEndpoint endpt = endpointRegistry.get(service,  endpointName);
        if(endpt != null) {
            return createWSAdapter(endpt, me);
        }
        throw new ServiceEngineException("Endpoint " +  endpointName + "not deployed in JBI");
    
private com.sun.enterprise.jbi.serviceengine.bridge.transport.JBIAdaptercreateWSAdapter(com.sun.enterprise.jbi.serviceengine.core.ServiceEngineEndpoint endpt, javax.jbi.messaging.MessageExchange me)

        try {
            
            EjbRuntimeEndpointInfo ejbEndPtInfo=null;
            if(endpt.isImplementedByEJB()) {
                
                ejbEndPtInfo = WebServiceEjbEndpointRegistry.
                        getRegistry().getEjbWebServiceEndpoint(endpt.getURI(), "POST", null);
                Adapter adapter = (Adapter) ejbEndPtInfo.prepareInvocation(true);
                endpt.setWsep(adapter.getEndpoint());
            }else {
                
                String url = endpt.getURI();
                String contextRoot = endpt.getContextRoot();
                Adapter adapter =
                        JAXWSAdapterRegistry.getInstance().getAdapter(contextRoot, url, url);
                if(adapter != null)
                    endpt.setWsep(adapter.getEndpoint());
                //for null adapter endpt is already set during comp app deployment
            }
            
            logger.log(Level.FINE,"Successfully created JBIAdapter for endpoint:"
                    + endpt.getWsep());
            if(endpt.getWsdlDocument() == null) {
                SDDocument sdDocument = endpt.getWsep().getServiceDefinition().getPrimary();
                synchronized(sdDocument) {
                    if(endpt.getWsdlDocument() == null) {
                        Document doc = getWSDLDocument(sdDocument);
                        endpt.setWsdlDocument(doc);
                    }
                }
            }
            return new JBIAdapter(endpt.getWsep(), endpt, me, endpt.getClassLoader(), ejbEndPtInfo);
            
        } catch (Exception e) {
            logger.log(Level.SEVERE,"Exception in creating JBIAdapter:"+e.getMessage(), e);
        }
        return null;
    
private com.sun.xml.ws.api.server.DocumentAddressResolvergetResolver()

        return new DocumentAddressResolver() {
            public String getRelativeAddressFor(SDDocument current,
                    SDDocument referenced) {
                // FIX for IT 2781
                logger.log(Level.FINE, "Current SDDocument URL = " + 
                        current.getURL() + ", isWSDL = " + current.isWSDL());
                logger.log(Level.FINE, "Referenced SDDocument URL = " + 
                        referenced.getURL() + ", isWSDL = " + referenced.isWSDL());
                if(referenced.isWSDL()) {
                    logger.log(Level.FINE, "Relative address for referenced " +
                            "SDDocument = " + referenced.getURL().toString());
                    return referenced.getURL().toString();
                }
                // END OF FIX for IT 2781.
                return "";
            }
        };
    
private org.w3c.dom.DocumentgetWSDLDocument(com.sun.xml.ws.api.server.SDDocument document)
Create a Dom document from the output stream provided by the given JAX-WS SDDocument

        
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        document.writeTo(null, getResolver(), baos);
        baos.flush();
        InputStream in  = new ByteArrayInputStream(baos.toByteArray());
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setValidating(false);
            
            DocumentBuilder db = factory.newDocumentBuilder();
            return db.parse(in, document.getURL().toString());
        } finally {
            in.close();
            baos.close();
        }