Beispiel #1
0
  private static Collection<FacetHandler<?>> loadFromIndex(File file, WorkArea workArea)
      throws IOException {
    // File springFile = new File(file, SPRING_CONFIG);
    // FileSystemXmlApplicationContext appCtx =
    //   new FileSystemXmlApplicationContext("file:" + springFile.getAbsolutePath());
    // return (Collection<FacetHandler<?>>) appCtx.getBean("handlers");

    Set<Entry<Class<?>, Object>> entries = workArea.map.entrySet();
    FileSystemXmlApplicationContext appCtx = new FileSystemXmlApplicationContext();
    for (Entry<Class<?>, Object> entry : entries) {
      Object obj = entry.getValue();
      if (obj instanceof ClassLoader) {
        appCtx.setClassLoader((ClassLoader) obj);
        break;
      }
    }

    String absolutePath = file.getAbsolutePath();
    String partOne = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator));
    String partTwo =
        URLEncoder.encode(
            absolutePath.substring(absolutePath.lastIndexOf(File.separator) + 1), "UTF-8");
    absolutePath = partOne + File.separator + partTwo;

    File springFile = new File(new File(absolutePath), SPRING_CONFIG);
    appCtx.setConfigLocation("file:" + springFile.getAbsolutePath());
    appCtx.refresh();

    return (Collection<FacetHandler<?>>) appCtx.getBean("handlers");
  }
Beispiel #2
0
  public void testParseXML() throws Exception {
    URL url = getClass().getResource("applicationContext.xml");

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

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

    String body = "<Hello service=\"hello\" message=\"Hello world!\"/>";
    File file = File.createTempFile("geoserver", "req");
    file.deleteOnExit();

    FileOutputStream output = new FileOutputStream(file);
    output.write(body.getBytes());
    output.flush();
    output.close();

    BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file)));

    input.mark(8192);

    Request req = new Request();
    req.setInput(input);

    Object object = dispatcher.parseRequestXML(null, input, req);
    assertEquals(new Message("Hello world!"), object);
  }
Beispiel #3
0
 public static void main(String[] args) throws IOException {
   //        ApplicationContext appContext = new
   // ClassPathXmlApplicationContext("classpath:applicationContext.xml");
   FileSystemXmlApplicationContext appContext =
       new FileSystemXmlApplicationContext("config/applicationContext.xml");
   OXMExample ex = (OXMExample) appContext.getBean("oxmExample");
   ex.go();
 }
Beispiel #4
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());
  }
  public void test() throws Throwable {
    System.setProperty("port2", "3333");

    FileSystemXmlApplicationContext ctx =
        new FileSystemXmlApplicationContext(
            "src/test/resources/spring-config/config-property-placeholder.xml");

    DefaultFtpServer server = (DefaultFtpServer) ctx.getBean("server");

    assertEquals(2222, server.getListener("listener0").getPort());
    assertEquals(3333, server.getListener("listener1").getPort());
  }
  public static void main(String[] args) {

    FileSystemXmlApplicationContext context =
        new FileSystemXmlApplicationContext(new String[] {"src/StudentExample.xml"});

    ProfessionFacade pf = (ProfessionFacade) context.getBean("professionFacade");
    ProfessionView pv = new ProfessionView();
    pf.addProfession(pv);
    pf.updateProfession(pv);
    pf.deleteProfession(pv);
    pf.findProfession();
  }
Beispiel #7
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());
  }
Beispiel #8
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());
  }
Beispiel #9
0
  /**
   * Assert that if the service bean implements the optional {@link DirectInvocationService}
   * operation, then the dispatcher executes the operation through its {@link
   * DirectInvocationService#invokeDirect} method instead of through {@link Method#invoke
   * reflection}.
   */
  public void testDirectInvocationService() throws Throwable {

    URL url = getClass().getResource("applicationContext.xml");

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

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

    final AtomicBoolean invokeDirectCalled = new AtomicBoolean();
    DirectInvocationService serviceBean =
        new DirectInvocationService() {

          @Override
          public Object invokeDirect(String operationName, Object[] parameters)
              throws IllegalArgumentException, Exception {
            invokeDirectCalled.set(true);
            if ("concat".equals(operationName)) {
              String param1 = (String) parameters[0];
              String param2 = (String) parameters[1];
              return concat(param1, param2);
            }
            throw new IllegalArgumentException("Unknown operation name");
          }

          public String concat(String param1, String param2) {
            return param1 + param2;
          }
        };

    Service service =
        new Service(
            "directCallService",
            serviceBean,
            new Version("1.0.0"),
            Collections.singletonList("concat"));
    Method method = serviceBean.getClass().getMethod("concat", String.class, String.class);
    Object[] parameters = {"p1", "p2"};
    Operation opDescriptor = new Operation("concat", service, method, parameters);

    Object result = dispatcher.execute(new Request(), opDescriptor);
    assertEquals("p1p2", result);
    assertTrue(invokeDirectCalled.get());
  }
Beispiel #10
0
  @Override
  protected void tearDown() throws Exception {
    super.tearDown();
    System.out.println("Ec2Setup.tearDown()");
    File nodeIdFile = new File(NODE_ID_FILE);
    String nodeId = FileUtils.readFileToString(nodeIdFile);
    FileUtils.deleteQuietly(nodeIdFile);
    File file = new File(String.format("storage%s", nodeId));
    FileUtils.deleteQuietly(file);
    FileUtils.deleteQuietly(new File("var"));

    koalaNode.stop();
    ctx.destroy();
  }
Beispiel #11
0
  public void testParseKVP() throws Exception {
    URL url = getClass().getResource("applicationContext.xml");

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

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

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/geoserver");

    request.setupAddParameter("service", "hello");
    request.setupAddParameter("request", "Hello");
    request.setupAddParameter("message", "Hello world!");

    request.setQueryString("service=hello&request=hello&message=Hello World!");

    Request req = new Request();
    req.setHttpRequest(request);

    dispatcher.parseKVP(req);

    Message message = (Message) dispatcher.parseRequestKVP(Message.class, req);
    assertEquals(new Message("Hello world!"), message);
  }
Beispiel #12
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    System.out.println("Ec2Setup.setUp()");
    try {
      Security.addProvider(new BouncyCastleProvider());

      ctx =
          new FileSystemXmlApplicationContext(
              new String[] {
                "src/integration/resources/applicationContext-p2p-api-integration.xml"
              });
      koalaNode = (KoalaNode) ctx.getBean("koalaNode");
      koalaNode.setCanStartNewRing(true);
      koalaNode.setPort(8765);
      koalaNode.setAddressPattern("^127.0.*");
      koalaNode.setPreferredBootstraps("127.0.0.1:8765");
      koalaNode.setNodeIdFile(NODE_ID_FILE);
      koalaNode.start();
      seedQueues(ctx);

      UserManagementService userManagementService =
          (UserManagementService) ctx.getBean("userManagementService");
      User user = new User(USER_ID, ACCESS_KEY, SECRET_KEY);
      byte[] cert =
          new byte[] {
            48, -126, 3, -111, 48, -126, 2, 121, -96, 3, 2, 1, 2, 2, 6, 1, 34, -88, -124, 126, -8,
            48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 13, 5, 0, 48, 127, 49, 11, 48, 9, 6, 3,
            85, 4, 6, 19, 2, 85, 83, 49, 11, 48, 9, 6, 3, 85, 4, 8, 19, 2, 67, 65, 49, 22, 48, 20,
            6, 3, 85, 4, 7, 19, 13, 83, 97, 110, 116, 97, 32, 66, 97, 114, 98, 97, 114, 97, 49, 25,
            48, 23, 6, 3, 85, 4, 10, 19, 16, 107, 111, 97, 108, 97, 45, 114, 111, 98, 117, 115, 116,
            110, 101, 115, 115, 49, 19, 48, 17, 6, 3, 85, 4, 11, 19, 10, 69, 117, 99, 97, 108, 121,
            112, 116, 117, 115, 49, 27, 48, 25, 6, 3, 85, 4, 3, 19, 18, 119, 119, 119, 46, 101, 117,
            99, 97, 108, 121, 112, 116, 117, 115, 46, 99, 111, 109, 48, 30, 23, 13, 48, 57, 48, 55,
            50, 51, 49, 54, 52, 57, 51, 49, 90, 23, 13, 49, 52, 48, 55, 50, 51, 49, 54, 52, 57, 51,
            49, 90, 48, 127, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 11, 48, 9, 6, 3, 85,
            4, 8, 19, 2, 67, 65, 49, 22, 48, 20, 6, 3, 85, 4, 7, 19, 13, 83, 97, 110, 116, 97, 32,
            66, 97, 114, 98, 97, 114, 97, 49, 25, 48, 23, 6, 3, 85, 4, 10, 19, 16, 107, 111, 97,
            108, 97, 45, 114, 111, 98, 117, 115, 116, 110, 101, 115, 115, 49, 19, 48, 17, 6, 3, 85,
            4, 11, 19, 10, 69, 117, 99, 97, 108, 121, 112, 116, 117, 115, 49, 27, 48, 25, 6, 3, 85,
            4, 3, 19, 18, 119, 119, 119, 46, 101, 117, 99, 97, 108, 121, 112, 116, 117, 115, 46, 99,
            111, 109, 48, -126, 1, 34, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3,
            -126, 1, 15, 0, 48, -126, 1, 10, 2, -126, 1, 1, 0, -102, 86, -42, -105, -103, -13, -125,
            -58, -35, 41, -113, 16, -107, -20, -24, -39, 41, -109, 81, -69, -30, -53, 118, 22, -51,
            -124, -127, 30, -28, 29, -120, 64, -86, 79, -11, -48, -27, -7, 93, -116, 28, 25, 113,
            -29, -84, 111, -25, 108, -99, 118, 91, -26, -13, 40, -119, -6, -20, -126, 29, 70, 101,
            83, -108, 1, 3, 36, -67, 9, -49, 125, 121, 54, 38, 52, 36, 39, 118, 40, -108, 36, -85,
            -116, 67, -80, -45, 79, -94, -63, 125, 48, -126, -69, -5, 65, 16, -116, -44, -32, 113,
            61, -78, -18, 94, -62, 39, 90, -98, -121, 56, -5, -114, 36, -38, 116, 19, 12, -111, 78,
            12, 112, 72, 42, 116, -40, 99, -36, -55, -44, 79, 121, 38, -17, -61, -88, 126, 6, 28,
            -123, 27, -89, 8, 22, 124, 32, -42, 63, 125, 59, -26, -60, -42, 13, 68, -73, -53, -71,
            91, -122, 64, -2, 57, 124, 81, 28, 26, -86, -14, -61, -68, 114, 115, -28, -68, 51, -104,
            27, 55, 48, 111, -3, 33, -44, -119, 88, -44, -6, -72, -72, -20, -23, -114, 30, 80, 79,
            -93, 21, 92, 124, -56, -120, 38, -43, 94, -97, 4, 45, 64, -47, 69, 48, -60, 54, -84,
            -14, -23, 56, -106, 80, 38, -70, -60, -79, 105, -22, -120, -19, 95, 5, 103, 120, 99,
            -93, 10, 97, -37, 4, -121, 87, 114, 26, -34, -70, 121, 98, 75, -82, 20, 8, -32, 16, 110,
            -42, -116, 10, 45, -71, 2, 3, 1, 0, 1, -93, 19, 48, 17, 48, 15, 6, 3, 85, 29, 19, 1, 1,
            -1, 4, 5, 48, 3, 1, 1, -1, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 13, 5, 0, 3,
            -126, 1, 1, 0, 109, -122, 104, 79, 83, 0, -120, -108, -76, -64, -73, 105, -37, -68, 57,
            -16, 110, 40, -90, 6, 0, -18, 41, -122, 51, -44, 22, -35, 1, -123, 115, 77, 31, -87,
            -18, -12, 5, -34, -102, -70, 112, 123, -125, -68, -93, -58, 36, 102, -113, 34, 42, 16,
            -4, -126, -43, 54, 90, 116, -117, 86, 85, -49, -78, 34, 77, -70, 40, 60, 68, -122, -53,
            28, -64, -103, -2, 2, -103, 25, 93, -116, -93, 36, 10, -91, 109, -27, -15, 87, 112, 47,
            53, 125, 24, 102, 91, -69, 6, -58, 90, -96, -19, -29, -2, -53, -105, 15, 80, -123, -120,
            -44, 58, -115, 21, -26, -5, 104, 110, -62, -87, -81, 96, 109, -41, 3, 24, 13, 121, -119,
            78, 2, -36, 0, 125, -125, -2, -109, -106, 32, 17, 41, -35, 101, 97, -9, 87, -1, -12, 5,
            45, -85, 80, 67, 84, 55, -14, -99, 50, -4, -94, -12, -7, -104, -27, -31, -122, -36, 23,
            2, -14, -88, -60, -101, 75, 4, 85, -94, 74, 4, 99, -3, 42, 114, 11, 14, -31, -106, 46,
            -34, -14, 71, -127, 27, 54, -107, -59, 114, -42, -48, -56, 51, 110, -74, -99, 56, -65,
            55, -55, -85, 86, 22, -27, -59, -9, -105, -77, -62, 75, 53, 124, -13, 57, -58, 17, -128,
            -112, -108, 125, -121, -97, 87, -44, 88, -65, 88, -55, 76, -92, -70, -47, 58, 83, 106,
            -9, -39, 67, 80, -128, 8, 103, 125, 108, 39, 75, 0, 105, -125
          };
      user.setCertificate(cert);
      userManagementService.addUser(
          user.getUsername(), user.getApiAccessKey(), user.getApiSecretKey());

      userManagementService.addCertificateToUser(USER_ID, Base64.encodeBase64String(cert));
    } catch (Throwable t) {
      System.err.println("Exception in setup: " + t.getMessage());
      t.printStackTrace();
    }
  }