1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.client.support;
18
19 import java.io.IOException;
20 import java.net.URI;
21 import java.net.URISyntaxException;
22
23 import org.springframework.beans.factory.InitializingBean;
24 import org.springframework.util.Assert;
25 import org.springframework.ws.WebServiceMessageFactory;
26 import org.springframework.ws.transport.WebServiceConnection;
27 import org.springframework.ws.transport.WebServiceMessageSender;
28 import org.springframework.xml.transform.TransformerObjectSupport;
29
30
31
32
33
34
35
36
37
38
39
40 public abstract class WebServiceAccessor extends TransformerObjectSupport implements InitializingBean {
41
42 private WebServiceMessageFactory messageFactory;
43
44 private WebServiceMessageSender[] messageSenders;
45
46
47 public WebServiceMessageFactory getMessageFactory() {
48 return messageFactory;
49 }
50
51
52 public void setMessageFactory(WebServiceMessageFactory messageFactory) {
53 this.messageFactory = messageFactory;
54 }
55
56
57 public WebServiceMessageSender[] getMessageSenders() {
58 return messageSenders;
59 }
60
61
62
63
64
65
66
67
68 public void setMessageSender(WebServiceMessageSender messageSender) {
69 Assert.notNull(messageSender, "'messageSender' must not be null");
70 messageSenders = new WebServiceMessageSender[]{messageSender};
71 }
72
73
74
75
76
77
78
79
80 public void setMessageSenders(WebServiceMessageSender[] messageSenders) {
81 Assert.notEmpty(messageSenders, "'messageSenders' must not be empty");
82 this.messageSenders = messageSenders;
83 }
84
85 public void afterPropertiesSet() {
86 Assert.notNull(getMessageFactory(), "Property 'messageFactory' is required");
87 Assert.notEmpty(getMessageSenders(), "Property 'messageSenders' is required");
88 }
89
90
91
92
93
94
95
96
97
98
99
100
101
102 protected WebServiceConnection createConnection(URI uri) throws IOException {
103 Assert.notEmpty(getMessageSenders(), "Property 'messageSenders' is required");
104 WebServiceMessageSender[] messageSenders = getMessageSenders();
105 for (WebServiceMessageSender messageSender : messageSenders) {
106 if (messageSender.supports(uri)) {
107 WebServiceConnection connection = messageSender.createConnection(uri);
108 if (logger.isDebugEnabled()) {
109 try {
110 logger.debug("Opening [" + connection + "] to [" + connection.getUri() + "]");
111 }
112 catch (URISyntaxException e) {
113
114 }
115 }
116 return connection;
117 }
118 }
119 throw new IllegalArgumentException("Could not resolve [" + uri + "] to a WebServiceMessageSender");
120 }
121
122 }