Java Code Examples for org.apache.servicecomb.foundation.common.utils.BeanUtils

The following examples show how to use org.apache.servicecomb.foundation.common.utils.BeanUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: servicecomb-samples   Source File: AuthConsumerMain.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  BeanUtils.init();
  Person person = new Person();
  person.setName("ServiceComb/Authenticate");
  System.out
      .println("RestTemplate Consumer or POJO Consumer.  You can choose whatever you like.");
  String sayHiResult = restTemplate
      .postForObject(
          "cse://auth-provider/springmvchello/sayhi?name=Authenticate",
          null,
          String.class);
  String sayHelloResult = restTemplate.postForObject(
      "cse://auth-provider/springmvchello/sayhello",
      person,
      String.class);
  System.out.println(sayHiResult);
  System.out.println(sayHelloResult);
}
 
Example 2
Source Project: skywalking   Source File: CodeFirstMain.java    License: Apache License 2.0 6 votes vote down vote up
public static void init() {
    while (true) {
        try {
            Log4jUtils.init();
            BeanUtils.init();
            return;
        } catch (Throwable e) {
            try {
                LOGGER.error(e.getMessage(), e);
                Thread.sleep(5000);
            } catch (InterruptedException ex) {
                // ignore
            }
        }
    }
}
 
Example 3
Source Project: servicecomb-java-chassis   Source File: ConsumerMain.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
  deploys.init();
  deploys.getServiceCenter().ensureReady();

  BeanUtils.init();
  ITUtils.waitBootFinished();

  try {
    run();
  } finally {
    SCBEngine.getInstance().destroy();
    deploys.getServiceCenter().stop();
  }

  resultPrinter.print();

  if (autoExit) {
    System.exit(0);
  }
}
 
Example 4
@Test
public void findExecutor_twoParam_opCfg_withOpDef(@Mocked Executor executor,
    @Mocked Executor defExecutor,
    @Mocked OperationMeta operationMeta) {
  String schemaQualifiedName = "schemaId.opId";
  String opBeanId = "opBeanId";
  ArchaiusUtils.setProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + schemaQualifiedName, opBeanId);
  new Expectations(BeanUtils.class) {
    {
      operationMeta.getSchemaQualifiedName();
      result = schemaQualifiedName;
      BeanUtils.getBean(opBeanId);
      result = executor;
    }
  };

  Assert.assertSame(executor, new ExecutorManager().findExecutor(operationMeta, defExecutor));
}
 
Example 5
Source Project: servicecomb-java-chassis   Source File: ConsumerMain.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  Log4jUtils.init();
  BeanUtils.init();

  new Consumer().testEncrypt();

  System.out.println("Running api dispatcher.");
  new Consumer().run("api");
  System.out.println("Running rest dispatcher.");
  new Consumer().run("rest");
  System.out.println("Running url dispatcher.");
  new Consumer().run("url");
  System.out.println("Running http dispatcher.");
  new Consumer().run("http");

  System.out.println("All test case finished.");
}
 
Example 6
@Test
public void findExecutor_twoParam_schemaCfg_withoutOpDef(@Mocked Executor executor,
    @Mocked OperationMeta operationMeta) {
  String schemaName = "schemaId";
  String opBeanId = "opBeanId";
  ArchaiusUtils.setProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + schemaName, opBeanId);
  new Expectations(BeanUtils.class) {
    {
      operationMeta.getSchemaId();
      result = schemaName;
      BeanUtils.getBean(opBeanId);
      result = executor;
    }
  };

  Assert.assertSame(executor, new ExecutorManager().findExecutor(operationMeta, null));
}
 
Example 7
Source Project: servicecomb-samples   Source File: MainServer.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  BeanUtils.init();
  while (true) {
    System.out.println(DynamicPropertyFactory.getInstance().getStringProperty("timeout", "default"));
    Thread.sleep(3000);
  }
}
 
Example 8
Source Project: servicecomb-samples   Source File: PojoConsumerMain.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  BeanUtils.init();
  System.out.println(hello.sayHi("Java Chassis"));
  Person person = new Person();
  person.setName("ServiceComb/Java Chassis");
  System.out.println(hello.sayHello(person));
  System.out.println("a=1, b=2, result=" + compute.add(1, 2));
}
 
Example 9
Source Project: servicecomb-samples   Source File: JaxrsConsumerMain.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  BeanUtils.init();
  System.out.println(hello.sayHi("Java Chassis"));
  Person person = new Person();
  person.setName("ServiceComb/Java Chassis");
  System.out.println(hello.sayHello(person));

  RestTemplate restTemplate = RestTemplateBuilder.create();
  String result = restTemplate.getForObject("cse://jaxrs/jaxrshello/saybye", String.class);
  System.out.println(result);
}
 
Example 10
Source Project: servicecomb-samples   Source File: SpringmvcConsumerMain.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  BeanUtils.init();

  SpringmvcBasicClient springmvcBasicClient = BeanUtils.getBean("SpringmvcBasicClient");
  SpringmvcHelloClient springmvcHelloClient = BeanUtils.getBean("SpringmvcHelloClient");

  long begin = System.currentTimeMillis();
  springmvcHelloClient.run();
  springmvcBasicClient.run();

  System.out.println("Spring MVC Consumer execute successfully." + (System.currentTimeMillis() - begin) );
}
 
Example 11
public static void main(String[] args) {
  BeanUtils.init();
  System.out.println(hello.sayHi("Java Chassis"));
  Person person = new Person();
  person.setName("ServiceComb/Java Chassis");
  System.out.println(hello.sayHello(person));
}
 
Example 12
Source Project: servicecomb-samples   Source File: CodeFirstConsumerMain.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  BeanUtils.init();
  System.out.println(hello.sayHi("Java Chassis"));
  System.out.println(jaxrsHello.sayHi("Java Chassis"));
  System.out.println(springmvcHello.sayHi("Java Chassis"));
  Person person = new Person();
  person.setName("ServiceComb/Java Chassis");
  System.out.println(hello.sayHello(person));
  System.out.println(jaxrsHello.sayHello(person));
  System.out.println(springmvcHello.sayHello(person));
}
 
Example 13
Source Project: txle   Source File: SagaConsumerHandler.java    License: Apache License 2.0 5 votes vote down vote up
public SagaConsumerHandler() {
  OmegaContext context = null;
  try {
    context = BeanUtils.getBean("omegaContext");
  } catch (NullPointerException npe) {
    LOG.warn("SagaConsumerHandler cannot work rightly, please make sure omegaContext is in the spring application context.");
  }
  this.omegaContext = context;
}
 
Example 14
Source Project: txle   Source File: SagaProviderHandler.java    License: Apache License 2.0 5 votes vote down vote up
public SagaProviderHandler() {
  OmegaContext context = null;
  try {
    context = BeanUtils.getBean("omegaContext");
  } catch (NullPointerException npe) {
    LOG.warn("SagaProviderHandler cannot work rightly, please make sure omegaContext is in the spring application context.\"");
  }
  this.omegaContext = context;
}
 
Example 15
Source Project: servicecomb-java-chassis   Source File: ExecutorManager.java    License: Apache License 2.0 5 votes vote down vote up
public Executor findExecutorById(String id) {
  Executor executor = executors.get(id);
  if (executor != null) {
    return executor;
  }

  return BeanUtils.getBean(id);
}
 
Example 16
@BeforeClass
public static void setUp() throws Exception {
  vertx = Vertx.vertx();
  vertx.deployVerticle(new SimApolloServer());

  Log4jUtils.init();
  BeanUtils.init();
}
 
Example 17
Source Project: servicecomb-java-chassis   Source File: BClientMain.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Log4jUtils.init();
  BeanUtils.init();

  BClient client = BeanUtils.getContext().getBean(BClient.class);
  client.run();

  TestMgr.summary();
}
 
Example 18
Source Project: servicecomb-java-chassis   Source File: MultipleClient.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Log4jUtils.init();
  BeanUtils.init();

  AClient aClient = BeanUtils.getContext().getBean(AClient.class);
  BClient bClient = BeanUtils.getContext().getBean(BClient.class);

  aClient.run();
  bClient.run();

  TestMgr.summary();
}
 
Example 19
Source Project: servicecomb-java-chassis   Source File: AClientMain.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Log4jUtils.init();
  BeanUtils.init();

  AClient client = BeanUtils.getContext().getBean(AClient.class);
  client.run();

  TestMgr.summary();
}
 
Example 20
@Test
public void findExecutor_oneParam(@Mocked Executor executor, @Mocked OperationMeta operationMeta) {
  new Expectations(BeanUtils.class) {
    {
      BeanUtils.getBean(ExecutorManager.EXECUTOR_DEFAULT);
      result = executor;
    }
  };

  Assert.assertSame(executor, new ExecutorManager().findExecutor(operationMeta));
}
 
Example 21
@Test
public void testGetConfigLocationsEmptyAndDefaultEmpty() {
  context.setDefaultBeanResource(null);
  String[] result = context.getConfigLocations();
  Assert.assertThat(result,
      Matchers.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE));
}
 
Example 22
Source Project: servicecomb-java-chassis   Source File: EdgeApplication.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
  new SpringApplicationBuilder().sources(EdgeApplication.class).web(WebApplicationType.NONE).build().run(args);

  SelfServiceInvoker invoker = BeanUtils.getBean("SelfServiceInvoker");
  invoker.latch.await(10, TimeUnit.SECONDS);
  TestMgr.check(invoker.result, "hello");

  TestMgr.summary();
  if (!TestMgr.errors().isEmpty()) {
    System.exit(1);
  }
}
 
Example 23
public static void main(final String[] args) throws Exception {
  new SpringApplicationBuilder().sources(ServerApplication.class).web(WebApplicationType.SERVLET).build().run(args);

  SelfServiceInvoker invoker = BeanUtils.getBean("SelfServiceInvoker");
  invoker.latch.await(10, TimeUnit.SECONDS);
  TestMgr.check(invoker.result, "hello");

  TestMgr.summary();
  if (!TestMgr.errors().isEmpty()) {
    System.exit(1);
  }
}
 
Example 24
Source Project: servicecomb-java-chassis   Source File: PerfMain.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  BeanUtils.init();

  // redis
  RedisClientUtils.init(VertxUtils.getOrCreateVertxByName("transport", null));

  List<String> argList = Arrays.asList(args);
  if (argList.contains("-c")) {
    PerfConsumer consumer = BeanUtils.getContext().getBean(PerfConsumer.class);
    consumer.runConsumer();
  }
}
 
Example 25
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  if (this.applicationContext == applicationContext) {
    // same object. avoid initialize many times.
    return;
  }
  this.applicationContext = applicationContext;
  BeanUtils.setContext(applicationContext);
  HttpClients.load();
  RegistrationManager.INSTANCE.init();
  DiscoveryManager.INSTANCE.init();
}
 
Example 26
public static void main(final String[] args) throws Exception {
  new SpringApplicationBuilder().sources(ServerApplication.class).web(WebApplicationType.SERVLET).build().run(args);

  SelfServiceInvoker invoker = BeanUtils.getBean("SelfServiceInvoker");
  invoker.latch.await(10, TimeUnit.SECONDS);
  TestMgr.check(invoker.result, "hello");

  TestMgr.summary();
  if (!TestMgr.errors().isEmpty()) {
    System.exit(1);
  }
}
 
Example 27
public static void runCategorizedTestCase(String microserviceName) throws Exception {
  Map<String, CategorizedTestCase> tests = BeanUtils.getContext().getBeansOfType(CategorizedTestCase.class);
  for (String transport : DemoConst.transports) {
    for (CategorizedTestCase testCase : tests.values()) {

      try {
        if (testCase.getMicroserviceName() != null) {
          changeTransport(testCase.getMicroserviceName(), transport);
        } else {
          changeTransport(microserviceName, transport);
        }

        testCase.testAllTransport();
        if ("rest".equals(transport)) {
          testCase.testRestTransport();
        } else if ("highway".equals(transport)) {
          testCase.testHighwayTransport();
        }
      } catch (Exception e) {
        e.printStackTrace();
        TestMgr.failed("run categorized test case " +
                testCase.getClass().getName() +
                " failed, reason " + e.getMessage(),
            e);
      }
    }
  }
}
 
Example 28
public static void main(final String[] args) throws Exception {
  new SpringApplicationBuilder().sources(ServerApplication.class).web(WebApplicationType.SERVLET).build().run(args);

  SelfServiceInvoker invoker = BeanUtils.getBean("SelfServiceInvoker");
  invoker.latch.await(10, TimeUnit.SECONDS);
  TestMgr.check(invoker.result, "hello");

  TestMgr.summary();
  if (!TestMgr.errors().isEmpty()) {
    System.exit(1);
  }
}
 
Example 29
Source Project: servicecomb-java-chassis   Source File: CrossappClient.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
  Log4jUtils.init();
  BeanUtils.init();

  run();

  TestMgr.summary();
  System.setProperty("sun.net.http.allowRestrictedHeaders", "false");
}
 
Example 30
Source Project: servicecomb-java-chassis   Source File: SpringmvcClient.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  try {
    Log4jUtils.init();
    BeanUtils.init();

    run();
  } catch (Throwable e) {
    TestMgr.check("success", "failed");
    LOGGER.error("-------------- test failed -------------");
    LOGGER.error("", e);
    LOGGER.error("-------------- test failed -------------");
  }
  TestMgr.summary();
}