1 /* |
1 /* |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
24 */ |
24 */ |
25 |
25 |
26 package com.sun.xml.internal.ws.wsdl.parser; |
26 package com.sun.xml.internal.ws.wsdl.parser; |
27 |
27 |
28 import com.sun.xml.internal.ws.api.addressing.AddressingVersion; |
28 import com.sun.xml.internal.ws.api.addressing.AddressingVersion; |
29 import com.sun.xml.internal.ws.api.model.wsdl.*; |
29 import com.sun.xml.internal.ws.api.model.wsdl.WSDLFeaturedObject; |
|
30 import static com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation.ANONYMOUS; |
|
31 import com.sun.xml.internal.ws.api.model.wsdl.editable.*; |
30 import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension; |
32 import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension; |
31 import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtensionContext; |
33 import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtensionContext; |
32 import com.sun.xml.internal.ws.model.wsdl.*; |
|
33 import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil; |
34 import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil; |
34 import com.sun.xml.internal.ws.resources.AddressingMessages; |
|
35 |
35 |
36 import javax.xml.namespace.QName; |
36 import javax.xml.namespace.QName; |
37 import javax.xml.stream.XMLStreamException; |
37 import javax.xml.stream.XMLStreamException; |
38 import javax.xml.stream.XMLStreamReader; |
38 import javax.xml.stream.XMLStreamReader; |
39 import javax.xml.ws.WebServiceException; |
39 import javax.xml.ws.WebServiceException; |
40 import javax.xml.ws.soap.AddressingFeature; |
40 import javax.xml.ws.soap.AddressingFeature; |
41 import java.util.Map; |
|
42 |
41 |
43 /** |
42 /** |
44 * W3C WS-Addressing Runtime WSDL parser extension |
43 * W3C WS-Addressing Runtime WSDL parser extension |
45 * |
44 * |
46 * @author Arun Gupta |
45 * @author Arun Gupta |
47 */ |
46 */ |
48 public class W3CAddressingWSDLParserExtension extends WSDLParserExtension { |
47 public class W3CAddressingWSDLParserExtension extends WSDLParserExtension { |
49 @Override |
48 @Override |
50 public boolean bindingElements(WSDLBoundPortType binding, XMLStreamReader reader) { |
49 public boolean bindingElements(EditableWSDLBoundPortType binding, XMLStreamReader reader) { |
51 return addressibleElement(reader, binding); |
50 return addressibleElement(reader, binding); |
52 } |
51 } |
53 |
52 |
54 @Override |
53 @Override |
55 public boolean portElements(WSDLPort port, XMLStreamReader reader) { |
54 public boolean portElements(EditableWSDLPort port, XMLStreamReader reader) { |
56 return addressibleElement(reader, port); |
55 return addressibleElement(reader, port); |
57 } |
56 } |
58 |
57 |
59 private boolean addressibleElement(XMLStreamReader reader, WSDLFeaturedObject binding) { |
58 private boolean addressibleElement(XMLStreamReader reader, WSDLFeaturedObject binding) { |
60 QName ua = reader.getName(); |
59 QName ua = reader.getName(); |
67 |
66 |
68 return false; |
67 return false; |
69 } |
68 } |
70 |
69 |
71 @Override |
70 @Override |
72 public boolean bindingOperationElements(WSDLBoundOperation operation, XMLStreamReader reader) { |
71 public boolean bindingOperationElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) { |
73 WSDLBoundOperationImpl impl = (WSDLBoundOperationImpl)operation; |
72 EditableWSDLBoundOperation edit = (EditableWSDLBoundOperation) operation; |
74 |
73 |
75 QName anon = reader.getName(); |
74 QName anon = reader.getName(); |
76 if (anon.equals(AddressingVersion.W3C.wsdlAnonymousTag)) { |
75 if (anon.equals(AddressingVersion.W3C.wsdlAnonymousTag)) { |
77 try { |
76 try { |
78 String value = reader.getElementText(); |
77 String value = reader.getElementText(); |
79 if (value == null || value.trim().equals("")) { |
78 if (value == null || value.trim().equals("")) { |
80 throw new WebServiceException("Null values not permitted in wsaw:Anonymous."); |
79 throw new WebServiceException("Null values not permitted in wsaw:Anonymous."); |
81 // TODO: throw exception only if wsdl:required=true |
80 // TODO: throw exception only if wsdl:required=true |
82 // TODO: is this the right exception ? |
81 // TODO: is this the right exception ? |
83 } else if (value.equals("optional")) { |
82 } else if (value.equals("optional")) { |
84 impl.setAnonymous(WSDLBoundOperation.ANONYMOUS.optional); |
83 edit.setAnonymous(ANONYMOUS.optional); |
85 } else if (value.equals("required")) { |
84 } else if (value.equals("required")) { |
86 impl.setAnonymous(WSDLBoundOperation.ANONYMOUS.required); |
85 edit.setAnonymous(ANONYMOUS.required); |
87 } else if (value.equals("prohibited")) { |
86 } else if (value.equals("prohibited")) { |
88 impl.setAnonymous(WSDLBoundOperation.ANONYMOUS.prohibited); |
87 edit.setAnonymous(ANONYMOUS.prohibited); |
89 } else { |
88 } else { |
90 throw new WebServiceException("wsaw:Anonymous value \"" + value + "\" not understood."); |
89 throw new WebServiceException("wsaw:Anonymous value \"" + value + "\" not understood."); |
91 // TODO: throw exception only if wsdl:required=true |
90 // TODO: throw exception only if wsdl:required=true |
92 // TODO: is this the right exception ? |
91 // TODO: is this the right exception ? |
93 } |
92 } |
99 } |
98 } |
100 |
99 |
101 return false; |
100 return false; |
102 } |
101 } |
103 |
102 |
104 public void portTypeOperationInputAttributes(WSDLInput input, XMLStreamReader reader) { |
103 public void portTypeOperationInputAttributes(EditableWSDLInput input, XMLStreamReader reader) { |
105 String action = ParserUtil.getAttribute(reader, getWsdlActionTag()); |
104 String action = ParserUtil.getAttribute(reader, getWsdlActionTag()); |
106 if (action != null) { |
105 if (action != null) { |
107 ((WSDLInputImpl)input).setAction(action); |
106 input.setAction(action); |
108 ((WSDLInputImpl)input).setDefaultAction(false); |
107 input.setDefaultAction(false); |
109 } |
108 } |
110 } |
109 } |
111 |
110 |
112 |
111 |
113 public void portTypeOperationOutputAttributes(WSDLOutput output, XMLStreamReader reader) { |
112 public void portTypeOperationOutputAttributes(EditableWSDLOutput output, XMLStreamReader reader) { |
114 String action = ParserUtil.getAttribute(reader, getWsdlActionTag()); |
113 String action = ParserUtil.getAttribute(reader, getWsdlActionTag()); |
115 if (action != null) { |
114 if (action != null) { |
116 ((WSDLOutputImpl)output).setAction(action); |
115 output.setAction(action); |
117 ((WSDLOutputImpl)output).setDefaultAction(false); |
116 output.setDefaultAction(false); |
118 } |
117 } |
119 } |
118 } |
120 |
119 |
121 |
120 |
122 public void portTypeOperationFaultAttributes(WSDLFault fault, XMLStreamReader reader) { |
121 public void portTypeOperationFaultAttributes(EditableWSDLFault fault, XMLStreamReader reader) { |
123 String action = ParserUtil.getAttribute(reader, getWsdlActionTag()); |
122 String action = ParserUtil.getAttribute(reader, getWsdlActionTag()); |
124 if (action != null) { |
123 if (action != null) { |
125 ((WSDLFaultImpl) fault).setAction(action); |
124 fault.setAction(action); |
126 ((WSDLFaultImpl) fault).setDefaultAction(false); |
125 fault.setDefaultAction(false); |
127 } |
126 } |
128 } |
127 } |
129 |
128 |
130 /** |
129 /** |
131 * Process wsdl:portType operation after the entire WSDL model has been populated. |
130 * Process wsdl:portType operation after the entire WSDL model has been populated. |
137 * </ul> |
136 * </ul> |
138 * @param context |
137 * @param context |
139 */ |
138 */ |
140 @Override |
139 @Override |
141 public void finished(WSDLParserExtensionContext context) { |
140 public void finished(WSDLParserExtensionContext context) { |
142 WSDLModel model = context.getWSDLModel(); |
141 EditableWSDLModel model = context.getWSDLModel(); |
143 for (WSDLService service : model.getServices().values()) { |
142 for (EditableWSDLService service : model.getServices().values()) { |
144 for (WSDLPort wp : service.getPorts()) { |
143 for (EditableWSDLPort port : service.getPorts()) { |
145 WSDLPortImpl port = (WSDLPortImpl)wp; |
144 EditableWSDLBoundPortType binding = port.getBinding(); |
146 WSDLBoundPortTypeImpl binding = port.getBinding(); |
|
147 |
145 |
148 // populate actions for the messages that do not have an explicit wsaw:Action |
146 // populate actions for the messages that do not have an explicit wsaw:Action |
149 populateActions(binding); |
147 populateActions(binding); |
150 |
148 |
151 // patch the default value of wsaw:Anonymous=optional if none is specified |
149 // patch the default value of wsaw:Anonymous=optional if none is specified |
164 /** |
162 /** |
165 * Populate all the Actions |
163 * Populate all the Actions |
166 * |
164 * |
167 * @param binding soapbinding:operation |
165 * @param binding soapbinding:operation |
168 */ |
166 */ |
169 private void populateActions(WSDLBoundPortTypeImpl binding) { |
167 private void populateActions(EditableWSDLBoundPortType binding) { |
170 WSDLPortTypeImpl porttype = binding.getPortType(); |
168 EditableWSDLPortType porttype = binding.getPortType(); |
171 for (WSDLOperationImpl o : porttype.getOperations()) { |
169 for (EditableWSDLOperation o : porttype.getOperations()) { |
172 // TODO: this may be performance intensive. Alternatively default action |
170 // TODO: this may be performance intensive. Alternatively default action |
173 // TODO: can be calculated when the operation is actually invoked. |
171 // TODO: can be calculated when the operation is actually invoked. |
174 WSDLBoundOperationImpl wboi = binding.get(o.getName()); |
172 EditableWSDLBoundOperation wboi = binding.get(o.getName()); |
175 |
173 |
176 if (wboi == null) { |
174 if (wboi == null) { |
177 //If this operation is unbound set the action to default |
175 //If this operation is unbound set the action to default |
178 o.getInput().setAction(defaultInputAction(o)); |
176 o.getInput().setAction(defaultInputAction(o)); |
179 continue; |
177 continue; |
214 /** |
212 /** |
215 * Patch the default value of wsaw:Anonymous=optional if none is specified |
213 * Patch the default value of wsaw:Anonymous=optional if none is specified |
216 * |
214 * |
217 * @param binding WSDLBoundPortTypeImpl |
215 * @param binding WSDLBoundPortTypeImpl |
218 */ |
216 */ |
219 protected void patchAnonymousDefault(WSDLBoundPortTypeImpl binding) { |
217 protected void patchAnonymousDefault(EditableWSDLBoundPortType binding) { |
220 for (WSDLBoundOperationImpl wbo : binding.getBindingOperations()) { |
218 for (EditableWSDLBoundOperation wbo : binding.getBindingOperations()) { |
221 if (wbo.getAnonymous() == null) |
219 if (wbo.getAnonymous() == null) |
222 wbo.setAnonymous(WSDLBoundOperation.ANONYMOUS.optional); |
220 wbo.setAnonymous(ANONYMOUS.optional); |
223 } |
221 } |
224 } |
222 } |
225 |
223 |
226 private String defaultInputAction(WSDLOperation o) { |
224 private String defaultInputAction(EditableWSDLOperation o) { |
227 return buildAction(o.getInput().getName(), o, false); |
225 return buildAction(o.getInput().getName(), o, false); |
228 } |
226 } |
229 |
227 |
230 private String defaultOutputAction(WSDLOperation o) { |
228 private String defaultOutputAction(EditableWSDLOperation o) { |
231 return buildAction(o.getOutput().getName(), o, false); |
229 return buildAction(o.getOutput().getName(), o, false); |
232 } |
230 } |
233 |
231 |
234 private String defaultFaultAction(String name, WSDLOperation o) { |
232 private String defaultFaultAction(String name, EditableWSDLOperation o) { |
235 return buildAction(name, o, true); |
233 return buildAction(name, o, true); |
236 } |
234 } |
237 |
235 |
238 protected static final String buildAction(String name, WSDLOperation o, boolean isFault) { |
236 protected static final String buildAction(String name, EditableWSDLOperation o, boolean isFault) { |
239 String tns = o.getName().getNamespaceURI(); |
237 String tns = o.getName().getNamespaceURI(); |
240 |
238 |
241 String delim = SLASH_DELIMITER; |
239 String delim = SLASH_DELIMITER; |
242 |
240 |
243 // TODO: is this the correct way to find the separator ? |
241 // TODO: is this the correct way to find the separator ? |