Project

General

Profile

« Previous | Next » 

Revision 9297

Added by Jing Tao over 9 years ago

Decode the string of the uri after we break the uri into parts base on the "/".

View differences:

src/edu/ucsb/nceas/metacat/restservice/D1HttpRequest.java
58 58
        String strip = this.getContextPath() + this.getServletPath();
59 59
        System.out.println("stripping " + strip + " from requestURI");
60 60
        s = reqUri.substring(strip.length());
61
        try
61
        /*try
62 62
        {
63 63
            s = URLDecoder.decode(s, "UTF-8");
64 64
        }
65 65
        catch (UnsupportedEncodingException e)
66 66
        {
67 67
            s = URLDecoder.decode(s);
68
        }
68
        }*/
69 69
        System.out.println("new pathinfo: " + s);
70 70
        return s;
71 71
    }
72
    
72 73
}
src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java
27 27
import java.io.InputStream;
28 28
import java.io.OutputStream;
29 29
import java.io.PrintWriter;
30
import java.io.UnsupportedEncodingException;
31
import java.net.URLDecoder;
30 32
import java.util.Enumeration;
31 33
import java.util.Hashtable;
32 34
import java.util.Iterator;
......
461 463
                    + e1.getMessage());
462 464
        }
463 465
    }
464

  
466
    
467
    /**
468
     * A method to decode the given string which is a part of a uri.
469
     * The default encoding is utf-8. If the utf-8 is not support in this system, the default one in the systme will be used.
470
     * @param s
471
     * @return null if the given string is null
472
     */
473
    public static String decode(String s) {
474
        String result = null;
475
        if(s != null) {
476
            try
477
            {
478
                result = URLDecoder.decode(s, "UTF-8");
479
            }
480
            catch (UnsupportedEncodingException e)
481
            {
482
                result = URLDecoder.decode(s);
483
            }
484
            System.out.println("After decoded: " + result);
485
        }
486
        
487
        return result;
488
    }
465 489
}
src/edu/ucsb/nceas/metacat/restservice/v1/CNResourceHandler.java
81 81

  
82 82
import edu.ucsb.nceas.metacat.dataone.v1.CNodeService;
83 83
import edu.ucsb.nceas.metacat.properties.PropertyService;
84
import edu.ucsb.nceas.metacat.restservice.D1HttpRequest;
84 85
import edu.ucsb.nceas.metacat.restservice.D1ResourceHandler;
85 86
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
86 87

  
......
169 170
                    logMetacat.debug("Setting access policy");
170 171
                    // after the command
171 172
                    extra = parseTrailing(resource, RESOURCE_ACCESS_RULES);
173
                    extra = decode(extra);
172 174
                    setAccess(extra);
173 175
                    status = true;
174 176
                    logMetacat.debug("done setting access");
......
178 180

  
179 181
                    // after the command
180 182
                    extra = parseTrailing(resource, RESOURCE_META);
181

  
183
                    extra = decode(extra);
182 184
                    // get
183 185
                    if (httpVerb == GET) {
184 186
                        getSystemMetadataObject(extra);
......
200 202

  
201 203
                    // after the command
202 204
                    extra = parseTrailing(resource, RESOURCE_RESOLVE);
203

  
205
                    extra = decode(extra);
204 206
                    // resolve the object location
205 207
                    if (httpVerb == GET) {
206 208
                        resolve(extra);
......
210 212

  
211 213
                    // after the command
212 214
                    extra = parseTrailing(resource, RESOURCE_OWNER);
213

  
215
                    extra = decode(extra);
214 216
                    // set the owner
215 217
                    if (httpVerb == PUT) {
216 218
                        owner(extra);
......
220 222

  
221 223
                    // after the command
222 224
                    extra = parseTrailing(resource, RESOURCE_IS_AUTHORIZED);
223

  
225
                    extra = decode(extra);
224 226
                    // authorized?
225 227
                    if (httpVerb == GET) {
226 228
                        isAuthorized(extra);
......
233 235

  
234 236
                    // after the command
235 237
                    extra = parseTrailing(resource, RESOURCE_OBJECTS);
236

  
238
                    extra = decode(extra);
237 239
                    logMetacat.debug("objectId: " + extra);
238 240
                    logMetacat.debug("verb:" + httpVerb);
239 241

  
......
260 262

  
261 263
                    // after the command
262 264
                    extra = parseTrailing(resource, RESOURCE_FORMATS);
263

  
265
                    extra = decode(extra);
264 266
                    // handle each verb
265 267
                    if (httpVerb == GET) {
266 268
                        if (extra == null) {
......
286 288
                    // handle archive events
287 289
                    if (httpVerb == PUT) {
288 290
                        extra = parseTrailing(resource, Constants.RESOURCE_ARCHIVE);
291
                        extra = decode(extra);
289 292
                        archive(extra);
290 293
                        status = true;
291 294
                    }
......
294 297

  
295 298
                    // after the command
296 299
                    extra = parseTrailing(resource, Constants.RESOURCE_CHECKSUM);
297

  
300
                    extra = decode(extra);
298 301
                    // handle checksum requests
299 302
                    if (httpVerb == GET) {
300 303

  
......
315 318
                            + RESOURCE_REPLICATION_POLICY);
316 319
                    // get the trailing pid
317 320
                    extra = parseTrailing(resource, RESOURCE_REPLICATION_POLICY);
321
                    extra = decode(extra);
318 322
                    setReplicationPolicy(extra);
319 323
                    status = true;
320 324

  
......
325 329
                            + RESOURCE_REPLICATION_META);
326 330
                    // get the trailing pid
327 331
                    extra = parseTrailing(resource, RESOURCE_REPLICATION_META);
332
                    extra = decode(extra);
328 333
                    updateReplicationMetadata(extra);
329 334
                    status = true;
330 335

  
......
335 340
                            + RESOURCE_REPLICATION_NOTIFY);
336 341
                    // get the trailing pid
337 342
                    extra = parseTrailing(resource, RESOURCE_REPLICATION_NOTIFY);
343
                    extra = decode(extra);
338 344
                    setReplicationStatus(extra);
339 345
                    status = true;
340 346

  
......
346 352
                    // get the trailing pid
347 353
                    extra = parseTrailing(resource,
348 354
                            RESOURCE_REPLICATION_AUTHORIZED);
355
                    extra = decode(extra);
349 356
                    isNodeAuthorized(extra);
350 357
                    status = true;
351 358

  
......
353 360
                    if (httpVerb == GET) {
354 361
                    	// after the command
355 362
                        extra = parseTrailing(resource, Constants.RESOURCE_MONITOR_PING);
356
                        
363
                        extra = decode(extra);
357 364
                        logMetacat.debug("processing ping request");
358 365
                        Date result = CNodeService.getInstance(request).ping();
359 366
                        // TODO: send to output	
......
366 373
                            + Constants.RESOURCE_META_OBSOLETEDBY);
367 374
                    // get the trailing pid
368 375
                    extra = parseTrailing(resource, Constants.RESOURCE_META_OBSOLETEDBY);
376
                    extra = decode(extra);
369 377
                    setObsoletedBy(extra);
370 378
                    status = true;
371 379
                } else if (resource.startsWith(Constants.RESOURCE_REPLICATION_DELETE_REPLICA)
......
375 383
                            + Constants.RESOURCE_REPLICATION_DELETE_REPLICA);
376 384
                    // get the trailing pid
377 385
                    extra = parseTrailing(resource, Constants.RESOURCE_REPLICATION_DELETE_REPLICA);
386
                    extra = decode(extra);
378 387
                    deleteReplica(extra);
379 388
                    status = true;
380 389
                }

Also available in: Unified diff