示例#1
0
  /**
   * Tests mixed get/post situations for cases in which there is no kvp parser
   *
   * @throws Exception
   */
  public void testHelloOperationMixed() throws Exception {
    URL url = getClass().getResource("applicationContextOnlyXml.xml");

    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString());

    Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher");

    final String body = "<Hello service=\"hello\" message=\"Hello world!\" version=\"1.0.0\" />";

    MockHttpServletRequest request =
        new MockHttpServletRequest() {
          String encoding;

          public int getServerPort() {
            return 8080;
          }

          public String getCharacterEncoding() {
            return encoding;
          }

          public void setCharacterEncoding(String encoding) {
            this.encoding = encoding;
          }

          public ServletInputStream getInputStream() throws IOException {
            final ServletInputStream stream = super.getInputStream();
            return new ServletInputStream() {
              public int read() throws IOException {
                return stream.read();
              }

              public int available() {
                return body.length();
              }
            };
          }
        };

    request.setScheme("http");
    request.setServerName("localhost");
    request.setContextPath("/geoserver");
    request.setMethod("POST");
    request.setRequestURI("http://localhost/geoserver/ows");
    request.setContentType("application/xml");
    request.setBodyContent(body);

    MockHttpServletResponse response = new MockHttpServletResponse();

    request.setupAddParameter("strict", "true");

    dispatcher.handleRequest(request, response);
    assertEquals("Hello world!", response.getOutputStreamContent());
  }
示例#2
0
  public void testDispatchWithNamespace() throws Exception {
    URL url = getClass().getResource("applicationContextNamespace.xml");
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString());

    Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher");
    MockHttpServletRequest request =
        new MockHttpServletRequest() {
          String encoding;

          public int getServerPort() {
            return 8080;
          }

          public String getCharacterEncoding() {
            return encoding;
          }

          public void setCharacterEncoding(String encoding) {
            this.encoding = encoding;
          }
        };

    request.setScheme("http");
    request.setServerName("localhost");

    request.setContextPath("/geoserver");
    request.setMethod("POST");

    MockHttpServletResponse response = new MockHttpServletResponse();

    request.setContentType("application/xml");
    request.setBodyContent(
        "<h:Hello service='hello' message='Hello world!' xmlns:h='http://hello.org' />");
    request.setRequestURI("http://localhost/geoserver/hello");

    dispatcher.handleRequest(request, response);
    assertEquals("Hello world!", response.getOutputStreamContent());

    request.setBodyContent(
        "<h:Hello service='hello' message='Hello world!' xmlns:h='http://hello.org/v2' />");

    response = new MockHttpServletResponse();
    dispatcher.handleRequest(request, response);
    assertEquals("Hello world!:V2", response.getOutputStreamContent());
  }
示例#3
0
  public void testHttpErrorCodeException() throws Exception {
    URL url = getClass().getResource("applicationContext.xml");

    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString());

    Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher");

    MockHttpServletRequest request =
        new MockHttpServletRequest() {
          String encoding;

          public int getServerPort() {
            return 8080;
          }

          public String getCharacterEncoding() {
            return encoding;
          }

          public void setCharacterEncoding(String encoding) {
            this.encoding = encoding;
          }
        };

    request.setScheme("http");
    request.setServerName("localhost");

    request.setContextPath("/geoserver");
    request.setMethod("GET");

    CodeExpectingHttpServletResponse response =
        new CodeExpectingHttpServletResponse(new MockHttpServletResponse());

    request.setupAddParameter("service", "hello");
    request.setupAddParameter("request", "httpErrorCodeException");
    request.setupAddParameter("version", "1.0.0");

    request.setRequestURI(
        "http://localhost/geoserver/ows?service=hello&request=hello&message=HelloWorld");
    request.setQueryString("service=hello&request=hello&message=HelloWorld");

    dispatcher.handleRequest(request, response);
    assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatusCode());
  }