aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.ws.api.server; aoqi@0: aoqi@0: import com.sun.istack.internal.NotNull; aoqi@0: import com.sun.xml.internal.ws.api.message.Message; aoqi@0: import com.sun.xml.internal.ws.api.message.Packet; aoqi@0: import com.sun.xml.internal.ws.resources.ServerMessages; aoqi@0: import com.sun.xml.internal.ws.resources.WsservletMessages; aoqi@0: import com.sun.xml.internal.ws.server.ServerRtException; aoqi@0: import com.sun.xml.internal.ws.server.SingletonResolver; aoqi@0: aoqi@0: import javax.xml.ws.Provider; aoqi@0: import javax.xml.ws.WebServiceContext; aoqi@0: import javax.xml.ws.WebServiceException; aoqi@0: import java.lang.annotation.Annotation; aoqi@0: import java.lang.reflect.InvocationTargetException; aoqi@0: import java.lang.reflect.Method; aoqi@0: import java.util.logging.Level; aoqi@0: import java.util.logging.Logger; aoqi@0: aoqi@0: /** aoqi@0: * Determines the instance that serves aoqi@0: * the given request packet. aoqi@0: * aoqi@0: *
aoqi@0: * The JAX-WS spec always use a singleton instance aoqi@0: * to serve all the requests, but this hook provides aoqi@0: * a convenient way to route messages to a proper receiver. aoqi@0: * aoqi@0: *
aoqi@0: * Externally, an instance of {@link InstanceResolver} is aoqi@0: * associated with {@link WSEndpoint}. aoqi@0: * aoqi@0: *
aoqi@0: * One can use WS-Addressing message properties to aoqi@0: * decide which instance to deliver a message. This aoqi@0: * would be an important building block for a stateful aoqi@0: * web services. aoqi@0: * aoqi@0: *
aoqi@0: * One can associate an instance of a service
aoqi@0: * with a specific WS-RM session.
aoqi@0: *
aoqi@0: * @author Kohsuke Kawaguchi
aoqi@0: */
aoqi@0: public abstract class InstanceResolver
aoqi@0: * This method is called concurrently by multiple threads.
aoqi@0: * It is also on a criticail path that affects the performance.
aoqi@0: * A good implementation should try to avoid any synchronization,
aoqi@0: * and should minimize the amount of work as much as possible.
aoqi@0: *
aoqi@0: * @param request
aoqi@0: * Always non-null. Represents the request message to be served.
aoqi@0: * The caller may not consume the {@link Message}.
aoqi@0: */
aoqi@0: public abstract @NotNull T resolve(@NotNull Packet request);
aoqi@0:
aoqi@0: /**
aoqi@0: * Called by the default {@link Invoker} after the method call is done.
aoqi@0: * This gives {@link InstanceResolver} a chance to do clean up.
aoqi@0: *
aoqi@0: *
aoqi@0: * Alternatively, one could override {@link #createInvoker()} to
aoqi@0: * create a custom invoker to do this in more flexible way.
aoqi@0: *
aoqi@0: *
aoqi@0: * The default implementation is a no-op.
aoqi@0: *
aoqi@0: * @param request
aoqi@0: * The same request packet given to {@link #resolve(Packet)} method.
aoqi@0: * @param servant
aoqi@0: * The object returned from the {@link #resolve(Packet)} method.
aoqi@0: * @since 2.1.2
aoqi@0: */
aoqi@0: public void postInvoke(@NotNull Packet request, @NotNull T servant) {
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Called by {@link WSEndpoint} when it's set up.
aoqi@0: *
aoqi@0: *
aoqi@0: * This is an opportunity for {@link InstanceResolver}
aoqi@0: * to do a endpoint-specific initialization process.
aoqi@0: *
aoqi@0: * @param wsc
aoqi@0: * The {@link WebServiceContext} instance to be injected
aoqi@0: * to the user instances (assuming {@link InstanceResolver}
aoqi@0: */
aoqi@0: public void start(@NotNull WSWebServiceContext wsc, @NotNull WSEndpoint endpoint) {
aoqi@0: // backward compatibility
aoqi@0: start(wsc);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * @deprecated
aoqi@0: * Use {@link #start(WSWebServiceContext,WSEndpoint)}.
aoqi@0: */
aoqi@0: public void start(@NotNull WebServiceContext wsc) {}
aoqi@0:
aoqi@0: /**
aoqi@0: * Called by {@link WSEndpoint}
aoqi@0: * when {@link WSEndpoint#dispose()} is called.
aoqi@0: *
aoqi@0: * This allows {@link InstanceResolver} to do final clean up.
aoqi@0: *
aoqi@0: *
aoqi@0: * This method is guaranteed to be only called once by {@link WSEndpoint}.
aoqi@0: */
aoqi@0: public void dispose() {}
aoqi@0:
aoqi@0:
aoqi@0: /**
aoqi@0: * Creates a {@link InstanceResolver} implementation that always
aoqi@0: * returns the specified singleton instance.
aoqi@0: */
aoqi@0: public static