1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.client.support.destination;
18
19 import java.io.IOException;
20 import java.net.URI;
21 import java.util.Properties;
22 import javax.xml.transform.Transformer;
23 import javax.xml.transform.TransformerException;
24 import javax.xml.transform.TransformerFactory;
25 import javax.xml.transform.dom.DOMResult;
26
27 import org.w3c.dom.Document;
28
29 import org.springframework.core.io.Resource;
30 import org.springframework.util.Assert;
31 import org.springframework.ws.client.WebServiceIOException;
32 import org.springframework.ws.client.WebServiceTransformerException;
33 import org.springframework.xml.transform.ResourceSource;
34 import org.springframework.xml.xpath.XPathExpression;
35 import org.springframework.xml.xpath.XPathExpressionFactory;
36
37
38
39
40
41
42
43
44
45
46
47
48 public class Wsdl11DestinationProvider extends AbstractCachingDestinationProvider {
49
50
51 public static final String DEFAULT_WSDL_LOCATION_EXPRESSION =
52 "/wsdl:definitions/wsdl:service/wsdl:port/soap:address/@location";
53
54 private static TransformerFactory transformerFactory = TransformerFactory.newInstance();
55
56 private Properties expressionNamespaces = new Properties();
57
58 private XPathExpression locationXPathExpression;
59
60 private Resource wsdlResource;
61
62 public Wsdl11DestinationProvider() {
63 expressionNamespaces.setProperty("wsdl", "http://schemas.xmlsoap.org/wsdl/");
64 expressionNamespaces.setProperty("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
65 expressionNamespaces.setProperty("soap12", "http://schemas.xmlsoap.org/wsdl/soap12/");
66
67 locationXPathExpression = XPathExpressionFactory
68 .createXPathExpression(DEFAULT_WSDL_LOCATION_EXPRESSION, expressionNamespaces);
69 }
70
71
72 public void setWsdl(Resource wsdlResource) {
73 Assert.notNull(wsdlResource, "'wsdl' must not be null");
74 Assert.isTrue(wsdlResource.exists(), wsdlResource + " does not exist");
75 this.wsdlResource = wsdlResource;
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89 public void setLocationExpression(String expression) {
90 Assert.hasText(expression, "'expression' must not be empty");
91 locationXPathExpression = XPathExpressionFactory
92 .createXPathExpression(expression, expressionNamespaces);
93 }
94
95 protected URI lookupDestination() {
96 try {
97 DOMResult result = new DOMResult();
98 Transformer transformer = transformerFactory.newTransformer();
99 transformer.transform(new ResourceSource(wsdlResource), result);
100 Document definitionDocument = (Document) result.getNode();
101 String location = locationXPathExpression.evaluateAsString(definitionDocument);
102 if (logger.isDebugEnabled()) {
103 logger.debug("Found location [" + location + "] in " + wsdlResource);
104 }
105 return location != null ? URI.create(location) : null;
106 }
107 catch (IOException ex) {
108 throw new WebServiceIOException("Error extracting location from WSDL [" + wsdlResource + "]", ex);
109 }
110 catch (TransformerException ex) {
111 throw new WebServiceTransformerException("Error extracting location from WSDL [" + wsdlResource + "]", ex);
112 }
113 }
114
115 }