PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/src/Core/org/objectweb/proactive/core/component/webservices/WSInfo.java

https://bitbucket.org/lp/programming-multiactivities
Java | 255 lines | 85 code | 24 blank | 146 comment | 14 complexity | a616f29f5eaa3fb4669476913a939e96 MD5 | raw file
  1. /*
  2. * ################################################################
  3. *
  4. * ProActive Parallel Suite(TM): The Java(TM) library for
  5. * Parallel, Distributed, Multi-Core Computing for
  6. * Enterprise Grids & Clouds
  7. *
  8. * Copyright (C) 1997-2012 INRIA/University of
  9. * Nice-Sophia Antipolis/ActiveEon
  10. * Contact: proactive@ow2.org or contact@activeeon.com
  11. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Affero General Public License
  14. * as published by the Free Software Foundation; version 3 of
  15. * the License.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this library; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  25. * USA
  26. *
  27. * If needed, contact us to obtain a release under GPL Version 2 or 3
  28. * or a different license than the AGPL.
  29. *
  30. * Initial developer(s): The ProActive Team
  31. * http://proactive.inria.fr/team_members.htm
  32. * Contributor(s):
  33. *
  34. * ################################################################
  35. * $$PROACTIVE_INITIAL_DEV$$
  36. */
  37. package org.objectweb.proactive.core.component.webservices;
  38. import java.io.Serializable;
  39. import java.net.MalformedURLException;
  40. import java.net.URL;
  41. import org.objectweb.fractal.api.control.IllegalBindingException;
  42. import org.objectweb.proactive.annotation.PublicAPI;
  43. /**
  44. * Web service informations used to bind a client interface of a component to a web service: contains the URL
  45. * of the web service and the name of the class which has to be used to call this web service.
  46. * <br>
  47. * The class in charge to call the web service must implement the {@link PAWSCaller} interface.
  48. * <br>
  49. * By default, the class {@link CXFWSCaller}, using the <a href="http://cxf.apache.org/">CXF</a> API,
  50. * is used.
  51. *
  52. * @author The ProActive Team
  53. */
  54. @PublicAPI
  55. public class WSInfo implements Serializable {
  56. /**
  57. * Name of the interface which must be implemented by the class in charge of calling the web service.
  58. */
  59. public static final String PAWSCALLER_ITF_NAME = PAWSCaller.class.getName();
  60. /**
  61. * Shortcut ID to specify that CXF must be used to call the web service.
  62. */
  63. public static final String CXFWSCALLER_ID = "CXF";
  64. /**
  65. * Full name of the class calling web services using CXF.
  66. */
  67. public static final String CXFWSCALLER_CLASSNAME = CXFWSCaller.class.getName();
  68. /**
  69. * Shortcut ID to specify that CXF configured for JAX-WS must be used to call the web service.
  70. */
  71. public static final String JAXWSCXFWSCALLER_ID = "JaxWsCXF";
  72. /**
  73. * Full name of the class calling web services using CXF configured for JAX-WS.
  74. */
  75. public static final String JAXWSCXFWSCALLER_CLASSNAME = JaxWsCXFWSCaller.class.getName();
  76. /**
  77. * Shortcut ID to specify that CXF configured for an Aegis data binding must be used to call the web service.
  78. */
  79. public static final String CXFAEGISWSCALLER_ID = "CXFAegis";
  80. /**
  81. * Full name of the class calling web services using CXF configured for an Aegis data binding.
  82. */
  83. public static final String CXFAEGISWSCALLER_CLASSNAME = CXFAegisWSCaller.class.getName();
  84. /**
  85. * Shortcut ID to specify that CXF with a dynamic client must be used to call the web service.
  86. */
  87. public static final String DYNAMICCXFWSCALLER_ID = "DynamicCXF";
  88. /**
  89. * Full name of the class calling web services using CXF with a dynamic client.
  90. */
  91. public static final String DYNAMICCXFWSCALLER_CLASSNAME = DynamicCXFWSCaller.class.getName();
  92. /**
  93. * Shortcut ID to specify that CXF must be used to call the RESTful service.
  94. */
  95. public static final String CXFRESTFULSERVICECALLER_ID = "CXFRESTful";
  96. /**
  97. * Full name of the class calling RESTful services using CXF.
  98. */
  99. public static final String CXFRESTFULSERVICECALLER_CLASSNAME = CXFRESTfulServiceCaller.class.getName();
  100. /**
  101. * URL of the web service.
  102. */
  103. private String wsUrl;
  104. /**
  105. * Full name of the class to use to call the web service.
  106. */
  107. private String wsCallerClassName;
  108. /**
  109. * Main constructor.
  110. * <br>
  111. * The String passed as argument is the URL of the web service (not the WSDL address).
  112. * By default the CXF API is used to call the web service, but it is also possible to
  113. * specify another library. If so, the URL must be followed, in parenthesis, by the ID
  114. * or the full name of the class to use to call the web service. The ID (not case
  115. * sensitive) may be CXF, JaxWsCXF, CXFAegis, DynamicCXF or CXFRESTful to use one of
  116. * these client configuration to call the web service. Otherwise, the full class name
  117. * given must be the one of a class implementing the {@link PAWSCaller} interface.
  118. * <br>
  119. * For instance:
  120. * <br>
  121. * "http://localhost:8080/proactive/services/Server_HelloWorld(org.objectweb.proactive.core.component.webservices.CXFWSCaller)"
  122. * <br>
  123. * which is equivalent to:
  124. * <br>
  125. * "http://localhost:8080/proactive/services/Server_HelloWorld(CXF)"
  126. * <br>
  127. * and which, as CXF is used by default, is also equivalent to:
  128. * <br>
  129. * "http://localhost:8080/proactive/services/Server_HelloWorld"
  130. *
  131. * @param infos URL of the web service, possibly followed in parenthesis by the ID or
  132. * the full name of the class to use to call the web service.
  133. * @throws IllegalBindingException If the URL is malformed or if the ID or class name is incorrect.
  134. */
  135. public WSInfo(String infos) throws IllegalBindingException {
  136. String[] wsInfo = infos.split("\\(|\\)");
  137. this.wsUrl = checkWSURL(wsInfo[0]);
  138. this.wsCallerClassName = selectWSCallerClassName(wsInfo);
  139. }
  140. /**
  141. * Secondary constructor.
  142. *
  143. * @param wsUrl The URL of the web service.
  144. * @param wsCallerClassName Name of the class, implementing the {@link PAWSCaller}
  145. * interface, to use to call the web service.
  146. * @throws IllegalBindingException If the URL is malformed or if the ID or class name is incorrect.
  147. */
  148. public WSInfo(String wsUrl, String wsCallerClassName) throws IllegalBindingException {
  149. this.wsUrl = checkWSURL(wsUrl);
  150. this.wsCallerClassName = checkClassName(wsCallerClassName);
  151. }
  152. /*
  153. * Checks if the given URL is valid.
  154. */
  155. private String checkWSURL(String wsUrl) throws IllegalBindingException {
  156. try {
  157. new URL(wsUrl);
  158. return wsUrl;
  159. } catch (MalformedURLException e) {
  160. IllegalBindingException ibe = new IllegalBindingException(
  161. "The URL of the web service is malformed: " + wsUrl);
  162. ibe.initCause(e);
  163. throw ibe;
  164. }
  165. }
  166. /*
  167. * Checks if the given class exists and implements the PROACTIVEWSCALLER_ITF_NAME interface.
  168. */
  169. private String checkClassName(String className) throws IllegalBindingException {
  170. try {
  171. Class<?> c = Class.forName(className);
  172. if (!Class.forName(PAWSCALLER_ITF_NAME).isAssignableFrom(c)) {
  173. throw new IllegalBindingException("The web service caller: " + className +
  174. " must implement the " + PAWSCALLER_ITF_NAME + " interface");
  175. }
  176. return className;
  177. } catch (ClassNotFoundException e) {
  178. IllegalBindingException ibe = new IllegalBindingException("Web service caller: " + className +
  179. " cannot be found");
  180. ibe.initCause(e);
  181. throw ibe;
  182. }
  183. }
  184. /*
  185. * Selects the appropriate name of the class to use to call the web service.
  186. */
  187. private String selectWSCallerClassName(String[] wsInfo) throws IllegalBindingException {
  188. if (wsInfo.length == 2) {
  189. if (wsInfo[1].equalsIgnoreCase(CXFWSCALLER_ID)) {
  190. return CXFWSCALLER_CLASSNAME;
  191. } else if (wsInfo[1].equalsIgnoreCase(JAXWSCXFWSCALLER_ID)) {
  192. return JAXWSCXFWSCALLER_CLASSNAME;
  193. } else if (wsInfo[1].equalsIgnoreCase(CXFAEGISWSCALLER_ID)) {
  194. return CXFAEGISWSCALLER_CLASSNAME;
  195. } else if (wsInfo[1].equalsIgnoreCase(DYNAMICCXFWSCALLER_ID)) {
  196. return DYNAMICCXFWSCALLER_CLASSNAME;
  197. } else if (wsInfo[1].equalsIgnoreCase(CXFRESTFULSERVICECALLER_ID)) {
  198. return CXFRESTFULSERVICECALLER_CLASSNAME;
  199. } else {
  200. return checkClassName(wsInfo[1]);
  201. }
  202. } else {
  203. return CXFWSCALLER_CLASSNAME;
  204. }
  205. }
  206. /**
  207. * Getter for the URL of the web service (not the WSDL address).
  208. *
  209. * @return URL of the web service.
  210. */
  211. public String getWSUrl() {
  212. return wsUrl;
  213. }
  214. /**
  215. * Setter for the URL of the web service (not the WSDL address).
  216. *
  217. * @param wsUrl URL of the web service.
  218. * @throws IllegalBindingException If the URL is malformed.
  219. */
  220. public void setWSUrl(String wsUrl) throws IllegalBindingException {
  221. this.wsUrl = checkWSURL(wsUrl);
  222. }
  223. /**
  224. * Getter for the full name of the class to use to call the web service.
  225. *
  226. * @return The full name of the class to use to call the web service.
  227. */
  228. public String getWSCallerClassName() {
  229. return wsCallerClassName;
  230. }
  231. }