Beispiel #1
0
  private static boolean replaceServerProperties(XMLServer server) {
    Class<?> serverclazz;

    try {
      serverclazz = Class.forName(server.getClazz());
    } catch (ClassNotFoundException e) {
      try {
        serverclazz = Class.forName("com.ingby.socbox.bischeck.servers." + server.getClazz());
      } catch (Exception ret) {
        return false;
      }
    }

    java.util.Properties defaultproperties = null;
    Method method;
    try {
      method = serverclazz.getMethod("getServerProperties");
      defaultproperties = (java.util.Properties) method.invoke(null);
    } catch (Exception ret) {
      return false;
    }

    Iterator<XMLProperty> iter = server.getProperty().iterator();
    // Update the default properties with what is currently set
    // in the server property
    while (iter.hasNext()) {
      XMLProperty xmlprop = iter.next();
      if (defaultproperties.containsKey(xmlprop.getKey()))
        defaultproperties.setProperty(xmlprop.getKey(), xmlprop.getValue());
    }

    // Create a new server property list
    List<XMLProperty> serverproperty = new ArrayList<XMLProperty>();
    Iterator<Object> keyiter = defaultproperties.keySet().iterator();

    while (keyiter.hasNext()) {
      String key = (String) keyiter.next();
      XMLProperty xmlprop = new XMLProperty();
      xmlprop.setKey(key);
      xmlprop.setValue((String) defaultproperties.get(key));
      serverproperty.add(xmlprop);
    }

    server.getProperty().clear();
    server.getProperty().addAll(serverproperty);

    return true;
  }
Beispiel #2
0
 public static Result routeAndCall(
     Class<? extends Routes> router, FakeRequest fakeRequest, long timeout) {
   try {
     Routes routes =
         (Routes)
             router
                 .getClassLoader()
                 .loadClass(router.getName() + "$")
                 .getDeclaredField("MODULE$")
                 .get(null);
     if (routes.routes().isDefinedAt(fakeRequest.getWrappedRequest())) {
       return invokeHandler(
           routes.routes().apply(fakeRequest.getWrappedRequest()), fakeRequest, timeout);
     } else {
       return null;
     }
   } catch (RuntimeException e) {
     throw e;
   } catch (Throwable t) {
     throw new RuntimeException(t);
   }
 }
Beispiel #3
0
 public static Result routeAndCall(
     Class<? extends Router> router, RequestBuilder requestBuilder, long timeout) {
   try {
     Request request = requestBuilder.build();
     Router routes =
         (Router)
             router
                 .getClassLoader()
                 .loadClass(router.getName() + "$")
                 .getDeclaredField("MODULE$")
                 .get(null);
     if (routes.routes().isDefinedAt(request._underlyingRequest())) {
       return invokeHandler(routes.routes().apply(request._underlyingRequest()), request, timeout);
     } else {
       return null;
     }
   } catch (RuntimeException e) {
     throw e;
   } catch (Throwable t) {
     throw new RuntimeException(t);
   }
 }