# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: D:\sources\glassfish\trunk\appserver\webservices\jsr109-impl # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: src/main/java/org/glassfish/webservices/JAXWSAdapterRegistry.java --- src/main/java/org/glassfish/webservices/JAXWSAdapterRegistry.java Base (BASE) +++ src/main/java/org/glassfish/webservices/JAXWSAdapterRegistry.java Locally Modified (Based On LOCAL) @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997-2012 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 @@ -42,7 +42,6 @@ import com.sun.xml.ws.api.server.Adapter; import com.sun.logging.LogDomains; -import com.sun.enterprise.util.i18n.StringManager; import java.util.*; import java.util.logging.Level; @@ -55,13 +54,13 @@ public class JAXWSAdapterRegistry { private static JAXWSAdapterRegistry registry = null; - private Map store; + private final Map store; final Logger logger = LogDomains.getLogger(JAXWSAdapterRegistry.class,LogDomains.WEBSERVICES_LOGGER); private ResourceBundle rb = logger.getResourceBundle(); /** Creates a new instance of JAXWSServletUtil */ private JAXWSAdapterRegistry() { - store = new HashMap(); + store = Collections.synchronizedMap(new HashMap()); } public static synchronized JAXWSAdapterRegistry getInstance() { @@ -74,32 +73,37 @@ Adapter info) { if (contextRoot == null) contextRoot = ""; - ContextAdapter contextRtInfo = - (ContextAdapter)store.get(contextRoot); - if(contextRtInfo == null) { - contextRtInfo = new ContextAdapter(); - } - contextRtInfo.addAdapter(urlPattern, info); - store.put(contextRoot, contextRtInfo); + synchronized (store) { + ContextAdapter contextRtInfo = store.get(contextRoot); + if(contextRtInfo == null) { + contextRtInfo = new ContextAdapter(); + } + contextRtInfo.addAdapter(urlPattern, info); + store.put(contextRoot, contextRtInfo); + } } public Adapter getAdapter(String contextRoot, String path, String urlPattern ) { - ContextAdapter serviceInfo = - (ContextAdapter)store.get(contextRoot); - if(serviceInfo == null) - return null; - return serviceInfo.getAdapter(path, urlPattern); + synchronized (store) { + ContextAdapter serviceInfo = store.get(contextRoot); + if(serviceInfo == null) { + return null; + } + return serviceInfo.getAdapter(path, urlPattern); + } } public void removeAdapter(String contextRoot) { if(contextRoot == null) contextRoot = ""; - ContextAdapter serviceInfo = - (ContextAdapter)store.get(contextRoot); - if(serviceInfo == null) - return ; - store.remove(contextRoot); + synchronized (store) { + ContextAdapter serviceInfo = store.get(contextRoot); + if(serviceInfo == null) { + return ; + } + store.remove(contextRoot); + } } class ContextAdapter { Index: src/test/java/org/glassfish/webservices/JAXWSAdapterRegistryTest.java --- src/test/java/org/glassfish/webservices/JAXWSAdapterRegistryTest.java No Base Revision +++ src/test/java/org/glassfish/webservices/JAXWSAdapterRegistryTest.java Locally New @@ -0,0 +1,228 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2012 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 com.sun.istack.NotNull; +import com.sun.xml.ws.api.Component; +import com.sun.xml.ws.api.WSBinding; +import com.sun.xml.ws.api.message.Packet; +import com.sun.xml.ws.api.model.SEIModel; +import com.sun.xml.ws.api.model.wsdl.WSDLPort; +import com.sun.xml.ws.api.pipe.Codec; +import com.sun.xml.ws.api.pipe.FiberContextSwitchInterceptor; +import com.sun.xml.ws.api.pipe.ServerTubeAssemblerContext; +import com.sun.xml.ws.api.server.Adapter; +import com.sun.xml.ws.api.server.Container; +import com.sun.xml.ws.api.server.ServiceDefinition; +import com.sun.xml.ws.api.server.WSEndpoint; +import com.sun.xml.ws.policy.PolicyMap; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.Executor; +import javax.xml.namespace.QName; +import org.glassfish.gmbal.ManagedObjectManager; +import org.junit.Assert; +import org.junit.Test; + +/** + * + * @author ljungman + */ +public class JAXWSAdapterRegistryTest { + + public JAXWSAdapterRegistryTest() { + } + + /** + * Test of addAdapter method, of class JAXWSAdapterRegistry. + * + * http://java.net/jira/browse/GLASSFISH-17836 + * Putting load on freshly-started Glassfish web-app messes up its initialization process + */ + @Test + public void testAddAdapter() { + final String contextRoot = "/cr"; + final String urlPattern = "/up"; + final JAXWSAdapterRegistry registry = JAXWSAdapterRegistry.getInstance(); + int size = 25; + Thread[] ts = new Thread[size]; + for (int i = 0; i < size; i++) { + final int j = i; + ts[i] = new Thread(new Runnable() { + @Override + public void run() { + registry.addAdapter(contextRoot, urlPattern + j, new A(j)); + } + }); + } + + for (int i = 0; i < size; i++) ts[i].start(); + + for (int i = 0; i < size; i++) { + try { + ts[i].join(); + } catch (InterruptedException ex) { + } + } + + for (int i = 0; i < size; i++) { + Adapter a = registry.getAdapter(contextRoot, urlPattern + i, urlPattern + i); + Assert.assertEquals(i, ((A)a).getX()); + } + } + + private class A extends Adapter { + + private int x; + + public A(int x) { + super(new WSE()); + this.x = x; + } + + public int getX() { + return x; + } + + @Override + protected Toolkit createToolkit() { + throw new UnsupportedOperationException("Not supported yet."); + } + } + + private class WSE extends WSEndpoint { + + @NotNull + @Override + public Set getComponents() { + return new HashSet(); + } + + @Override + public Codec createCodec() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public QName getServiceName() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public QName getPortName() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Class getImplementationClass() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public WSBinding getBinding() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Container getContainer() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public WSDLPort getPort() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setExecutor(Executor exctr) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void schedule(Packet packet, CompletionCallback cc, FiberContextSwitchInterceptor fcsi) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public PipeHead createPipeHead() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void dispose() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public ServiceDefinition getServiceDefinition() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Set getComponentRegistry() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public SEIModel getSEIModel() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public PolicyMap getPolicyMap() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public ManagedObjectManager getManagedObjectManager() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void closeManagedObjectManager() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public ServerTubeAssemblerContext getAssemblerContext() { + throw new UnsupportedOperationException("Not supported yet."); + } + } +}