|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
EndpointReference.java | 74% | 83.7% | 90% | 80.7% |
|
1 |
/*
|
|
2 |
* Copyright 1999-2004 The Apache Software Foundation.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package org.apache.axis.message.addressing;
|
|
19 |
|
|
20 |
import org.apache.axis.message.addressing.util.TextExtractor;
|
|
21 |
|
|
22 |
import org.apache.axis.types.URI;
|
|
23 |
import org.apache.axis.utils.XMLUtils;
|
|
24 |
import org.apache.axis.message.MessageElement;
|
|
25 |
|
|
26 |
import org.apache.commons.logging.Log;
|
|
27 |
import org.apache.commons.logging.LogFactory;
|
|
28 |
|
|
29 |
import org.w3c.dom.Document;
|
|
30 |
import org.w3c.dom.Element;
|
|
31 |
import org.w3c.dom.Node;
|
|
32 |
import org.w3c.dom.NodeList;
|
|
33 |
|
|
34 |
import java.util.Iterator;
|
|
35 |
|
|
36 |
import javax.xml.namespace.QName;
|
|
37 |
import javax.xml.soap.SOAPElement;
|
|
38 |
import javax.xml.soap.SOAPEnvelope;
|
|
39 |
import javax.xml.soap.SOAPHeaderElement;
|
|
40 |
import javax.xml.soap.SOAPHeader;
|
|
41 |
import javax.xml.parsers.ParserConfigurationException;
|
|
42 |
|
|
43 |
/**
|
|
44 |
* Java content class for EndpointReference element declaration.
|
|
45 |
* <p>The following schema fragment specifies the expected content contained within this java content object. (defined at http://schemas.xmlsoap.org/ws/2004/08/addressing line 45)
|
|
46 |
* <p>
|
|
47 |
* <pre>
|
|
48 |
* <element name="EndpointReference" type="{http://schemas.xmlsoap.org/ws/2004/08/addressing}EndpointReferenceType"/>
|
|
49 |
* </pre>
|
|
50 |
*
|
|
51 |
* @author Davanum Srinivas (dims@yahoo.com)
|
|
52 |
*/
|
|
53 |
public class EndpointReference extends EndpointReferenceType { |
|
54 |
|
|
55 |
private static Log log = |
|
56 |
LogFactory.getLog(EndpointReference.class.getName());
|
|
57 |
|
|
58 |
/**
|
|
59 |
* Constructor EndpointReference
|
|
60 |
*
|
|
61 |
* @param address
|
|
62 |
*/
|
|
63 | 8 |
public EndpointReference(Address address) {
|
64 | 8 |
setAddress(address); |
65 |
} |
|
66 |
|
|
67 |
/**
|
|
68 |
* Constructor EndpointReference
|
|
69 |
*
|
|
70 |
* @param uri
|
|
71 |
*/
|
|
72 | 4 |
public EndpointReference(URI uri) {
|
73 | 4 |
setAddress(new Address(uri));
|
74 |
} |
|
75 |
|
|
76 |
/**
|
|
77 |
* Constructor EndpointReference
|
|
78 |
*
|
|
79 |
* @param endpoint
|
|
80 |
*/
|
|
81 | 11 |
public EndpointReference(EndpointReferenceType endpoint) {
|
82 | 11 |
super(endpoint);
|
83 |
} |
|
84 |
|
|
85 |
/**
|
|
86 |
* Constructor EndpointReference
|
|
87 |
*
|
|
88 |
* @param endpoint
|
|
89 |
* @throws URI.MalformedURIException
|
|
90 |
*/
|
|
91 | 6 |
public EndpointReference(final String endpoint)
|
92 |
throws URI.MalformedURIException {
|
|
93 | 6 |
setAddress(new Address(new URI(endpoint))); |
94 |
} |
|
95 |
|
|
96 |
/**
|
|
97 |
* Constructor EndpointReference
|
|
98 |
*
|
|
99 |
* @param el
|
|
100 |
* @throws Exception
|
|
101 |
*/
|
|
102 | 27 |
public EndpointReference(SOAPElement element)
|
103 |
throws Exception {
|
|
104 | 27 |
Iterator iter = element.getChildElements(); |
105 | 27 |
while(iter.hasNext()) {
|
106 | 35 |
javax.xml.soap.Node child = (javax.xml.soap.Node)iter.next(); |
107 | 35 |
if (child instanceof SOAPElement) { |
108 | 35 |
if (!Constants.NS_URI_ADDRESSING_DEFAULT.equals(
|
109 |
child.getNamespaceURI())) { |
|
110 |
// skip now. does not handle extensibiliy elements now
|
|
111 | 0 |
continue;
|
112 |
} |
|
113 | 35 |
String localName = child.getLocalName(); |
114 | 35 |
if (Constants.ADDRESS.equals(localName)) {
|
115 | 27 |
Address address = |
116 |
Address.fromSOAPElement((SOAPElement)child); |
|
117 | 27 |
setAddress(address); |
118 | 8 |
} else if (Constants.PORT_TYPE.equals(localName)) { |
119 | 4 |
PortType portType = |
120 |
PortType.fromSOAPElement((SOAPElement)child); |
|
121 | 4 |
setPortType(portType); |
122 | 4 |
} else if (Constants.SERVICE_NAME.equals(localName)) { |
123 | 4 |
ServiceNameType serviceName = |
124 |
ServiceNameType.fromSOAPElement((SOAPElement)child); |
|
125 | 4 |
setServiceName(serviceName); |
126 | 0 |
} else if (Constants.REFERENCE_PROPERTIES.equals(localName)) { |
127 | 0 |
ReferencePropertiesType props = |
128 |
ReferencePropertiesType.fromSOAPElement((SOAPElement)child); |
|
129 | 0 |
setProperties(props); |
130 |
} else {
|
|
131 |
// ignore others
|
|
132 |
} |
|
133 |
} |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
137 |
/**
|
|
138 |
* Constructor EndpointReference
|
|
139 |
*
|
|
140 |
* @param el
|
|
141 |
* @throws Exception
|
|
142 |
*/
|
|
143 | 1 |
public EndpointReference(final Element element)
|
144 |
throws Exception {
|
|
145 | 1 |
NodeList children = element.getChildNodes(); |
146 | 1 |
for (int i=0;i<children.getLength();i++) { |
147 | 5 |
Node child = (Node)children.item(i); |
148 | 5 |
if (child instanceof Element) { |
149 | 5 |
if (!Constants.NS_URI_ADDRESSING_DEFAULT.equals(
|
150 |
child.getNamespaceURI())) { |
|
151 |
// skip now. does not handle extensibiliy elements now
|
|
152 | 1 |
continue;
|
153 |
} |
|
154 | 4 |
String localName = child.getLocalName(); |
155 | 4 |
if (Constants.ADDRESS.equals(localName)) {
|
156 | 1 |
Address address = |
157 |
Address.fromElement((Element)child); |
|
158 | 1 |
setAddress(address); |
159 | 3 |
} else if (Constants.PORT_TYPE.equals(localName)) { |
160 | 1 |
PortType portType = |
161 |
PortType.fromElement((Element)child); |
|
162 | 1 |
setPortType(portType); |
163 | 2 |
} else if (Constants.SERVICE_NAME.equals(localName)) { |
164 | 1 |
ServiceNameType serviceName = |
165 |
ServiceNameType.fromElement((Element)child); |
|
166 | 1 |
setServiceName(serviceName); |
167 | 1 |
} else if (Constants.REFERENCE_PROPERTIES.equals(localName)) { |
168 | 1 |
ReferencePropertiesType props = |
169 |
ReferencePropertiesType.fromElement((Element)child); |
|
170 | 1 |
setProperties(props); |
171 |
} else {
|
|
172 |
// ignore others
|
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
/**
|
|
179 |
* Method toDOM.
|
|
180 |
*
|
|
181 |
* @param doc
|
|
182 |
*/
|
|
183 | 1 |
public Element toDOM(Document doc) {
|
184 | 1 |
return toDOM(doc, Constants.ENDPOINT_REFERENCE);
|
185 |
} |
|
186 |
|
|
187 |
/**
|
|
188 |
* Method toDOM.
|
|
189 |
*
|
|
190 |
* @param doc
|
|
191 |
* @param name
|
|
192 |
*/
|
|
193 | 15 |
public Element toDOM(Document doc, String elementName) {
|
194 | 15 |
if (doc == null) { |
195 | 0 |
try {
|
196 | 0 |
doc = XMLUtils.newDocument(); |
197 |
} catch (ParserConfigurationException e) {
|
|
198 | 0 |
return null; |
199 |
} |
|
200 |
} |
|
201 |
|
|
202 | 15 |
Element parent = doc.createElementNS(Constants.NS_URI_ADDRESSING_DEFAULT, |
203 |
elementName); |
|
204 | 15 |
if (doc.getDocumentElement() == null) { |
205 | 15 |
doc.appendChild(parent); |
206 |
} else {
|
|
207 | 0 |
doc.getDocumentElement().appendChild(parent); |
208 |
} |
|
209 |
|
|
210 | 15 |
if (getAddress() != null) { |
211 | 15 |
getAddress().append(parent, Constants.ADDRESS); |
212 |
} |
|
213 | 15 |
if (getPortType() != null) { |
214 | 2 |
getPortType().append(parent, Constants.PORT_TYPE); |
215 |
} |
|
216 | 15 |
if (getServiceName() != null) { |
217 | 2 |
getServiceName().append(parent, Constants.SERVICE_NAME); |
218 |
} |
|
219 | 15 |
ReferencePropertiesType referenceProperties = getProperties(); |
220 | 15 |
if (referenceProperties != null && referenceProperties.size() > 0) { |
221 | 2 |
referenceProperties.append(parent, Constants.REFERENCE_PROPERTIES); |
222 |
} |
|
223 | 15 |
MessageElement [] any = get_any(); |
224 | 15 |
if (any != null && any.length > 0) { |
225 | 1 |
for (int i = 0; i < any.length; i++) { |
226 | 1 |
try {
|
227 | 1 |
parent.appendChild(doc.importNode(any[i].getAsDOM(), |
228 |
true));
|
|
229 |
} catch (Exception e) {
|
|
230 | 0 |
log.debug("", e);
|
231 |
} |
|
232 |
} |
|
233 |
} |
|
234 | 15 |
return parent;
|
235 |
} |
|
236 |
|
|
237 | 0 |
public SOAPHeaderElement toSOAPHeaderElement(SOAPEnvelope env,
|
238 |
String actorURI) |
|
239 |
throws Exception {
|
|
240 | 0 |
return toSOAPHeaderElement(env, actorURI,
|
241 |
Constants.ENDPOINT_REFERENCE); |
|
242 |
} |
|
243 |
|
|
244 | 14 |
protected SOAPHeaderElement toSOAPHeaderElement(SOAPEnvelope env,
|
245 |
String actorURI, |
|
246 |
String name) |
|
247 |
throws Exception {
|
|
248 | 14 |
if (name == null) { |
249 | 0 |
throw new IllegalArgumentException(); |
250 |
} |
|
251 | 14 |
if (!(env instanceof org.apache.axis.message.SOAPEnvelope)) { |
252 | 0 |
throw new Exception("Not supported"); |
253 |
} |
|
254 |
|
|
255 | 14 |
SOAPHeader header = env.getHeader(); |
256 | 14 |
if (header == null) { |
257 | 0 |
header = env.addHeader(); |
258 |
} |
|
259 |
|
|
260 | 14 |
Document doc = XMLUtils.newDocument(); |
261 |
|
|
262 | 14 |
org.apache.axis.message.SOAPHeaderElement headerElem = |
263 |
new org.apache.axis.message.SOAPHeaderElement(toDOM(doc, name));
|
|
264 | 14 |
headerElem.setActor(actorURI); |
265 | 14 |
((org.apache.axis.message.SOAPEnvelope)env).addHeader(headerElem); |
266 |
|
|
267 | 14 |
return headerElem;
|
268 |
} |
|
269 |
|
|
270 |
} |
|
271 |
|
|