View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  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       * public String processCitationInput(String citationString,String routeRequestorReceipt, String requestorsNote,String
42       * requestorsFirstName, String requestorsLastName, String requestorsAddress1, String requestorsAddress2, String requestorsCity,
43       * String requestorsState, String requestorsZipCode, String requestorsCountryCode, String requestorsPhone, String
44       * requestorsEmail, String requestorsSMS, String requestorType) {
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               * docNumber = preOrderService.createPreOrderForCitation(citationString,routeRequestorReceipt,
76               * requestorsNote,requestorsFirstName, requestorsLastName, requestorsAddress1, requestorsAddress2, requestorsCity,
77               * requestorsState, requestorsZipCode, requestorsCountryCode, requestorsPhone, requestorsEmail, requestorsSMS,
78               * requestorType);
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      * public String processWebformInput(String title, String author, String edition, String series, String publisher, String
101      * placeOfPublication, String yearOfPublication, String standardNumber, String typeOfStandardNumber, String
102      * routeRequesterReceipt, String requestorsNote,String requestorsFirstName, String requestorsLastName, String
103      * requestorsAddress1, String requestorsAddress2, String requestorsCity, String requestorsState, String requestorsZipCode,
104      * String requestorsCountryCode, String requestorsPhone, String requestorsEmail, String requestorsSMS, String requestorType) {
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              * docNumber = preOrderService.createPreOrderForForm(title, author, edition, series, publisher, placeOfPublication,
140              * yearOfPublication, standardNumber, typeOfStandardNumber, routeRequesterReceipt, requestorsNote,requestorsFirstName,
141              * requestorsLastName, requestorsAddress1, requestorsAddress2, requestorsCity, requestorsState, requestorsZipCode,
142              * requestorsCountryCode, requestorsPhone, requestorsEmail, requestorsSMS, requestorType);
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      * public String processOpenUrlInput(String openUrlString, String routeRequesterReceipt, String requestorsNote,String
165      * requestorsFirstName, String requestorsLastName, String requestorsAddress1, String requestorsAddress2, String requestorsCity,
166      * String requestorsState, String requestorsZipCode, String requestorsCountryCode, String requestorsPhone, String
167      * requestorsEmail, String requestorsSMS, String requestorType) {
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              * docNumber = preOrderService.createPreOrderForOpenURL(openUrlString,routeRequesterReceipt,
202              * requestorsNote,requestorsFirstName, requestorsLastName, requestorsAddress1, requestorsAddress2, requestorsCity,
203              * requestorsState, requestorsZipCode, requestorsCountryCode, requestorsPhone, requestorsEmail, requestorsSMS,
204              * requestorType);
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         //   String[] input = new String[] { "http://resolver.example.edu/cgi?url_ver=Z39.88-2004&rft_val_fmt=info:ofi/fmt:kev:mtx:book&amp;rft.isbn=0836218310&rft.btitle=The+Far+Side+Gallery+3", "", "", "", "", "", "", "", "", "", "", "" };
234         // ;
235 
236         /*
237          * String response = ws.processOpenUrlInput(
238          * "http://resolver.example.edu/cgi?url_ver=Z39.88-2004&rft_val_fmt=info:ofi/fmt:kev:mtx:book&amp;rft.isbn=0836218310&rft.btitle=The+Far+Side+Gallery+3"
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&amp;rft.isbn=0836218310&rft.btitle=The+Far+Side+Gallery+3",
244                         "", "", "", "");
245 
246     }
247 
248 }