Project

General

Profile

« Previous | Next » 

Revision 6284

simplify the MN rest servlet mapping to match CN mappings - also streamlined the handler code to share extra path info parsing

View differences:

lib/web.xml.tomcat5
272 272
		<servlet-name>MNRestServlet</servlet-name>
273 273
		<url-pattern>/d1/mn/*</url-pattern>
274 274
	</servlet-mapping>
275
	<!-- MNCore-->
276
	<servlet-mapping>
277
		<servlet-name>MNRestServlet</servlet-name>
278
		<url-pattern>/d1/mn/monitor/*</url-pattern>
279
	</servlet-mapping>
280
	<servlet-mapping>
281
		<servlet-name>MNRestServlet</servlet-name>
282
		<url-pattern>/d1/mn/log/*</url-pattern>
283
	</servlet-mapping>
284
	<servlet-mapping>
285
		<servlet-name>MNRestServlet</servlet-name>
286
		<url-pattern>/d1/mn/node</url-pattern>
287
	</servlet-mapping>
288
	<!-- MNRead-->
289
	<servlet-mapping>
290
		<servlet-name>MNRestServlet</servlet-name>
291
		<url-pattern>/d1/mn/meta/*</url-pattern>
292
	</servlet-mapping>
293
	<servlet-mapping>
294
		<servlet-name>MNRestServlet</servlet-name>
295
		<url-pattern>/d1/mn/object/*</url-pattern>
296
	</servlet-mapping>
297
	<servlet-mapping>
298
		<servlet-name>MNRestServlet</servlet-name>
299
		<url-pattern>/d1/mn/checksum/*</url-pattern>
300
	</servlet-mapping>
301
	<servlet-mapping>
302
		<servlet-name>MNRestServlet</servlet-name>
303
		<url-pattern>/d1/mn/error</url-pattern>
304
	</servlet-mapping>
305
	<!-- MNAuthorization -->
306
	<servlet-mapping>
307
		<servlet-name>MNRestServlet</servlet-name>
308
		<url-pattern>/d1/mn/isAuthorized/*</url-pattern>
309
	</servlet-mapping>
310
	<servlet-mapping>
311
		<servlet-name>MNRestServlet</servlet-name>
312
		<url-pattern>/d1/mn/accessRules/*</url-pattern>
313
	</servlet-mapping>
314
	<!-- MNReplication -->
315
	<servlet-mapping>
316
		<servlet-name>MNRestServlet</servlet-name>
317
		<url-pattern>/d1/mn/replicate/*</url-pattern>
318
	</servlet-mapping>
319 275
	
320

  
321 276
 <!-- uncomment this if you want the admin servlet -->
322 277
  <servlet-mapping>
323 278
    <servlet-name>AdminServlet</servlet-name>
src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java
140 140
    	super.handle(httpVerb);
141 141
    	
142 142
        try {
143
            String resourcePrefix = RESOURCE_BASE_URL + "/mn/";
144
        	String resource = request.getServletPath();
143
        	// get the resource
144
            String resource = request.getPathInfo();
145
            resource = resource.substring(resource.indexOf("/") + 1);
145 146
            
146
            if (resource.endsWith(resourcePrefix)) {
147
            // default to node info
148
            if (resource.equals("")) {
147 149
                resource = RESOURCE_NODE;
148 150
            }
149
            else {
150
            	// remove prefix
151
                resource = resource.substring(resource.indexOf(resourcePrefix) + resourcePrefix.length());
152
                resource = resource.trim();
151
            
152
            // get the rest of the path info
153
            String extra = null;
154
            if (resource.lastIndexOf("/") != -1) {
155
                extra = resource.substring(resource.lastIndexOf("/") + 1);
153 156
            }
154 157
                        
155 158
            logMetacat.debug("handling verb " + httpVerb + " request with resource '" + resource + "'");
......
158 161
            
159 162
            if (resource != null) {
160 163

  
161
                if (resource.equals(RESOURCE_NODE)) {
164
                if (resource.startsWith(RESOURCE_NODE)) {
162 165
                    // node response
163 166
                    node();
164 167
                    status = true;
165
                    
166
                } else if (resource.equals(RESOURCE_ACCESS_RULES)) {
168
                } else if (resource.startsWith(RESOURCE_ACCESS_RULES)) {
167 169
                    if (httpVerb == POST) {
168 170
	                	// set the access rules
169 171
	                    setAccess();
170 172
	                    status = true;
171 173
	                    logMetacat.debug("done setting access");
172 174
                    }
173
                } else if (resource.equals(RESOURCE_IS_AUTHORIZED)) {
175
                } else if (resource.startsWith(RESOURCE_IS_AUTHORIZED)) {
174 176
                    if (httpVerb == GET) {
175 177
	                	// check the access rules
176
                    	String objectId = request.getPathInfo();
177
                        if (objectId != null && objectId.length() > 1) {
178
                            objectId = request.getPathInfo().substring(1);
179
                        }
180
	                    isAuthorized(objectId);
178
	                    isAuthorized(extra);
181 179
	                    status = true;
182 180
	                    logMetacat.debug("done getting access");
183 181
                    }
184
                } else if (resource.equals(RESOURCE_META)) {
182
                } else if (resource.startsWith(RESOURCE_META)) {
185 183
                    logMetacat.debug("Using resource 'meta'");
186
                    String objectId = request.getPathInfo();
187
                    if (objectId != null && objectId.length() > 1) {
188
                        objectId = request.getPathInfo().substring(1);
189
                    }
190
                    
191 184
                    // get
192 185
                    if (httpVerb == GET) {
193
                        getSystemMetadataObject(objectId);
186
                        getSystemMetadataObject(extra);
194 187
                        status = true;
195 188
                    }
196 189
                    
197
                } else if (resource.equals(RESOURCE_OBJECTS)) {
190
                } else if (resource.startsWith(RESOURCE_OBJECTS)) {
198 191
                    logMetacat.debug("Using resource 'object'");
199

  
200
                    String objectId = request.getPathInfo();
201
                    if (objectId != null && objectId.length() > 1) {
202
                        objectId = request.getPathInfo().substring(1);
203
                    } else {
204
                        objectId = null;
205
                    }
206 192
                    
207
                    logMetacat.debug("objectId: " + objectId);
193
                    logMetacat.debug("objectId: " + extra);
208 194
                    logMetacat.debug("verb:" + httpVerb);
209 195

  
210 196
                    if (httpVerb == GET) {
211
                        getObject(objectId);
197
                        getObject(extra);
212 198
                        status = true;
213 199
                    } else if (httpVerb == POST) {
214
                        putObject(objectId, FUNCTION_NAME_INSERT);
200
                        putObject(extra, FUNCTION_NAME_INSERT);
215 201
                        status = true;
216 202
                    } else if (httpVerb == PUT) {
217
                        putObject(objectId, FUNCTION_NAME_UPDATE);
203
                        putObject(extra, FUNCTION_NAME_UPDATE);
218 204
                        status = true;
219 205
                    } else if (httpVerb == DELETE) {
220
                        deleteObject(objectId);
206
                        deleteObject(extra);
221 207
                        status = true;
222 208
                    } else if (httpVerb == HEAD) {
223
                        describeObject(objectId);
209
                        describeObject(extra);
224 210
                        status = true;
225 211
                    }
226 212
                  
227
                } else if (resource.equals(RESOURCE_LOG)) {
213
                } else if (resource.startsWith(RESOURCE_LOG)) {
228 214
                    logMetacat.debug("Using resource 'log'");
229 215
                    // handle log events
230 216
                    if (httpVerb == GET) {
231 217
                        getLog();
232 218
                        status = true;
233 219
                    }
234
                } else if (resource.equals(RESOURCE_CHECKSUM)) {
220
                } else if (resource.startsWith(RESOURCE_CHECKSUM)) {
235 221
                    logMetacat.debug("Using resource 'checksum'");
236 222
                    // handle checksum requests
237 223
                    if (httpVerb == GET) {
238
                        checksum();
224
                        checksum(extra);
239 225
                        status = true;
240 226
                    }
241 227
                } else if (resource.startsWith(RESOURCE_MONITOR)) {
242 228
                    // there are various parts to monitoring
243 229
                    if (httpVerb == GET) {
244 230
                    	// health monitoring calls
245
                        status = monitor();
231
                        status = monitor(extra);
246 232
                    }
247
                } else if (resource.equals(RESOURCE_REPLICATE)) {
233
                } else if (resource.startsWith(RESOURCE_REPLICATE)) {
248 234
                	if (httpVerb == POST) {
249 235
	                    logMetacat.debug("processing replicate request");
250 236
	                    replicate();
251 237
	                    status = true;
252 238
                	}
253
                } else if (resource.equals(RESOURCE_ERROR)) {
239
                } else if (resource.startsWith(RESOURCE_ERROR)) {
254 240
	                // sync error
255 241
	                if (httpVerb == POST) {
256 242
	                    syncError();
......
346 332
     * @throws IOException
347 333
     * @throws JiBXException
348 334
     */
349
    private boolean monitor() throws NotFound, ParseException, NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, InsufficientResources, UnsupportedType, IOException, JiBXException {
335
    private boolean monitor(String pathInfo) throws NotFound, ParseException, NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, InsufficientResources, UnsupportedType, IOException, JiBXException {
350 336
    	logMetacat.debug("processing monitor request");
351
        String pathInfo = request.getPathInfo();
352 337
        
353 338
        logMetacat.debug("verb is GET");
354 339
        logMetacat.debug("pathInfo is " + pathInfo);
355
        pathInfo = pathInfo.substring(1);
356 340
        
357 341
        if (pathInfo.toLowerCase().equals("ping")) {
358 342
            logMetacat.debug("processing ping request");
......
436 420
     * @throws NotFound
437 421
     * @throws InvalidRequest
438 422
     */
439
    private void checksum() throws NotImplemented, JiBXException, IOException, InvalidToken, ServiceFailure, NotAuthorized, NotFound, InvalidRequest {
423
    private void checksum(String guid) throws NotImplemented, JiBXException, IOException, InvalidToken, ServiceFailure, NotAuthorized, NotFound, InvalidRequest {
440 424
    	String checksumAlgorithm = "MD5";
441
        String guid = request.getPathInfo();
442
        if (guid != null && guid.length() > 1) {
443
            guid = request.getPathInfo().substring(1); // trim the slash
444
        }
425
        
445 426
        Identifier guidid = new Identifier();
446 427
        guidid.setValue(guid);
447 428
        try {

Also available in: Unified diff