Skip to content

Instantly share code, notes, and snippets.

@johnllao
johnllao / Launcher.java
Created May 5, 2016 09:04
Embedded Tomcat
package quickweb;
import javax.servlet.ServletException;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
public class Launcher {
public static void main(String[] args) {
package quickhttp;
import com.sun.net.httpserver.HttpContext;
public interface QuickHandler {
byte[] handle(final HttpContext ctx);
}
@johnllao
johnllao / HelpApi.java
Created January 16, 2016 07:13
Jersey REST Sample
package org.hello.web.api;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import org.hello.web.models.Result;
@Path("/help")
public class HelpApi {
@GET
@johnllao
johnllao / HelloProto.java
Created November 5, 2015 04:25
Protobuf Descriptor and Dynamic Messages
package org.hello.protobuf;
import java.util.Map;
import com.google.protobuf.*;
import com.google.protobuf.Descriptors.*;
import com.google.protobuf.DescriptorProtos.*;
public class HelloProto {
@johnllao
johnllao / ApplicationConfig.java
Created October 7, 2015 15:04
REST Tomcat + Jersey
package org.hello.tomcat;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
package org.hello.tomcat.servlets;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
package org.hello.tomcat.data;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
package org.hello.kafka;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import org.apache.kafka.clients.producer.KafkaProducer;
package org.hello.derby;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class HelloDerby {
public static void main(String[] args) {
package org.hello.avro;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.generic.GenericRecord;