コード例 #1
0
ファイル: RESTServiceAdmin.java プロジェクト: jerrevds/ODS
  public void activate() throws RESTException {
    /*
     * server opstarten
     */
    servicesByID = new HashMap<String, Object>();
    methodsByString = new HashMap<String, Method>();
    clientsByString = new HashMap<String, ClientResource>();

    component = new Component();
    Server server = component.getServers().add(Protocol.HTTP, 8080);
    try {
      server.start();
    } catch (Exception e1) {
      throw new RESTException("Error starting the server", e1);
    }

    /*
     * ServiceListener that automatically exports services with exported interfaces
     * as defined by the Remote Services specification
     */
    try {
      ServiceTracker serviceTracker =
          new ServiceTracker(
              context,
              context.createFilter("(service.exported.interfaces=*)"),
              new ServiceTrackerCustomizer() {

                @Override
                public Object addingService(ServiceReference ref) {
                  Collection<ExportRegistration> regs = exportService(ref, null);
                  return regs;
                }

                @Override
                public void modifiedService(ServiceReference ref, Object regs) {}

                @Override
                public void removedService(ServiceReference ref, Object regs) {
                  for (ExportRegistration r : (Collection<ExportRegistration>) regs) {
                    r.close();
                  }
                }
              });
      serviceTracker.open();
    } catch (InvalidSyntaxException e) {
    }
  }
コード例 #2
0
 /**
  * Launches the application with an HTTP server.
  *
  * @param args The arguments.
  * @throws Exception
  */
 public static void main(String[] args) throws Exception {
   Server mailServer = new Server(Protocol.HTTP, 8111);
   mailServer.setNext(new MailServerApplication());
   mailServer.start();
 }