Exemplo n.º 1
0
  /**
   * Creates a new helper for a given server connector.
   *
   * @param server The server to help.
   * @param helperClass Optional helper class name.
   * @return The new helper.
   */
  @SuppressWarnings("unchecked")
  public ConnectorHelper<org.restlet.Server> createHelper(
      org.restlet.Server server, String helperClass) {
    ConnectorHelper<org.restlet.Server> result = null;

    if (server.getProtocols().size() > 0) {
      ConnectorHelper<org.restlet.Server> connector = null;
      for (final Iterator<ConnectorHelper<org.restlet.Server>> iter =
              getRegisteredServers().iterator();
          (result == null) && iter.hasNext(); ) {
        connector = iter.next();

        if ((helperClass == null) || connector.getClass().getCanonicalName().equals(helperClass)) {
          if (connector.getProtocols().containsAll(server.getProtocols())) {
            try {
              result =
                  connector.getClass().getConstructor(org.restlet.Server.class).newInstance(server);
            } catch (Exception e) {
              Context.getCurrentLogger()
                  .log(Level.SEVERE, "Exception while instantiation the server connector.", e);
            }
          }
        }
      }

      if (result == null) {
        // Couldn't find a matching connector
        final StringBuilder sb = new StringBuilder();
        sb.append("No available server connector supports the required protocols: ");

        for (final Protocol p : server.getProtocols()) {
          sb.append("'").append(p.getName()).append("' ");
        }

        sb.append(". Please add the JAR of a matching connector to your classpath.");

        if (Edition.CURRENT == Edition.ANDROID) {
          sb.append(" Then, register this connector helper manually.");
        }

        Context.getCurrentLogger().log(Level.WARNING, sb.toString());
      }
    }

    return result;
  }
Exemplo n.º 2
0
 @Override
 public ServerHelper createHelper(Server server, String helperClass) {
   if (server.getProtocols().contains(Protocol.HTTPS)) return new HttpsServerHelper(server);
   else return new HttpServerHelper(server);
 }