Netty and Vert.x logging

      InternalLoggerFactory.setDefaultFactory(Log4J2LoggerFactory.INSTANCE);

      NetServerOptions nsoptions = new NetServerOptions().setLogActivity(true);
      NetServer server = vertx.createNetServer(nsoptions);

      NetClientOptions ncoptions = new NetClientOptions().setLogActivity(true);
      NetClient client = vertx.createNetClient(ncoptions);      

Tags: #netty #vertx #vert.x #logging

14-Feb-2017

Neo4j Browser configuration for Spring Boot with embedded Neo4j

Add these dependencies to pom.xml:

    <dependency>
        <groupId>org.neo4j.app</groupId>
        <artifactId>neo4j-server</artifactId>
        <version>2.3.6</version>
    </dependency>
    <dependency>
        <groupId>org.neo4j.app</groupId>
        <artifactId>neo4j-server</artifactId>
        <version>2.3.6</version>
        <classifier>static-web</classifier>
    </dependency>

Invoke this method,

    @SuppressWarnings("deprecation")
    public void neo4jBrowser() {
        EmbeddedDriver embeddedDriver = (EmbeddedDriver) Components.driver();
        GraphDatabaseService gdb = embeddedDriver.getGraphDatabaseService();
        try {
            WrappingNeoServerBootstrapper neoServerBootstrapper;
            GraphDatabaseAPI api = (GraphDatabaseAPI) gdb;

            ServerConfigurator config = new ServerConfigurator(api);
            config.configuration()
                .addProperty(Configurator.WEBSERVER_ADDRESS_PROPERTY_KEY, "127.0.0.1");
            config.configuration()
                .addProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY, "8686");

            neoServerBootstrapper = new WrappingNeoServerBootstrapper(api, config);
            neoServerBootstrapper.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

I do this from

    @EventListener
    public void onApplicationEvent(ContextRefreshedEvent event) {
        neo4j.neo4jBrowser();

Tags: #spring-boot #spring-data-neo4j

26-Aug-2016

FTP Maven artifact to Sharefile

To ftp a Maven artifact to Sharefile use Wagon and the Wagon plugin: pom.xml

  <distributionManagement>
    <repository>
      <id>ftp-repository</id>
      <url>ftp://newrelic.sharefileftp.com</url>
    </repository>
  </distributionManagement>

  <build>
    <extensions>
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ftp</artifactId>
        <version>2.10</version>
      </extension>
    </extensions>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>wagon-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <id>upload-assembly</id>
            <phase>install</phase>
            <goals>
              <goal>upload-single</goal>
            </goals>
            <configuration>
              <serverId>sharefile-ftp</serverId>
              <fromFile>${project.build.directory}/${project.build.finalName}.jar</fromFile>
              <url>ftp://*organization*.sharefileftp.com/*full*path*to*subdirectory/</url>
              <toDir>/</toDir>
            </configuration>
          </execution>
        </executions>
      </plugin>

settings.xml

<settings>
    <servers>
        <server>
            <id>sharefile-ftp</id>
            <username></username>
            <password></password>
        </server>
    </servers>
</settings>

mvn install will then ftp the file to Sharefile.

Sharefile config information is found in your Sharefile account under My Settings -> FTP Settings.

11-Aug-2016

POST Form data with Spring RestTemplate

Simulates a browser Form submit (POST).

      RestTemplate rest = new RestTemplate();
      List<HttpMessageConverter<?>> converters = new ArrayList<>(2);
      converters.add(new FormHttpMessageConverter());
      converters.add(new StringHttpMessageConverter());
      rest.setMessageConverters(converters);

      // Form data goes into the map
      MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
      map.add("firstName", getFirstName());
      map.add("lastName", getLastName());
      map.add("departureCity", getCity().getId().toString());
      Date departureDate = getDateAfter(new Date());
      map.add("departureDate", departureDate.toString());
      map.add("arrivalCity", getCity().getId().toString());
      map.add("returnDate", getDateAfter(departureDate).toString());

      String result = rest.postForObject("http://localhost:8080/reserve", map, String.class);

18-Jul-2016

Minimal standalone Spring Boot application

@SpringBootApplication
public class AnApplication {

   public static void main(String[] args) {
      ConfigurableApplicationContext ctx = SpringApplication.run(AnApplication.class, args);
      AnApplication main = ctx.getBean(AnApplication.class);
      main.init();
   }

   private void init() {
   }
}

15-Jul-2016

Spring @Value default values

@Value(${"someProperty:<defaultValue>"}

15-Jul-2016

Adding the New Relic Agent to a Spring Boot project

Add this to your pom.xml

<dependency>
    <groupId>com.newrelic.agent.java</groupId>
    <artifactId>newrelic-agent</artifactId>
    <version>${newrelic.agent.version}</version>
</dependency>
...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifestEntries>
                <Premain-Class>com.newrelic.bootstrap.BootstrapAgent</Premain-Class>
                <Can-Redefine-Classes>true</Can-Redefine-Classes>
                <Can-Retransform-Classes>true</Can-Retransform-Classes>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>
mvn clean install spring-boot:run -Drun.jvmArguments="-javaagent:./target/<your-jar>.jar -Dnewrelic.config.file=./target/classes/newrelic.yml -Dnewrelic.config.app_name=<your-app-name>"

15-Jul-2016

GitHub Flavored Markdown

Documentation

Support