Project

General

Profile

« Previous | Next » 

Revision 2818

Added apache commons logging to the LSID servlet using log4j. Remove println statements.

View differences:

lib/lsid_conf/log4j.properties
20 20
# EXAMPLE: Print only messages of level WARN or above in the package com.foo:
21 21
# log4j.logger.com.foo=WARN
22 22

  
23
#log4j.logger.edu.ucsb.nceas.metacat=INFO
24

  
23
#log4j.logger.org.apache.axis.utils.NetworkUtils=DEBUG
24
#log4j.logger.org.apache.axis.transport.http.QSWSDLHandler=DEBUG
src/edu/ucsb/nceas/metacat/lsid/LSIDDataLookup.java
24 24

  
25 25
package edu.ucsb.nceas.metacat.lsid;
26 26

  
27
import java.io.*;
28
import java.net.*;
29

  
30
//import java.sql.Connection;
27
import java.io.IOException;
28
import java.io.InputStream;
29
import java.net.MalformedURLException;
30
import java.net.URL;
31 31
import java.util.ResourceBundle;
32 32

  
33
import org.apache.commons.logging.Log;
34
import org.apache.commons.logging.LogFactory;
35

  
33 36
import com.ibm.lsid.LSID;
34 37
import com.ibm.lsid.server.LSIDServerException;
35 38

  
......
40 43
	public static final int UNKNOWN = 1;
41 44
	public static final int ABSTRACT = 2;
42 45
	public static final int CONCRETE = 4;
46
    
47
    private static Log logger = LogFactory.getLog( "edu.ucsb.nceas.metacat.lsid" );
43 48

  
44

  
45 49
	public LSIDDataLookup() throws LSIDServerException {
46
        System.out.println("Creating LSIDDataLookup (Metacat).");
50
        logger.info("Creating LSIDDataLookup (Metacat).");
47 51
  	}
48 52

  
49 53

  
......
64 68
		// http://metacat.nceas.ucsb.edu/knb/metacat?action=read&qformat=xml&docid=knb-lter-gce.109.6
65 69
		//
66 70
		
67
    ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid");
68
    String theServer = rb.getString("metacatserver");
69
		System.out.println("the server is " + theServer);
71
		ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid");
72
		String theServer = rb.getString("metacatserver");
73
		logger.debug("the server is " + theServer);
70 74

  
71 75
		String url = theServer + "?action=read&qformat=xml&docid=";
72 76
		url = url + ns + "." + id + "." + ver;
......
74 78
			URL theDoc = new URL(url);
75 79
			docStream  = theDoc.openStream();
76 80
		} catch (MalformedURLException mue) {
77
         		System.out.println("MalformedURLException in LSIDDataLookup: " + mue);
81
         		logger.error("MalformedURLException in LSIDDataLookup: " + mue);
78 82
         		mue.printStackTrace();
79 83
   		} catch (IOException ioe) {
80
         		System.out.println("IOException in LSIDDataLookup: " + ioe);
84
         		logger.error("IOException in LSIDDataLookup: " + ioe);
81 85
         		ioe.printStackTrace();
82 86
		}
83 87

  
src/edu/ucsb/nceas/metacat/lsid/LSIDAuthorityMetaData.java
24 24

  
25 25
package edu.ucsb.nceas.metacat.lsid;
26 26

  
27
import java.io.InputStream;
27
import java.io.BufferedReader;
28 28
import java.io.ByteArrayInputStream;
29

  
30
import com.ibm.lsid.LSID;
31
import com.ibm.lsid.MetadataResponse;
32
import com.ibm.lsid.MalformedLSIDException;
33

  
34
import com.ibm.lsid.server.LSIDMetadataService;
35
import com.ibm.lsid.server.LSIDServerException;
36
import com.ibm.lsid.server.LSIDServiceConfig;
37

  
38
import com.ibm.lsid.server.LSIDRequestContext;
39

  
40 29
import java.io.ByteArrayOutputStream;
41 30
import java.io.IOException;
31
import java.io.InputStream;
32
import java.io.InputStreamReader;
42 33
import java.io.Reader;
43 34
import java.io.StringReader;
44
import java.io.InputStreamReader;
45
import java.io.BufferedReader;
35
import java.util.Hashtable;
36
import java.util.ResourceBundle;
46 37

  
47 38
import javax.xml.transform.Transformer;
48 39
import javax.xml.transform.TransformerFactory;
49 40
import javax.xml.transform.stream.StreamResult;
50 41
import javax.xml.transform.stream.StreamSource;
51 42

  
52
import java.util.Hashtable;
43
import org.apache.commons.logging.Log;
44
import org.apache.commons.logging.LogFactory;
53 45

  
54
import edu.ucsb.nceas.metacat.client.*;
55
import java.util.ResourceBundle;
46
import com.ibm.lsid.LSID;
47
import com.ibm.lsid.MalformedLSIDException;
48
import com.ibm.lsid.MetadataResponse;
49
import com.ibm.lsid.server.LSIDMetadataService;
50
import com.ibm.lsid.server.LSIDRequestContext;
51
import com.ibm.lsid.server.LSIDServerException;
52
import com.ibm.lsid.server.LSIDServiceConfig;
56 53

  
54
import edu.ucsb.nceas.metacat.client.Metacat;
55
import edu.ucsb.nceas.metacat.client.MetacatFactory;
56
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
57

  
57 58
public class LSIDAuthorityMetaData implements LSIDMetadataService {
58 59

  
59 60
	private LSIDDataLookup lookup = null;
60 61
	private static Hashtable currentLSIDs = new Hashtable();
61

  
62
    private static Log logger = LogFactory.getLog( "edu.ucsb.nceas.metacat.lsid" );
63
    
62 64
	public void initService(LSIDServiceConfig cf) throws LSIDServerException {
63
        System.out.println("Starting LSIDAuthorityMetadata (Metacat).");
65
        logger.info("Starting LSIDAuthorityMetadata.");
64 66
		lookup = new LSIDDataLookup();
65 67
	}
66 68

  
......
84 86

  
85 87
	private ByteArrayInputStream doMetadataRequest(LSID lsid)
86 88
		throws LSIDServerException {
87
		System.out.println("getting metadata for lsid " + lsid.getLsid());
89
		logger.debug("getting metadata for lsid " + lsid.getLsid());
88 90
		try {
89 91

  
90 92
			String styleSheetName = null;
......
125 127
				result.append(line);
126 128
			}
127 129
		} catch (IOException e) {
128
			System.out.println("IOexception " + e);
130
			logger.error("IOexception " + e);
129 131
		}
130 132

  
131 133
		return result.toString();
......
158 160
				loop++;
159 161
			}
160 162
		} catch (IOException e) {
161
			System.out.println("ioerror in LSIDAuthorityMetadata: " + e);
163
			logger.error("ioerror in LSIDAuthorityMetadata: " + e);
162 164
		}
163 165
		return itIsEML;
164 166
	}
......
194 196
	 */
195 197

  
196 198
	private String getMetaCatQuery(LSID lsid) {
197
        System.out.println("getting Metacat Query for: " + lsid.toString());
199
        logger.debug("getting Metacat Query for: " + lsid.toString());
198 200
		String ns = lsid.getNamespace();
199 201
		String id = lsid.getObject();
200 202
		String ver = lsid.getRevision();
......
227 229
	 * given a query string, query MetaCat and return the response
228 230
	 */
229 231
	private Reader getMetaCatResponse(String query) {
230
        System.out.println("Querying the metacat server.");
232
        logger.debug("Querying the metacat server.");
231 233
		//  get the metacat server from the configuration file
232 234
		//
233 235
		ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid");
......
239 241
			r = m.query(new StringReader(query));
240 242

  
241 243
		} catch (MetacatInaccessibleException mie) {
242
			System.out.println("Metacat Inaccessible:\n" + mie.getMessage());
244
            logger.error("Metacat Inaccessible:\n" + mie.getMessage());
243 245
		} catch (Exception e) {
244
			System.out.println("General exception:\n" + e.getMessage());
246
			logger.error("General exception:\n" + e.getMessage());
245 247
		}
246 248
		return r;
247 249
	}
......
251 253
	 */
252 254
	private InputStream parseMetaCatResponse(Reader reader, LSID theLSID) {
253 255
		InputStream response = null;
254
        System.out.println("Parsing the metacat response.");
256
        logger.debug("Parsing the metacat response.");
255 257
		// if there's more than one document, then return rdf listing the documents
256 258
		// otherwise get the document and return rdf  based on it
257 259

  
......
333 335
				result = doMetadataRequest(newLSID);
334 336

  
335 337
			} catch (MalformedLSIDException e) {
336
				System.out.println("problem generating LSID: " + e);
338
                logger.error("problem generating LSID: " + e);
337 339
				e.printStackTrace();
338 340
			} catch (LSIDServerException e) {
339
				System.out.println("problem generating LSID: " + e);
341
                logger.error("problem generating LSID: " + e);
340 342
				e.printStackTrace();
341 343
			}
342 344
		}
......
370 372
			bufReader.close();
371 373

  
372 374
		} catch (IOException e) {
373
			System.out.println("error getting string from reader " + e);
375
			logger.error("error getting string from reader " + e);
374 376
		}
375 377
		return response.toString();
376 378
	}
src/edu/ucsb/nceas/metacat/lsid/LSIDAuthorityMain.java
24 24

  
25 25
package edu.ucsb.nceas.metacat.lsid;
26 26

  
27
import java.util.regex.Matcher;
27 28
import java.util.regex.Pattern;
28
import java.util.regex.Matcher;
29 29

  
30
import org.apache.commons.logging.Log;
31
import org.apache.commons.logging.LogFactory;
32

  
33
import com.ibm.lsid.ExpiringResponse;
30 34
import com.ibm.lsid.LSID;
31
import com.ibm.lsid.ExpiringResponse;
35
import com.ibm.lsid.server.LSIDServerException;
36
import com.ibm.lsid.server.LSIDServiceConfig;
37
import com.ibm.lsid.server.impl.SimpleAuthority;
38
import com.ibm.lsid.wsdl.HTTPLocation;
32 39
import com.ibm.lsid.wsdl.LSIDDataPort;
33 40
import com.ibm.lsid.wsdl.LSIDMetadataPort;
34

  
35 41
import com.ibm.lsid.wsdl.SOAPLocation;
36
import com.ibm.lsid.wsdl.HTTPLocation;
37 42

  
38
import com.ibm.lsid.server.LSIDServerException;
39
import com.ibm.lsid.server.LSIDServiceConfig;
40

  
41
import com.ibm.lsid.server.impl.SimpleAuthority;
42

  
43 43
public class LSIDAuthorityMain extends SimpleAuthority {
44 44

  
45 45
	private LSIDDataLookup lookup = null;
46

  
46
    private static Log logger = LogFactory.getLog( "edu.ucsb.nceas.metacat.lsid" );
47
    
47 48
	public void initService(LSIDServiceConfig cf) throws LSIDServerException {
48
        System.out.println("Starting LSIDAuthorityMain (Metacat).");
49
        logger.info("Starting LSIDAuthorityMain.");
49 50
		lookup = new LSIDDataLookup();
50 51
	}
51 52

  
52 53
	public ExpiringResponse getKnownURIs() throws LSIDServerException {
54
        logger.debug("In LSIDAuthorityMain.getKnownURIs()");
53 55
		return null;
54 56
	}
55 57

  
56 58
	public LSIDMetadataPort[] getMetadataLocations(LSID lsid, String url) {
57
		if (lookup == null)
59
        logger.debug("In LSIDAuthorityMain.getMetadataLocations()");
60
        if (lookup == null)
58 61
			return null;
59 62

  
60 63
		int lsType;
......
82 85
	}
83 86

  
84 87
	public LSIDDataPort[] getDataLocations(LSID lsid, String url) {
88
        logger.debug("In LSIDAuthorityMain.getDataLocations()");
85 89
		if (lookup == null)
86 90
			return null;
87 91

  
......
122 126
		public String baseURL;
123 127
		
124 128
		public HostDescriptor(String url) {
129
            logger.debug("Creating a HostDescriptor for: " + url);
130
            //Thread.dumpStack();
125 131
			host = "localhost";
126 132
			port = -1;
127 133
			pathPrefix = "";
128 134
			if (url != null || url.length() > 0) {
135
                logger.debug("HostDescriptor: url is > 0 length");
129 136
				Matcher m = HOST_PTN.matcher(url);
130 137
				if (m.lookingAt()) {
131 138
					host = m.group(1);
132
					if ((m.group(2) != null) && (m.group(2).length() > 0))
139
                    logger.debug("HostDescriptor.host: " + host);
140
					if ((m.group(2) != null) && (m.group(2).length() > 0)) {
133 141
						port = Integer.parseInt(m.group(2));
142
                    }
143
                    logger.debug("HostDescriptor.port: " + port);
134 144
					pathPrefix = m.group(3);
145
                    logger.debug("HostDescriptor.pathPrefix: " + pathPrefix);
135 146
				}
136 147
			}
137
			if (port > 0)
148
			if (port > 0) {
138 149
				baseURL = "http://" + host + ":" + port +
139 150
					pathPrefix + "/authority/";
140
			else
151
            } else {
141 152
				baseURL = "http://" + host + pathPrefix + "/authority/";
153
            }
154
            logger.debug("HostDescriptor.baseURL: " + baseURL);
142 155
		}
143 156
	}
144 157
}
src/edu/ucsb/nceas/metacat/lsid/LSIDAuthorityData.java
26 26

  
27 27
import java.io.InputStream;
28 28

  
29
import org.apache.commons.logging.Log;
30
import org.apache.commons.logging.LogFactory;
31

  
29 32
import com.ibm.lsid.server.LSIDDataService;
33
import com.ibm.lsid.server.LSIDRequestContext;
30 34
import com.ibm.lsid.server.LSIDServerException;
31 35
import com.ibm.lsid.server.LSIDServiceConfig;
32
import com.ibm.lsid.server.LSIDRequestContext;
33 36

  
34 37
public class LSIDAuthorityData implements LSIDDataService {
35 38

  
36 39
	private LSIDDataLookup lookup = null;
37

  
40
    private static Log logger = LogFactory.getLog( "edu.ucsb.nceas.metacat.lsid" );
41
    
38 42
	public InputStream getData(LSIDRequestContext lsid) throws LSIDServerException {
39
        System.out.println("Getting data (Metacat): " + lsid.getLsid().toString());
43
        logger.debug("Getting data (Metacat): " + lsid.getLsid().toString());
40 44
		if (lookup == null)
41 45
			throw new LSIDServerException(500, "Cannot query database");
42 46
		return lookup.lsidData(lsid.getLsid());
......
49 53
	}
50 54

  
51 55
	public void initService(LSIDServiceConfig cf) throws LSIDServerException {
52
        System.out.println("Starting LSIDAuthorityData (Metacat).");
56
        logger.info("Starting LSIDAuthorityData (Metacat).");
53 57
		lookup = new LSIDDataLookup();
54 58
	}
55 59
}

Also available in: Unified diff