annotate client/src/main/java/info/textgrid/middleware/digilib/clients/cli/DigilibCli.java @ 11:ab4794707336 default tip

pluginManagement crap for new m2e Eclipse plugin...
author casties
date Thu, 23 Jun 2011 19:22:56 +0200
parents fe0a111cc8f5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
1 /**
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
2 *
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
3 */
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
4 package info.textgrid.middleware.digilib.clients.cli;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
5
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
6 import java.io.File;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
7 import java.io.FileOutputStream;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
8 import java.io.IOException;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
9 import java.io.OutputStream;
8
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
10 import java.net.MalformedURLException;
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
11 import java.net.URL;
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
12
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
13 import javax.xml.ws.Holder;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
14
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
15 import info.textgrid.namespaces.middleware.digilib.services.digilibservice.DigilibService;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
16 import info.textgrid.namespaces.middleware.digilib.services.digilibservice.DigilibServicePortType;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
17
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
18 /**
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
19 * @author casties
10
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
20 *
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
21 */
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
22 public class DigilibCli {
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
23
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
24 /**
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
25 * @param args
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
26 */
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
27 public static void main(String[] args) {
10
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
28 if (args.length < 4) {
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
29 System.err
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
30 .println("use: DigilibCli SID URI QUERY FILENAME [SERVERURL]");
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
31 System.exit(1);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
32 }
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
33 String sid = args[0];
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
34 String uri = args[1];
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
35 String query = args[2];
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
36 String filename = args[3];
8
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
37 URL serverUrl = null;
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
38 try {
10
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
39 if (args.length > 4) {
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
40 serverUrl = new URL(args[4]);
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
41 } else {
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
42 serverUrl = new URL(
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
43 "http://localhost:8080/digilibservice-service/service?wsdl");
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
44 }
8
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
45 } catch (MalformedURLException e1) {
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
46 // TODO Auto-generated catch block
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
47 e1.printStackTrace();
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
48 }
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
49 System.out.println("service at " + serverUrl);
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
50 // call service
8
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
51 byte[] imageData = getScaledImage(sid, uri, query, serverUrl);
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
52 // try to copy to file
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
53 System.out.println("writing " + filename);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
54 File f = new File(filename);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
55 try {
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
56 OutputStream ostream = new FileOutputStream(f);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
57 ostream.write(imageData);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
58 ostream.close();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
59 } catch (IOException e) {
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
60 // TODO Auto-generated catch block
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
61 e.printStackTrace();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
62 }
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
63 System.out.println("Done.");
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
64 }
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
65
10
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
66 public static byte[] getScaledImage(String sid, String uri, String query,
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
67 URL serverUrl) {
8
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
68 DigilibService service = new DigilibService(serverUrl);
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
69 DigilibServicePortType port = service.getDigilibServicePort();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
70 String logParam = null;
10
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
71 // Holder for return data
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
72 Holder<String> mimeType = new Holder<String>();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
73 Holder<byte[]> imageData = new Holder<byte[]>();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
74 Holder<Integer> width = new Holder<Integer>();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
75 Holder<Integer> height = new Holder<Integer>();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
76 // call service -- fills Holder
10
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
77 port.getScaledImage(sid, uri, query, logParam, mimeType, imageData,
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
78 width, height);
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
79 System.out.println("mimeType=" + mimeType.value);
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
80 System.out.println("imageData=" + imageData.value);
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
81 System.out.println("width=" + width.value);
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
82 System.out.println("height=" + height.value);
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
83 return imageData.value;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
84 }
10
fe0a111cc8f5 server creates tgcrud port in constructor. client takes external server url.
casties
parents: 9
diff changeset
85
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
86 }