src/share/jaxws_classes/com/sun/xml/internal/ws/server/provider/SOAPProviderArgumentBuilder.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/server/provider/SOAPProviderArgumentBuilder.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,162 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.server.provider;
    1.30 +
    1.31 +import com.sun.istack.internal.Nullable;
    1.32 +import com.sun.xml.internal.ws.api.SOAPVersion;
    1.33 +import com.sun.xml.internal.ws.api.WSBinding;
    1.34 +import com.sun.xml.internal.ws.api.message.Message;
    1.35 +import com.sun.xml.internal.ws.api.message.Messages;
    1.36 +import com.sun.xml.internal.ws.api.message.Packet;
    1.37 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    1.38 +import com.sun.xml.internal.ws.fault.SOAPFaultBuilder;
    1.39 +import com.sun.xml.internal.ws.resources.ServerMessages;
    1.40 +
    1.41 +import javax.xml.soap.MimeHeader;
    1.42 +import javax.xml.soap.MimeHeaders;
    1.43 +import javax.xml.soap.SOAPException;
    1.44 +import javax.xml.soap.SOAPMessage;
    1.45 +import javax.xml.transform.Source;
    1.46 +import javax.xml.ws.Service;
    1.47 +import javax.xml.ws.WebServiceException;
    1.48 +import java.util.ArrayList;
    1.49 +import java.util.HashMap;
    1.50 +import java.util.Iterator;
    1.51 +import java.util.List;
    1.52 +import java.util.Map;
    1.53 +
    1.54 +/**
    1.55 + * @author Jitendra Kotamraju
    1.56 + */
    1.57 +abstract class SOAPProviderArgumentBuilder<T> extends ProviderArgumentsBuilder<T> {
    1.58 +    protected final SOAPVersion soapVersion;
    1.59 +
    1.60 +    private SOAPProviderArgumentBuilder(SOAPVersion soapVersion) {
    1.61 +        this.soapVersion = soapVersion;
    1.62 +    }
    1.63 +
    1.64 +    static ProviderArgumentsBuilder create(ProviderEndpointModel model, SOAPVersion soapVersion) {
    1.65 +        if (model.mode == Service.Mode.PAYLOAD) {
    1.66 +            return new PayloadSource(soapVersion);
    1.67 +        } else {
    1.68 +            if(model.datatype==Source.class)
    1.69 +                return new MessageSource(soapVersion);
    1.70 +            if(model.datatype==SOAPMessage.class)
    1.71 +                return new SOAPMessageParameter(soapVersion);
    1.72 +            if(model.datatype==Message.class)
    1.73 +                return new MessageProviderArgumentBuilder(soapVersion);
    1.74 +            throw new WebServiceException(ServerMessages.PROVIDER_INVALID_PARAMETER_TYPE(model.implClass,model.datatype));
    1.75 +        }
    1.76 +    }
    1.77 +
    1.78 +    private static final class PayloadSource extends SOAPProviderArgumentBuilder<Source> {
    1.79 +        PayloadSource(SOAPVersion soapVersion) {
    1.80 +            super(soapVersion);
    1.81 +        }
    1.82 +
    1.83 +        protected Source getParameter(Packet packet) {
    1.84 +            return packet.getMessage().readPayloadAsSource();
    1.85 +        }
    1.86 +
    1.87 +        protected Message getResponseMessage(Source source) {
    1.88 +            return Messages.createUsingPayload(source, soapVersion);
    1.89 +        }
    1.90 +
    1.91 +        protected Message getResponseMessage(Exception e) {
    1.92 +            return SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
    1.93 +        }
    1.94 +
    1.95 +    }
    1.96 +
    1.97 +    private static final class MessageSource extends SOAPProviderArgumentBuilder<Source> {
    1.98 +        MessageSource(SOAPVersion soapVersion) {
    1.99 +            super(soapVersion);
   1.100 +        }
   1.101 +
   1.102 +        protected Source getParameter(Packet packet) {
   1.103 +            return packet.getMessage().readEnvelopeAsSource();
   1.104 +        }
   1.105 +
   1.106 +        protected Message getResponseMessage(Source source) {
   1.107 +            return Messages.create(source, soapVersion);
   1.108 +        }
   1.109 +
   1.110 +        protected Message getResponseMessage(Exception e) {
   1.111 +            return SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
   1.112 +        }
   1.113 +    }
   1.114 +
   1.115 +    private static final class SOAPMessageParameter extends SOAPProviderArgumentBuilder<SOAPMessage> {
   1.116 +        SOAPMessageParameter(SOAPVersion soapVersion) {
   1.117 +            super(soapVersion);
   1.118 +        }
   1.119 +
   1.120 +        protected SOAPMessage getParameter(Packet packet) {
   1.121 +            try {
   1.122 +                return packet.getMessage().readAsSOAPMessage(packet, true);
   1.123 +            } catch (SOAPException se) {
   1.124 +                throw new WebServiceException(se);
   1.125 +            }
   1.126 +        }
   1.127 +
   1.128 +        protected Message getResponseMessage(SOAPMessage soapMsg) {
   1.129 +            return Messages.create(soapMsg);
   1.130 +        }
   1.131 +
   1.132 +        protected Message getResponseMessage(Exception e) {
   1.133 +            return SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
   1.134 +        }
   1.135 +
   1.136 +        @Override
   1.137 +        protected Packet getResponse(Packet request, @Nullable SOAPMessage returnValue, WSDLPort port, WSBinding binding) {
   1.138 +            Packet response = super.getResponse(request, returnValue, port, binding);
   1.139 +            // Populate SOAPMessage's transport headers
   1.140 +            if (returnValue != null && response.supports(Packet.OUTBOUND_TRANSPORT_HEADERS)) {
   1.141 +                MimeHeaders hdrs = returnValue.getMimeHeaders();
   1.142 +                Map<String, List<String>> headers = new HashMap<String, List<String>>();
   1.143 +                Iterator i = hdrs.getAllHeaders();
   1.144 +                while(i.hasNext()) {
   1.145 +                    MimeHeader header = (MimeHeader)i.next();
   1.146 +                    if(header.getName().equalsIgnoreCase("SOAPAction"))
   1.147 +                        // SAAJ sets this header automatically, but it interferes with the correct operation of JAX-WS.
   1.148 +                        // so ignore this header.
   1.149 +                        continue;
   1.150 +
   1.151 +                    List<String> list = headers.get(header.getName());
   1.152 +                    if (list == null) {
   1.153 +                        list = new ArrayList<String>();
   1.154 +                        headers.put(header.getName(), list);
   1.155 +                    }
   1.156 +                    list.add(header.getValue());
   1.157 +                }
   1.158 +                response.put(Packet.OUTBOUND_TRANSPORT_HEADERS, headers);
   1.159 +            }
   1.160 +            return response;
   1.161 +        }
   1.162 +
   1.163 +    }
   1.164 +
   1.165 +}

mercurial