Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 package org.glassfish.webservices;
 
 
 import java.io.File;
 import java.net.URI;
 import java.net.URL;
Runtime dispatch information about one ejb web service endpoint. This class must support concurrent access, since a single instance will be used for all web service invocations through the same ejb endpoint.

NOT THREAD SAFE

Author(s):
Jerome Dochez
 
 public class EjbRuntimeEndpointInfo {
 
     private static final Logger logger = LogUtils.getLogger();
 
     protected final WebServiceEndpoint endpoint;
 
     protected final EjbEndpointFacade container;
 
     protected final Object webServiceEndpointServant;
 
     // the variables below are access in non-thread-safe ways
     private volatile ServletAdapter adapter = null;
     private ServletAdapterList adapterList = null;
 
     private WebServiceContextImpl wsCtxt = null;
     private boolean handlersConfigured = false;
 
     protected EjbMessageDispatcher messageDispatcher = null;
    public EjbRuntimeEndpointInfo(WebServiceEndpoint webServiceEndpoint,
                                  EjbEndpointFacade ejbContainer,
                                  Object servant) {
         = webServiceEndpoint;
          = ejbContainer;
         = servant;
    }
    public WebServiceEndpoint getEndpoint() {
        return ;
    }
    public String getEndpointAddressUri() {
        return .getEndpointAddressUri();
    }
    public synchronized WebServiceContext getWebServiceContext() {
        return ;
    }
    public Object prepareInvocation(boolean doPreInvoke)
        throws Exception {
        ComponentInvocation inv = null;
        AdapterInvocationInfo adapterInvInfo = new AdapterInvocationInfo();
        // For proper injection of handlers, we have to configure handler
        // after invManager.preInvoke but the Invocation.contextData has to be set
        // before invManager.preInvoke. So the steps of configuring jaxws handlers and
        // init'ing jaxws is done here - this sequence is important
        if (==null) {
            synchronized(this) {
                if( == null) {
                    try {
                        // Set webservice context here
                        // If the endpoint has a WebServiceContext with @Resource then
                        // that has to be used
                        EjbDescriptor ejbDesc = .getEjbComponentImpl();
                        Iterator<ResourceReferenceDescriptorit = ejbDesc.getResourceReferenceDescriptors().iterator();
                        while(it.hasNext()) {
                            ResourceReferenceDescriptor r = it.next();
                            if(r.isWebServiceContext()) {
                                Iterator<InjectionTargetiter = r.getInjectionTargets().iterator();
                                boolean matchingClassFound = false;
                                while(iter.hasNext()) {
                                    InjectionTarget target = iter.next();
                                    if(ejbDesc.getEjbClassName().equals(target.getClassName())) {
                                        matchingClassFound = true;
                                        break;
                                    }
                                }
                                if(!matchingClassFound) {
                                    continue;
                                }
                                try {
                                    javax.naming.InitialContext ic = new javax.naming.InitialContext();
                                     = (WebServiceContextImplic.lookup("java:comp/env/" + r.getName());
                                } catch (Throwable t) {
                                    if (.isLoggable(.)) {
                                        .log(..t.getCause());
                                    }
                                }
                            }
                        }
                        if( == null) {
                             = new WebServiceContextImpl();
                        }
                    } catch (Throwable t) {
                        LogHelper.log(.,
                                .t.getName());
                        return null;
                    }
                }
            }
        }
        if(doPreInvoke) {
            inv =  .startInvocation();
            adapterInvInfo.setInv(inv);
        }
        // Now process handlers and init jaxws RI
        synchronized(this) {
            if (! && doPreInvoke) {
                try {
                    WsUtil wsu = new WsUtil();
                    String implClassName = .getEjbComponentImpl().getEjbClassName();
                    Class clazz = .getEndpointClassLoader().loadClass(implClassName);
                    // Get the proper binding using BindingID
                    String givenBinding = .getProtocolBinding();
                    // Get list of all wsdls and schema
                    SDDocumentSource primaryWsdl = null;
                    Collection docs = null;
                    if(.getWebService().hasWsdlFile()) {
                        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
                        ApplicationRegistry appRegistry = wscImpl.getApplicationRegistry();
                        ApplicationInfo appInfo = appRegistry.get(.getBundleDescriptor().getApplication().getRegistrationName());
                        URI deployedDir =appInfo.getSource().getURI();
                        URL pkgedWsdl;
                        if(deployedDir != null) {
                            if(.getBundleDescriptor().getApplication().isVirtual()) {
                                pkgedWsdl = deployedDir.resolve(.getWebService().getWsdlFileUri()).toURL();
                            } else {
                                String moduleUri1 = .getBundleDescriptor().getModuleDescriptor().getArchiveUri();
                                //Fix for issue 7024099
                                //Only replace the last "." with "_" for moduleDescriptor's archive uri
                                String moduleUri = FileUtils.makeFriendlyFilenameExtension(moduleUri1);
                                pkgedWsdl = deployedDir.resolve(moduleUri+"/"+.getWebService().getWsdlFileUri()).toURL();
                            }
                        } else {
                            pkgedWsdl = .getWebService().getWsdlFileUrl();
                        }
                        if (pkgedWsdl != null) {
                            primaryWsdl = SDDocumentSource.create(pkgedWsdl);
                            docs = wsu.getWsdlsAndSchemas(pkgedWsdl);
                        }
                    }
                    // Create a Container to pass ServletContext and also inserting the pipe
                    JAXWSContainer container = new JAXWSContainer(null,
                            );
                    // Get catalog info
                    java.net.URL catalogURL = clazz.getResource('/' + .getBundleDescriptor().getDeploymentDescriptorDir() + . + "jax-ws-catalog.xml");
                    // Create Binding and set service side handlers on this binding
                    boolean mtomEnabled = wsu.getMtom();
                    WSBinding binding = null;
                    ArrayList<WebServiceFeaturewsFeatures = new ArrayList<WebServiceFeature>();
                    // Only if MTOm is enabled create the Binding with the MTOMFeature
                    if (mtomEnabled) {
                        int mtomThreshold = .getMtomThreshold() != null ? new Integer(.getMtomThreshold()):0;
                        MTOMFeature mtom = new MTOMFeature(true,mtomThreshold);
                        wsFeatures.add(mtom);
                    }
                    Addressing addressing = .getAddressing();
                    if (.getAddressing() != null) {
                        AddressingFeature addressingFeature = new AddressingFeature(addressing.isEnabled(),
                            addressing.isRequired(),getResponse(addressing.getResponses()));
                        wsFeatures.add(addressingFeature);
                    }
                    if (wsFeatures.size()>0){
                        binding = BindingID.parse(givenBinding).createBinding(wsFeatures.toArray
                                (new WebServiceFeature[wsFeatures.size()]));
                    } else {
                        binding = BindingID.parse(givenBinding).createBinding();
                    }
                    wsu.configureJAXWSServiceHandlers(,
                        .getProtocolBinding(), binding);
                    // Create the jaxws2.1 invoker and use this
                    Invoker invoker = new InstanceResolverImpl(clazz).createInvoker();
                    WSEndpoint wsep = WSEndpoint.create(
                            clazz// The endpoint class
                            false// we do not want JAXWS to process @HandlerChain
                            new EjbInvokerImpl(clazzinvoker), // the invoker
                            .getServiceName(), // the service QName
                            .getWsdlPort(), // the port
                            container,
                            binding// Derive binding
                            primaryWsdl// primary WSDL
                            docs// Collection of imported WSDLs and schema
                            catalogURL
                            );
                    String uri = .getEndpointAddressUri();
                    String urlPattern = uri.startsWith("/") ? uri : "/" + uri;
                    // All set; Create the adapter
                    if( == null) {
                         = new ServletAdapterList();
                    }
                     = .createAdapter(.getName(), urlPatternwsep);
                    =true;
                } catch (Throwable t) {
                        LogHelper.log(.,
                                .t.getName());
                     = null;
                }
            }
        }
        //Issue 10776 The wsCtxt created using WebServiceReferenceManagerImpl
        //does not have the jaxwsContextDelegate set
        //set it using this method
        synchronized (this) {
            addWSContextInfo();
            if (inv != null && inv instanceof EJBInvocation) {
                EJBInvocation ejbInv = (EJBInvocationinv;
                ejbInv.setWebServiceContext();
            }
        }
        adapterInvInfo.setAdapter();
        return adapterInvInfo;
    }
    private void addWSContextInfo(WebServiceContextImpl wsCtxt) {
        WebServiceContextImpl wsc = null;
        EjbDescriptor bundle = .getEjbComponentImpl();
        while(it.hasNext()) {
            ResourceReferenceDescriptor r = it.next();
            if(r.isWebServiceContext()) {
                try {
                    javax.naming.InitialContext ic = new javax.naming.InitialContext();
                    wsc = (WebServiceContextImplic.lookup("java:comp/env/" + r.getName());
                } catch (Throwable t) {
                    if (.isLoggable(.)) {
                        .log(..t);
                    }
                }
                if(wsc != null) {
                    wsc.setContextDelegate(wsCtxt.getContextDelegate());
                }
            }
        }
    }

   
Force initialization of the endpoint runtime information as well as the handlers injection
    public synchronized void initRuntimeInfo(ServletAdapterList listthrows Exception {
       AdapterInvocationInfo aInfo =null;
        try {
            this. = list;
            aInfo = (AdapterInvocationInfo)prepareInvocation(true);
        } finally {
            if (aInfo != null) {
                releaseImplementor(aInfo.getInv())       ;
            }    
        }
    }
        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
        return wscImpl.getInvocationManager();
    }

    
Called after attempt to handle message. This is coded defensively so we attempt to clean up no matter how much progress we made in getImplementor. One important thing is to complete the invocation manager preInvoke().
    public void releaseImplementor(ComponentInvocation inv) {
        .endInvocation(inv);
    }
        if (==null) {
             = new Ejb3MessageDispatcher();
        }
        return ;
    }
    public EjbEndpointFacade getContainer() {
        return ;
    }
        if (s != null) {
            return AddressingFeature.Responses.valueOf(AddressingFeature.Responses.class,s);
        } else return ..;
    }
New to GrepCode? Check out our FAQ X