Project

General

Profile

« Previous | Next » 

Revision 4732

Added by daigle almost 16 years ago

Get the metacat url from the SystemUtil.

View differences:

src/edu/ucsb/nceas/metacat/advancedsearch/AdvancedSearchServlet.java
24 24

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

  
27
import java.io.File;
28 27
import java.io.IOException;
29 28

  
30 29
import javax.servlet.RequestDispatcher;
......
39 38
import edu.ucsb.nceas.metacat.client.*;
40 39
import edu.ucsb.nceas.metacat.service.PropertyService;
41 40
import edu.ucsb.nceas.metacat.service.ServiceException;
41
import edu.ucsb.nceas.metacat.util.SystemUtil;
42 42
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
43 43

  
44 44
/** 
......
51 51
  /*
52 52
   * Class fields
53 53
   */
54
  private static final String CONFIG_DIR = "WEB-INF";
55
  private static final String CONFIG_NAME = "metacat.properties";
56 54
  static final long serialVersionUID = 0;  // Needed for Eclipse warning.
57 55
	   
58 56
  // Instance Variables
59
  private String contextString = "";
60 57

  
61 58
  // Methods
62 59
  
......
81 78
    // First check whether the metacat URL was set as a context-param.
82 79
    metacatURL = servletContext.getInitParameter("metacatURL");
83 80
 
84
    // If no metacat URL was configured, then derive the metacat URL from the
85
    // server name and server port.
81
    // If no metacat URL was configured, then get metacat URL from system utility
86 82
    if (metacatURL == null || metacatURL.equals("")) {
87
      String serverName = request.getServerName();
88
      int serverPort = request.getServerPort();
89
      metacatURL = 
90
    	 metacatHelper.constructMetacatURL(serverName, serverPort, contextString);
91
    }
83
		try {
84
			metacatURL = SystemUtil.getContextURL() + "/metacat";
85
		} catch (PropertyNotFoundException pnfe) {
86
			throw new ServletException("Could not get Metacat URL: "
87
					+ pnfe.getMessage());
88
		}
89
	}
92 90

  
93 91
    // Get the advancedSearchBean object that has been loaded up with user
94 92
    // input. Pass the bean to the advancedSearch object, execute the query,
......
113 111
	 * @throws ServletException
114 112
	 */
115 113
	public void init(ServletConfig config) throws ServletException {
116
		ServletContext context = null;
117
		String dirPath;
118 114

  
119 115
		super.init(config);
120
		context = config.getServletContext();
121
		dirPath = context.getRealPath(CONFIG_DIR);
122 116

  
123 117
		try {
124 118
			PropertyService.getInstance();
125
			this.contextString = PropertyService.getProperty("application.context");
126 119
		} catch (ServiceException se) {
127 120
			System.err.println("Error in loading properties: " + se.getMessage());
128
		} catch (PropertyNotFoundException pnfe) {
129
			System.err.println("couldn't read property during initialization: " 
130
					+ pnfe.getMessage());
131
		}
132

  
121
		} 
133 122
	}
134 123
}

Also available in: Unified diff