annotate client/src/main/java/info/textgrid/middleware/digilib/clients/cli/DigilibCli.java @ 9:55bc70b1cb18

use localhost for service url.
author casties
date Thu, 16 Jun 2011 18:39:32 +0200
parents 99bd25677ba8
children fe0a111cc8f5
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
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
20 *
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) {
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
28 if (args.length != 4) {
8
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
29 System.err.println("use: DigilibCli SID URI QUERY FILENAME");
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
30 System.exit(1);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
31 }
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
32 String sid = args[0];
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
33 String uri = args[1];
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
34 String query = args[2];
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
35 String filename = args[3];
8
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
36 URL serverUrl = null;
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
37 try {
9
55bc70b1cb18 use localhost for service url.
casties
parents: 8
diff changeset
38 serverUrl = new URL("http://localhost:8080/digilibservice-service/service?wsdl");
8
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
39 } catch (MalformedURLException e1) {
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
40 // TODO Auto-generated catch block
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
41 e1.printStackTrace();
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
42 }
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
43 System.out.println("service at " + serverUrl);
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
44 // call service
8
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
45 byte[] imageData = getScaledImage(sid, uri, query, serverUrl);
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
46 // try to copy to file
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
47 System.out.println("writing " + filename);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
48 File f = new File(filename);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
49 try {
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
50 OutputStream ostream = new FileOutputStream(f);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
51 ostream.write(imageData);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
52 ostream.close();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
53 } catch (IOException e) {
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
54 // TODO Auto-generated catch block
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
55 e.printStackTrace();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
56 }
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
57 System.out.println("Done.");
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
58 }
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
59
8
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
60 public static byte[] getScaledImage(String sid, String uri, String query, URL serverUrl) {
99bd25677ba8 add server url parameter
casties
parents: 7
diff changeset
61 DigilibService service = new DigilibService(serverUrl);
7
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
62 DigilibServicePortType port = service.getDigilibServicePort();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
63 String logParam = null;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
64 // Holder for return data
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
65 Holder<String> mimeType = new Holder<String>();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
66 Holder<byte[]> imageData = new Holder<byte[]>();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
67 Holder<Integer> width = new Holder<Integer>();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
68 Holder<Integer> height = new Holder<Integer>();
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
69 // call service -- fills Holder
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
70 port.getScaledImage(sid, uri, query, logParam, mimeType, imageData, width, height);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
71 System.out.println("mimeType="+mimeType.value);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
72 System.out.println("imageData="+imageData.value);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
73 System.out.println("width="+width.value);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
74 System.out.println("height="+height.value);
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
75 return imageData.value;
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
76 }
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
77
39c4892724ae new version with maven modules for service and client.
casties
parents:
diff changeset
78 }