Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2013, 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.binding; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.sun.istack.internal.NotNull; |
aoqi@0 | 29 | import com.sun.xml.internal.ws.api.BindingID; |
aoqi@0 | 30 | import com.sun.xml.internal.ws.api.SOAPVersion; |
aoqi@0 | 31 | import com.sun.xml.internal.ws.client.HandlerConfiguration; |
aoqi@0 | 32 | import com.sun.xml.internal.ws.encoding.soap.streaming.SOAP12NamespaceConstants; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.resources.ClientMessages; |
aoqi@0 | 34 | |
aoqi@0 | 35 | import javax.xml.namespace.QName; |
aoqi@0 | 36 | import javax.xml.soap.MessageFactory; |
aoqi@0 | 37 | import javax.xml.soap.SOAPFactory; |
aoqi@0 | 38 | |
aoqi@0 | 39 | import javax.xml.ws.WebServiceException; |
aoqi@0 | 40 | import javax.xml.ws.WebServiceFeature; |
aoqi@0 | 41 | import javax.xml.ws.handler.Handler; |
aoqi@0 | 42 | import javax.xml.ws.soap.MTOMFeature; |
aoqi@0 | 43 | import javax.xml.ws.soap.SOAPBinding; |
aoqi@0 | 44 | import java.util.*; |
aoqi@0 | 45 | |
aoqi@0 | 46 | /** |
aoqi@0 | 47 | * @author WS Development Team |
aoqi@0 | 48 | */ |
aoqi@0 | 49 | public final class SOAPBindingImpl extends BindingImpl implements SOAPBinding { |
aoqi@0 | 50 | |
aoqi@0 | 51 | public static final String X_SOAP12HTTP_BINDING = |
aoqi@0 | 52 | "http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/"; |
aoqi@0 | 53 | |
aoqi@0 | 54 | private static final String ROLE_NONE = SOAP12NamespaceConstants.ROLE_NONE; |
aoqi@0 | 55 | //protected boolean enableMtom; |
aoqi@0 | 56 | protected final SOAPVersion soapVersion; |
aoqi@0 | 57 | |
aoqi@0 | 58 | private Set<QName> portKnownHeaders = Collections.emptySet(); |
aoqi@0 | 59 | private Set<QName> bindingUnderstoodHeaders = new HashSet<QName>(); |
aoqi@0 | 60 | |
aoqi@0 | 61 | /** |
aoqi@0 | 62 | * Use {@link BindingImpl#create(BindingID)} to create this. |
aoqi@0 | 63 | * |
aoqi@0 | 64 | * @param bindingId SOAP binding ID |
aoqi@0 | 65 | */ |
aoqi@0 | 66 | SOAPBindingImpl(BindingID bindingId) { |
aoqi@0 | 67 | this(bindingId,EMPTY_FEATURES); |
aoqi@0 | 68 | } |
aoqi@0 | 69 | |
aoqi@0 | 70 | /** |
aoqi@0 | 71 | * Use {@link BindingImpl#create(BindingID)} to create this. |
aoqi@0 | 72 | * |
aoqi@0 | 73 | * @param bindingId binding id |
aoqi@0 | 74 | * @param features |
aoqi@0 | 75 | * These features have a precedence over |
aoqi@0 | 76 | * {@link BindingID#createBuiltinFeatureList() the implicit features} |
aoqi@0 | 77 | * associated with the {@link BindingID}. |
aoqi@0 | 78 | */ |
aoqi@0 | 79 | SOAPBindingImpl(BindingID bindingId, WebServiceFeature... features) { |
aoqi@0 | 80 | super(bindingId, features); |
aoqi@0 | 81 | this.soapVersion = bindingId.getSOAPVersion(); |
aoqi@0 | 82 | //populates with required roles and updates handlerConfig |
aoqi@0 | 83 | setRoles(new HashSet<String>()); |
aoqi@0 | 84 | //Is this still required? comment out for now |
aoqi@0 | 85 | //setupSystemHandlerDelegate(serviceName); |
aoqi@0 | 86 | |
aoqi@0 | 87 | this.features.addAll(bindingId.createBuiltinFeatureList()); |
aoqi@0 | 88 | } |
aoqi@0 | 89 | |
aoqi@0 | 90 | /** |
aoqi@0 | 91 | * This method should be called if the binding has SOAPSEIModel |
aoqi@0 | 92 | * The Headers understood by the Port are set, so that they can be used for MU |
aoqi@0 | 93 | * processing. |
aoqi@0 | 94 | * |
aoqi@0 | 95 | * @param headers SOAP header names |
aoqi@0 | 96 | */ |
aoqi@0 | 97 | public void setPortKnownHeaders(@NotNull Set<QName> headers) { |
aoqi@0 | 98 | this.portKnownHeaders = headers; |
aoqi@0 | 99 | } |
aoqi@0 | 100 | |
aoqi@0 | 101 | /** |
aoqi@0 | 102 | * TODO A feature should be created to configure processing of MU headers. |
aoqi@0 | 103 | * @param header |
aoqi@0 | 104 | * @return |
aoqi@0 | 105 | */ |
aoqi@0 | 106 | public boolean understandsHeader(QName header) { |
aoqi@0 | 107 | return serviceMode == javax.xml.ws.Service.Mode.MESSAGE |
aoqi@0 | 108 | || portKnownHeaders.contains(header) |
aoqi@0 | 109 | || bindingUnderstoodHeaders.contains(header); |
aoqi@0 | 110 | |
aoqi@0 | 111 | } |
aoqi@0 | 112 | |
aoqi@0 | 113 | /** |
aoqi@0 | 114 | * Sets the handlers on the binding and then sorts the handlers in to logical and protocol handlers. |
aoqi@0 | 115 | * Creates a new HandlerConfiguration object and sets it on the BindingImpl. Also parses Headers understood by |
aoqi@0 | 116 | * Protocol Handlers and sets the HandlerConfiguration. |
aoqi@0 | 117 | */ |
aoqi@0 | 118 | public void setHandlerChain(List<Handler> chain) { |
aoqi@0 | 119 | setHandlerConfig(new HandlerConfiguration(getHandlerConfig().getRoles(), chain)); |
aoqi@0 | 120 | } |
aoqi@0 | 121 | |
aoqi@0 | 122 | protected void addRequiredRoles(Set<String> roles) { |
aoqi@0 | 123 | roles.addAll(soapVersion.requiredRoles); |
aoqi@0 | 124 | } |
aoqi@0 | 125 | |
aoqi@0 | 126 | public Set<String> getRoles() { |
aoqi@0 | 127 | return getHandlerConfig().getRoles(); |
aoqi@0 | 128 | } |
aoqi@0 | 129 | |
aoqi@0 | 130 | /** |
aoqi@0 | 131 | * Adds the next and other roles in case this has |
aoqi@0 | 132 | * been called by a user without them. |
aoqi@0 | 133 | * Creates a new HandlerConfiguration object and sets it on the BindingImpl. |
aoqi@0 | 134 | */ |
aoqi@0 | 135 | public void setRoles(Set<String> roles) { |
aoqi@0 | 136 | if (roles == null) { |
aoqi@0 | 137 | roles = new HashSet<String>(); |
aoqi@0 | 138 | } |
aoqi@0 | 139 | if (roles.contains(ROLE_NONE)) { |
aoqi@0 | 140 | throw new WebServiceException(ClientMessages.INVALID_SOAP_ROLE_NONE()); |
aoqi@0 | 141 | } |
aoqi@0 | 142 | addRequiredRoles(roles); |
aoqi@0 | 143 | setHandlerConfig(new HandlerConfiguration(roles, getHandlerConfig())); |
aoqi@0 | 144 | } |
aoqi@0 | 145 | |
aoqi@0 | 146 | |
aoqi@0 | 147 | /** |
aoqi@0 | 148 | * Used typically by the runtime to enable/disable Mtom optimization |
aoqi@0 | 149 | */ |
aoqi@0 | 150 | public boolean isMTOMEnabled() { |
aoqi@0 | 151 | return isFeatureEnabled(MTOMFeature.class); |
aoqi@0 | 152 | } |
aoqi@0 | 153 | |
aoqi@0 | 154 | /** |
aoqi@0 | 155 | * Client application can override if the MTOM optimization should be enabled |
aoqi@0 | 156 | */ |
aoqi@0 | 157 | public void setMTOMEnabled(boolean b) { |
aoqi@0 | 158 | features.setMTOMEnabled(b); |
aoqi@0 | 159 | } |
aoqi@0 | 160 | |
aoqi@0 | 161 | public SOAPFactory getSOAPFactory() { |
aoqi@0 | 162 | return soapVersion.getSOAPFactory(); |
aoqi@0 | 163 | } |
aoqi@0 | 164 | |
aoqi@0 | 165 | public MessageFactory getMessageFactory() { |
aoqi@0 | 166 | return soapVersion.getMessageFactory(); |
aoqi@0 | 167 | } |
aoqi@0 | 168 | |
aoqi@0 | 169 | } |