1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.testing;
17
18 import org.kuali.ole.sys.OLEConstants;
19 import org.kuali.ole.sys.context.SpringContext;
20 import org.kuali.rice.core.api.config.property.ConfigurationService;
21
22 import javax.xml.namespace.QName;
23 import javax.xml.ws.soap.SOAPBinding;
24 import java.net.MalformedURLException;
25 import java.net.URL;
26 import java.util.logging.Logger;
27
28 public class WebserviceClient {
29
30 private ConfigurationService kualiConfigurationService;
31 static String preOrderUrlProperty = null;
32 private final static Logger logger = Logger.getLogger(org.kuali.ole.select.testing.PreOrderService_Service.class.getName());
33
34 public WebserviceClient() {
35 kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
36 String environment = kualiConfigurationService.getPropertyValueAsString(OLEConstants.ENVIRONMENT_KEY);
37 preOrderUrlProperty = "PREORDER_URL";
38 }
39
40
41
42
43
44
45
46 public String processCitationInput(String citationString, String routeRequestorReceipt, String requestorsNote,
47 String requestorType, String requestorId) {
48 String url = kualiConfigurationService.getPropertyValueAsString(preOrderUrlProperty);
49 WebserviceInfo wsInfo = new WebserviceInfo();
50 wsInfo.setUrl(url);
51 wsInfo.setNameSpace(kualiConfigurationService.getPropertyValueAsString("PREORDER_NAMESPACE"));
52 wsInfo.setServiceName(kualiConfigurationService.getPropertyValueAsString("PREORDER_SERVICENAME"));
53 wsInfo.setPortName(kualiConfigurationService.getPropertyValueAsString("PREORDER_PORTNAME"));
54 wsInfo.setOperationName(kualiConfigurationService.getPropertyValueAsString("PREORDER_CITATION_OPR"));
55
56 String docNumber = null;
57 URL preOrderUrl = null;
58
59 try {
60 URL baseUrl;
61 baseUrl = org.kuali.ole.select.testing.PreOrderService_Service.class.getResource(".");
62 preOrderUrl = new URL(wsInfo.getUrl() + "?wsdl");
63 } catch (MalformedURLException e) {
64 logger.warning("Failed to create URL for the wsdl Location: " + preOrderUrl + ", retrying as a local file");
65 logger.warning(e.getMessage());
66 }
67 QName serviceQName = new QName(wsInfo.getNameSpace(), wsInfo.getServiceName());
68 PreOrderService_Service soapService = new PreOrderService_Service(preOrderUrl, serviceQName);
69 soapService.addPort(new QName(wsInfo.getNameSpace(), wsInfo.getServiceName()), SOAPBinding.SOAP12HTTP_BINDING,
70 wsInfo.getUrl());
71 PreOrderService preOrderService = soapService.getPreOrderServicePort();
72
73 try {
74
75
76
77
78
79
80 docNumber = preOrderService.createPreOrderForCitation(citationString, routeRequestorReceipt,
81 requestorsNote, requestorType, requestorId);
82
83
84 CreatePreOrderForCitationResponse createPreOrderForCitationResponse = new CreatePreOrderForCitationResponse();
85 createPreOrderForCitationResponse.getReturn();
86
87 if (isNumber(docNumber)) {
88 docNumber = "Document Created successfully with Document ID : " + docNumber;
89 }
90 } catch (Exception exception) {
91 exception.printStackTrace();
92 docNumber = "ERROR: " + exception.getMessage();
93 } finally {
94 return docNumber;
95 }
96 }
97
98
99
100
101
102
103
104
105
106 public String processWebformInput(String title, String author, String edition, String series, String publisher,
107 String placeOfPublication, String yearOfPublication, String standardNumber, String typeOfStandardNumber,
108 String requestorsNote, String requestorType, String requestorId) {
109 String url = kualiConfigurationService.getPropertyValueAsString(preOrderUrlProperty);
110 WebserviceInfo wsInfo = new WebserviceInfo();
111 wsInfo.setUrl(url);
112 logger.info("wsInfo.getUrl() >>>>>>>>>>>" + wsInfo.getUrl());
113 wsInfo.setNameSpace(kualiConfigurationService.getPropertyValueAsString("PREORDER_NAMESPACE"));
114 wsInfo.setServiceName(kualiConfigurationService.getPropertyValueAsString("PREORDER_SERVICENAME"));
115 wsInfo.setOperationName(kualiConfigurationService.getPropertyValueAsString("PREORDER_WFRM_OPR"));
116 wsInfo.setPortName(kualiConfigurationService.getPropertyValueAsString("PREORDER_PORTNAME"));
117
118 String docNumber = null;
119 QName serviceQName = new QName(wsInfo.getNameSpace(), wsInfo.getServiceName());
120 URL preOrderUrl = null;
121
122 try {
123 URL baseUrl;
124 baseUrl = org.kuali.ole.select.testing.PreOrderService_Service.class.getResource(".");
125 preOrderUrl = new URL(wsInfo.getUrl() + "?wsdl");
126 logger.info("PreOrderService url : "+preOrderUrl);
127 } catch (MalformedURLException e) {
128 logger.warning("Failed to create URL for the wsdl Location: " + preOrderUrl + ", retrying as a local file");
129 logger.warning(e.getMessage());
130 }
131
132 PreOrderService_Service soapService = new PreOrderService_Service(preOrderUrl, serviceQName);
133 soapService.addPort(new QName(wsInfo.getNameSpace(), wsInfo.getServiceName()), SOAPBinding.SOAP12HTTP_BINDING,
134 wsInfo.getUrl());
135 PreOrderService preOrderService = soapService.getPreOrderServicePort();
136
137 try {
138
139
140
141
142
143
144 docNumber = preOrderService.createPreOrderForForm(title, author, edition, series, publisher,
145 placeOfPublication, yearOfPublication, standardNumber, typeOfStandardNumber, requestorsNote,
146 requestorType, requestorId);
147 CreatePreOrderForFormResponse createPreOrderForFormResponse = new CreatePreOrderForFormResponse();
148 createPreOrderForFormResponse.getReturn();
149 logger.info("PreOrderService Document Created successfully with Document ID : " +docNumber);
150
151 if (isNumber(docNumber)) {
152 docNumber = "Document Created successfully with Document ID : " + docNumber;
153 }
154 } catch (Exception exception) {
155 exception.printStackTrace();
156 docNumber = "ERROR: " + exception.getMessage();
157 } finally {
158 return docNumber;
159 }
160
161 }
162
163
164
165
166
167
168
169 public String processOpenUrlInput(String openUrlString, String routeRequesterReceipt, String requestorsNote,
170 String requestorType, String requestorId) {
171 String url = kualiConfigurationService.getPropertyValueAsString(preOrderUrlProperty);
172
173 WebserviceInfo wsInfo = new WebserviceInfo();
174 wsInfo.setUrl(url);
175 wsInfo.setNameSpace(kualiConfigurationService.getPropertyValueAsString("PREORDER_NAMESPACE"));
176 wsInfo.setServiceName(kualiConfigurationService.getPropertyValueAsString("PREORDER_SERVICENAME"));
177 wsInfo.setPortName(kualiConfigurationService.getPropertyValueAsString("PREORDER_PORTNAME"));
178 wsInfo.setOperationName(kualiConfigurationService.getPropertyValueAsString("PREORDER_OPENURL_OPR"));
179
180 String docNumber = null;
181 QName serviceQName = new QName(wsInfo.getNameSpace(), wsInfo.getServiceName());
182 URL preOrderUrl = null;
183
184 try {
185 URL baseUrl;
186 baseUrl = org.kuali.ole.select.testing.PreOrderService_Service.class.getResource(".");
187 preOrderUrl = new URL(wsInfo.getUrl() + "?wsdl");
188 } catch (MalformedURLException e) {
189 logger.warning("Failed to create URL for the wsdl Location: " + preOrderUrl + ", retrying as a local file");
190 logger.warning(e.getMessage());
191 }
192
193 PreOrderService_Service soapService = new PreOrderService_Service(preOrderUrl, serviceQName);
194 soapService.addPort(new QName(wsInfo.getNameSpace(), wsInfo.getServiceName()), SOAPBinding.SOAP12HTTP_BINDING,
195 wsInfo.getUrl());
196 PreOrderService preOrderService = soapService.getPreOrderServicePort();
197
198
199 try {
200
201
202
203
204
205
206 docNumber = preOrderService.createPreOrderForOpenURL(openUrlString, routeRequesterReceipt, requestorsNote,
207 requestorType, requestorId);
208 CreatePreOrderForOpenURLResponse createPreOrderForOpenURLResponse = new CreatePreOrderForOpenURLResponse();
209 createPreOrderForOpenURLResponse.getReturn();
210 if (isNumber(docNumber)) {
211 docNumber = "Document Created successfully with Document ID : " + docNumber;
212 }
213 } catch (Exception exception) {
214 exception.printStackTrace();
215 docNumber = "ERROR: " + exception.getMessage();
216 } finally {
217 return docNumber;
218 }
219 }
220
221 public boolean isNumber(String string) {
222 char[] c = string.toCharArray();
223 for (int i = 0; i < string.length(); i++) {
224 if (!Character.isDigit(c[i])) {
225 return false;
226 }
227 }
228 return true;
229 }
230
231 public static void main(String[] args) {
232 WebserviceClient ws = new WebserviceClient();
233
234
235
236
237
238
239
240
241 String response = ws
242 .processOpenUrlInput(
243 "http://resolver.example.edu/cgi?url_ver=Z39.88-2004&rft_val_fmt=info:ofi/fmt:kev:mtx:book&rft.isbn=0836218310&rft.btitle=The+Far+Side+Gallery+3",
244 "", "", "", "");
245
246 }
247
248 }