Project

General

Profile

« Previous | Next » 

Revision 5750

Added by berkley almost 14 years ago

fix for paths with semi-colons or other 'reserved' characters in them for D1 rest services

View differences:

test/edu/ucsb/nceas/metacattest/ReaderWriterTest.java
61 61
     */
62 62
    public void setUp() 
63 63
    {
64
        
64
        System.out.println("default charset is: " + Charset.defaultCharset().displayName());
65 65
    }
66 66

  
67 67
    /**
......
77 77
    public static Test suite() 
78 78
    {
79 79
        TestSuite suite = new TestSuite();
80
        suite.addTest(new ReaderWriterTest("initialize"));
81
        suite.addTest(new ReaderWriterTest("testStringReaderAndWriter"));
82
        suite.addTest(new ReaderWriterTest("testFileReaderAndWriter"));
83
        suite.addTest(new ReaderWriterTest("testBufferedReaderAndWriter"));
84
        suite.addTest(new ReaderWriterTest("charArrayReaderAndWriter"));
80
//        suite.addTest(new ReaderWriterTest("initialize"));
81
//        suite.addTest(new ReaderWriterTest("testStringReaderAndWriter"));
82
//        suite.addTest(new ReaderWriterTest("testFileReaderAndWriter"));
83
//        suite.addTest(new ReaderWriterTest("testBufferedReaderAndWriter"));
84
//        suite.addTest(new ReaderWriterTest("charArrayReaderAndWriter"));
85 85
        suite.addTest(new ReaderWriterTest("testInputStreamReaderAndWriter"));
86 86
//        suite.addTest(new ReaderWriterTest("testBufferedReaderAndWriter"));
87 87
//        suite.addTest(new ReaderWriterTest("testBufferedReaderAndWriter"));
......
106 106
            
107 107
            FileInputStream fis = new FileInputStream(tmpFile);
108 108
            InputStreamReader isr = new InputStreamReader(fis);
109
            String s = isr.toString();
109
            String s = readReader(isr);
110
            System.out.println("s: " + s);
110 111
            assertTrue(s.equals(testStr));
111 112
        }
112 113
        catch(Exception e)
test/edu/ucsb/nceas/metacattest/NonAsciiCharacterTest.java
25 25

  
26 26
package edu.ucsb.nceas.metacattest;
27 27

  
28
import java.io.InputStream;
28 29
import java.io.InputStreamReader;
29 30
import java.io.Reader;
30 31
import java.io.StringReader;
......
48 49
import junit.framework.TestSuite;
49 50
import java.io.File;
50 51

  
52
import org.apache.commons.io.IOUtils;
53

  
51 54
/**
52 55
 * A JUnit test for testing Metacat when Non Ascii Characters are inserted
53 56
 */
......
603 606
            Thread.sleep(3000);
604 607
            queryDocWhichHasTitle(newdocid  + ".1", testTitle, EML2_0_1, SUCCESS);
605 608
            
606
            deleteDocid(newdocid  + ".1", SUCCESS, false);
609
            //deleteDocid(newdocid  + ".1", SUCCESS, false);
607 610
            
608 611
            m.logout();
609 612
        }
......
844 847
                                         boolean result,
845 848
                                         boolean expectedKarmaFailure) {
846 849
        try {
847
            Reader r = new InputStreamReader(m.read(docid));
850
            Reader r = new InputStreamReader(m.read(docid), "UTF-8");
851
            //InputStream is = m.read(docid);
848 852
            String doc = IOUtil.getAsString(r, true);
853
            //String doc = IOUtils.toString(is);
854
            
849 855
            if (result) {
850 856

  
851 857
                if (!testDoc.equals(doc)) {
lib/web.xml.tomcat5
91 91
  -->
92 92

  
93 93

  
94
  <!-- D1 filters -->
95
  <filter>
96
    <filter-name>D1URLFilter</filter-name>
97
    <filter-class>edu.ucsb.nceas.metacat.restservice.D1URLFilter</filter-class>
98
  </filter>
99
  
100
  <filter-mapping>
101
    <filter-name>D1URLFilter</filter-name>
102
    <url-pattern>/d1/*</url-pattern>
103
    <dispatcher>REQUEST</dispatcher>
104
  </filter-mapping>
94 105

  
95 106

  
96 107
  <!-- spring dispatcher servlet, dispatches incoming requests to controllers -->
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
340 340
                    {
341 341
                        objectId = null;
342 342
                    }
343
                    
344
                    System.out.println("objectId in ReasourceHandler.handle: " + objectId);
343 345

  
344 346
                    logMetacat.debug("verb:" + httpVerb);
345 347

  
......
1578 1580
                cs.setParamsFromRequest(request);
1579 1581
                Identifier id = new Identifier();
1580 1582
                id.setValue(guid);
1583
                System.out.println("creating object with guid " + id.getValue());
1581 1584
                Identifier rId = cs.create(token, id, object, m);
1582 1585
                serializeServiceType(Identifier.class, rId, out);
1583 1586
                
src/edu/ucsb/nceas/metacat/restservice/D1HttpRequest.java
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2010 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author: berkley $'
7
 *     '$Date: 2009-06-13 13:28:21 +0300  $'
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 */
23
 
24
package edu.ucsb.nceas.metacat.restservice;
25

  
26
import java.util.Enumeration;
27
import java.util.Map;
28

  
29
import javax.servlet.ServletRequest;
30
import javax.servlet.http.*;
31

  
32
/**
33
 * @author berkley
34
 * Class to override getPathInfo on the servlet request
35
 */
36
public class D1HttpRequest extends HttpServletRequestWrapper
37
{
38
    HttpServletRequest request;
39
    String lastPathElement;
40
    
41
    /**
42
     * HttpServletRequestWrapper(HttpServletRequest request) 
43
     */
44
    public D1HttpRequest(ServletRequest request)
45
    {
46
        super((HttpServletRequest)request);
47
        this.request = (HttpServletRequest)request;
48
        
49
        /*Enumeration<String> paramNames = request.getParameterNames();
50
        while(paramNames.hasMoreElements())
51
        {
52
            System.out.println("paramName: " + paramNames.nextElement());
53
        }*/
54
        System.out.println("request uri: " + this.request.getRequestURI());
55
        String reqUri = this.request.getRequestURI();
56
        this.lastPathElement = reqUri.substring(reqUri.lastIndexOf("/"), reqUri.length());
57
    }
58
    
59
    /**
60
     * override getPathInfo to handle special characters
61
     * @return
62
     */
63
    @Override
64
    public String getPathInfo()
65
    {
66
        //String s = super.getPathInfo();
67
        String s = this.lastPathElement;
68
        System.out.println("pathinfo: " + s);
69
        return s;
70
    }
71
}
src/edu/ucsb/nceas/metacat/restservice/D1URLFilter.java
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2010 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author: berkley $'
7
 *     '$Date: 2009-06-13 13:28:21 +0300  $'
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 */
23

  
24
package edu.ucsb.nceas.metacat.restservice;
25

  
26
import javax.servlet.*;
27
import java.io.*;
28

  
29
/**
30
 * @author berkley
31
 *
32
 */
33
public class D1URLFilter implements Filter
34
{
35
    ServletContext context;
36
    
37
    public void init(FilterConfig filterConfig) 
38
    {
39
        System.out.println("D1URLFilter init.");
40
        this.context = filterConfig.getServletContext();
41
    }
42
    
43
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 
44
        throws IOException, ServletException 
45
    {
46
        System.out.println("In D1URLFilter.");
47
        D1HttpRequest d1h = new D1HttpRequest(request);
48
        chain.doFilter(d1h, response);
49
    }
50
    
51
    public void destroy() 
52
    {
53
        System.out.println("D1URLFilter destroy.");
54
    }
55
}
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
302 302
        logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getValue() + "|" + sysmeta.getIdentifier().getValue());
303 303
        if (!guid.getValue().equals(sysmeta.getIdentifier().getValue())) {
304 304
            throw new InvalidSystemMetadata("1180", 
305
                "GUID in method call does not match GUID in system metadata.");
305
                "GUID in method call (" + guid.getValue() + ") does not match GUID in system metadata (" +
306
                sysmeta.getIdentifier().getValue() + ").");
306 307
        }
307 308

  
308 309
        logMetacat.debug("Checking if identifier exists...");

Also available in: Unified diff