blob: da73ab02d3c4ca73654ae3e287952cc0eca397a3 [file] [log] [blame]
/*
* Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.xml.internal.ws.server.sei;
import com.sun.istack.internal.NotNull;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.message.Message;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.fault.SOAPFaultBuilder;
import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
import com.sun.xml.internal.ws.model.JavaMethodImpl;
import com.sun.xml.internal.ws.resources.ServerMessages;
import com.sun.xml.internal.ws.util.QNameMap;
import javax.xml.namespace.QName;
/**
* An {@link com.sun.xml.internal.ws.server.sei.EndpointMethodDispatcher} that uses
* SOAP payload first child's QName as the key for dispatching.
* <p/>
* A map of all payload QNames on the port and the corresponding {@link EndpointMethodHandler}
* is initialized in the constructor. The payload QName is extracted from the
* request {@link Packet} and used as the key to return the correct
* handler.
*
* @author Arun Gupta
*/
final class PayloadQNameBasedDispatcher implements EndpointMethodDispatcher {
private final QNameMap<EndpointMethodHandler> methodHandlers;
private static final String EMPTY_PAYLOAD_LOCAL = "";
private static final String EMPTY_PAYLOAD_NSURI = "";
private WSBinding binding;
public PayloadQNameBasedDispatcher(AbstractSEIModelImpl model, WSBinding binding, SEIInvokerTube invokerTube) {
this.binding = binding;
methodHandlers = new QNameMap<EndpointMethodHandler>();
for( JavaMethodImpl m : model.getJavaMethods() ) {
EndpointMethodHandler handler = new EndpointMethodHandler(invokerTube,m,binding);
QName payloadName = model.getQNameForJM(m); // TODO need a new method on JavaMethodImpl
methodHandlers.put(payloadName.getNamespaceURI(), payloadName.getLocalPart(), handler);
}
}
/**
* {@link PayloadQNameBasedDispatcher} never returns null because this is always
* the last {@link EndpointMethodHandler} to kick in.
*/
public @NotNull EndpointMethodHandler getEndpointMethodHandler(Packet request) throws DispatchException {
Message message = request.getMessage();
String localPart = message.getPayloadLocalPart();
String nsUri;
if (localPart == null) {
localPart = EMPTY_PAYLOAD_LOCAL;
nsUri = EMPTY_PAYLOAD_NSURI;
} else {
nsUri = message.getPayloadNamespaceURI();
}
EndpointMethodHandler h = methodHandlers.get(nsUri, localPart);
if (h==null) {
String dispatchKey = "{" + nsUri + "}" + localPart;
String faultString = ServerMessages.DISPATCH_CANNOT_FIND_METHOD(dispatchKey, "Payload QName-based Dispatcher");
throw new DispatchException(SOAPFaultBuilder.createSOAPFaultMessage(
binding.getSOAPVersion(), faultString, binding.getSOAPVersion().faultCodeClient));
}
return h;
}
}