Wed, 12 Jun 2013 14:47:09 +0100
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
8003542: Improve processing of MTOM attachments
8005432: Update access to JAX-WS
Reviewed-by: mullan
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 1997, 2012, 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.api.message; |
ohair@286 | 27 | |
ohair@286 | 28 | import com.sun.istack.internal.NotNull; |
ohair@286 | 29 | import com.sun.xml.internal.bind.api.Bridge; |
ohair@286 | 30 | import com.sun.xml.internal.bind.api.JAXBRIContext; |
ohair@286 | 31 | import com.sun.xml.internal.bind.v2.runtime.MarshallerImpl; |
ohair@286 | 32 | import com.sun.xml.internal.ws.api.SOAPVersion; |
ohair@286 | 33 | import com.sun.xml.internal.ws.api.pipe.Pipe; |
ohair@286 | 34 | import com.sun.xml.internal.ws.message.DOMHeader; |
ohair@286 | 35 | import com.sun.xml.internal.ws.message.StringHeader; |
ohair@286 | 36 | import com.sun.xml.internal.ws.message.jaxb.JAXBHeader; |
ohair@286 | 37 | import com.sun.xml.internal.ws.message.saaj.SAAJHeader; |
ohair@286 | 38 | import com.sun.xml.internal.ws.message.stream.StreamHeader11; |
ohair@286 | 39 | import com.sun.xml.internal.ws.message.stream.StreamHeader12; |
ohair@286 | 40 | import com.sun.xml.internal.ws.spi.db.BindingContext; |
ohair@286 | 41 | import com.sun.xml.internal.ws.spi.db.BindingContextFactory; |
ohair@286 | 42 | import com.sun.xml.internal.ws.spi.db.XMLBridge; |
ohair@286 | 43 | |
ohair@286 | 44 | import org.w3c.dom.Element; |
ohair@286 | 45 | |
ohair@286 | 46 | import javax.xml.bind.JAXBContext; |
ohair@286 | 47 | import javax.xml.bind.JAXBElement; |
ohair@286 | 48 | import javax.xml.bind.Marshaller; |
ohair@286 | 49 | import javax.xml.namespace.QName; |
ohair@286 | 50 | import javax.xml.soap.SOAPHeaderElement; |
ohair@286 | 51 | import javax.xml.stream.XMLStreamException; |
ohair@286 | 52 | import javax.xml.stream.XMLStreamReader; |
ohair@286 | 53 | |
ohair@286 | 54 | /** |
ohair@286 | 55 | * Factory methods for various {@link Header} implementations. |
ohair@286 | 56 | * |
ohair@286 | 57 | * <p> |
ohair@286 | 58 | * This class provides various methods to create different |
ohair@286 | 59 | * flavors of {@link Header} classes that store data |
ohair@286 | 60 | * in different formats. |
ohair@286 | 61 | * |
ohair@286 | 62 | * <p> |
ohair@286 | 63 | * This is a part of the JAX-WS RI internal API so that |
ohair@286 | 64 | * {@link Pipe} implementations can reuse the implementations |
ohair@286 | 65 | * done inside the JAX-WS without having a strong dependency |
ohair@286 | 66 | * to the actual class. |
ohair@286 | 67 | * |
ohair@286 | 68 | * <p> |
ohair@286 | 69 | * If you find some of the useful convenience methods missing |
ohair@286 | 70 | * from this class, please talk to us. |
ohair@286 | 71 | * |
ohair@286 | 72 | * |
ohair@286 | 73 | * @author Kohsuke Kawaguchi |
ohair@286 | 74 | */ |
ohair@286 | 75 | public abstract class Headers { |
ohair@286 | 76 | private Headers() {} |
ohair@286 | 77 | |
ohair@286 | 78 | /** |
ohair@286 | 79 | * @deprecated |
ohair@286 | 80 | * Use {@link #create(BindingContext, Object)} instead. |
ohair@286 | 81 | */ |
ohair@286 | 82 | public static Header create(SOAPVersion soapVersion, Marshaller m, Object o) { |
ohair@286 | 83 | return new JAXBHeader(BindingContextFactory.getBindingContext(m),o); |
ohair@286 | 84 | } |
ohair@286 | 85 | |
ohair@286 | 86 | /** |
ohair@286 | 87 | * Creates a {@link Header} backed a by a JAXB bean. |
ohair@286 | 88 | */ |
ohair@286 | 89 | public static Header create(JAXBContext context, Object o) { |
ohair@286 | 90 | return new JAXBHeader(BindingContextFactory.create(context),o); |
ohair@286 | 91 | } |
ohair@286 | 92 | |
ohair@286 | 93 | public static Header create(BindingContext context, Object o) { |
ohair@286 | 94 | return new JAXBHeader(context,o); |
ohair@286 | 95 | } |
ohair@286 | 96 | |
ohair@286 | 97 | /** |
ohair@286 | 98 | * Creates a {@link Header} backed a by a JAXB bean, with the given tag name. |
ohair@286 | 99 | * |
ohair@286 | 100 | * See {@link #create(SOAPVersion, Marshaller, Object)} for the meaning |
ohair@286 | 101 | * of other parameters. |
ohair@286 | 102 | * |
ohair@286 | 103 | * @param tagName |
ohair@286 | 104 | * The name of the newly created header. Must not be null. |
ohair@286 | 105 | * @param o |
ohair@286 | 106 | * The JAXB bean that represents the contents of the header. Must not be null. |
ohair@286 | 107 | */ |
ohair@286 | 108 | public static Header create(SOAPVersion soapVersion, Marshaller m, QName tagName, Object o) { |
ohair@286 | 109 | return create(soapVersion,m,new JAXBElement(tagName,o.getClass(),o)); |
ohair@286 | 110 | } |
ohair@286 | 111 | |
ohair@286 | 112 | /** |
ohair@286 | 113 | * Creates a {@link Header} backed a by a JAXB bean. |
ohair@286 | 114 | * @deprecated |
ohair@286 | 115 | */ |
ohair@286 | 116 | public static Header create(Bridge bridge, Object jaxbObject) { |
ohair@286 | 117 | return new JAXBHeader(new com.sun.xml.internal.ws.db.glassfish.BridgeWrapper(null,bridge), jaxbObject); |
ohair@286 | 118 | } |
ohair@286 | 119 | |
ohair@286 | 120 | public static Header create(XMLBridge bridge, Object jaxbObject) { |
ohair@286 | 121 | return new JAXBHeader(bridge, jaxbObject); |
ohair@286 | 122 | } |
ohair@286 | 123 | |
ohair@286 | 124 | /** |
ohair@286 | 125 | * Creates a new {@link Header} backed by a SAAJ object. |
ohair@286 | 126 | */ |
ohair@286 | 127 | public static Header create(SOAPHeaderElement header) { |
ohair@286 | 128 | return new SAAJHeader(header); |
ohair@286 | 129 | } |
ohair@286 | 130 | |
ohair@286 | 131 | /** |
ohair@286 | 132 | * Creates a new {@link Header} backed by an {@link Element}. |
ohair@286 | 133 | */ |
ohair@286 | 134 | public static Header create( Element node ) { |
ohair@286 | 135 | return new DOMHeader<Element>(node); |
ohair@286 | 136 | } |
ohair@286 | 137 | |
ohair@286 | 138 | /** |
ohair@286 | 139 | * @deprecated |
ohair@286 | 140 | * Use {@link #create(Element)} |
ohair@286 | 141 | */ |
ohair@286 | 142 | public static Header create( SOAPVersion soapVersion, Element node ) { |
ohair@286 | 143 | return create(node); |
ohair@286 | 144 | } |
ohair@286 | 145 | |
ohair@286 | 146 | /** |
ohair@286 | 147 | * Creates a new {@link Header} that reads from {@link XMLStreamReader}. |
ohair@286 | 148 | * |
ohair@286 | 149 | * <p> |
ohair@286 | 150 | * Note that the header implementation will read the entire data |
ohair@286 | 151 | * into memory anyway, so this might not be as efficient as you might hope. |
ohair@286 | 152 | */ |
ohair@286 | 153 | public static Header create( SOAPVersion soapVersion, XMLStreamReader reader ) throws XMLStreamException { |
ohair@286 | 154 | switch(soapVersion) { |
ohair@286 | 155 | case SOAP_11: |
ohair@286 | 156 | return new StreamHeader11(reader); |
ohair@286 | 157 | case SOAP_12: |
ohair@286 | 158 | return new StreamHeader12(reader); |
ohair@286 | 159 | default: |
ohair@286 | 160 | throw new AssertionError(); |
ohair@286 | 161 | } |
ohair@286 | 162 | } |
ohair@286 | 163 | |
ohair@286 | 164 | /** |
ohair@286 | 165 | * Creates a new {@link Header} that that has a single text value in it |
ohair@286 | 166 | * (IOW, of the form <foo>text</foo>.) |
ohair@286 | 167 | * |
ohair@286 | 168 | * @param name QName of the header element |
ohair@286 | 169 | * @param value text value of the header |
ohair@286 | 170 | */ |
ohair@286 | 171 | public static Header create(QName name, String value) { |
ohair@286 | 172 | return new StringHeader(name, value); |
ohair@286 | 173 | } |
ohair@286 | 174 | |
ohair@286 | 175 | /** |
ohair@286 | 176 | * Creates a new {@link Header} that that has a single text value in it |
ohair@286 | 177 | * (IOW, of the form <foo>text</foo>.) |
ohair@286 | 178 | * |
ohair@286 | 179 | * @param name QName of the header element |
ohair@286 | 180 | * @param value text value of the header |
ohair@286 | 181 | */ |
ohair@286 | 182 | public static Header createMustUnderstand(@NotNull SOAPVersion soapVersion, @NotNull QName name,@NotNull String value) { |
ohair@286 | 183 | return new StringHeader(name, value,soapVersion,true); |
ohair@286 | 184 | } |
ohair@286 | 185 | } |