Project

General

Profile

« Previous | Next » 

Revision 6053

remove very old "metacat webservice" code - as far as i can tell it is never referenced or used. plus we have eocgrid and the new D1 rest services covering this territory now

View differences:

src/edu/ucsb/nceas/metacat/stringclient/impl/MetacatString.java
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author$'
7
 *     '$Date$'
8
 * '$Revision$'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 */
24

  
25
package edu.ucsb.nceas.metacat.stringclient.impl;
26

  
27
/**
28
 *  This interface provides methods for initializing and logging in to a 
29
 *  Metacat server, and then querying, reading, transforming, inserting, 
30
 *  updating and deleting documents from that server.
31
 */
32
public interface MetacatString
33
{
34
    /**
35
     *  Method used to log in to a metacat server. Implementations will need
36
     *  to cache a cookie value to make the session persistent.  Each time a
37
     *  call is made to one of the other methods (e.g., read), the cookie will
38
     *  need to be passed back to the metacat server along with the request.
39
     *
40
     *  @param username   the username of the user, like an LDAP DN
41
     *  @param password   the password for that user for authentication
42
     */
43
    public void login(String username, String password);
44
    
45
    /**
46
     *  Method used to log out a metacat server. When Metacat server will end
47
     *  the session when this call is invoken.
48
     *
49
     *  @throws MetacatInaccessibleException when the metacat server can not be
50
     *                                    reached or does not respond
51
     */
52
    public void logout();
53

  
54
    /**
55
     * Read an XML document from the metacat server session, accessed by docid,
56
     * and returned as a String.
57
     *
58
     * @param docid the identifier of the document to be read
59
     * @return a String for accessing the document
60
     */
61
    public String read(String docid);
62

  
63
    /**
64
     * Query the metacat document store with the given metacat-compatible 
65
     * query document, and return the result set as a String
66
     */
67
    public String query(String xmlQuery);
68

  
69
    /**
70
     * Insert an XML document into the repository.
71
     *
72
     * @param docid the docid to insert the document
73
     * @param xmlDocument a String for accessing the XML document to be inserted
74
     * @param schema a String for accessing the DTD or XML Schema for 
75
     *               the document
76
     * @return the metacat response message
77
     */
78
    public String insert(String docid, String xmlDocument, String schema);
79

  
80
    /**
81
     * Update an XML document in the repository.
82
     *
83
     * @param docid the docid to update
84
     * @param xmlDocument a String for accessing the XML text to be updated
85
     * @param schema a String for accessing the DTD or XML Schema for 
86
     *               the document
87
     * @return the metacat response message
88
     */
89
    public String update(String docid, String xmlDocument, String schema);
90

  
91
    /**
92
     * Delete an XML document in the repository.
93
     *
94
     * @param docid the docid to delete
95
     * @return the metacat response message
96
     * @throws InsufficientKarmaException when the user has insufficent rights 
97
     *                                    for the operation
98
     * @throws MetacatInaccessibleException when the metacat server can not be
99
     *                                    reached or does not respond
100
     * @throws MetacatException when the metacat server generates another error
101
     */
102
    public String delete(String docid);
103

  
104
    /**
105
     * When the MetacatFactory creates an instance it needs to set the
106
     * MetacatUrl to which connections should be made.
107
     *
108
     * @param metacatUrl the URL for the metacat server
109
     */
110
    public void setMetacatUrl(String metacatUrl);
111
}
112 0

  
src/edu/ucsb/nceas/metacat/stringclient/impl/MetacatStringImpl.java
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author$'
7
 *     '$Date$'
8
 * '$Revision$'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 */
24

  
25
package edu.ucsb.nceas.metacat.stringclient.impl;
26

  
27
import java.io.BufferedReader;
28
import java.io.InputStream;
29
import java.io.InputStreamReader;
30
import java.io.PushbackReader;
31
import java.io.IOException;
32
import java.io.StringWriter;
33
import java.io.Reader;
34
import java.net.URL;
35
import java.util.Properties;
36

  
37
import edu.ucsb.nceas.utilities.HttpMessage;
38

  
39

  
40
import org.globus.ogsa.impl.ogsi.GridServiceImpl;
41
import edu.ucsb.nceas.metacat.stringclient.MetacatString.MetacatStringPortType;
42
import java.rmi.RemoteException;
43

  
44
/**
45
 *  This interface provides methods for initializing and logging in to a 
46
 *  Metacat server, and then querying, reading, transforming, inserting, 
47
 *  updating and deleting documents from that server.
48
 */
49
public class MetacatStringImpl extends GridServiceImpl 
50
                               implements MetacatStringPortType
51
{
52
    /** The URL string for the metacat server */
53
    private String metacatUrl="http://dev.nceas.ucsb.edu/tao/servlet/metacat";
54

  
55
    /**
56
     *  Method used to log in to a metacat server. Implementations will need
57
     *  to cache a cookie value to make the session persistent.  Each time a
58
     *  call is made to one of the other methods (e.g., read), the cookie will
59
     *  need to be passed back to the metacat server along with the request.
60
     *
61
     *  @param username   the username of the user, like an LDAP DN
62
     *  @param password   the password for that user for authentication
63
     */
64
    public void login(String username, String password) throws RemoteException
65
        
66
    {
67
        Properties prop = new Properties();
68
        prop.put("action", "login");
69
        prop.put("qformat", "xml");
70
        prop.put("username", username);
71
        prop.put("password", password);
72

  
73
        String response = null;
74
        try {
75
            response = sendDataForString(prop);
76
        } catch (Exception e) {
77
            throw new RemoteException(e.getMessage());
78
        }
79

  
80
        if (response.indexOf("<login>") == -1) {
81
            HttpMessage.setCookie(null);
82
            throw new RemoteException(response);
83
        }
84
    }
85

  
86
    /**
87
     *  Method used to log out a metacat server. When Metacat server will end
88
     *  the session when this call is invoken.
89
     *
90
     *  @throws MetacatInaccessibleException when the metacat server can not be
91
     *                                    reached or does not respond
92
     */
93
    public void logout() throws RemoteException
94
    {
95
        Properties prop = new Properties();
96
        prop.put("action", "logout");
97
        prop.put("qformat", "xml"); 
98
       
99
        String response = null;
100
        try {
101
            response = sendDataForString(prop);
102
        } catch (Exception e) {
103
            throw new RemoteException(e.getMessage());
104
        }
105
        
106
        if (response.indexOf("<logout>") == -1) {
107
            throw new RemoteException(response);
108
        }
109
    }
110
    
111
    
112
    /**
113
     * Read an XML document from the metacat server session, accessed by docid,
114
     * and returned as a String.
115
     *
116
     * @param docid the identifier of the document to be read
117
     * @return a String for accessing the document
118
     */
119
    public String read(String docid) throws RemoteException
120
    {
121
        Properties prop = new Properties();
122
        prop.put("action", "read");
123
        prop.put("qformat", "xml");
124
        prop.put("docid", docid);
125

  
126
        String response = null;
127
        try {
128
            response = sendDataForString(prop);
129
        } catch (Exception e) {
130
            throw new RemoteException(e.getMessage());
131
        }
132
        if (response != null && response.indexOf("<error>") != -1) {
133
                if (response.indexOf("does not have permission") != -1) {
134
                    throw new RemoteException(response);
135
                } else {
136
                    throw new RemoteException(response);
137
                }
138
         }
139
     
140
        return response;
141
    }
142

  
143
    /**
144
     * Query the metacat document store with the given metacat-compatible 
145
     * query document, and return the result set as a Reader.
146
     *
147
     * @param xmlQuery a string for accessing the XML version of the query
148
     * @return a string for accessing the result set
149
     */
150
    public String query(String xmlQuery) throws RemoteException 
151
    {
152
        String query = xmlQuery;
153
      
154
        //set up properties
155
        Properties prop = new Properties();
156
        prop.put("action", "squery");
157
        prop.put("qformat", "xml");
158
        prop.put("query", query);
159
        
160
        String response = null;
161
        try {
162
            response = sendDataForString(prop);
163
          
164
        } catch (Exception e) {
165
            throw new RemoteException(e.getMessage());
166
        }
167
       
168
        return response;
169
    }
170

  
171
    /**
172
     * Insert an XML document into the repository.
173
     *
174
     * @param docid the docid to insert the document
175
     * @param xmlDocument a Reader for accessing the XML document to be inserted
176
     * @param schema a Reader for accessing the DTD or XML Schema for 
177
     *               the document
178
     * @return the metacat response message
179
     */
180
    public String insert(String docid, String xmlDocument, String schema)
181
        throws RemoteException
182
    {
183
        String doctext = xmlDocument;
184
        String schematext = schema;
185
     
186
     //set up properties
187
        Properties prop = new Properties();
188
        prop.put("action", "insert");
189
        prop.put("docid", docid);
190
        prop.put("doctext", doctext);
191
        if (schematext != null) {
192
            prop.put("dtdtext", schematext);
193
        }
194
        
195
        String response = null;
196
        try {
197
            response = sendDataForString(prop);
198
        } catch (Exception e) {
199
            throw new RemoteException(e.getMessage());
200
        }
201

  
202
        // Check for an error condition
203
        if (response.indexOf("<error>") != -1) {
204
            if (response.indexOf("does not have permission") != -1) {
205
                throw new RemoteException(response);
206
            } else {
207
                throw new RemoteException(response);
208
            }
209
        }
210

  
211
        return response;
212
    }
213

  
214
    /**
215
     * Update an XML document in the repository.
216
     *
217
     * @param docid the docid to update
218
     * @param xmlDocument a Reader for accessing the XML text to be updated
219
     * @param schema a Reader for accessing the DTD or XML Schema for 
220
     *               the document
221
     * @return the metacat response message
222
     */
223
    public String update(String docid, String xmlDocument, String schema)
224
        throws RemoteException
225
    {
226
        String doctext = xmlDocument;
227
        String schematext = schema;
228
      
229

  
230
        //set up properties
231
        Properties prop = new Properties();
232
        prop.put("action", "update");
233
        prop.put("docid", docid);
234
        prop.put("doctext", doctext);
235
        if (schematext != null) {
236
            prop.put("dtdtext", schematext);
237
        }
238
        
239
        String response = null;
240
        try {
241
            response = sendDataForString(prop);
242
        } catch (Exception e) {
243
            throw new RemoteException(e.getMessage());
244
        }
245

  
246
        // Check for an error condition
247
        if (response.indexOf("<error>") != -1) {
248
            if (response.indexOf("does not have permission") != -1) {
249
                throw new RemoteException(response);
250
            } else {
251
                throw new RemoteException(response);
252
            }
253
        }
254

  
255
        return response;
256
    }
257

  
258
    /**
259
     * Delete an XML document in the repository.
260
     *
261
     * @param docid the docid to delete
262
     * @return the metacat response message
263
     */
264
    public String delete(String docid) throws RemoteException
265
    {
266
        //set up properties
267
        Properties prop = new Properties();
268
        prop.put("action", "delete");
269
        prop.put("docid", docid);
270
        
271
        String response = null;
272
        try {
273
            response = sendDataForString(prop);
274
        } catch (Exception e) {
275
            throw new RemoteException(e.getMessage());
276
        }
277

  
278
        // Check for an error condition
279
        if (response.indexOf("<error>") != -1) {
280
            if (response.indexOf("does not have permission") != -1) {
281
                throw new RemoteException(response);
282
            } else {
283
                throw new RemoteException(response);
284
            }
285
        }
286

  
287
        return response;
288
    }
289
    
290
    /**
291
     * When the MetacatFactory creates an instance it needs to set the
292
     * MetacatUrl to which connections should be made.
293
     *
294
     * @param metacatUrl the URL for the metacat server
295
     */
296
    public void setMetacatUrl(String metacatUrl) throws RemoteException
297
    {
298
      this.metacatUrl = metacatUrl;
299
    }
300
 
301
    /************************************************************************
302
     * PRIVATE METHODS
303
     ************************************************************************/
304

  
305
    /**
306
     * Send a request to metacat.
307
     *
308
     * @param prop the properties to be URL encoded and sent
309
     */
310
    synchronized private InputStream sendDataOnce(Properties prop) 
311
        throws Exception
312
    {
313
        InputStream returnStream = null;
314
        URL url = new URL(metacatUrl);
315
        HttpMessage msg = new HttpMessage(url);
316
        returnStream = msg.sendPostData(prop);
317
        return returnStream;
318
    }
319

  
320
    /**
321
     * Send a request to Metacat
322
     *
323
     * @param prop  the properties to be sent to Metacat
324
     * @return      InputStream as returned by Metacat
325
     */
326
    synchronized private InputStream sendData(Properties prop) throws Exception
327
    {   
328
        InputStream returnStream = null;
329

  
330
        /*
331
            Note:  The reason that there are three try statements all executing
332
            the same code is that there is a problem with the initial connection
333
            using the HTTPClient protocol handler.  These try statements make 
334
            sure that a connection is made because it gives each connection a 
335
            2nd and 3rd chance to work before throwing an error.
336
            THIS IS A TOTAL HACK.  THIS NEEDS TO BE LOOKED INTO AFTER THE BETA1
337
            RELEASE OF MORPHO!!!  cwb (7/24/01)
338
          */
339
        try {
340
           return sendDataOnce(prop);
341
        } catch (Exception e) {
342
            try {
343
                return sendDataOnce(prop);
344
            } catch (Exception e2) {
345
                try {
346
                    return sendDataOnce(prop);
347
                } catch (Exception e3) {
348
                    System.err.println(
349
                            "Failed to send data to metacat 3 times.");
350
                    throw e3;
351
                }
352
            }
353
        }
354
    }
355

  
356
    /**
357
     * Send a request to Metacat
358
     *
359
     * @param prop  the properties to be sent to Metacat
360
     * @return      a string as returned by Metacat
361
     */
362
    synchronized private String sendDataForString(Properties prop) 
363
        throws Exception
364
    {
365
        String response = null;
366

  
367
        try {
368
            InputStreamReader returnStream =
369
                    new InputStreamReader(sendData(prop));
370
            StringWriter sw = new StringWriter();
371
            int len;
372
            char[] characters = new char[512];
373
            while ((len = returnStream.read(characters, 0, 512)) != -1) {
374
                sw.write(characters, 0, len);
375
            }
376
            returnStream.close();
377
            response = sw.toString();
378
            sw.close();
379
        } catch (Exception e) {
380
            throw e;
381
        }
382
        return response;
383
    }
384
}
385 0

  
src/edu/ucsb/nceas/metacat/stringclient/application/MetacatStringServiceApplication.java
1
package edu.ucsb.nceas.metacat.stringclient.application;
2

  
3
import edu.ucsb.nceas.metacat.stringclient.MetacatString.MetacatStringServiceLocator;
4
import edu.ucsb.nceas.metacat.stringclient.MetacatString.MetacatStringPortType;
5
import java.net.URL;
6

  
7
public class MetacatStringServiceApplication
8
{
9
	public static void main(String[] args)
10
	{
11
		try
12
		{
13
			// Get command-line arguments
14
			String docid = args[1];
15
			URL GSH = new java.net.URL(args[0]);
16

  
17
			// Get a reference to the remote web service
18
			MetacatStringServiceLocator metacatService 
19
                                    = new MetacatStringServiceLocator();
20
			MetacatStringPortType metacat = 
21
                              metacatService.getMetacatStringService(GSH);
22

  
23
			// Call remote method 'add'
24
                        String message = metacat.read(docid);
25

  
26
			// Print result
27
			System.out.println(message);
28
		}catch(Exception e)
29
		{
30
			System.out.println("ERROR!");
31
			e.printStackTrace();
32
		}
33
	}
34
}
35 0

  
workflowscheduler.build.xml
220 220

  
221 221
		<javac srcdir="${build.src}" destdir="${build.dest}"
222 222
			debug="${debug}"
223
			excludes="**/*.sql **/stringclient/** **/client/*.java **/harvesterClient/*.java">
223
			excludes="**/*.sql **/client/*.java **/harvesterClient/*.java">
224 224
			<classpath>
225 225
				<path refid="compile.classpath" />
226 226
			</classpath>
build.xml
441 441

  
442 442
		<javac srcdir="${build.src}" destdir="${build.dest}"
443 443
			debug="${debug}"
444
			excludes="**/*.sql **/stringclient/** **/client/*.java **/harvesterClient/*.java">
444
			excludes="**/*.sql **/client/*.java **/harvesterClient/*.java">
445 445
			<classpath>
446 446
				<path refid="compile.classpath" />
447 447
			</classpath>
......
1410 1410
		</xslt>
1411 1411
	</target>
1412 1412

  
1413

  
1414
	<target name="compilewebclient" depends="prepare">
1415
		<javac srcdir="${build.src}" destdir="${build.dest}"
1416
			includes="**/application/*.java" classpathref="webservicepath" />
1417
	</target>
1418

  
1419
	<target name="runwebclient" depends="compilewebclient">
1420
		<java
1421
			classname="edu.ucsb.nceas.metacat.stringclient.application.MetacatStringServiceApplication"
1422
			dir="${build.dest}" fork="yes" classpathref="webservicepath"
1423
			classpath="./lib/utilities.jar" failonerror="true">
1424
			<arg value="${serviceUrl}" />
1425
			<arg value="${docid}" />
1426
		</java>
1427
	</target>
1428

  
1429 1413
	<target name="spatial_option" depends="prepare"
1430 1414
		description=" -- compiles code for the spatial option">
1431 1415

  

Also available in: Unified diff