Wiki source code of SOAP-based Service

Version 5.1 by uru on 2013/11/27 02:00

Hide last authors
uru 3.1 1 One of the goals of KWebS is to provide the KIELER layout to a broader range of users by hiding its java nature behind a web service. As the server uses a SOAP web service, it describes the user interface in a platform independent way using the Web Service Description Language (WSDL). You can use this contract to automatically generate the code necessary to access the operations provided by KWebS. For example, if you have a java based project, you can use the tool wsimport:
2
uru 4.1 3 {{code}}
4 wsimport -p my.kwebs.client -keep http://layout.rtsys.informatik.uni-kiel.de:9442/layout?wsdl
5 {{/code}}
6
uru 3.1 7 Normally, {{code language="none"}}wsimport{{/code}} will derive the package where it puts the generated classes into from the XML name space declared in the contract, but this will in general not fit to your needs. You can declare a different package with the **-p** option, in the given example the classes will be generated to the package {{code language="none"}}my.kwebs.client{{/code}}. The {{code language="none"}}-keep{{/code}} option tells {{code language="none"}}wsimport{{/code}} not to delete the generated java sources after it has compiled them to class files. As a last option, {{code language="none"}}wsimport{{/code}} requires the contract from which it shall generate the code. This may be a file on your local computer, or as an alternative, {{code language="none"}}wsimport{{/code}} can download it from the internet. The public demo service of KWebS is located at **[[http:~~/~~/layout.rtsys.informatik.uni-kiel.de:9442/layout>>url:http://layout.rtsys.informatik.uni-kiel.de:9442/layout||shape="rect"]]**, and you can access its contract by adding {{code language="none"}}?wsdl{{/code}} to this location.
8
9 After code generation, you have a bunch of java source and class files. They contain the code necessary for invoking the service-based layout. The most important classes are {{code language="none"}}LayoutService{{/code}} and {{code language="none"}}LayoutServicePort{{/code}}. You need them to create a //proxy// to the service:
10
11 {{code theme="Eclipse" language="java"}}
12 package my.kwebs.client;
13
14 import java.net.URL;
15 import javax.xml.namespace.QName;
16
17 public class KWebSClient {
18
19 // The endpoint address the service is bound to
20 private static final String SERVICE_URL
21 = "http://layout.rtsys.informatik.uni-kiel.de:9442/layout";
22
23 // The qualified name of the service interface
24 private static final String SERVICE_QNAME
25 = "http://layout.rtsys.informatik.uni-kiel.de/layout";
26
27 // The name of the service
28 private static final String SERVICE_NAME
29 = "LayoutService";
30
31 /**
32 * Entry point of the client application
33 */
34 public static void main(final String args[]) {
35
36 try {
37
38 // Connect to the service
39 LayoutService layoutService = new LayoutService(
40 new URL(SERVICE_URL + "?wsdl"),
41 new QName(SERVICE_QNAME, SERVICE_NAME)
42 );
43
44 // Create a proxy to access its operations
45 LayoutServicePort layoutServicePort = layoutService.getLayoutServicePort();
46
47 // Create the serial notation of the source graph
48 String graph = ...
49
50 // Call the "graphLayout" operation of the service. As result you get the
51 // serial notation of the layouted graph in the same serial notation as
52 // you used for invoking the layout.
53 String layout = layoutServicePort.graphLayout(
54 graph, // the source model
55 "de.cau.cs.kieler.kgraph", // we use the KGraph format
56 null, // we want the result in KGraph format
57 null // we don't declare any options
58 );
59
60 // Handle exceptions here
61 } catch (final Exception e) {
62 e.printStackTrace();
63 }
64
65 }
66
67 }
68 {{/code}}