aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, 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.server.provider; aoqi@0: aoqi@0: import com.sun.istack.internal.Nullable; aoqi@0: import com.sun.xml.internal.ws.api.SOAPVersion; aoqi@0: import com.sun.xml.internal.ws.api.WSBinding; aoqi@0: import com.sun.xml.internal.ws.api.message.Message; aoqi@0: import com.sun.xml.internal.ws.api.message.Messages; aoqi@0: import com.sun.xml.internal.ws.api.message.Packet; aoqi@0: import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; aoqi@0: import com.sun.xml.internal.ws.fault.SOAPFaultBuilder; aoqi@0: import com.sun.xml.internal.ws.resources.ServerMessages; aoqi@0: aoqi@0: import javax.xml.soap.MimeHeader; aoqi@0: import javax.xml.soap.MimeHeaders; aoqi@0: import javax.xml.soap.SOAPException; aoqi@0: import javax.xml.soap.SOAPMessage; aoqi@0: import javax.xml.transform.Source; aoqi@0: import javax.xml.ws.Service; aoqi@0: import javax.xml.ws.WebServiceException; aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.HashMap; aoqi@0: import java.util.Iterator; aoqi@0: import java.util.List; aoqi@0: import java.util.Map; aoqi@0: aoqi@0: /** aoqi@0: * @author Jitendra Kotamraju aoqi@0: */ aoqi@0: abstract class SOAPProviderArgumentBuilder extends ProviderArgumentsBuilder { aoqi@0: protected final SOAPVersion soapVersion; aoqi@0: aoqi@0: private SOAPProviderArgumentBuilder(SOAPVersion soapVersion) { aoqi@0: this.soapVersion = soapVersion; aoqi@0: } aoqi@0: aoqi@0: static ProviderArgumentsBuilder create(ProviderEndpointModel model, SOAPVersion soapVersion) { aoqi@0: if (model.mode == Service.Mode.PAYLOAD) { aoqi@0: return new PayloadSource(soapVersion); aoqi@0: } else { aoqi@0: if(model.datatype==Source.class) aoqi@0: return new MessageSource(soapVersion); aoqi@0: if(model.datatype==SOAPMessage.class) aoqi@0: return new SOAPMessageParameter(soapVersion); aoqi@0: if(model.datatype==Message.class) aoqi@0: return new MessageProviderArgumentBuilder(soapVersion); aoqi@0: throw new WebServiceException(ServerMessages.PROVIDER_INVALID_PARAMETER_TYPE(model.implClass,model.datatype)); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private static final class PayloadSource extends SOAPProviderArgumentBuilder { aoqi@0: PayloadSource(SOAPVersion soapVersion) { aoqi@0: super(soapVersion); aoqi@0: } aoqi@0: aoqi@0: /*protected*/ public Source getParameter(Packet packet) { aoqi@0: return packet.getMessage().readPayloadAsSource(); aoqi@0: } aoqi@0: aoqi@0: protected Message getResponseMessage(Source source) { aoqi@0: return Messages.createUsingPayload(source, soapVersion); aoqi@0: } aoqi@0: aoqi@0: protected Message getResponseMessage(Exception e) { aoqi@0: return SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e); aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: private static final class MessageSource extends SOAPProviderArgumentBuilder { aoqi@0: MessageSource(SOAPVersion soapVersion) { aoqi@0: super(soapVersion); aoqi@0: } aoqi@0: aoqi@0: /*protected*/ public Source getParameter(Packet packet) { aoqi@0: return packet.getMessage().readEnvelopeAsSource(); aoqi@0: } aoqi@0: aoqi@0: protected Message getResponseMessage(Source source) { aoqi@0: return Messages.create(source, soapVersion); aoqi@0: } aoqi@0: aoqi@0: protected Message getResponseMessage(Exception e) { aoqi@0: return SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private static final class SOAPMessageParameter extends SOAPProviderArgumentBuilder { aoqi@0: SOAPMessageParameter(SOAPVersion soapVersion) { aoqi@0: super(soapVersion); aoqi@0: } aoqi@0: aoqi@0: /*protected*/ public SOAPMessage getParameter(Packet packet) { aoqi@0: try { aoqi@0: return packet.getMessage().readAsSOAPMessage(packet, true); aoqi@0: } catch (SOAPException se) { aoqi@0: throw new WebServiceException(se); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: protected Message getResponseMessage(SOAPMessage soapMsg) { aoqi@0: return Messages.create(soapMsg); aoqi@0: } aoqi@0: aoqi@0: protected Message getResponseMessage(Exception e) { aoqi@0: return SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: protected Packet getResponse(Packet request, @Nullable SOAPMessage returnValue, WSDLPort port, WSBinding binding) { aoqi@0: Packet response = super.getResponse(request, returnValue, port, binding); aoqi@0: // Populate SOAPMessage's transport headers aoqi@0: if (returnValue != null && response.supports(Packet.OUTBOUND_TRANSPORT_HEADERS)) { aoqi@0: MimeHeaders hdrs = returnValue.getMimeHeaders(); aoqi@0: Map> headers = new HashMap>(); aoqi@0: Iterator i = hdrs.getAllHeaders(); aoqi@0: while(i.hasNext()) { aoqi@0: MimeHeader header = (MimeHeader)i.next(); aoqi@0: if(header.getName().equalsIgnoreCase("SOAPAction")) aoqi@0: // SAAJ sets this header automatically, but it interferes with the correct operation of JAX-WS. aoqi@0: // so ignore this header. aoqi@0: continue; aoqi@0: aoqi@0: List list = headers.get(header.getName()); aoqi@0: if (list == null) { aoqi@0: list = new ArrayList(); aoqi@0: headers.put(header.getName(), list); aoqi@0: } aoqi@0: list.add(header.getValue()); aoqi@0: } aoqi@0: response.put(Packet.OUTBOUND_TRANSPORT_HEADERS, headers); aoqi@0: } aoqi@0: return response; aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: }