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

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.xml.internal.ws.server.provider;
aoqi@0 27
aoqi@0 28 import com.sun.istack.internal.Nullable;
aoqi@0 29 import com.sun.xml.internal.ws.api.SOAPVersion;
aoqi@0 30 import com.sun.xml.internal.ws.api.WSBinding;
aoqi@0 31 import com.sun.xml.internal.ws.api.message.Message;
aoqi@0 32 import com.sun.xml.internal.ws.api.message.Messages;
aoqi@0 33 import com.sun.xml.internal.ws.api.message.Packet;
aoqi@0 34 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
aoqi@0 35 import com.sun.xml.internal.ws.fault.SOAPFaultBuilder;
aoqi@0 36 import com.sun.xml.internal.ws.resources.ServerMessages;
aoqi@0 37
aoqi@0 38 import javax.xml.soap.MimeHeader;
aoqi@0 39 import javax.xml.soap.MimeHeaders;
aoqi@0 40 import javax.xml.soap.SOAPException;
aoqi@0 41 import javax.xml.soap.SOAPMessage;
aoqi@0 42 import javax.xml.transform.Source;
aoqi@0 43 import javax.xml.ws.Service;
aoqi@0 44 import javax.xml.ws.WebServiceException;
aoqi@0 45 import java.util.ArrayList;
aoqi@0 46 import java.util.HashMap;
aoqi@0 47 import java.util.Iterator;
aoqi@0 48 import java.util.List;
aoqi@0 49 import java.util.Map;
aoqi@0 50
aoqi@0 51 /**
aoqi@0 52 * @author Jitendra Kotamraju
aoqi@0 53 */
aoqi@0 54 abstract class SOAPProviderArgumentBuilder<T> extends ProviderArgumentsBuilder<T> {
aoqi@0 55 protected final SOAPVersion soapVersion;
aoqi@0 56
aoqi@0 57 private SOAPProviderArgumentBuilder(SOAPVersion soapVersion) {
aoqi@0 58 this.soapVersion = soapVersion;
aoqi@0 59 }
aoqi@0 60
aoqi@0 61 static ProviderArgumentsBuilder create(ProviderEndpointModel model, SOAPVersion soapVersion) {
aoqi@0 62 if (model.mode == Service.Mode.PAYLOAD) {
aoqi@0 63 return new PayloadSource(soapVersion);
aoqi@0 64 } else {
aoqi@0 65 if(model.datatype==Source.class)
aoqi@0 66 return new MessageSource(soapVersion);
aoqi@0 67 if(model.datatype==SOAPMessage.class)
aoqi@0 68 return new SOAPMessageParameter(soapVersion);
aoqi@0 69 if(model.datatype==Message.class)
aoqi@0 70 return new MessageProviderArgumentBuilder(soapVersion);
aoqi@0 71 throw new WebServiceException(ServerMessages.PROVIDER_INVALID_PARAMETER_TYPE(model.implClass,model.datatype));
aoqi@0 72 }
aoqi@0 73 }
aoqi@0 74
aoqi@0 75 private static final class PayloadSource extends SOAPProviderArgumentBuilder<Source> {
aoqi@0 76 PayloadSource(SOAPVersion soapVersion) {
aoqi@0 77 super(soapVersion);
aoqi@0 78 }
aoqi@0 79
aoqi@0 80 /*protected*/ public Source getParameter(Packet packet) {
aoqi@0 81 return packet.getMessage().readPayloadAsSource();
aoqi@0 82 }
aoqi@0 83
aoqi@0 84 protected Message getResponseMessage(Source source) {
aoqi@0 85 return Messages.createUsingPayload(source, soapVersion);
aoqi@0 86 }
aoqi@0 87
aoqi@0 88 protected Message getResponseMessage(Exception e) {
aoqi@0 89 return SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
aoqi@0 90 }
aoqi@0 91
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 private static final class MessageSource extends SOAPProviderArgumentBuilder<Source> {
aoqi@0 95 MessageSource(SOAPVersion soapVersion) {
aoqi@0 96 super(soapVersion);
aoqi@0 97 }
aoqi@0 98
aoqi@0 99 /*protected*/ public Source getParameter(Packet packet) {
aoqi@0 100 return packet.getMessage().readEnvelopeAsSource();
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 protected Message getResponseMessage(Source source) {
aoqi@0 104 return Messages.create(source, soapVersion);
aoqi@0 105 }
aoqi@0 106
aoqi@0 107 protected Message getResponseMessage(Exception e) {
aoqi@0 108 return SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
aoqi@0 109 }
aoqi@0 110 }
aoqi@0 111
aoqi@0 112 private static final class SOAPMessageParameter extends SOAPProviderArgumentBuilder<SOAPMessage> {
aoqi@0 113 SOAPMessageParameter(SOAPVersion soapVersion) {
aoqi@0 114 super(soapVersion);
aoqi@0 115 }
aoqi@0 116
aoqi@0 117 /*protected*/ public SOAPMessage getParameter(Packet packet) {
aoqi@0 118 try {
aoqi@0 119 return packet.getMessage().readAsSOAPMessage(packet, true);
aoqi@0 120 } catch (SOAPException se) {
aoqi@0 121 throw new WebServiceException(se);
aoqi@0 122 }
aoqi@0 123 }
aoqi@0 124
aoqi@0 125 protected Message getResponseMessage(SOAPMessage soapMsg) {
aoqi@0 126 return Messages.create(soapMsg);
aoqi@0 127 }
aoqi@0 128
aoqi@0 129 protected Message getResponseMessage(Exception e) {
aoqi@0 130 return SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
aoqi@0 131 }
aoqi@0 132
aoqi@0 133 @Override
aoqi@0 134 protected Packet getResponse(Packet request, @Nullable SOAPMessage returnValue, WSDLPort port, WSBinding binding) {
aoqi@0 135 Packet response = super.getResponse(request, returnValue, port, binding);
aoqi@0 136 // Populate SOAPMessage's transport headers
aoqi@0 137 if (returnValue != null && response.supports(Packet.OUTBOUND_TRANSPORT_HEADERS)) {
aoqi@0 138 MimeHeaders hdrs = returnValue.getMimeHeaders();
aoqi@0 139 Map<String, List<String>> headers = new HashMap<String, List<String>>();
aoqi@0 140 Iterator i = hdrs.getAllHeaders();
aoqi@0 141 while(i.hasNext()) {
aoqi@0 142 MimeHeader header = (MimeHeader)i.next();
aoqi@0 143 if(header.getName().equalsIgnoreCase("SOAPAction"))
aoqi@0 144 // SAAJ sets this header automatically, but it interferes with the correct operation of JAX-WS.
aoqi@0 145 // so ignore this header.
aoqi@0 146 continue;
aoqi@0 147
aoqi@0 148 List<String> list = headers.get(header.getName());
aoqi@0 149 if (list == null) {
aoqi@0 150 list = new ArrayList<String>();
aoqi@0 151 headers.put(header.getName(), list);
aoqi@0 152 }
aoqi@0 153 list.add(header.getValue());
aoqi@0 154 }
aoqi@0 155 response.put(Packet.OUTBOUND_TRANSPORT_HEADERS, headers);
aoqi@0 156 }
aoqi@0 157 return response;
aoqi@0 158 }
aoqi@0 159
aoqi@0 160 }
aoqi@0 161
aoqi@0 162 }

mercurial