323031774ce7465fa2fb7006164f64619ed6c8d2
[jabaws.git] / webservices / compbio / ws / server / SimpleWSPublisher.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.ws.server;\r
20 \r
21 import javax.jws.WebService;\r
22 import javax.xml.ws.Endpoint;\r
23 \r
24 /**\r
25  * This class publish a web service. This is not a production implementation.\r
26  * Should be used only for during development and testing\r
27  * \r
28  * @author pvtroshin\r
29  * @date October 2009\r
30  */\r
31 public class SimpleWSPublisher {\r
32 \r
33     public SimpleWSPublisher(Object exec, String context) {\r
34 \r
35     }\r
36 \r
37     public static void main(String[] args) {\r
38         if (args.length != 2) {\r
39             System.out.println("Usage: ");\r
40             System.out.println("SimpleWSPublisher context class");\r
41             System.out\r
42                     .println("where context is a context name, the name after the address by "\r
43                             + "which web service can be called e.g. Clustal "\r
44                             + " and class is a web service implementation class");\r
45 \r
46         }\r
47         String context = args[0];\r
48         String clazzName = args[1];\r
49         try {\r
50             Class<?> clazz = Class.forName(clazzName);\r
51             if (!clazz.isAnnotationPresent(WebService.class)) {\r
52                 System.out.println("Can only start web services. "\r
53                         + "Please check whether the class provided is "\r
54                         + "annotated with Webservice annotation");\r
55                 System.exit(1);\r
56             }\r
57             Endpoint.publish("http://127.0.0.1:7979/" + context, clazz\r
58                     .newInstance());\r
59         } catch (InstantiationException e) {\r
60             e.printStackTrace();\r
61             System.exit(1);\r
62         } catch (IllegalAccessException e) {\r
63             e.printStackTrace();\r
64             System.exit(1);\r
65         } catch (ClassNotFoundException e) {\r
66             e.printStackTrace();\r
67             System.exit(1);\r
68         } catch (IllegalArgumentException e) {\r
69             e.printStackTrace();\r
70             System.exit(1);\r
71         }\r
72     }\r
73 }\r