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

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

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

mercurial