コード例 #1
0
ファイル: RazorServer.java プロジェクト: booking1234/booking
 /**
  * Instantiates a new razor server, its services, and starts the scheduler. This can be replaced
  * by a dynamic handler manager but has the benefit of simplicity.
  */
 public RazorServer() {
   super();
   SERVICES.put(Service.ACCOUNT, AccountService.getInstance());
   SERVICES.put(Service.ALERT, AlertService.getInstance());
   SERVICES.put(Service.ASSET, AssetService.getInstance());
   SERVICES.put(Service.ATTRIBUTE, AttributeService.getInstance());
   SERVICES.put(Service.AUDIT, AuditService.getInstance());
   SERVICES.put(Service.CONTRACT, ContractService.getInstance());
   SERVICES.put(Service.FINANCE, FinanceService.getInstance());
   SERVICES.put(Service.JOURNAL, JournalService.getInstance());
   SERVICES.put(Service.IMAGE, ImageService.getInstance());
   SERVICES.put(Service.IMAGETEXT, ImageTextService.getInstance());
   SERVICES.put(Service.LICENSE, LicenseService.getInstance());
   SERVICES.put(Service.LOCATION, LocationService.getInstance());
   SERVICES.put(Service.MAIL, MailService.getInstance());
   SERVICES.put(Service.MONITOR, MonitorService.getInstance());
   SERVICES.put(Service.PARTNER, PartnerService.getInstance());
   SERVICES.put(Service.PARTY, PartyService.getInstance());
   SERVICES.put(Service.PRICE, PriceService.getInstance());
   SERVICES.put(Service.PRODUCT, ProductService.getInstance());
   SERVICES.put(Service.RATE, RateService.getInstance());
   SERVICES.put(Service.REPORT, ReportService.getInstance());
   SERVICES.put(Service.RESERVATION, ReservationService.getInstance());
   SERVICES.put(Service.SESSION, SessionService.getInstance());
   SERVICES.put(Service.SMS, SmsService.getInstance());
   SERVICES.put(Service.TASK, TaskService.getInstance());
   SERVICES.put(Service.TAX, TaxService.getInstance());
   SERVICES.put(Service.TEXT, TextService.getInstance());
   SERVICES.put(Service.WORKFLOW, WorkflowService.getInstance());
   //		startScheduler();
   //		PartnerService.startSchedulers();
 }
コード例 #2
0
ファイル: RazorServer.java プロジェクト: booking1234/booking
  /**
   * Executes the specified action on the action.service() service.
   *
   * @param action the action to be executed.
   * @return the response.
   * @throws SerializationException the serialization exception
   */
  public HasResponse execute(HasService action) throws SerializationException {

    HasResponse response = null;
    LOG.debug("\n\nRazorServer execute " + action.getClass().getName() + "\naction " + action);
    String classname = action.service().classname();

    try {
      Class<?> c = Class.forName(classname); // say AccountService
      Method[] allMethods = c.getDeclaredMethods(); // can be static
      for (Method m : allMethods) {
        String mname = m.getName();
        if (mname.equals("execute")) {
          Type[] pType = m.getGenericParameterTypes();
          if (pType[1].toString().equals("class " + action.getClass().getName())) {
            SqlSession sqlSession = openSession();
            try {
              m.setAccessible(true);
              Object t = getService(action.service());
              response = (HasResponse) m.invoke(t, sqlSession, action);
              sqlSession.commit();
            } catch (IllegalAccessException x) {
              LOG.error(
                  "IllegalAccessException " + action.getClass().getName() + "\n" + x.getMessage());
            } catch (InvocationTargetException x) {
              LOG.error(
                  "InvocationTargetException exception "
                      + action.getClass().getName()
                      + "\n"
                      + x.getMessage());
            } catch (Throwable x) {
              sqlSession.rollback();
              MonitorService.log(x);
            } finally {
              sqlSession.close();
            }
          }
        }
      }
    } catch (ClassNotFoundException x) {
      MonitorService.log(x);
      LOG.error("ClassNotFoundException " + action.getClass().getName() + "\n" + x.getMessage());
    }
    return response;
  }
コード例 #3
0
ファイル: RazorServer.java プロジェクト: booking1234/booking
 /* (non-Javadoc)
  * @see net.cbtltd.client.RazorService#send(net.cbtltd.shared.api.HasService)
  */
 public HasResponse send(HasService action) throws SerializationException {
   try {
     Date timestamp = new Date();
     HasResponse response = execute(action);
     MonitorService.monitor(action.getClass().getSimpleName(), timestamp);
     return response;
   } catch (PatternSyntaxException x) {
     LOG.error("PatternSyntaxException " + x.toString());
     throw new SerializationException("PatternSyntaxException");
   }
 }
コード例 #4
0
  @Test
  public void canFetchData() throws URISyntaxException, UnsupportedEncodingException {
    UriInfo mockUri = mock(UriInfo.class);
    URI uri = new URI("http://peteriscool.com:6666/");
    when(mockUri.getBaseUri()).thenReturn(uri);
    Response resp = monitorService.getData();

    String entity = new String((byte[]) resp.getEntity(), "UTF-8");

    assertEquals(entity, 200, resp.getStatus());
    assertThat(entity, containsString("timestamps"));
    assertThat(entity, containsString("end_time"));
    assertThat(entity, containsString("property_count"));
  }
コード例 #5
0
  @Test
  public void correctRepresentation() throws Exception {
    Response resp = monitorService.getServiceDefinition();

    assertEquals(200, resp.getStatus());

    Map<String, Object> resultAsMap = output.getResultAsMap();
    @SuppressWarnings("unchecked")
    Map<String, Object> resources = (Map<String, Object>) resultAsMap.get("resources");
    assertThat((String) resources.get("data_from"), containsString("/fetch/{start}"));
    assertThat((String) resources.get("data_period"), containsString("/fetch/{start}/{stop}"));
    String latest_data = (String) resources.get("latest_data");
    assertThat(latest_data, containsString("/fetch"));
  }