Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.xml.internal.ws.addressing;
28 import com.sun.xml.internal.ws.api.server.WSEndpoint;
29 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
30 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
31 import com.sun.xml.internal.ws.api.WSBinding;
32 import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
33 import com.sun.xml.internal.ws.api.message.Packet;
34 import com.sun.xml.internal.ws.api.pipe.Tube;
35 import com.sun.xml.internal.ws.api.pipe.TubeCloner;
36 import com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException;
37 import com.sun.xml.internal.ws.addressing.model.InvalidAddressingHeaderException;
38 import static com.sun.xml.internal.ws.addressing.W3CAddressingConstants.ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED;
39 import static com.sun.xml.internal.ws.addressing.W3CAddressingConstants.ONLY_ANONYMOUS_ADDRESS_SUPPORTED;
40 import com.sun.xml.internal.ws.resources.AddressingMessages;
41 import com.sun.istack.internal.NotNull;
42 import com.sun.istack.internal.Nullable;
44 import javax.xml.ws.soap.AddressingFeature;
45 import javax.xml.ws.WebServiceException;
47 /**
48 * @author Rama Pulavarthi
49 */
50 public class W3CWsaServerTube extends WsaServerTube{
51 private final AddressingFeature af;
53 public W3CWsaServerTube(WSEndpoint endpoint, @NotNull WSDLPort wsdlPort, WSBinding binding, Tube next) {
54 super(endpoint, wsdlPort, binding, next);
55 af = binding.getFeature(AddressingFeature.class);
56 }
58 public W3CWsaServerTube(W3CWsaServerTube that, TubeCloner cloner) {
59 super(that, cloner);
60 this.af = that.af;
61 }
63 @Override
64 public W3CWsaServerTube copy(TubeCloner cloner) {
65 return new W3CWsaServerTube(this, cloner);
66 }
68 @Override
69 protected void checkMandatoryHeaders(
70 Packet packet, boolean foundAction, boolean foundTo, boolean foundReplyTo,
71 boolean foundFaultTo, boolean foundMessageId, boolean foundRelatesTo) {
72 super.checkMandatoryHeaders(packet, foundAction, foundTo, foundReplyTo,
73 foundFaultTo, foundMessageId, foundRelatesTo);
75 // find Req/Response or Oneway using WSDLModel(if it is availabe)
76 WSDLBoundOperation wbo = getWSDLBoundOperation(packet);
77 // Taking care of protocol messages as they do not have any corresponding operations
78 if (wbo != null) {
79 // if two-way and no wsa:MessageID is found
80 if (!wbo.getOperation().isOneWay() && !foundMessageId) {
81 throw new MissingAddressingHeaderException(addressingVersion.messageIDTag,packet);
82 }
83 }
85 }
87 @Override
88 protected boolean isAnonymousRequired(@Nullable WSDLBoundOperation wbo) {
89 return getResponseRequirement(wbo) == WSDLBoundOperation.ANONYMOUS.required;
90 }
92 private WSDLBoundOperation.ANONYMOUS getResponseRequirement(@Nullable WSDLBoundOperation wbo) {
93 try {
94 if (af.getResponses() == AddressingFeature.Responses.ANONYMOUS) {
95 return WSDLBoundOperation.ANONYMOUS.required;
96 } else if (af.getResponses() == AddressingFeature.Responses.NON_ANONYMOUS) {
97 return WSDLBoundOperation.ANONYMOUS.prohibited;
98 }
99 } catch (NoSuchMethodError e) {
100 //Ignore error, defaut to optional
101 }
102 //wsaw wsdl binding case will have some value set on wbo
103 return wbo != null ? wbo.getAnonymous() : WSDLBoundOperation.ANONYMOUS.optional;
104 }
106 @Override
107 protected void checkAnonymousSemantics(WSDLBoundOperation wbo, WSEndpointReference replyTo, WSEndpointReference faultTo) {
108 String replyToValue = null;
109 String faultToValue = null;
111 if (replyTo != null)
112 replyToValue = replyTo.getAddress();
114 if (faultTo != null)
115 faultToValue = faultTo.getAddress();
116 WSDLBoundOperation.ANONYMOUS responseRequirement = getResponseRequirement(wbo);
118 switch (responseRequirement) {
119 case prohibited:
120 if (replyToValue != null && replyToValue.equals(addressingVersion.anonymousUri))
121 throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED);
123 if (faultToValue != null && faultToValue.equals(addressingVersion.anonymousUri))
124 throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED);
125 break;
126 case required:
127 if (replyToValue != null && !replyToValue.equals(addressingVersion.anonymousUri))
128 throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, ONLY_ANONYMOUS_ADDRESS_SUPPORTED);
130 if (faultToValue != null && !faultToValue.equals(addressingVersion.anonymousUri))
131 throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, ONLY_ANONYMOUS_ADDRESS_SUPPORTED);
132 break;
133 default:
134 // ALL: no check
135 }
136 }
138 /*
139 @Override
140 protected boolean isAnonymousRequired(@Nullable WSDLBoundOperation wbo) {
141 return getResponseRequirement(wbo) == AddressingFeature.Responses.ANONYMOUS;
142 }
144 private AddressingFeature.Responses getResponseRequirement(@Nullable WSDLBoundOperation wbo) {
145 if (af.getResponses() == AddressingFeature.Responses.ALL && wbo != null) {
146 //wsaw wsdl binding case will have some value set on wbo
147 WSDLBoundOperation.ANONYMOUS anon = wbo.getAnonymous();
148 if (wbo.getAnonymous() == WSDLBoundOperation.ANONYMOUS.required)
149 return AddressingFeature.Responses.ANONYMOUS;
150 else if (wbo.getAnonymous() == WSDLBoundOperation.ANONYMOUS.prohibited)
151 return AddressingFeature.Responses.NON_ANONYMOUS;
152 else
153 return AddressingFeature.Responses.ALL;
155 } else
156 return af.getResponses();
157 }
159 @Override
160 protected void checkAnonymousSemantics(WSDLBoundOperation wbo, WSEndpointReference replyTo, WSEndpointReference faultTo) {
161 String replyToValue = null;
162 String faultToValue = null;
164 if (replyTo != null)
165 replyToValue = replyTo.getAddress();
167 if (faultTo != null)
168 faultToValue = faultTo.getAddress();
169 AddressingFeature.Responses responseRequirement = getResponseRequirement(wbo);
171 switch (responseRequirement) {
172 case NON_ANONYMOUS:
173 if (replyToValue != null && replyToValue.equals(addressingVersion.anonymousUri))
174 throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED);
176 if (faultToValue != null && faultToValue.equals(addressingVersion.anonymousUri))
177 throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED);
178 break;
179 case ANONYMOUS:
180 if (replyToValue != null && !replyToValue.equals(addressingVersion.anonymousUri))
181 throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, ONLY_ANONYMOUS_ADDRESS_SUPPORTED);
183 if (faultToValue != null && !faultToValue.equals(addressingVersion.anonymousUri))
184 throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, ONLY_ANONYMOUS_ADDRESS_SUPPORTED);
185 break;
186 default:
187 // ALL: no check
188 }
189 }
190 */
191 }