|
1 /* |
|
2 * Copyright (c) 1997, 2012, 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 */ |
|
25 |
|
26 package com.sun.xml.internal.ws.addressing; |
|
27 |
|
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.istack.internal.NotNull; |
|
41 import com.sun.istack.internal.Nullable; |
|
42 |
|
43 import javax.xml.ws.soap.AddressingFeature; |
|
44 |
|
45 /** |
|
46 * @author Rama Pulavarthi |
|
47 */ |
|
48 public class W3CWsaServerTube extends WsaServerTube{ |
|
49 private final AddressingFeature af; |
|
50 |
|
51 public W3CWsaServerTube(WSEndpoint endpoint, @NotNull WSDLPort wsdlPort, WSBinding binding, Tube next) { |
|
52 super(endpoint, wsdlPort, binding, next); |
|
53 af = binding.getFeature(AddressingFeature.class); |
|
54 } |
|
55 |
|
56 public W3CWsaServerTube(W3CWsaServerTube that, TubeCloner cloner) { |
|
57 super(that, cloner); |
|
58 this.af = that.af; |
|
59 } |
|
60 |
|
61 @Override |
|
62 public W3CWsaServerTube copy(TubeCloner cloner) { |
|
63 return new W3CWsaServerTube(this, cloner); |
|
64 } |
|
65 |
|
66 @Override |
|
67 protected void checkMandatoryHeaders( |
|
68 Packet packet, boolean foundAction, boolean foundTo, boolean foundReplyTo, |
|
69 boolean foundFaultTo, boolean foundMessageId, boolean foundRelatesTo) { |
|
70 super.checkMandatoryHeaders(packet, foundAction, foundTo, foundReplyTo, |
|
71 foundFaultTo, foundMessageId, foundRelatesTo); |
|
72 |
|
73 // find Req/Response or Oneway using WSDLModel(if it is availabe) |
|
74 WSDLBoundOperation wbo = getWSDLBoundOperation(packet); |
|
75 // Taking care of protocol messages as they do not have any corresponding operations |
|
76 if (wbo != null) { |
|
77 // if two-way and no wsa:MessageID is found |
|
78 if (!wbo.getOperation().isOneWay() && !foundMessageId) { |
|
79 throw new MissingAddressingHeaderException(addressingVersion.messageIDTag,packet); |
|
80 } |
|
81 } |
|
82 |
|
83 } |
|
84 |
|
85 @Override |
|
86 protected boolean isAnonymousRequired(@Nullable WSDLBoundOperation wbo) { |
|
87 return getResponseRequirement(wbo) == WSDLBoundOperation.ANONYMOUS.required; |
|
88 } |
|
89 |
|
90 private WSDLBoundOperation.ANONYMOUS getResponseRequirement(@Nullable WSDLBoundOperation wbo) { |
|
91 try { |
|
92 if (af.getResponses() == AddressingFeature.Responses.ANONYMOUS) { |
|
93 return WSDLBoundOperation.ANONYMOUS.required; |
|
94 } else if (af.getResponses() == AddressingFeature.Responses.NON_ANONYMOUS) { |
|
95 return WSDLBoundOperation.ANONYMOUS.prohibited; |
|
96 } |
|
97 } catch (NoSuchMethodError e) { |
|
98 //Ignore error, defaut to optional |
|
99 } |
|
100 //wsaw wsdl binding case will have some value set on wbo |
|
101 return wbo != null ? wbo.getAnonymous() : WSDLBoundOperation.ANONYMOUS.optional; |
|
102 } |
|
103 |
|
104 @Override |
|
105 protected void checkAnonymousSemantics(WSDLBoundOperation wbo, WSEndpointReference replyTo, WSEndpointReference faultTo) { |
|
106 String replyToValue = null; |
|
107 String faultToValue = null; |
|
108 |
|
109 if (replyTo != null) |
|
110 replyToValue = replyTo.getAddress(); |
|
111 |
|
112 if (faultTo != null) |
|
113 faultToValue = faultTo.getAddress(); |
|
114 WSDLBoundOperation.ANONYMOUS responseRequirement = getResponseRequirement(wbo); |
|
115 |
|
116 switch (responseRequirement) { |
|
117 case prohibited: |
|
118 if (replyToValue != null && replyToValue.equals(addressingVersion.anonymousUri)) |
|
119 throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED); |
|
120 |
|
121 if (faultToValue != null && faultToValue.equals(addressingVersion.anonymousUri)) |
|
122 throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED); |
|
123 break; |
|
124 case required: |
|
125 if (replyToValue != null && !replyToValue.equals(addressingVersion.anonymousUri)) |
|
126 throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, ONLY_ANONYMOUS_ADDRESS_SUPPORTED); |
|
127 |
|
128 if (faultToValue != null && !faultToValue.equals(addressingVersion.anonymousUri)) |
|
129 throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, ONLY_ANONYMOUS_ADDRESS_SUPPORTED); |
|
130 break; |
|
131 default: |
|
132 // ALL: no check |
|
133 } |
|
134 } |
|
135 |
|
136 } |