Java Code Examples for org.apache.commons.configuration.Configuration.setProperty()

The following are Jave code examples for showing how to use setProperty() of the org.apache.commons.configuration.Configuration class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-servicecomb-java-chassis   File: RestServletInitializer.java   Source Code and License Vote up 7 votes
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
  if (getPort() == 0) {
    LOGGER.warn(
        "spring boot embed web container listen port is 0, serviceComb will not use container's port to handler RESTful request.");
    return;
  }

  // web container did not did listen now.
  // so mock to listen, and then close.
  try (ServerSocket ss = new ServerSocket(getPort(), 0, getAddress())) {
    if (StringUtils.isEmpty(ServletConfig.getServletUrlPattern())) {
      // ensure the servlet will be instantiated
      Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
      configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, ServletConfig.DEFAULT_URL_PATTERN);
    }
    RestServletInjector.defaultInject(servletContext);
    ServletUtils.saveUrlPrefix(servletContext);
  } catch (IOException e) {
    throw new ServletException(e);
  }
}
 
Example 2
Project: incubator-servicecomb-java-chassis   File: TestRestServletInitializer.java   Source Code and License Vote up 7 votes
@Test
public void testOnStartup() throws Exception {
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  String urlPattern = "/rest/*";
  configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, urlPattern);

  ServletContext servletContext = mock(ServletContext.class);
  Dynamic dynamic = mock(Dynamic.class);
  when(servletContext.addServlet(RestServletInjector.SERVLET_NAME, RestServlet.class)).thenReturn(dynamic);

  RestServletInitializer restServletInitializer = new RestServletInitializer();
  restServletInitializer.setPort(TEST_PORT);
  restServletInitializer.onStartup(servletContext);

  verify(dynamic).setAsyncSupported(true);
  verify(dynamic).addMapping(urlPattern);
  verify(dynamic).setLoadOnStartup(0);
}
 
Example 3
Project: incubator-servicecomb-java-chassis   File: EdgeBootListener.java   Source Code and License Vote up 7 votes
@Override
public void onBootEvent(BootEvent event) {
  if (!EventType.BEFORE_PRODUCER_PROVIDER.equals(event.getEventType())) {
    return;
  }

  String defaultExecutor = DynamicPropertyFactory.getInstance()
      .getStringProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, null)
      .get();
  if (defaultExecutor != null) {
    LOGGER.info("Edge service default executor is {}.", defaultExecutor);
    return;
  }

  // change default to reactive mode
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  configuration.setProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, ExecutorManager.EXECUTOR_REACTIVE);
  LOGGER.info("Set ReactiveExecutor to be edge service default executor.");
}
 
Example 4
Project: incubator-servicecomb-java-chassis   File: TestServletConfig.java   Source Code and License Vote up 7 votes
@Test
public void testGetServletUrlPattern() {
  DynamicPropertyFactory.getInstance();
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, "/*");
  Assert.assertEquals("/*", ServletConfig.getServletUrlPattern());
}
 
Example 5
Project: incubator-servicecomb-java-chassis   File: TestRestServletInitializer.java   Source Code and License Vote up 6 votes
@Before
public void setUp() throws Exception {
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  configuration.clearProperty(ServletConfig.KEY_SERVLET_URL_PATTERN);
  configuration.setProperty(ServletConfig.KEY_CSE_REST_ADDRESS, LISTEN_ADDRESS);

  PowerMockito.mockStatic(NetUtils.class);
  PowerMockito.when(NetUtils.parseIpPortFromURI(anyString())).thenReturn(new IpPort(LISTEN_ADDRESS, TEST_PORT));
  PowerMockito.when(NetUtils.canTcpListen(anyObject(), anyInt())).thenReturn(false);
}
 
Example 6
Project: bitsy   File: BitsyGraph.java   Source Code and License Vote up 6 votes
@Override
public Configuration configuration() {
	if (this.origConfig != null) {
		return this.origConfig;
	} else {
        Configuration ans = new BaseConfiguration();
        ans.setProperty(DB_PATH_KEY, dbPath.toString());
        ans.setProperty(ALLOW_FULL_GRAPH_SCANS_KEY, allowFullGraphScans);
        ans.setProperty(DEFAULT_ISOLATION_LEVEL_KEY, defaultIsolationLevel.toString());
        ans.setProperty(TX_LOG_THRESHOLD_KEY, getTxLogThreshold());
        ans.setProperty(REORG_FACTOR_KEY, getReorgFactor());
        ans.setProperty(CREATE_DIR_IF_MISSING_KEY, createDirIfMissing);

        ans.setProperty(VERTEX_INDICES_KEY, String.join(",", getIndexedKeys(Vertex.class)));
        ans.setProperty(EDGE_INDICES_KEY, String.join(",", getIndexedKeys(Vertex.class)));

        return ans;
	}
}
 
Example 7
Project: tinkergraph-gremlin   File: TinkerIoRegistryV3d0.java   Source Code and License Vote up 6 votes
@Override
public TinkerGraph deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list");
    final TinkerGraph graph = TinkerGraph.open(conf);

    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        if (jsonParser.getCurrentName().equals("vertices")) {
            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jsonParser.currentToken() == JsonToken.START_OBJECT) {
                    final DetachedVertex v = (DetachedVertex) deserializationContext.readValue(jsonParser, Vertex.class);
                    v.attach(Attachable.Method.getOrCreate(graph));
                }
            }
        } else if (jsonParser.getCurrentName().equals("edges")) {
            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jsonParser.currentToken() == JsonToken.START_OBJECT) {
                    final DetachedEdge e = (DetachedEdge) deserializationContext.readValue(jsonParser, Edge.class);
                    e.attach(Attachable.Method.getOrCreate(graph));
                }
            }
        }
    }

    return graph;
}
 
Example 8
Project: tinkergraph-gremlin   File: TinkerGraphTest.java   Source Code and License Vote up 6 votes
@Test
public void shouldPersistWithRelativePath() {
    final String graphLocation = TestHelper.convertToRelative(TinkerGraphTest.class,
            new File(TestHelper.makeTestDataDirectory(TinkerGraphTest.class)))  + "shouldPersistToGryoRelative.kryo";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, false);
    reloadedGraph.close();
}
 
Example 9
Project: tinkergraph-gremlin   File: TinkerGraphTest.java   Source Code and License Vote up 6 votes
@Test
public void shouldPersistToGraphML() {
    final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class) + "shouldPersistToGraphML.xml";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "graphml");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, true);
    reloadedGraph.close();
}
 
Example 10
Project: tinkergraph-gremlin   File: TinkerGraphTest.java   Source Code and License Vote up 6 votes
@Test
public void shouldPersistToGraphSON() {
    final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class) + "shouldPersistToGraphSON.json";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "graphson");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, false);
    reloadedGraph.close();
}
 
Example 11
Project: tinkergraph-gremlin   File: TinkerGraphTest.java   Source Code and License Vote up 6 votes
@Test
public void shouldPersistToGryo() {
    final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class) + "shouldPersistToGryo.kryo";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, false);
    reloadedGraph.close();
}
 
Example 12
Project: tinkergraph-gremlin   File: TinkerGraphTest.java   Source Code and License Vote up 5 votes
@Test
public void shouldPersistToAnyGraphFormat() {
    final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class) + "shouldPersistToAnyGraphFormat.dat";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, TestIoBuilder.class.getName());
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);

    //Test write graph
    graph.close();
    assertEquals(TestIoBuilder.calledOnMapper, 1);
    assertEquals(TestIoBuilder.calledGraph, 1);
    assertEquals(TestIoBuilder.calledCreate, 1);

    try (BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(f))){
        os.write("dummy string".getBytes());
    } catch (Exception e) {
        e.printStackTrace();
    }

    //Test read graph
    final TinkerGraph readGraph = TinkerGraph.open(conf);
    assertEquals(TestIoBuilder.calledOnMapper, 1);
    assertEquals(TestIoBuilder.calledGraph, 1);
    assertEquals(TestIoBuilder.calledCreate, 1);
}
 
Example 13
Project: tinkergraph-gremlin   File: TinkerFactory.java   Source Code and License Vote up 5 votes
public static TinkerGraph createTheCrew() {
    final Configuration conf = getNumberIdManagerConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.name());
    final TinkerGraph g = TinkerGraph.open(conf);
    generateTheCrew(g);
    return g;
}
 
Example 14
Project: tinkergraph-gremlin   File: TinkerFactory.java   Source Code and License Vote up 5 votes
private static Configuration getNumberIdManagerConfiguration() {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER, TinkerGraph.DefaultIdManager.INTEGER.name());
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER, TinkerGraph.DefaultIdManager.INTEGER.name());
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER, TinkerGraph.DefaultIdManager.LONG.name());
    return conf;
}
 
Example 15
Project: tinkergraph-gremlin   File: TinkerIoRegistryV1d0.java   Source Code and License Vote up 5 votes
@Override
public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list");
    final TinkerGraph graph = TinkerGraph.open(conf);
    final int len = input.readInt();
    final byte[] bytes = input.readBytes(len);
    try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) {
        GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph);
    } catch (Exception io) {
        throw new RuntimeException(io);
    }

    return graph;
}
 
Example 16
Project: gremzeppelin   File: GremlinInterpreter.java   Source Code and License Vote up 5 votes
@Override
public void open() {
    logger.info("init gremlin client via {}", property);
    Configuration configuration = new BaseConfiguration();
    property.keySet().forEach(key -> configuration.setProperty(key.toString(), property.get(key)));
    //transform hosts
    String hosts = configuration.getString(GREMLIN_SERVER_HOSTS, DEFAULT_GREMLIN_SERVER_HOSTS);
    configuration.clearProperty(GREMLIN_SERVER_HOSTS);
    configuration.setProperty(GREMLIN_SERVER_HOSTS, Arrays.asList(hosts.split(",")));

    cluster = Cluster.open(configuration.subset("gremlin.server"));
    client = cluster.connect();
}
 
Example 17
Project: tinkergraph-gremlin   File: TinkerIoRegistryV2d0.java   Source Code and License Vote up 5 votes
@Override
public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list");
    final TinkerGraph graph = TinkerGraph.open(conf);
    final int len = input.readInt();
    final byte[] bytes = input.readBytes(len);
    try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) {
        GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph);
    } catch (Exception io) {
        throw new RuntimeException(io);
    }

    return graph;
}
 
Example 18
Project: incubator-servicecomb-java-chassis   File: ConfigUtil.java   Source Code and License Vote up 4 votes
private static void setMicroserviceConfigLoader(Configuration config, MicroserviceConfigLoader loader) {
  config.setProperty(MICROSERVICE_CONFIG_LOADER_KEY, loader);
}
 
Example 19
Project: tinkergraph-gremlin   File: TinkerGraphTest.java   Source Code and License Vote up 4 votes
@Test(expected = IllegalStateException.class)
public void shouldRequireGraphLocationIfFormatIsSet() {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "graphml");
    TinkerGraph.open(conf);
}
 
Example 20
Project: tinkergraph-gremlin   File: TinkerGraphTest.java   Source Code and License Vote up 4 votes
@Test(expected = IllegalStateException.class)
public void shouldRequireGraphFormatIfLocationIsSet() {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, TestHelper.makeTestDataDirectory(TinkerGraphTest.class));
    TinkerGraph.open(conf);
}