mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-18 01:06:03 +10:00
Merge remote-tracking branch 'testweb/master' into merge
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
# testweb
|
||||
mvn clean eclipse:eclipse package dependency:copy-dependencies -Dmaven.test.skip
|
||||
@@ -0,0 +1,498 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.nhn.pinpoint</groupId>
|
||||
<artifactId>pinpoint-testweb</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<name>pinpoint test web</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<spring.version>3.2.3.RELEASE</spring.version>
|
||||
<slf4j.version>1.7.5</slf4j.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>nhn</id>
|
||||
<url>http://repo.nhncorp.com/maven2/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>cubrid.release.repository</id>
|
||||
<url>http://maven.cubrid.org</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!-- cookie run test -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpasyncclient</artifactId>
|
||||
<version>4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore-nio</artifactId>
|
||||
<version>4.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.3.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.nhncorp.lucy</groupId>
|
||||
<artifactId>lucy-npc</artifactId>
|
||||
<version>1.5.19</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>17.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ning</groupId>
|
||||
<artifactId>async-http-client</artifactId>
|
||||
<version>1.8.3</version>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>com.nhncorp.lucy</groupId>
|
||||
<artifactId>lucy-rb-nimmconnector</artifactId>
|
||||
<version>1.0.2</version>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>com.nhncorp.lucy</groupId>
|
||||
<artifactId>lucy-nimmconnector</artifactId>
|
||||
<version>2.1.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Apache HTTP Client -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpasyncclient</artifactId>
|
||||
<version>4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore-nio</artifactId>
|
||||
<version>4.3</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.3.3</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<dependency>
|
||||
<groupId>arcus</groupId>
|
||||
<artifactId>arcus-spring</artifactId>
|
||||
<version>0.3.5</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>arcus-client</artifactId>
|
||||
<groupId>arcus</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<groupId>org.springframework</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>arcus</groupId>
|
||||
<artifactId>arcus-client</artifactId>
|
||||
<version>1.6.2.1</version>
|
||||
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>6.0.35</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.20</version>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>mysql</groupId>-->
|
||||
<!--<artifactId>mysql-connector-java</artifactId>-->
|
||||
<!--<version>3.1.11</version>-->
|
||||
<!--</dependency>-->
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.jtds</groupId>
|
||||
<artifactId>jtds</artifactId>
|
||||
<version>1.2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<version>1.4-p2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cubrid</groupId>
|
||||
<artifactId>cubrid-jdbc</artifactId>
|
||||
<version>8.4.3.1005</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>oracle</groupId>
|
||||
<artifactId>ojdbc6</artifactId>
|
||||
<version>11.2.0.3.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>oracle</groupId>-->
|
||||
<!--<artifactId>ojdbc6</artifactId>-->
|
||||
<!--<version>11.1.0.7.0</version>-->
|
||||
<!--<scope>provided</scope>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<!-- web -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>taglibs</groupId>
|
||||
<artifactId>standard</artifactId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ORM dependencies -->
|
||||
<dependency>
|
||||
<groupId>com.ibatis</groupId>
|
||||
<artifactId>ibatis2-sqlmap</artifactId>
|
||||
<version>2.3.4.726-p4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.2.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>1.2.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring depedencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-oxm</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-instrument</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aop</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aspects</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-orm</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Caching dependecies -->
|
||||
<dependency>
|
||||
<groupId>net.sf.ehcache</groupId>
|
||||
<artifactId>ehcache</artifactId>
|
||||
<version>1.6.2</version>
|
||||
</dependency>
|
||||
<!-- DBMS dependecies -->
|
||||
<dependency>
|
||||
<groupId>javax.transaction</groupId>
|
||||
<artifactId>jta</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
<!-- Logging depedencies -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- commons-logging-adapter -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.16</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Test dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.8.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dbunit</groupId>
|
||||
<artifactId>dbunit</artifactId>
|
||||
<version>2.4.3</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- AspectJ dependencies -->
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib-nodep</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>1.6.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>1.6.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>1.4.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${basedir}/src/main/java</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>${basedir}/src/test/java</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</testResource>
|
||||
<testResource>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/test/resources</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<configuration>
|
||||
<downloadSources>true</downloadSources>
|
||||
<downloadJavadocs>true</downloadJavadocs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<inherited>true</inherited>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<debug>true</debug>
|
||||
<optimize>true</optimize>
|
||||
<encoding>UTF-8</encoding>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/Abstract*</exclude>
|
||||
<exclude>**/*$*</exclude>
|
||||
<exclude>**/TestInterceptor*.java</exclude>
|
||||
<exclude>**/Mock*.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.tomcat.maven</groupId>
|
||||
<artifactId>tomcat6-maven-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<path>/</path>
|
||||
<!--<additionalClassesDirs>-->
|
||||
<!--<additionalClasspathDir>${basedir}/target/classes</additionalClasspathDir>-->
|
||||
<!--</additionalClassesDirs>-->
|
||||
<warSourceDirectory>src/main/webapp</warSourceDirectory>
|
||||
<port>20330</port>
|
||||
<fork>true</fork>
|
||||
<uriEncoding>utf-8</uriEncoding>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-tomcat</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-tomcat</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>shutdown</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
package com.linecorp.games.common.baseFramework.handlers;
|
||||
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.isKeepAlive;
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONNECTION;
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH;
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.COOKIE;
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.SET_COOKIE;
|
||||
import static org.jboss.netty.handler.codec.http.HttpResponseStatus.OK;
|
||||
import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.spy.memcached.ArcusClient;
|
||||
import net.spy.memcached.ConnectionFactoryBuilder;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBuffers;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.ChannelFutureListener;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.ExceptionEvent;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
|
||||
import org.jboss.netty.handler.codec.http.Cookie;
|
||||
import org.jboss.netty.handler.codec.http.CookieDecoder;
|
||||
import org.jboss.netty.handler.codec.http.CookieEncoder;
|
||||
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders;
|
||||
import org.jboss.netty.handler.codec.http.HttpMethod;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.jboss.netty.handler.codec.http.HttpVersion;
|
||||
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
|
||||
import org.jboss.netty.util.CharsetUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.convert.ConverterNotFoundException;
|
||||
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.nhn.pinpoint.testweb.connector.ningasync.NingAsyncHttpClient;
|
||||
import com.ning.http.client.Response;
|
||||
|
||||
public class HttpCustomServerHandler extends SimpleChannelUpstreamHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(HttpCustomServerHandler.class.getName());
|
||||
|
||||
private final ListeningExecutorService listeningExecutorService;
|
||||
|
||||
private final ArcusClient arcus;
|
||||
private final NingAsyncHttpClient asyncHttpInvoker = new NingAsyncHttpClient();
|
||||
|
||||
public HttpCustomServerHandler() {
|
||||
this.listeningExecutorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
|
||||
this.arcus = ArcusClient.createArcusClient("dev.arcuscloud.nhncorp.com:17288", "dev", new ConnectionFactoryBuilder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
|
||||
System.out.println("HttpCustomServerHandler.messageReceived (" + Thread.currentThread().getName() + ")");
|
||||
this.listeningExecutorService.submit(new InvokeTask(ctx, e));
|
||||
}
|
||||
|
||||
private void accessArcus() {
|
||||
Future<Boolean> future = null;
|
||||
try {
|
||||
future = arcus.set("pinpoint:test", 10, "Hello, Arcus");
|
||||
future.get(100L, TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
if (future != null) {
|
||||
future.cancel(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void accessNaver() {
|
||||
asyncHttpInvoker.requestGet("http://blog.naver.com", NingAsyncHttpClient.getDummyParams(), NingAsyncHttpClient.getDummyHeaders(), NingAsyncHttpClient.getDummyCookies());
|
||||
}
|
||||
|
||||
private void accessPinPointDev() {
|
||||
asyncHttpInvoker.requestGet("http://10.101.55.177:9080/threetier.pinpoint", null, null, null);
|
||||
}
|
||||
|
||||
private class InvokeTask implements Runnable {
|
||||
private final ChannelHandlerContext ctx;
|
||||
private final MessageEvent e;
|
||||
|
||||
public InvokeTask(ChannelHandlerContext ctx, MessageEvent e) {
|
||||
this.ctx = ctx;
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
System.out.println("InvokeTask.run (" + Thread.currentThread().getName() + ")");
|
||||
|
||||
if (!(e.getMessage() instanceof HttpRequest)) {
|
||||
logger.debug("[n/a] received message is illegal.");
|
||||
DefaultHttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST);
|
||||
ctx.getChannel().write(res).addListener(ChannelFutureListener.CLOSE);
|
||||
return;
|
||||
}
|
||||
|
||||
HttpRequest request = (HttpRequest) e.getMessage();
|
||||
|
||||
// intercept
|
||||
|
||||
try {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
// this.request = (HttpRequest) e.getMessage();
|
||||
Object[] requestBody = null;
|
||||
Object functionsResult = null;
|
||||
|
||||
HttpResponseStatus status = OK;
|
||||
String uri = request.getUri().substring(1);
|
||||
|
||||
// List<Entry<String, String>> headers = request.getHeaders();
|
||||
List<Entry<String, String>> reponseHeader = new ArrayList<Entry<String, String>>();
|
||||
|
||||
buf.setLength(0);
|
||||
|
||||
HttpMethod reqMethod = request.getMethod();
|
||||
if (reqMethod.equals(HttpMethod.POST) || reqMethod.equals(HttpMethod.PUT) || reqMethod.equals(HttpMethod.DELETE)) {
|
||||
ChannelBuffer content = request.getContent();
|
||||
|
||||
// invoke bo (async ??)
|
||||
|
||||
buf.append("HelloNetty");
|
||||
|
||||
if (content.readable()) {
|
||||
try {
|
||||
|
||||
} catch (ConverterNotFoundException e1) {
|
||||
status = HttpResponseStatus.BAD_REQUEST;
|
||||
logger.error("convert fail : exception={}", e1.getMessage());
|
||||
buf.append(getResultString(status.getCode(), "Invalid parameter"));
|
||||
}
|
||||
} else {
|
||||
status = HttpResponseStatus.BAD_REQUEST;
|
||||
buf.append(getResultString(status.getCode(), "No content on request."));
|
||||
}
|
||||
} else if (reqMethod.equals(HttpMethod.GET)) {
|
||||
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri);
|
||||
Map<String, List<String>> queries = queryStringDecoder.getParameters();
|
||||
|
||||
buf.append("HelloNetty");
|
||||
|
||||
} else {
|
||||
status = HttpResponseStatus.METHOD_NOT_ALLOWED;
|
||||
buf.append(getResultString(status.getCode(), "method not supports"));
|
||||
}
|
||||
|
||||
// for demo
|
||||
accessArcus();
|
||||
accessNaver();
|
||||
accessPinPointDev();
|
||||
|
||||
writeResponse(request, e, status, reponseHeader, buf);
|
||||
} catch (Exception ex) {
|
||||
handleException(request, this.ctx, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeResponse(HttpRequest request, MessageEvent e, HttpResponseStatus status, List<Entry<String, String>> reponseHeader, StringBuilder resultContents) {
|
||||
// Decide whether to close the connection or not.
|
||||
boolean keepAlive = isKeepAlive(request);
|
||||
|
||||
// Build the response object.
|
||||
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
|
||||
|
||||
response.setContent(ChannelBuffers.copiedBuffer(resultContents.toString(), CharsetUtil.UTF_8));
|
||||
|
||||
// response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
|
||||
response.setHeader(CONTENT_TYPE, "application/json");
|
||||
|
||||
response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
|
||||
if (keepAlive) {
|
||||
response.setHeader(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
|
||||
}
|
||||
|
||||
for (Entry<String, String> header : reponseHeader) {
|
||||
response.setHeader(header.getKey(), header.getValue());
|
||||
}
|
||||
|
||||
// Encode the cookie.
|
||||
String cookieString = request.getHeader(COOKIE);
|
||||
if (cookieString != null) {
|
||||
CookieDecoder cookieDecoder = new CookieDecoder();
|
||||
Set<Cookie> cookies = cookieDecoder.decode(cookieString);
|
||||
if (!cookies.isEmpty()) {
|
||||
CookieEncoder cookieEncoder = new CookieEncoder(true);
|
||||
for (Cookie cookie : cookies) {
|
||||
cookieEncoder.addCookie(cookie);
|
||||
response.addHeader(SET_COOKIE, cookieEncoder.encode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ChannelFuture future = e.getChannel().write(response);
|
||||
|
||||
if (!keepAlive) {
|
||||
future.addListener(ChannelFutureListener.CLOSE);
|
||||
} else
|
||||
future.addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
|
||||
}
|
||||
|
||||
private String stackTraceToStr(Throwable e) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
|
||||
|
||||
Channel channel = ctx.getChannel();
|
||||
if (channel.isOpen()) {
|
||||
|
||||
logger.error("channel error : exception={}", e);
|
||||
channel.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void handleException(HttpRequest request, ChannelHandlerContext ctx, Exception e) {
|
||||
Channel channel = ctx.getChannel();
|
||||
if (channel.isOpen()) {
|
||||
String body = request.getContent().readable() ? new String(request.getContent().array()) : "";
|
||||
String cause = stackTraceToStr(e.getCause());
|
||||
|
||||
logger.error("exceptionCaught : method={} \r\nURI={}, \r\nheaders={}, \r\nbody={}, \r\ncauseBy={}", request.getMethod().getName(), request.getUri(), request.getHeaders(), body, cause);
|
||||
|
||||
if (channel.isWritable() && !(e.getCause() instanceof java.io.IOException)) {
|
||||
|
||||
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
|
||||
|
||||
response.setHeader(CONTENT_TYPE, "application/json; charset=UTF-8");
|
||||
response.setContent(ChannelBuffers.copiedBuffer(this.getResultString(500, "Internal Server Error", e.getCause().toString()), CharsetUtil.UTF_8));
|
||||
|
||||
channel.write(response);
|
||||
|
||||
String uri = request.getUri().substring(1);
|
||||
HttpMethod reqMethod = request.getMethod();
|
||||
|
||||
}
|
||||
channel.close();
|
||||
}
|
||||
}
|
||||
|
||||
private String getResultString(int statusCode, String message) {
|
||||
return String.format("{\"statusCode\":%s,\"statusMessage\":\"%s\"}", statusCode, message);
|
||||
}
|
||||
|
||||
private String getResultString(int statusCode, String message, String cause) {
|
||||
return String.format("{\"statusCode\":%s,\"statusMessage\":\"%s\",\"causeBy\":\"%s\"}", statusCode, message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.linecorp.games.common.baseFramework.handlers;
|
||||
|
||||
public class SimpleApp {
|
||||
public static void main(String[] args) throws Exception {
|
||||
HttpCustomServerHandler handler = new HttpCustomServerHandler();
|
||||
System.out.println(handler);
|
||||
handler.messageReceived(null, null);
|
||||
System.out.println("Hello PinPoint!---------");
|
||||
Thread.sleep(1000L);
|
||||
System.out.println("Hello PinPoint!=============");
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package com.linecorp.games.common.baseFramework.handlers;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jboss.netty.bootstrap.ServerBootstrap;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelPipelineFactory;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
|
||||
import org.jboss.netty.handler.codec.http.HttpContentCompressor;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nhn.pinpoint.testweb.connector.ningasync.NingAsyncHttpClient;
|
||||
import com.ning.http.client.Response;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* line game의 netty server lib을 참조해서 만든 서버 프로토타입
|
||||
*
|
||||
* vm options for test
|
||||
* -javaagent:/Users/netspider/Documents/workspace_pinpoint/pinpoint-testbed/agent/pinpoint-bootstrap-1.0.2-SNAPSHOT.jar -Dpinpoint.agentId=netty.test.1 -Dpinpoint.applicationName=NETTY-HTTP-SERVER
|
||||
* </pre>
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public class SimpleNettyServerApp {
|
||||
|
||||
static final Logger logger = LoggerFactory.getLogger(SimpleNettyServerApp.class);
|
||||
static final int SERVER_PORT = 2222;
|
||||
static final int CLIENT_COUNT = 1;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
logger.info("TEST BEGIN");
|
||||
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
|
||||
PipelineFactory factory = new PipelineFactory();
|
||||
bootstrap.setPipelineFactory(factory);
|
||||
bootstrap.bind(new InetSocketAddress(SERVER_PORT));
|
||||
|
||||
final NingAsyncHttpClient invoker = new NingAsyncHttpClient();
|
||||
final CountDownLatch startLatch = new CountDownLatch(1);
|
||||
final CountDownLatch stopLatch = new CountDownLatch(CLIENT_COUNT);
|
||||
final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
for (int i = 0; i < CLIENT_COUNT; i++) {
|
||||
executor.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
startLatch.await();
|
||||
Response response = invoker.requestGet("http://localhost:" + SERVER_PORT, NingAsyncHttpClient.getDummyParams(), NingAsyncHttpClient.getDummyHeaders(), NingAsyncHttpClient.getDummyCookies());
|
||||
logger.info(response.getResponseBody());
|
||||
|
||||
Response response2 = invoker.requestPost("http://localhost:" + SERVER_PORT, NingAsyncHttpClient.getDummyHeaders(), "I_AM_BODY");
|
||||
logger.info(response2.getResponseBody());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
stopLatch.countDown();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
startLatch.countDown();
|
||||
stopLatch.await();
|
||||
|
||||
// bootstrap.shutdown();
|
||||
// executor.shutdown();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
logger.info("TEST END. awaiting other requests.");
|
||||
try {
|
||||
Thread.sleep(Long.MAX_VALUE);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PipelineFactory implements ChannelPipelineFactory {
|
||||
@Override
|
||||
public ChannelPipeline getPipeline() throws Exception {
|
||||
ChannelPipeline p = Channels.pipeline();
|
||||
p.addLast("decoder", new HttpRequestDecoder());
|
||||
p.addLast("aggregator", new HttpChunkAggregator(65535));
|
||||
p.addLast("encoder", new HttpResponseEncoder());
|
||||
p.addLast("deflater", new HttpContentCompressor());
|
||||
p.addLast("handler", new HttpCustomServerHandler());
|
||||
return p;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.nhn.pinpoint.testweb.configuration;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public abstract class DemoURLHolder {
|
||||
|
||||
public abstract String getBackendWebURL();
|
||||
|
||||
public abstract String getBackendApiURL();
|
||||
|
||||
public static DemoURLHolder getHolder() {
|
||||
try {
|
||||
String hostname = java.net.InetAddress.getLocalHost().getHostName();
|
||||
|
||||
if (hostname == null) {
|
||||
return new DemoURLHolderLocal();
|
||||
}
|
||||
|
||||
if (hostname.endsWith("nhnsystem.com")) {
|
||||
return new DemoURLHolderDev();
|
||||
} else {
|
||||
return new DemoURLHolderLocal();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new DemoURLHolderLocal();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.nhn.pinpoint.testweb.configuration;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public class DemoURLHolderDev extends DemoURLHolder {
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
private static final String[] BACKENDWEB_CALL_URL = {
|
||||
"http://dev-pinpoint-workload002.ncl:8080/backendweb.pinpoint",
|
||||
"http://dev-pinpoint-workload002.ncl:9080/backendweb.pinpoint"
|
||||
};
|
||||
|
||||
private static final String[] BACKENDAPI_CALL_URL = {
|
||||
"http://dev-pinpoint-workload003.ncl:8080/backendapi.pinpoint",
|
||||
"http://dev-pinpoint-workload003.ncl:9080/backendapi.pinpoint"
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getBackendWebURL() {
|
||||
return BACKENDWEB_CALL_URL[random.nextInt(BACKENDWEB_CALL_URL.length)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBackendApiURL() {
|
||||
return BACKENDAPI_CALL_URL[random.nextInt(BACKENDAPI_CALL_URL.length)];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.nhn.pinpoint.testweb.configuration;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public class DemoURLHolderLocal extends DemoURLHolder {
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
private static final String[] BACKENDWEB_CALL_URL = {
|
||||
"http://localhost:10080/backendweb.pinpoint",
|
||||
"http://localhost:11080/backendweb.pinpoint"
|
||||
};
|
||||
|
||||
private static final String[] BACKENDAPI_CALL_URL = {
|
||||
"http://localhost:12080/backendapi.pinpoint",
|
||||
"http://localhost:13080/backendapi.pinpoint"
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getBackendWebURL() {
|
||||
return BACKENDWEB_CALL_URL[random.nextInt(BACKENDWEB_CALL_URL.length)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBackendApiURL() {
|
||||
return BACKENDAPI_CALL_URL[random.nextInt(BACKENDAPI_CALL_URL.length)];
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package com.nhn.pinpoint.testweb.connector.apachehttp4;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.Consts;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
|
||||
import org.apache.http.impl.nio.client.HttpAsyncClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author netspider
|
||||
*/
|
||||
@Component
|
||||
public class ApacheClosableAsyncHttpClient {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ApacheClosableAsyncHttpClient.class);
|
||||
|
||||
private final CloseableHttpAsyncClient httpClient;
|
||||
|
||||
public ApacheClosableAsyncHttpClient() {
|
||||
this.httpClient = HttpAsyncClients.custom().useSystemProperties().build();
|
||||
this.httpClient.start();
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void close() {
|
||||
try {
|
||||
this.httpClient.close();
|
||||
} catch (IOException e) {
|
||||
logger.warn("CloseableHttpAsyncClient close error Caused:" + e.getCause(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public String post() {
|
||||
try {
|
||||
HttpPost httpRequest = new HttpPost("http://dev.pinpoint.nhncorp.com/");
|
||||
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new BasicNameValuePair("param1", "value1"));
|
||||
httpRequest.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8.name()));
|
||||
|
||||
Future<HttpResponse> responseFuture = this.httpClient.execute(httpRequest, null);
|
||||
HttpResponse response = (HttpResponse) responseFuture.get();
|
||||
|
||||
String result = null;
|
||||
if ((response != null) && (response.getEntity() != null)) {
|
||||
try {
|
||||
InputStream is = response.getEntity().getContent();
|
||||
result = IOUtils.toString(is);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.nhn.pinpoint.testweb.connector.apachehttp4;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.ResponseHandler;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.BasicResponseHandler;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.SingleClientConnManager;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class ApacheHttpClient4 {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public final static int SLOW_REQUEST_TIME = 1000;
|
||||
|
||||
private HttpConnectorOptions connectorOptions;
|
||||
|
||||
public ApacheHttpClient4() {
|
||||
this(new HttpConnectorOptions());
|
||||
}
|
||||
|
||||
public ApacheHttpClient4(HttpConnectorOptions connectorOptions) {
|
||||
this.connectorOptions = connectorOptions;
|
||||
}
|
||||
|
||||
private HttpClient getHttpClient(HttpParams params) {
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||
if (connectorOptions != null && connectorOptions.getPort() > 0) {
|
||||
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), connectorOptions.getPort()));
|
||||
}
|
||||
schemeRegistry.register(new Scheme("https", PlainSocketFactory.getSocketFactory(), 443));
|
||||
|
||||
SingleClientConnManager cm = new SingleClientConnManager(getHttpParams(), schemeRegistry);
|
||||
DefaultHttpClient httpClient = new DefaultHttpClient(cm, getHttpParams());
|
||||
httpClient.setParams(params);
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
public String execute(String uri, Map<String, Object> paramMap, String cookie) {
|
||||
if (null == uri) {
|
||||
return null;
|
||||
}
|
||||
|
||||
HttpClient httpClient = null;
|
||||
try {
|
||||
HttpPost post = new HttpPost(uri);
|
||||
if (cookie != null) {
|
||||
post.setHeader("Cookie", cookie);
|
||||
}
|
||||
post.setEntity(getEntity(paramMap));
|
||||
post.setParams(getHttpParams());
|
||||
post.addHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
|
||||
ResponseHandler<String> responseHandler = new BasicResponseHandler();
|
||||
|
||||
httpClient = getHttpClient(getHttpParams());
|
||||
|
||||
return httpClient.execute(post, responseHandler);
|
||||
} catch (Exception e) {
|
||||
logger.warn("HttpClient.execute() error. Caused:{}", e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
} finally {
|
||||
if (null != httpClient && null != httpClient.getConnectionManager()) {
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String execute(String uri, Map<String, Object> paramMap) {
|
||||
return execute(uri, paramMap, null);
|
||||
}
|
||||
|
||||
public int executeToBlocWithReturnInt(String uri, Map<String, Object> paramMap) {
|
||||
if (null == uri) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
String responseBody = null;
|
||||
HttpClient httpClient = null;
|
||||
try {
|
||||
HttpPost post = new HttpPost(uri);
|
||||
post.setEntity(getEntity(paramMap));
|
||||
post.setParams(getHttpParams());
|
||||
post.addHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
|
||||
ResponseHandler<String> responseHandler = new BasicResponseHandler();
|
||||
|
||||
httpClient = getHttpClient(getHttpParams());
|
||||
|
||||
responseBody = httpClient.execute(post, responseHandler);
|
||||
|
||||
return Integer.parseInt(responseBody);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
} finally {
|
||||
if (null != httpClient && null != httpClient.getConnectionManager()) {
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private HttpEntity getEntity(Map<String, Object> paramMap) throws UnsupportedEncodingException {
|
||||
if (paramMap.size() != 0) {
|
||||
// size가 0일때 호출하면 entity에 {}가 들어감.
|
||||
return new StringEntity(paramMap.toString(), "UTF-8");
|
||||
} else {
|
||||
return new StringEntity("", "UTF-8");
|
||||
}
|
||||
}
|
||||
|
||||
private HttpParams getHttpParams() {
|
||||
HttpParams params = new BasicHttpParams();
|
||||
HttpConnectionParams.setConnectionTimeout(params, (int) connectorOptions.getConnectionTimeout());
|
||||
HttpConnectionParams.setSoTimeout(params, connectorOptions.getSoTimeout());
|
||||
params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");
|
||||
params.setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, "UTF-8");
|
||||
return params;
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package com.nhn.pinpoint.testweb.connector.apachehttp4;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public class HttpConnectorOptions {
|
||||
private String host;
|
||||
private int port;
|
||||
private int callTimeout;
|
||||
private int connectionTimeout;
|
||||
private int soTimeout;
|
||||
private Charset charset;
|
||||
private String modulePath;
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public int getCallTimeout() {
|
||||
return callTimeout;
|
||||
}
|
||||
|
||||
public void setCallTimeout(int callTimeout) {
|
||||
this.callTimeout = callTimeout;
|
||||
}
|
||||
|
||||
public int getConnectionTimeout() {
|
||||
return connectionTimeout;
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(int connectionTimeout) {
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
}
|
||||
|
||||
public int getSoTimeout() {
|
||||
return soTimeout;
|
||||
}
|
||||
|
||||
public void setSoTimeout(int soTimeout) {
|
||||
this.soTimeout = soTimeout;
|
||||
}
|
||||
|
||||
public Charset getCharset() {
|
||||
return charset;
|
||||
}
|
||||
|
||||
public void setCharset(Charset charset) {
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
public String getModulePath() {
|
||||
return modulePath;
|
||||
}
|
||||
|
||||
public void setModulePath(String modulePath) {
|
||||
this.modulePath = modulePath;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
/*
|
||||
* @(#)HttpUtil.java $version 2011. 12. 14.
|
||||
*
|
||||
* Copyright 2007 NHN Corp. All rights Reserved.
|
||||
* NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
||||
*/
|
||||
|
||||
package com.nhn.pinpoint.testweb.connector.apachehttp4.nhnent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.SingleClientConnManager;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
||||
/**
|
||||
* 간편하게 http데이터를 가져올 수 있는 클래스<br/>
|
||||
* <br/>
|
||||
* 사용법은, <br/>
|
||||
* HttpUtil.url(String url).call(); <br/>
|
||||
* 이 기본이다.<br/>
|
||||
* 이렇게 호출을 하면, GET방식으로 해당 url을 호출하게 되며, 다른 옵션들은 url()과 call()사이에 넣어주면 된다<br/>
|
||||
* .<br/>
|
||||
* 최대 사용할 수 있는 파라메터는 다음과 같으며<br/>
|
||||
* HttpUtil.url(String
|
||||
* url).method(Method.POST).charset("EUC-KR").passSSLError(true
|
||||
* ).connectionTimeout(1000).readTimeout(1000).call();<br/>
|
||||
* 이중에서 자신이 원하는 파라메터들만 선택해서 사용할 수 있다.<br/>
|
||||
* 반드시 url()이 맨 먼저 와야 하고, call()이 맨 뒤에 와야 하며, 그외 다른 옵션들은 순서에 관계 없다.<br/>
|
||||
* <br/>
|
||||
* 각 옵션들의 디폴트 값은 다음과 같다.<br/>
|
||||
* method : Method.GET<br/>
|
||||
* charset : 페이지 기본값<br/>
|
||||
* passSSLError : false<br/>
|
||||
* connectionTimeout : 0 (JRE기본값)<br/>
|
||||
* readTimeout : 0 (무제한)<br/>
|
||||
*
|
||||
* @author Xenos
|
||||
*/
|
||||
public class HttpUtil {
|
||||
private static Charset defaultCharset = Charset.forName("UTF-8");
|
||||
private static X509TrustManager IgnoreSLLErrorTrustManager = new X509TrustManager() {
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] ax509certificate, String s) throws CertificateException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] ax509certificate, String s) throws CertificateException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* HttpUtil이 지원하는 Method
|
||||
*
|
||||
* @author Xenos
|
||||
*/
|
||||
public enum Method {
|
||||
GET, POST
|
||||
};
|
||||
|
||||
/**
|
||||
* Static Util 클래스이므로, 생성자 막음
|
||||
*/
|
||||
private HttpUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* HttpUtil을 사용하기 위해서 최초로 호출해야 하는 함수 이 함수는 Parameters를 반환한다.
|
||||
*
|
||||
* @param theURL
|
||||
* 호출하고자 하는 URL
|
||||
* @return HttpUtil을 이용할 수 있는 파라메터들을 담고 있는 Parameters 클래스
|
||||
* @throws WrongParameterException
|
||||
* theURL에 null이 들어왔을 경우 발생하는 Exception
|
||||
*/
|
||||
public static Parameters url(String theURL) throws HttpUtilException {
|
||||
return new Parameters(theURL);
|
||||
}
|
||||
|
||||
/**
|
||||
* theURL로 http(s)연결을 하여 응답값의 내용을 반환한다. JSON 형태의 파라미터로 요청하기 위한 method
|
||||
*
|
||||
* @param theURL
|
||||
* 연결할 http(s) 주소
|
||||
* @param method
|
||||
* GET/POST
|
||||
* @param charset
|
||||
* 응답값의 charset(null이면 페이지 기본값)
|
||||
* @param passSSLError
|
||||
* SSL오류를 무시할지 여부
|
||||
* @param connectionTimeout
|
||||
* 접속 제한시간 (0이면 JRE 기본값)
|
||||
* @param readTimeout
|
||||
* 데이터를 받아오는데 제한시간 (0이면 무제한)
|
||||
* @param jsonEntity
|
||||
* 넘겨주고자 하는 String 요소값
|
||||
* @return 결과값의 InputStreamReader형태
|
||||
* @throws HttpUtilException
|
||||
*/
|
||||
static InputStreamReader callUrl(String theURL, Method method, Charset charset, boolean passSSLError, int connectionTimeout, int readTimeout, String jsonEntity, Map<String, String> header) throws HttpUtilException {
|
||||
|
||||
// 타임아웃을 설정
|
||||
HttpParams params = new BasicHttpParams();
|
||||
HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
|
||||
HttpConnectionParams.setSoTimeout(params, readTimeout);
|
||||
|
||||
HttpClient httpClient;
|
||||
|
||||
// SSL 오류 우회하는 설정
|
||||
if (passSSLError) {
|
||||
// 포트 번호를 추출
|
||||
int sslPort = getPortFromURL(theURL);
|
||||
|
||||
try {
|
||||
SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||
sslContext.init(null, new TrustManager[] { IgnoreSLLErrorTrustManager }, new SecureRandom());
|
||||
SSLSocketFactory sf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
Scheme httpsScheme = new Scheme("https", sslPort, sf);
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(httpsScheme);
|
||||
|
||||
ClientConnectionManager conman = new SingleClientConnManager(schemeRegistry);
|
||||
|
||||
httpClient = new DefaultHttpClient(conman, params);
|
||||
} catch (NoSuchAlgorithmException en) {
|
||||
throw new HttpUtilException(en.toString(), en);
|
||||
} catch (KeyManagementException ek) {
|
||||
throw new HttpUtilException(ek.toString(), ek);
|
||||
}
|
||||
} else {
|
||||
httpClient = new DefaultHttpClient(params);
|
||||
}
|
||||
|
||||
HttpRequestBase request = null;
|
||||
|
||||
try {
|
||||
// Method를 결정
|
||||
switch (method) {
|
||||
case GET:
|
||||
request = new HttpGet(theURL);
|
||||
break;
|
||||
case POST:
|
||||
String[] splitURL = StringUtils.split(theURL, "?", 2);
|
||||
|
||||
HttpPost requestPost = new HttpPost(splitURL[0]);
|
||||
|
||||
if (jsonEntity == null) {
|
||||
requestPost.setEntity(makeFormEntity(splitURL.length < 2 ? null : splitURL[1], charset));
|
||||
} else {
|
||||
requestPost.setEntity(new StringEntity(jsonEntity, "application/json", "UTF-8"));
|
||||
requestPost.addHeader("Content-Type", "application/json");
|
||||
requestPost.addHeader("accept", "text/plain, application/json");
|
||||
}
|
||||
|
||||
request = requestPost;
|
||||
break;
|
||||
}
|
||||
|
||||
// 헤더를 추가
|
||||
if (header != null && header.size() > 0) {
|
||||
Set<Entry<String, String>> entrySet = header.entrySet();
|
||||
for (Entry<String, String> entry : entrySet) {
|
||||
request.addHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
HttpResponse response = httpClient.execute(request);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
|
||||
if (statusCode < 200 || statusCode >= 300) {
|
||||
throw new HttpUtilException(response.getStatusLine().getStatusCode() + ":" + response.getStatusLine().getReasonPhrase());
|
||||
}
|
||||
|
||||
// HTML문서의 charset을 가져온다. 만약에 사용자가 charset을 지정 하였다면, 해당 charset으로 변경
|
||||
Charset encodingCharset = null;
|
||||
try {
|
||||
Header contentEncoding = response.getEntity().getContentEncoding();
|
||||
if (contentEncoding != null) {
|
||||
encodingCharset = Charset.forName(contentEncoding.getValue());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 오류따윈 무시함
|
||||
}
|
||||
|
||||
// 지정된 캐릭터셋이 있으면 설정
|
||||
if (charset != null) {
|
||||
encodingCharset = charset;
|
||||
}
|
||||
|
||||
// 케리터셋이 결정되지 않았다면, 디폴트
|
||||
if (encodingCharset == null) {
|
||||
encodingCharset = defaultCharset;
|
||||
}
|
||||
|
||||
return new InputStreamReader(response.getEntity().getContent(), encodingCharset);
|
||||
} catch (IOException e) {
|
||||
throw new HttpUtilException(e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 포트 번호 검색을 위한 urlPattern - 미리 컴파일 해둔다.
|
||||
*/
|
||||
private static Pattern urlPattern = Pattern.compile("^(https?):\\/\\/([^:\\/\\s]+)((:([^\\/]*))?(((\\/[^\\s/\\/]+)*)?\\/([^#\\s\\?]*)(\\?([^#\\s]*))?(#(\\w*))?)?)?$");
|
||||
|
||||
/**
|
||||
* url로부터 포트번호를 찾아서 반환한다.
|
||||
*
|
||||
* @param url
|
||||
* 포트번호를 찾을 url
|
||||
* @return 포트번호
|
||||
*/
|
||||
private static int getPortFromURL(String url) {
|
||||
int returnPort = 80;
|
||||
|
||||
try {
|
||||
// url처음이 http로 시작하지 않으면 http를 붙여준다.
|
||||
if (!url.toLowerCase().startsWith("http")) {
|
||||
url = "http://" + url;
|
||||
}
|
||||
|
||||
// 포트번호를 검색한다.
|
||||
Matcher match = urlPattern.matcher(url);
|
||||
|
||||
if (match.matches() && match.group(5) != null) {
|
||||
// 지정된 포트 번호가 있는 경우
|
||||
returnPort = Integer.parseInt(match.group(5));
|
||||
} else if (url.toLowerCase().startsWith("https://")) {
|
||||
// 지정된 포트는 없지만, https인 경우
|
||||
returnPort = 443;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
/* 오류시엔 기본포트(80)으로 반환한다. */
|
||||
}
|
||||
|
||||
return returnPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* url의 queryString을 잘라서, UrlEncodedFormEntity 형태로 반환한다.
|
||||
*
|
||||
* @param url
|
||||
* 데이터를 잘라낼 url
|
||||
* @return UrlEncodedFormEntity 형태로 변환된 데이터
|
||||
*/
|
||||
private static UrlEncodedFormEntity makeFormEntity(String queryString, Charset charset) {
|
||||
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
|
||||
|
||||
if (StringUtils.isNotEmpty(queryString)) {
|
||||
String[] data = queryString.split("&");
|
||||
|
||||
for (String aData : data) {
|
||||
String[] splitData = StringUtils.split(aData, "=", 2);
|
||||
|
||||
if (splitData.length < 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
postParams.add(new BasicNameValuePair(splitData[0].trim(), splitData[1].trim()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
if (charset != null) {
|
||||
return new UrlEncodedFormEntity(postParams, charset.toString());
|
||||
} else {
|
||||
return new UrlEncodedFormEntity(postParams);
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.nhn.pinpoint.testweb.connector.apachehttp4.nhnent;
|
||||
|
||||
/**
|
||||
* DUMMY
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public class HttpUtilException extends RuntimeException {
|
||||
public HttpUtilException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public HttpUtilException(String message, Throwable e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* @(#)Parameters.java $version 2012. 2. 3.
|
||||
*
|
||||
* Copyright 2007 NHN Corp. All rights Reserved.
|
||||
* NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
||||
*/
|
||||
|
||||
package com.nhn.pinpoint.testweb.connector.apachehttp4.nhnent;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpException;
|
||||
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.nhnent.HttpUtil.Method;
|
||||
|
||||
/**
|
||||
* HttpUtil에 들어가는 파라메터 클래스 HttpUtil을 보다 쉽게 사용하기 위해서 제공되는 클래스 외부에서 생성할 수 있는 방법은
|
||||
* 없고, HttpUtil.url()을 통해서만 생성할 수 있다.
|
||||
*
|
||||
* @author Xenos
|
||||
*/
|
||||
public class Parameters {
|
||||
private static final int READ_BUFFER_SIZE = 4096;
|
||||
|
||||
private String urlValue;
|
||||
private Method methodValue = Method.GET; /* default = GET */
|
||||
private Charset charsetValue = null; /* default = 페이지 기본값 */
|
||||
private boolean passSSLErrorValue = false; /* default = false */
|
||||
private int connectionTimeoutValue = 0; /* default = JRE기본값 */
|
||||
private int readTimeoutValue = 0; /* default = 무제한 */
|
||||
private String jsonEntityValue = null; /* jsonEntity */
|
||||
private Map<String, String> header = new HashMap<String, String>(); /*
|
||||
* 헤더내용
|
||||
* 추가
|
||||
*/
|
||||
|
||||
Parameters(String theURL) throws HttpUtilException {
|
||||
if (theURL == null) {
|
||||
throw new HttpUtilException("url have to be not null");
|
||||
}
|
||||
this.urlValue = theURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 호출할 Method를 선택<br/>
|
||||
* HttpUtil.Method의 값을 전달해야 한다.<br/>
|
||||
* <br/>
|
||||
* default : HttpUtil.Method.GET<br/>
|
||||
*
|
||||
* @param value
|
||||
* HttpUtil.Method 값
|
||||
* @return Parameters 클래스
|
||||
*/
|
||||
public Parameters method(Method value) {
|
||||
this.methodValue = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 호출할 페이지의 인코딩 방식을 결정한다.<br/>
|
||||
* default : null(페이지 기본값)
|
||||
*
|
||||
* @param value
|
||||
* 캐릭터셋
|
||||
* @return Parameters 클래스
|
||||
*/
|
||||
public Parameters charset(Charset value) {
|
||||
this.charsetValue = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 호출할때에, SSL오류를 무시할지 여부를 결정한다.<br/>
|
||||
* default : false<br/>
|
||||
* <br/>
|
||||
* 참고사항 : 이 값을 true로 설정하고, readTimeout을 함께 설정할 경우, timeout시에도
|
||||
* java.net.SocketTimeoutException: Read timed out 이 발생하지 않고,
|
||||
* javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated 가 발생하는
|
||||
* 문제가 있음<br/>
|
||||
*
|
||||
* @param value
|
||||
* true/false 값
|
||||
* @return Parameters 클래스
|
||||
*/
|
||||
public Parameters passSSLError(boolean value) {
|
||||
this.passSSLErrorValue = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 접속시 timeout을 설정한다.<br/>
|
||||
* default : 무제한<br/>
|
||||
*
|
||||
* @param value
|
||||
* 0 이상의 정수
|
||||
* @return Parameters 클래스
|
||||
* @throws HttpUtilException
|
||||
* 설정값이 0 이하인 경우
|
||||
*/
|
||||
public Parameters connectionTimeout(int value) throws HttpUtilException {
|
||||
if (value < 0) {
|
||||
throw new HttpUtilException("connectionTimeout");
|
||||
}
|
||||
this.connectionTimeoutValue = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 접속이 이루어진 후, 응답값을 기다리는 최대 시간을 설정한다.<br/>
|
||||
* default : 무제한<br/>
|
||||
*
|
||||
* @param value
|
||||
* 0 이상의 정수
|
||||
* @return Parameters 클래스
|
||||
* @throws HttpUtilException
|
||||
* 설정값이 0 이하인 경우
|
||||
*/
|
||||
public Parameters readTimeout(int value) throws HttpUtilException {
|
||||
if (value < 0) {
|
||||
throw new HttpUtilException("readTimeout");
|
||||
}
|
||||
this.readTimeoutValue = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* request에 추가할 헤더 기본적으로 헤더는 없음
|
||||
*
|
||||
* @param name
|
||||
* 헤더 이름
|
||||
* @param value
|
||||
* 헤더 값
|
||||
* @return Parameters 클래스
|
||||
* @throws HttpUtilException
|
||||
* name에 값이 없을 경우
|
||||
*/
|
||||
public Parameters addHeader(String name, String value) throws HttpUtilException {
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
throw new HttpUtilException("header");
|
||||
}
|
||||
this.header.put(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Parameters jsonEntity(String value) {
|
||||
this.jsonEntityValue = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 설정된 Parameters로 url을 호출한다.<br/>
|
||||
*
|
||||
* @return 해당 url의 응답값의 String 형태
|
||||
* @throws HttpException
|
||||
* http통신중 오류 발생시
|
||||
*/
|
||||
public String getContents() throws HttpUtilException {
|
||||
Writer writer = new StringWriter();
|
||||
char[] buffer = new char[READ_BUFFER_SIZE];
|
||||
Reader reader = new BufferedReader(getInputStreamReader());
|
||||
int readSize;
|
||||
try {
|
||||
while ((readSize = reader.read(buffer)) != -1) {
|
||||
writer.write(buffer, 0, readSize);
|
||||
}
|
||||
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
throw new HttpUtilException("Http read error! " + this.toString(), e);
|
||||
}
|
||||
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 설정된 Parameters로 url을 호출한다.<br/>
|
||||
* inputStreamReader를 모두 읽고 난 뒤에, close해주어야 한다.<br/>
|
||||
*
|
||||
* @return 해당 url의 응답값의 inputStreamReader
|
||||
* @throws HttpException
|
||||
* http통신준 오류 발생시
|
||||
*/
|
||||
public InputStreamReader getInputStreamReader() throws HttpUtilException {
|
||||
return HttpUtil.callUrl(urlValue, methodValue, charsetValue, passSSLErrorValue, connectionTimeoutValue, readTimeoutValue, jsonEntityValue, header);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Parameters[");
|
||||
sb.append("url=").append(urlValue);
|
||||
sb.append(", method=").append(methodValue.toString());
|
||||
if (charsetValue != null) {
|
||||
sb.append(", charset=").append(charsetValue.toString());
|
||||
} else {
|
||||
sb.append(", charset=null");
|
||||
}
|
||||
sb.append(", passSSLError=").append(passSSLErrorValue);
|
||||
sb.append(", connectionTimeout=").append(connectionTimeoutValue);
|
||||
sb.append(", readTimeout=").append(readTimeoutValue);
|
||||
sb.append(", jsonEntityValue=").append(jsonEntityValue);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.nhn.pinpoint.testweb.connector.ningasync;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ning.http.client.AsyncHttpClient;
|
||||
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder;
|
||||
import com.ning.http.client.AsyncHttpClientConfig;
|
||||
import com.ning.http.client.Part;
|
||||
import com.ning.http.client.Response;
|
||||
import com.ning.http.client.cookie.Cookie;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class NingAsyncHttpClient {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(NingAsyncHttpClient.class);
|
||||
|
||||
private final AsyncHttpClient asyncHttpClient;
|
||||
private String defaultUserAgent;
|
||||
|
||||
public NingAsyncHttpClient() {
|
||||
asyncHttpClient = new AsyncHttpClient(new AsyncHttpClientConfig.Builder().setAllowPoolingConnection(true).setCompressionEnabled(true).build());
|
||||
defaultUserAgent = "pinpoint/test";
|
||||
logger.debug("init HttpClient : defaultAgent={}", defaultUserAgent);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void close() {
|
||||
asyncHttpClient.close();
|
||||
}
|
||||
|
||||
public Response requestPost(String url, Map<String, String> headers, String body) {
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
BoundRequestBuilder requestBuilder = asyncHttpClient.preparePost(url);
|
||||
|
||||
try {
|
||||
if (headers != null) {
|
||||
for (Entry<String, String> entry : headers.entrySet()) {
|
||||
requestBuilder.addHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
requestBuilder.setBody(body).setBodyEncoding("UTF-8");
|
||||
|
||||
Future<Response> f = requestBuilder.execute();
|
||||
Response response = f.get(500L, TimeUnit.MILLISECONDS);
|
||||
|
||||
logger.debug("\n\t [POST] url \t: " + url + "\n\t headers \t: " + headers + "\n\t body \t\t: " + body + "\n\t reponse \t: " + response.toString());
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
logger.debug("request read-timeout : url \t: " + url + "\n\t headers \t: " + headers + "\n\t body \t: " + body);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Response requestMultipart(String url, Map<String, String> headers, List<Part> parts) {
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
BoundRequestBuilder requestBuilder = asyncHttpClient.preparePost(url);
|
||||
|
||||
try {
|
||||
if (headers != null) {
|
||||
for (Entry<String, String> entry : headers.entrySet()) {
|
||||
requestBuilder.addHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (parts != null) {
|
||||
for (Part part : parts) {
|
||||
requestBuilder.addBodyPart(part);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Response> f = requestBuilder.execute();
|
||||
Response response = f.get(500L, TimeUnit.MILLISECONDS);
|
||||
|
||||
logger.debug("\n\t [POST] url \t: " + url + "\n\t headers \t: " + headers + "\n\t parts \t\t: " + parts + "\n\t reponse \t: " + response.toString());
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
logger.debug("request read-timeout : url \t: " + url + "\n\t headers \t: " + headers + "\n\t parts \t: " + parts);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Response requestGet(String url, Map<String, String> queries, Map<String, String> headers, List<Cookie> cookies) {
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BoundRequestBuilder requestBuilder = asyncHttpClient.prepareGet(url);
|
||||
|
||||
if (cookies != null) {
|
||||
for (Cookie cookie : cookies) {
|
||||
requestBuilder.addCookie(cookie);
|
||||
}
|
||||
}
|
||||
|
||||
if (queries != null) {
|
||||
for (Entry<String, String> entry : queries.entrySet()) {
|
||||
requestBuilder.addParameter(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (headers != null) {
|
||||
for (Entry<String, String> entry : headers.entrySet()) {
|
||||
requestBuilder.addHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Future<Response> f = requestBuilder.execute();
|
||||
Response response = f.get(60000L, TimeUnit.MILLISECONDS);
|
||||
|
||||
logger.debug("\n\t [GET] url \t: " + url + "\n\t headers \t: " + headers + "\n\t queries \t: " + queries + "\n\t reponse \t: " + response.toString());
|
||||
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
logger.debug("request read-timeout : url \t: " + url + "\n\t headers \t: " + headers + "\n\t queries \t: " + queries);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, String> getDummyParams() {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("query", "naver");
|
||||
params.put("ie", "utf8");
|
||||
return params;
|
||||
}
|
||||
|
||||
public static Map<String, String> getDummyHeaders() {
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
headers.put("header1", "header1");
|
||||
headers.put("header2", "header2");
|
||||
return headers;
|
||||
}
|
||||
|
||||
public static List<Cookie> getDummyCookies() {
|
||||
List<Cookie> cookies = new ArrayList<Cookie>();
|
||||
cookies.add(new Cookie("cookieName1", "cookieValue1", "cookieRawValue1", "", "/", 10, 10, false, false));
|
||||
cookies.add(new Cookie("cookieName2", "cookieValue2", "cookieRawValue2", "", "/", 10, 10, false, false));
|
||||
return cookies;
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.ApacheClosableAsyncHttpClient;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class ApacheClosableAsyncHttpClientController {
|
||||
|
||||
@Autowired
|
||||
private ApacheClosableAsyncHttpClient client;
|
||||
|
||||
@RequestMapping(value = "/apacheClosableAsyncHttp/get")
|
||||
public @ResponseBody
|
||||
String requestGet(Model model) {
|
||||
return "NOT_IMPLEMENTED";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/apacheClosableAsyncHttp/getWithParam")
|
||||
public @ResponseBody
|
||||
String requestGetWithParam(Model model) {
|
||||
return "NOT_IMPLEMENTED";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/apacheClosableAsyncHttp/post")
|
||||
public @ResponseBody
|
||||
String requestPost(Model model) {
|
||||
client.post();
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/apacheClosableAsyncHttp/postWithBody")
|
||||
public @ResponseBody
|
||||
String requestPostWithBody(Model model) {
|
||||
return "NOT_IMPLEMENTED";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/apacheClosableAsyncHttp/postWithMultipart")
|
||||
public @ResponseBody
|
||||
String requestPostWithMultipart(Model model) {
|
||||
return "NOT_IMPLEMENTED";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.nhnent.HttpUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class BLOC4Controller {
|
||||
|
||||
private final String LOCAL_BLOC4_FORMAT = "http://%s:%s/welcome/test/hello?name=netspider";
|
||||
|
||||
@RequestMapping(value = "/bloc4/callLocal")
|
||||
public @ResponseBody
|
||||
String requestGet(Model model,
|
||||
@RequestParam(required = false, defaultValue = "localhost") String host,
|
||||
@RequestParam(required = false, defaultValue = "5001") String port) {
|
||||
return HttpUtil.url(String.format(LOCAL_BLOC4_FORMAT, host, port)).method(HttpUtil.Method.GET).connectionTimeout(10000).readTimeout(10000).getContents();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nhn.pinpoint.testweb.service.CubridService;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class CubridController {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private CubridService cubridService;
|
||||
|
||||
@RequestMapping(value = "/cubrid/selectOne")
|
||||
public @ResponseBody
|
||||
String selectOne(Model model) {
|
||||
try {
|
||||
logger.info("selectOne start");
|
||||
|
||||
int i = cubridService.selectOne();
|
||||
|
||||
logger.info("selectOne end:{}", i);
|
||||
return "OK";
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cubrid/createStatement")
|
||||
public @ResponseBody
|
||||
String oracleStatement(Model model) {
|
||||
try {
|
||||
logger.info("createStatement start");
|
||||
|
||||
cubridService.createStatement();
|
||||
|
||||
logger.info("createStatement end:{}");
|
||||
return "OK";
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nhn.pinpoint.testweb.configuration.DemoURLHolder;
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.ApacheHttpClient4;
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.HttpConnectorOptions;
|
||||
import com.nhn.pinpoint.testweb.connector.ningasync.NingAsyncHttpClient;
|
||||
import com.nhn.pinpoint.testweb.service.CacheService;
|
||||
import com.nhn.pinpoint.testweb.service.CubridService;
|
||||
import com.nhn.pinpoint.testweb.service.MemberService;
|
||||
import com.ning.http.client.cookie.Cookie;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class DemoController {
|
||||
|
||||
private final DemoURLHolder urls;
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
@Autowired
|
||||
private CacheService cacheService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("memberService")
|
||||
private MemberService mysqlService;
|
||||
|
||||
@Autowired
|
||||
private CubridService cubridService;
|
||||
|
||||
@Autowired
|
||||
private NingAsyncHttpClient ningAsyncHttpClient;
|
||||
|
||||
@Autowired
|
||||
private ApacheHttpClient4 apacheHttpClient;
|
||||
|
||||
public DemoController() {
|
||||
urls = DemoURLHolder.getHolder();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/netspider")
|
||||
public @ResponseBody
|
||||
String demo1() {
|
||||
accessNaverBlog();
|
||||
accessNaverCafe();
|
||||
randomSlowMethod();
|
||||
callRemote(urls.getBackendApiURL());
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/emeroad")
|
||||
public @ResponseBody
|
||||
String demo2() {
|
||||
randomSlowMethod();
|
||||
callRemote(urls.getBackendWebURL());
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/harebox")
|
||||
public @ResponseBody
|
||||
String demo3() {
|
||||
cacheService.memcached();
|
||||
accessNaver();
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/denny")
|
||||
public @ResponseBody
|
||||
String demo4() {
|
||||
mysqlService.list();
|
||||
randomSlowMethod();
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/backendweb")
|
||||
public @ResponseBody
|
||||
String backendweb() {
|
||||
cacheService.arcus();
|
||||
mysqlService.list();
|
||||
if (random.nextBoolean()) {
|
||||
callRemote(urls.getBackendApiURL());
|
||||
}
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/backendapi")
|
||||
public @ResponseBody
|
||||
String backendapi() {
|
||||
mysqlService.list();
|
||||
cubrid();
|
||||
return "OK";
|
||||
}
|
||||
|
||||
private void callRemote(String url) {
|
||||
apacheHttpClient.execute(url, new HashMap<String, Object>());
|
||||
}
|
||||
|
||||
private void cubrid() {
|
||||
switch (new Random().nextInt(3)) {
|
||||
case 1:
|
||||
cubridService.createErrorStatement();
|
||||
case 2:
|
||||
cubridService.createStatement();
|
||||
case 3:
|
||||
cubridService.selectOne();
|
||||
}
|
||||
}
|
||||
|
||||
private void accessNaver() {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("query", "naver");
|
||||
params.put("ie", "utf8");
|
||||
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
headers.put("header1", "header1");
|
||||
headers.put("header2", "header2");
|
||||
|
||||
List<Cookie> cookies = new ArrayList<Cookie>();
|
||||
cookies.add(new Cookie("cookieName1", "cookieValue1", "cookieRawValue1", "", "/", 10, 10, false, false));
|
||||
cookies.add(new Cookie("cookieName2", "cookieValue2", "cookieRawValue2", "", "/", 10, 10, false, false));
|
||||
|
||||
ningAsyncHttpClient.requestGet("http://search.naver.com/search.naver?where=nexearch", params, headers, cookies);
|
||||
}
|
||||
|
||||
private void accessNaverBlog() {
|
||||
ApacheHttpClient4 client = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client.execute("http://section.blog.naver.com/", new HashMap<String, Object>());
|
||||
}
|
||||
|
||||
private void accessNaverCafe() {
|
||||
HttpURLConnection connection = null;
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
connection = (HttpURLConnection) new URL("http://section.cafe.naver.com/").openConnection();
|
||||
connection.connect();
|
||||
|
||||
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (connection != null) {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void randomSlowMethod() {
|
||||
try {
|
||||
Thread.sleep(((new Random().nextInt(90)) + 10) * 10L);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nhn.pinpoint.testweb.util.Description;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class DoNothingController {
|
||||
@Description("아무일도 하지 않음.")
|
||||
@RequestMapping(value = "/donothing")
|
||||
public @ResponseBody
|
||||
String donothing(Model model) {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.HttpConnectorOptions;
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.ApacheHttpClient4;
|
||||
import com.nhn.pinpoint.testweb.util.Description;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Controller
|
||||
public class ExceptionalCaseController {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
/**
|
||||
* 루트의 완성이 지연될 경우 먼저 끝난 rpc콜을 정상적으로 읽을수 있는지 테스트
|
||||
*/
|
||||
@Description("root의 완료가 지연될경우 parent가 완료된 데이터를 정상적으로 확인가능지.")
|
||||
@RequestMapping(value = "/exceptionalcase/rootslow")
|
||||
public void rootSlow() {
|
||||
ApacheHttpClient4 client2 = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client2.execute("http://localhost:8080/donothing.pinpoint", new HashMap<String, Object>());
|
||||
|
||||
try {
|
||||
final int sleep = 1000 * 30;
|
||||
logger.info("sleep:{}", sleep);
|
||||
Thread.sleep(sleep);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.spy.memcached.AddrUtil;
|
||||
import net.spy.memcached.ArcusClient;
|
||||
import net.spy.memcached.ConnectionFactoryBuilder;
|
||||
import net.spy.memcached.MemcachedClient;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import perftest.LevelManager;
|
||||
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.HttpConnectorOptions;
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.ApacheHttpClient4;
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
import com.nhn.pinpoint.testweb.service.CacheService;
|
||||
import com.nhn.pinpoint.testweb.service.DummyService;
|
||||
import com.nhn.pinpoint.testweb.service.MemberService;
|
||||
import com.nhn.pinpoint.testweb.util.Description;
|
||||
import com.nhncorp.lucy.net.invoker.InvocationFuture;
|
||||
import com.nhncorp.lucy.npc.connector.NpcHessianConnector;
|
||||
|
||||
@Controller
|
||||
@Deprecated
|
||||
public class HelloWorldController implements DisposableBean {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final ArcusClient arcus;
|
||||
private final MemcachedClient memcached;
|
||||
private final LevelManager levelManager;
|
||||
|
||||
public HelloWorldController() throws IOException {
|
||||
arcus = ArcusClient.createArcusClient("dev.arcuscloud.nhncorp.com:17288", "dev", new ConnectionFactoryBuilder());
|
||||
memcached = new MemcachedClient(AddrUtil.getAddresses("10.25.149.80:11244,10.25.149.80:11211,10.25.149.79:11211"));
|
||||
levelManager = new LevelManager();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Qualifier("memberService")
|
||||
private MemberService service;
|
||||
|
||||
@Autowired
|
||||
private DummyService dummyService;
|
||||
|
||||
@Autowired
|
||||
private CacheService cacheService;
|
||||
|
||||
private void randomSlowMethod() {
|
||||
try {
|
||||
Thread.sleep((new Random().nextInt(3)) * 1000L);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/dummy")
|
||||
public @ResponseBody
|
||||
String dummy(Model model) {
|
||||
dummyService.doSomething();
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/encoding")
|
||||
public @ResponseBody
|
||||
String encoding(Model model, @RequestParam("name") String name) {
|
||||
logger.debug("name=" + name);
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/arcus")
|
||||
public @ResponseBody
|
||||
String arcus(Model model) {
|
||||
cacheService.arcus();
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/memcached")
|
||||
public @ResponseBody
|
||||
String memcached(Model model) {
|
||||
cacheService.memcached();
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/mysql")
|
||||
public @ResponseBody
|
||||
String mysql(Model model) {
|
||||
int id = (new Random()).nextInt();
|
||||
|
||||
Member member = new Member();
|
||||
member.setId(id);
|
||||
member.setName("chisu");
|
||||
member.setJoined(new Date());
|
||||
|
||||
// add
|
||||
service.add(member);
|
||||
|
||||
// list
|
||||
service.list();
|
||||
|
||||
// del
|
||||
service.delete(id);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@Description("바인드 변수 + 상수값 파싱 로직테스트")
|
||||
@RequestMapping(value = "/mysqlStatement")
|
||||
public @ResponseBody
|
||||
String mysqlStatement(Model model) {
|
||||
int id = (new Random()).nextInt();
|
||||
|
||||
Member member = new Member();
|
||||
member.setId(id);
|
||||
member.setName("chisu");
|
||||
member.setJoined(new Date());
|
||||
|
||||
// add
|
||||
service.addStatement(member);
|
||||
|
||||
// list
|
||||
service.list();
|
||||
|
||||
// del
|
||||
service.delete(id);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/nested")
|
||||
public @ResponseBody
|
||||
String nested(Model model) {
|
||||
ApacheHttpClient4 client2 = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client2.execute("http://localhost:8080/donothing.pinpoint", new HashMap<String, Object>());
|
||||
|
||||
ApacheHttpClient4 client = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client.execute("http://www.naver.com/", new HashMap<String, Object>());
|
||||
mysql(model);
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/remotecombination")
|
||||
public @ResponseBody
|
||||
String remotecombination(Model model) {
|
||||
String[] ports = new String[] { "9080", "10080", "11080" };
|
||||
Random random = new Random();
|
||||
String port = ports[random.nextInt(3)];
|
||||
|
||||
ApacheHttpClient4 client = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client.execute("http://localhost:" + port + "/combination.pinpoint", new HashMap<String, Object>());
|
||||
|
||||
ApacheHttpClient4 client2 = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client2.execute("http://localhost:8080/arcus.pinpoint", new HashMap<String, Object>());
|
||||
|
||||
client.execute("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.execute("http://www.naver.com/", new HashMap<String, Object>());
|
||||
try {
|
||||
client.execute("http://very.very.very.long.long.url/", new HashMap<String, Object>());
|
||||
client.execute("http://url1/", new HashMap<String, Object>());
|
||||
client.execute("http://url2/", new HashMap<String, Object>());
|
||||
client.execute("http://url2/", new HashMap<String, Object>());
|
||||
client.execute("http://url3/", new HashMap<String, Object>());
|
||||
client.execute("http://url3/", new HashMap<String, Object>());
|
||||
client.execute("http://url3/", new HashMap<String, Object>());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/remotearcus")
|
||||
public @ResponseBody
|
||||
String remotearcus(Model model) {
|
||||
arcus(model);
|
||||
|
||||
String[] ports = new String[] { "9080", "10080", "11080" };
|
||||
Random random = new Random();
|
||||
String port = ports[random.nextInt(3)];
|
||||
ApacheHttpClient4 client = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client.execute("http://localhost:" + port + "/arcus.pinpoint", new HashMap<String, Object>());
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/combination")
|
||||
public @ResponseBody
|
||||
String combination(Model model) {
|
||||
try {
|
||||
mysql(model);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
arcus(model);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
memcached(model);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
randomSlowMethod();
|
||||
|
||||
ApacheHttpClient4 client = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client.execute("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.execute("http://www.naver.com/", new HashMap<String, Object>());
|
||||
|
||||
client.execute("http://section.cafe.naver.com/", new HashMap<String, Object>());
|
||||
client.execute("http://section.cafe.naver.com/", new HashMap<String, Object>());
|
||||
|
||||
npc(model);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/httperror")
|
||||
public @ResponseBody
|
||||
String httperror(Model model) {
|
||||
ApacheHttpClient4 client = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client.execute("http://127.0.0.1/", new HashMap<String, Object>());
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/error500")
|
||||
public @ResponseBody
|
||||
String error500(Model model) {
|
||||
try {
|
||||
int i = 1 / 0;
|
||||
return "OK";
|
||||
} catch (Exception e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/slow")
|
||||
public @ResponseBody
|
||||
String slow(Model model) {
|
||||
try {
|
||||
Thread.sleep(new Random().nextInt(10) * 100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/throwexception")
|
||||
public @ResponseBody
|
||||
String exception(Model model) {
|
||||
throw new RuntimeException("Exception test");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/arcustimeout")
|
||||
public @ResponseBody
|
||||
String arcustimeout(Model model) {
|
||||
Future<Boolean> future = null;
|
||||
try {
|
||||
future = arcus.set("pinpoint:expect-timeout", 10, "Hello, Timeout.");
|
||||
future.get(10L, TimeUnit.MICROSECONDS);
|
||||
} catch (Exception e) {
|
||||
if (future != null)
|
||||
future.cancel(true);
|
||||
e.printStackTrace();
|
||||
return e.getMessage();
|
||||
}
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/remotesimple")
|
||||
public @ResponseBody
|
||||
String remotesimple(Model model) {
|
||||
String[] ports = new String[] { "9080", "10080", "11080" };
|
||||
Random random = new Random();
|
||||
String port = ports[random.nextInt(3)];
|
||||
|
||||
arcus(model);
|
||||
|
||||
ApacheHttpClient4 client = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client.execute("http://localhost:" + port + "/arcus.pinpoint", new HashMap<String, Object>());
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/remoteerror")
|
||||
public @ResponseBody
|
||||
String remoteError(Model model) {
|
||||
ApacheHttpClient4 client = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client.execute("http://localhost:10080/rpcerror.pinpoint", new HashMap<String, Object>());
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/rpcerror")
|
||||
public @ResponseBody
|
||||
String rpcError(Model model) {
|
||||
ApacheHttpClient4 client = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client.execute("UNKNOWN_URL", new HashMap<String, Object>());
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/npc")
|
||||
public @ResponseBody
|
||||
String npc(Model model) {
|
||||
try {
|
||||
InetSocketAddress serverAddress = new InetSocketAddress("127.0.0.1", 5000);
|
||||
NpcHessianConnector connector = new NpcHessianConnector(serverAddress, true);
|
||||
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("message", "hello pinpoint");
|
||||
|
||||
InvocationFuture future = connector.invoke("welcome/com.nhncorp.lucy.bloc.welcome.EchoBO", "execute", params);
|
||||
|
||||
future.await();
|
||||
|
||||
// Object result = future.get();
|
||||
Object result = future.getReturnValue();
|
||||
System.out.println("npc result=" + result);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
}
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/perftest")
|
||||
public @ResponseBody
|
||||
String perfTest(Model model) {
|
||||
levelManager.traverse();
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
arcus.shutdown();
|
||||
memcached.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.ApacheHttpClient4;
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.HttpConnectorOptions;
|
||||
import com.nhn.pinpoint.testweb.util.Description;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class HttpClient4Controller {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Description("에러시 cookie덤프")
|
||||
@RequestMapping(value = "/httpclient4/cookie")
|
||||
public @ResponseBody
|
||||
String cookie(@RequestHeader(value = "Cookie", required = false) String cookie) {
|
||||
logger.info("Cookie:{}", cookie);
|
||||
|
||||
ApacheHttpClient4 client = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client.execute("http://localhost:" + 9999 + "/combination.pinpoint", new HashMap<String, Object>(), cookie);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@Description("에러시 post덤프")
|
||||
@RequestMapping(value = "/httpclient4/post")
|
||||
public @ResponseBody
|
||||
String post() {
|
||||
logger.info("Post");
|
||||
// String[] ports = new String[] { "9080", "10080", "11080" };
|
||||
// Random random = new Random();
|
||||
// String port = ports[random.nextInt(3)];
|
||||
//
|
||||
ApacheHttpClient4 client = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
HashMap<String, Object> post = new HashMap<String, Object>();
|
||||
post.put("test", "1");
|
||||
post.put("test2", "2");
|
||||
client.execute("http://localhost:" + 9999 + "/combination.pinpoint", post);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import com.nhn.pinpoint.testweb.vo.RequestMappingInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class MainController {
|
||||
|
||||
@RequestMapping(value = "/docs", method = RequestMethod.GET)
|
||||
public String getEndPointsInView(Model model) {
|
||||
model.addAttribute("mapping", getMappingInfo());
|
||||
return "docs";
|
||||
}
|
||||
|
||||
public Map<String, List<RequestMappingInfo>> getMappingInfo() {
|
||||
Map<String, List<RequestMappingInfo>> info = new HashMap<String, List<RequestMappingInfo>>();
|
||||
try {
|
||||
String packaze = "com.nhn.pinpoint.testweb.controller";
|
||||
ArrayList<String> classNamesFromPackage = MainController.getClassNamesFromPackage(packaze);
|
||||
|
||||
for (String className : classNamesFromPackage) {
|
||||
Class<?> clazz = Class.forName(packaze + "." + className);
|
||||
|
||||
List<RequestMappingInfo> requestInfo = new ArrayList<RequestMappingInfo>();
|
||||
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
|
||||
for (Method m : methods) {
|
||||
Annotation[] annotations = m.getDeclaredAnnotations();
|
||||
|
||||
org.springframework.web.bind.annotation.RequestMapping mappingInfo = null;
|
||||
com.nhn.pinpoint.testweb.util.Description description = null;
|
||||
|
||||
for (Annotation a : annotations) {
|
||||
if (a instanceof org.springframework.web.bind.annotation.RequestMapping) {
|
||||
mappingInfo = (org.springframework.web.bind.annotation.RequestMapping) a;
|
||||
}
|
||||
if (a instanceof com.nhn.pinpoint.testweb.util.Description) {
|
||||
description = (com.nhn.pinpoint.testweb.util.Description) a;
|
||||
}
|
||||
}
|
||||
|
||||
if (mappingInfo != null) {
|
||||
requestInfo.add(new RequestMappingInfo(mappingInfo.value()[0], (description == null) ? "" : description.value()));
|
||||
}
|
||||
}
|
||||
|
||||
if (requestInfo.size() > 0) {
|
||||
info.put(clazz.getSimpleName(), requestInfo);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
// spring에서 제공하는 기능이 있는것 같긴 하지만 그냥 구식으로.
|
||||
public static ArrayList<String> getClassNamesFromPackage(String packageName) throws IOException, URISyntaxException {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
URL packageURL;
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
|
||||
packageName = packageName.replace(".", "/");
|
||||
packageURL = classLoader.getResource(packageName);
|
||||
|
||||
if (packageURL.getProtocol().equals("jar")) {
|
||||
String jarFileName;
|
||||
JarFile jf;
|
||||
Enumeration<JarEntry> jarEntries;
|
||||
String entryName;
|
||||
|
||||
// build jar file name, then loop through zipped entries
|
||||
jarFileName = URLDecoder.decode(packageURL.getFile(), "UTF-8");
|
||||
jarFileName = jarFileName.substring(5, jarFileName.indexOf("!"));
|
||||
System.out.println(">" + jarFileName);
|
||||
jf = new JarFile(jarFileName);
|
||||
jarEntries = jf.entries();
|
||||
while (jarEntries.hasMoreElements()) {
|
||||
entryName = jarEntries.nextElement().getName();
|
||||
if (entryName.startsWith(packageName) && entryName.length() > packageName.length() + 5) {
|
||||
entryName = entryName.substring(packageName.length(), entryName.lastIndexOf('.'));
|
||||
names.add(entryName);
|
||||
}
|
||||
}
|
||||
|
||||
// loop through files in classpath
|
||||
} else {
|
||||
URI uri = new URI(packageURL.toString());
|
||||
File folder = new File(uri.getPath());
|
||||
// won't work with path which contains blank (%20)
|
||||
// File folder = new File(packageURL.getFile());
|
||||
File[] contenuti = folder.listFiles();
|
||||
String entryName;
|
||||
for (File actual : contenuti) {
|
||||
entryName = actual.getName();
|
||||
entryName = entryName.substring(0, entryName.lastIndexOf('.'));
|
||||
names.add(entryName);
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
import com.nhn.pinpoint.testweb.service.MemberService;
|
||||
import com.nhn.pinpoint.testweb.service.MySqlService;
|
||||
import com.nhn.pinpoint.testweb.util.Description;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class MySqlController {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private MySqlService mySqlService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("memberService")
|
||||
private MemberService service;
|
||||
|
||||
@RequestMapping(value = "/mysql/crud")
|
||||
public @ResponseBody
|
||||
String crud(Model model) {
|
||||
try {
|
||||
int id = (new Random()).nextInt();
|
||||
|
||||
Member member = new Member();
|
||||
member.setId(id);
|
||||
member.setName("chisu");
|
||||
member.setJoined(new Date());
|
||||
|
||||
service.add(member);
|
||||
service.list();
|
||||
service.delete(id);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
}
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/mysql/crudWithStatement")
|
||||
public @ResponseBody
|
||||
String crudWithStatement(Model model) {
|
||||
try {
|
||||
int id = (new Random()).nextInt();
|
||||
|
||||
Member member = new Member();
|
||||
member.setId(id);
|
||||
member.setName("chisu");
|
||||
member.setJoined(new Date());
|
||||
|
||||
service.addStatement(member);
|
||||
service.list();
|
||||
service.delete(id);
|
||||
|
||||
return "OK";
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@Description("preparedStatement 테스트. resultset은 가지고 오지 않음.")
|
||||
@RequestMapping(value = "/mysql/selectOne")
|
||||
public @ResponseBody
|
||||
String selectOne(Model model) {
|
||||
try {
|
||||
logger.info("selectOne start");
|
||||
|
||||
int i = mySqlService.selectOne();
|
||||
|
||||
logger.info("selectOne end:{}", i);
|
||||
return "OK";
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@Description("statement 테스트. resultset은 가지고 오지 않음.")
|
||||
@RequestMapping(value = "/mysql/createStatement")
|
||||
public @ResponseBody
|
||||
String oracleStatement(Model model) {
|
||||
try {
|
||||
logger.info("createStatement start");
|
||||
|
||||
mySqlService.createStatement();
|
||||
|
||||
logger.info("createStatement end:{}");
|
||||
return "OK";
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.nhnent.HttpUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class NHNEntHttpClientController {
|
||||
|
||||
@RequestMapping(value = "/nhnent/get")
|
||||
public @ResponseBody
|
||||
String requestGet(Model model, @RequestParam(required = false, defaultValue = "http") String protocol) {
|
||||
return HttpUtil.url(protocol + "://www.naver.com").method(HttpUtil.Method.GET).connectionTimeout(10000).readTimeout(10000).getContents();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/nhnent/getWithParam")
|
||||
public @ResponseBody
|
||||
String requestGetWithParam(Model model) {
|
||||
return "NOT_IMPLEMENTED";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/nhnent/post")
|
||||
public @ResponseBody
|
||||
String requestPost(Model model, @RequestParam(required = false, defaultValue = "http") String protocol) {
|
||||
return HttpUtil.url(protocol + "://www.naver.com").method(HttpUtil.Method.POST).connectionTimeout(10000).readTimeout(10000).getContents();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/nhnent/postWithBody")
|
||||
public @ResponseBody
|
||||
String requestPostWithBody(Model model) {
|
||||
return "NOT_IMPLEMENTED";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/nhnent/postWithMultipart")
|
||||
public @ResponseBody
|
||||
String requestPostWithMultipart(Model model) {
|
||||
return "NOT_IMPLEMENTED";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nhn.pinpoint.testweb.nimm.mockupserver.NimmInvokerTest;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class NIMMController implements DisposableBean {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private NimmInvokerTest nimm;
|
||||
|
||||
@RequestMapping(value = "/nimm/1")
|
||||
public @ResponseBody
|
||||
String npc(Model model) {
|
||||
try {
|
||||
nimm.testInvoke();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return e.getMessage();
|
||||
}
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
try {
|
||||
nimm.tearDown();
|
||||
} catch (Exception e) {
|
||||
logger.warn("tearDown() error Caused:" + e.getMessage(), e);
|
||||
}
|
||||
nimm.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nhncorp.lucy.net.invoker.InvocationFuture;
|
||||
import com.nhncorp.lucy.net.invoker.InvocationFutureListener;
|
||||
import com.nhncorp.lucy.npc.connector.ConnectionFactory;
|
||||
import com.nhncorp.lucy.npc.connector.KeepAliveNpcHessianConnector;
|
||||
import com.nhncorp.lucy.npc.connector.NpcConnectionFactory;
|
||||
import com.nhncorp.lucy.npc.connector.NpcHessianConnector;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class NPCController {
|
||||
|
||||
/**
|
||||
* using basic connector
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/npc/1")
|
||||
public @ResponseBody
|
||||
String npc(Model model) {
|
||||
NpcHessianConnector connector = null;
|
||||
try {
|
||||
InetSocketAddress serverAddress = new InetSocketAddress("127.0.0.1", 5000);
|
||||
connector = new NpcHessianConnector(serverAddress, true);
|
||||
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("message", "hello pinpoint");
|
||||
|
||||
InvocationFuture future = connector.invoke("welcome/com.nhncorp.lucy.bloc.welcome.EchoBO", "execute", params);
|
||||
|
||||
future.await();
|
||||
|
||||
// Object result = future.get();
|
||||
Object result = future.getReturnValue();
|
||||
System.out.println("npc result=" + result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return e.getMessage();
|
||||
} finally {
|
||||
if (connector != null) {
|
||||
connector.dispose();
|
||||
}
|
||||
}
|
||||
return "OK";
|
||||
}
|
||||
|
||||
/**
|
||||
* using keepalive connector
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/npc/2")
|
||||
public @ResponseBody
|
||||
String npc2(Model model) {
|
||||
KeepAliveNpcHessianConnector connector = null;
|
||||
try {
|
||||
InetSocketAddress serverAddress = new InetSocketAddress("127.0.0.1", 5000);
|
||||
|
||||
connector = new KeepAliveNpcHessianConnector(serverAddress);
|
||||
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("message", "hello pinpoint");
|
||||
|
||||
InvocationFuture future = connector.invoke("welcome/com.nhncorp.lucy.bloc.welcome.EchoBO", "execute", params);
|
||||
|
||||
future.await();
|
||||
|
||||
// Object result = future.get();
|
||||
Object result = future.getReturnValue();
|
||||
System.out.println("npc result=" + result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return e.getMessage();
|
||||
} finally {
|
||||
if (connector != null) {
|
||||
connector.dispose();
|
||||
}
|
||||
}
|
||||
return "OK";
|
||||
}
|
||||
|
||||
/**
|
||||
* using connection factory
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/npc/3")
|
||||
public @ResponseBody
|
||||
String npc3(Model model) {
|
||||
NpcHessianConnector connector = null;
|
||||
try {
|
||||
InetSocketAddress serverAddress = new InetSocketAddress("127.0.0.1", 5000);
|
||||
|
||||
ConnectionFactory npcConnectionFactory = new NpcConnectionFactory();
|
||||
|
||||
npcConnectionFactory.setTimeout(1000L);
|
||||
npcConnectionFactory.setAddress(serverAddress);
|
||||
|
||||
connector = npcConnectionFactory.create();
|
||||
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("message", "hello pinpoint");
|
||||
|
||||
InvocationFuture future = connector.invoke("welcome/com.nhncorp.lucy.bloc.welcome.EchoBO", "execute", params);
|
||||
|
||||
future.await();
|
||||
|
||||
// Object result = future.get();
|
||||
Object result = future.getReturnValue();
|
||||
System.out.println("npc result=" + result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return e.getMessage();
|
||||
} finally {
|
||||
if (connector != null) {
|
||||
connector.dispose();
|
||||
}
|
||||
}
|
||||
return "OK";
|
||||
}
|
||||
|
||||
/**
|
||||
* using lightweight connector
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/npc/4")
|
||||
public @ResponseBody
|
||||
String npc4(Model model) {
|
||||
NpcHessianConnector connector = null;
|
||||
try {
|
||||
InetSocketAddress serverAddress = new InetSocketAddress("127.0.0.1", 5000);
|
||||
|
||||
ConnectionFactory npcConnectionFactory = new NpcConnectionFactory();
|
||||
|
||||
npcConnectionFactory.setTimeout(1000L);
|
||||
npcConnectionFactory.setAddress(serverAddress);
|
||||
npcConnectionFactory.setLightWeight(true);
|
||||
|
||||
connector = npcConnectionFactory.create();
|
||||
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("message", "hello pinpoint");
|
||||
|
||||
InvocationFuture future = connector.invoke("welcome/com.nhncorp.lucy.bloc.welcome.EchoBO", "execute", params);
|
||||
|
||||
future.await();
|
||||
|
||||
// Object result = future.get();
|
||||
Object result = future.getReturnValue();
|
||||
System.out.println("npc result=" + result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return e.getMessage();
|
||||
} finally {
|
||||
if (connector != null) {
|
||||
connector.dispose();
|
||||
}
|
||||
}
|
||||
return "OK";
|
||||
}
|
||||
|
||||
/**
|
||||
* using lightweight connector and listener
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/npc/5")
|
||||
public @ResponseBody
|
||||
String npc5(Model model) {
|
||||
NpcHessianConnector connector = null;
|
||||
try {
|
||||
InetSocketAddress serverAddress = new InetSocketAddress("127.0.0.1", 5000);
|
||||
|
||||
ConnectionFactory npcConnectionFactory = new NpcConnectionFactory();
|
||||
|
||||
npcConnectionFactory.setTimeout(1000L);
|
||||
npcConnectionFactory.setAddress(serverAddress);
|
||||
npcConnectionFactory.setLightWeight(true);
|
||||
|
||||
connector = npcConnectionFactory.create();
|
||||
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("message", "hello pinpoint");
|
||||
|
||||
InvocationFuture future = connector.invoke("welcome/com.nhncorp.lucy.bloc.welcome.EchoBO", "execute", params);
|
||||
|
||||
future.addListener(new InvocationFutureListener() {
|
||||
@Override
|
||||
public void invocationComplete(InvocationFuture future) throws Exception {
|
||||
Object result = future.getReturnValue();
|
||||
System.out.println("npc result=" + result);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return e.getMessage();
|
||||
} finally {
|
||||
if (connector != null) {
|
||||
connector.dispose();
|
||||
}
|
||||
}
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/npc/6")
|
||||
public @ResponseBody
|
||||
String npcStream(Model model) {
|
||||
return "NOT_IMPLEMENTED";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nhn.pinpoint.testweb.connector.ningasync.NingAsyncHttpClient;
|
||||
import com.ning.http.client.Part;
|
||||
import com.ning.http.client.Response;
|
||||
import com.ning.http.client.cookie.Cookie;
|
||||
import com.ning.http.multipart.StringPart;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class NingAsyncHTTPClientController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(NingAsyncHTTPClientController.class);
|
||||
|
||||
@Autowired
|
||||
private NingAsyncHttpClient ningAsyncHttpClient;
|
||||
|
||||
@Autowired
|
||||
private NingAsyncHttpClient httpInvoker;
|
||||
|
||||
@RequestMapping(value = "/ningAsyncHttp/get")
|
||||
public @ResponseBody
|
||||
String requestGet(Model model) {
|
||||
try {
|
||||
Response r = httpInvoker.requestGet("http://www.naver.com", null, null, null);
|
||||
logger.debug("r={}" + r.toString());
|
||||
return "OK";
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/ningAsyncHttp/getWithParam")
|
||||
public @ResponseBody
|
||||
String requestGetWithParam(Model model) {
|
||||
try {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("query", "naver");
|
||||
params.put("ie", "utf8");
|
||||
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
headers.put("header1", "header1");
|
||||
headers.put("header2", "header2");
|
||||
|
||||
List<Cookie> cookies = new ArrayList<Cookie>();
|
||||
cookies.add(new Cookie("cookieName1", "cookieValue1", "cookieRawValue1", "", "/", 10, 10, false, false));
|
||||
cookies.add(new Cookie("cookieName2", "cookieValue2", "cookieRawValue2", "", "/", 10, 10, false, false));
|
||||
|
||||
Response r = httpInvoker.requestGet("http://search.naver.com/search.naver?where=nexearch", params, headers, cookies);
|
||||
logger.debug("r={}" + r.toString());
|
||||
return "OK";
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/ningAsyncHttp/post")
|
||||
public @ResponseBody
|
||||
String requestPost(Model model) {
|
||||
try {
|
||||
Response r = httpInvoker.requestPost("http://www.naver.com", null, null);
|
||||
logger.debug("r={}" + r.toString());
|
||||
return "OK";
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/ningAsyncHttp/postWithBody")
|
||||
public @ResponseBody
|
||||
String requestPostWithBody(Model model) {
|
||||
try {
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
headers.put("header1", "header1");
|
||||
headers.put("header2", "header2");
|
||||
|
||||
Response r = httpInvoker.requestPost("http://www.naver.com", headers, "postbody");
|
||||
logger.debug("r={}" + r.toString());
|
||||
return "OK";
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/ningAsyncHttp/postWithMultipart")
|
||||
public @ResponseBody
|
||||
String requestPostWithMultipart(Model model) {
|
||||
try {
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
headers.put("header1", "header1");
|
||||
headers.put("header2", "header2");
|
||||
|
||||
List<Part> parts = new ArrayList<Part>();
|
||||
parts.add(new com.ning.http.client.ByteArrayPart("name1", "filename1", "data".getBytes(), "plain/text", "utf-8"));
|
||||
parts.add(new com.ning.http.client.FilePart("name2", new File("./test"), "mimeType", "utf-8"));
|
||||
parts.add(new com.ning.http.client.StringPart("name3", "value3"));
|
||||
parts.add(new com.ning.http.multipart.FilePart("name4", new File("./test")));
|
||||
parts.add(new StringPart("name5", "value5"));
|
||||
|
||||
Response r = httpInvoker.requestMultipart("http://www.naver.com", headers, parts);
|
||||
logger.debug("r={}" + r.toString());
|
||||
return "OK";
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import com.nhn.pinpoint.testweb.service.OracleService;
|
||||
import com.nhn.pinpoint.testweb.util.Description;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class OracleController {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private OracleService oracleService;
|
||||
|
||||
@Description("preparedStatement 테스트. resultset은 가지고 오지 않음.")
|
||||
@RequestMapping(value = "/oracle/selectOne")
|
||||
public @ResponseBody
|
||||
String selectOne(Model model) {
|
||||
logger.info("selectOne start");
|
||||
|
||||
int i = oracleService.selectOne();
|
||||
|
||||
logger.info("selectOne end:{}", i);
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@Description("statement 테스트. resultset은 가지고 오지 않음")
|
||||
@RequestMapping(value = "/oracle/createStatement")
|
||||
public @ResponseBody
|
||||
String oracleStatement(Model model) {
|
||||
logger.info("createStatement start");
|
||||
|
||||
oracleService.createStatement();
|
||||
|
||||
logger.info("createStatement end:{}");
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
import com.nhn.pinpoint.testweb.service.MemberService;
|
||||
|
||||
/**
|
||||
* @author Hyun Jeong
|
||||
*/
|
||||
@Controller
|
||||
public class OrmController {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public static final String IBATIS_VIEW = "orm/ibatis";
|
||||
public static final String MYBATIS_VIEW = "orm/mybatis";
|
||||
|
||||
@Autowired
|
||||
@Qualifier("sqlMapClientMemberService")
|
||||
private MemberService sqlMapClientMemberService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("sqlMapSessionMemberService")
|
||||
private MemberService sqlMapSessionMemberService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("myBatisMemberService")
|
||||
private MemberService myBatisMemberService;
|
||||
|
||||
@RequestMapping(value = "/orm/ibatis/sqlMapClient/query")
|
||||
public String iBatisSqlMapClientQuery(Model model) {
|
||||
logger.info("/orm/ibatis/sqlMapClient/query");
|
||||
|
||||
this.sqlMapClientMemberService.get(0);
|
||||
|
||||
return IBATIS_VIEW;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/orm/ibatis/sqlMapClient/transaction")
|
||||
public String iBatisSqlMapClientTranscation(Model model) {
|
||||
logger.info("/orm/ibatis/sqlMapClient/transaction - add, update, get, delete");
|
||||
|
||||
runTransaction(this.sqlMapClientMemberService);
|
||||
|
||||
return IBATIS_VIEW;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/orm/ibatis/sqlMapSession/query")
|
||||
public String iBatisSqlMapSessionQuery(Model model) {
|
||||
logger.info("/orm/ibatis/sqlMapSession/query");
|
||||
|
||||
this.sqlMapSessionMemberService.get(0);
|
||||
|
||||
return IBATIS_VIEW;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/orm/ibatis/sqlMapSession/transaction")
|
||||
public String iBatisSqlMapSessionTransaction(Model model) {
|
||||
logger.info("/orm/ibatis/sqlMapSession/transaction - add, update, get, delete");
|
||||
|
||||
runTransaction(this.sqlMapSessionMemberService);
|
||||
|
||||
return IBATIS_VIEW;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/orm/mybatis/sqlSessionTemplate/query")
|
||||
public String myBatisSqlSessionTemplateQuery(Model model) {
|
||||
logger.info("/orm/mybatis/sqlSessionTemplate/query");
|
||||
|
||||
this.myBatisMemberService.get(0);
|
||||
|
||||
return MYBATIS_VIEW;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/orm/mybatis/sqlSessionTemplate/transaction")
|
||||
public String myBatisSqlSessionTemplateTransaction(Model model) {
|
||||
logger.info("/orm/mybatis/sqlSessionTemplate/transaction");
|
||||
|
||||
runTransaction(this.myBatisMemberService);
|
||||
|
||||
return MYBATIS_VIEW;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/orm/mybatis/sqlSessionTemplate/invalid")
|
||||
public String myBatisSqlSessionTemplateInvalid(Model model) {
|
||||
logger.info("/orm/mybatis/sqlSessionTemplate/invalid");
|
||||
|
||||
this.myBatisMemberService.list();
|
||||
|
||||
return MYBATIS_VIEW;
|
||||
}
|
||||
|
||||
private void runTransaction(MemberService memberService) {
|
||||
|
||||
final int memberId = 1574;
|
||||
|
||||
Member member = new Member();
|
||||
member.setId(memberId);
|
||||
member.setName("test User");
|
||||
member.setJoined(new Date(System.currentTimeMillis()));
|
||||
|
||||
memberService.add(member);
|
||||
|
||||
member.setName("updated test User");
|
||||
memberService.update(member);
|
||||
|
||||
memberService.get(memberId);
|
||||
logger.info("\tId:[" + member.getId() + "], name:[" + member.getName() + "]");
|
||||
|
||||
memberService.delete(memberId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.nhn.pinpoint.testweb.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Member {
|
||||
|
||||
int id;
|
||||
|
||||
String name;
|
||||
|
||||
Date joined;
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* the id to set
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the joined
|
||||
*/
|
||||
public Date getJoined() {
|
||||
return joined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param joined
|
||||
* the joined to set
|
||||
*/
|
||||
public void setJoined(Date joined) {
|
||||
this.joined = joined;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.nhn.pinpoint.testweb.nimm.mockupserver;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.NimmConnector;
|
||||
import com.nhncorp.lucy.nimm.connector.util.ThreadSleepUtils;
|
||||
import com.nhncorp.lucy.nimm.mockupserver.MockUpServerSettler;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* original source : com.nhncorp.lucy.nimm.connector.AbstractNimmTest
|
||||
* </pre>
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractNimmTest {
|
||||
private static final Logger log = Logger.getLogger(AbstractNimmTest.class.getName());
|
||||
|
||||
protected MockUpServerSettler mockUpServerSettler;
|
||||
|
||||
protected void initialize(final String configFileName) {
|
||||
boolean success = false;
|
||||
try {
|
||||
checkMockupServer();
|
||||
log.info("mockserver start");
|
||||
mockUpServerSettler = new MockUpServerSettler(configFileName);
|
||||
mockUpServerSettler.setUp();
|
||||
log.info("mockserver setup-end");
|
||||
success = true;
|
||||
} finally {
|
||||
if (success) {
|
||||
log.info("NimmConnector start");
|
||||
NimmConnector.registerMMNetDriver(configFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void connectorFirstInitialize(final String configFileName) {
|
||||
checkMockupServer();
|
||||
mockUpServerSettler = new MockUpServerSettler(configFileName);
|
||||
|
||||
Thread start = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000 * 5);
|
||||
log.info("mockserver start");
|
||||
mockUpServerSettler.setUp();
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "mockserver start error", e);
|
||||
}
|
||||
}
|
||||
}, "mockserver start thread");
|
||||
start.setDaemon(true);
|
||||
start.start();
|
||||
|
||||
log.info("NimmConnector start");
|
||||
NimmConnector.registerMMNetDriver(configFileName);
|
||||
|
||||
}
|
||||
|
||||
protected void checkMockupServer() {
|
||||
if (mockUpServerSettler != null) {
|
||||
throw new NullPointerException("mockupserver already started, testcase check");
|
||||
}
|
||||
}
|
||||
|
||||
protected void reconnectInitialize(final String configFileName) {
|
||||
checkMockupServer();
|
||||
mockUpServerSettler = new MockUpServerSettler(configFileName);
|
||||
mockUpServerSettler.setUp();
|
||||
|
||||
log.info("NimmConnector start");
|
||||
NimmConnector.registerMMNetDriver(configFileName);
|
||||
ThreadSleepUtils.sleepUninterruptibly(1000);
|
||||
|
||||
Logger logger = Logger.getLogger(AbstractNimmTest.class.getName());
|
||||
logger.severe("mockupServer-down:start");
|
||||
mockUpServerSettler.setDown();
|
||||
logger.severe("mockupServer-down:end");
|
||||
ThreadSleepUtils.sleepUninterruptibly(2000);
|
||||
logger.severe("mockupServer-start");
|
||||
mockUpServerSettler = new MockUpServerSettler(configFileName);
|
||||
mockUpServerSettler.setUp();
|
||||
|
||||
// Connector가 재접속할때까지 대기한다. reconnect 재시도 시간이 5초이므로, 5초이상 쉬어야 한다.
|
||||
ThreadSleepUtils.sleepUninterruptibly(1000 * 8);
|
||||
}
|
||||
|
||||
protected void gracefulShutdownInitialize(final String configFileName) {
|
||||
checkMockupServer();
|
||||
mockUpServerSettler = new MockUpServerSettler(configFileName);
|
||||
mockUpServerSettler.setUp();
|
||||
|
||||
log.info("NimmConnector start");
|
||||
NimmConnector.registerMMNetDriver(configFileName);
|
||||
ThreadSleepUtils.sleepUninterruptibly(2000);
|
||||
|
||||
Logger.getLogger(AbstractNimmTest.class.getName()).severe("mockupServer-down:start");
|
||||
mockUpServerSettler.setGracefulDown();
|
||||
Logger.getLogger(AbstractNimmTest.class.getName()).severe("mockupServer-down:end");
|
||||
ThreadSleepUtils.sleepUninterruptibly(2000);
|
||||
Logger.getLogger(AbstractNimmTest.class.getName()).severe("mockupServer-start");
|
||||
mockUpServerSettler = new MockUpServerSettler(configFileName);
|
||||
mockUpServerSettler.setUp();
|
||||
|
||||
// Connector가 재접속할때까지 대기한다. reconnect 재시도 시간이 5초이므로, 5초이상 쉬어야 한다.
|
||||
ThreadSleepUtils.sleepUninterruptibly(8000);
|
||||
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
try {
|
||||
log.info("NimmConnector dispose");
|
||||
NimmConnector.shutdownGracefully();
|
||||
} finally {
|
||||
if (mockUpServerSettler != null) {
|
||||
log.info("mockserver dispose");
|
||||
mockUpServerSettler.setDown();
|
||||
mockUpServerSettler = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public AbstractNimmTest() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
package com.nhn.pinpoint.testweb.nimm.mockupserver;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
//import org.junit.Assert;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.nhncorp.lucy.net.call.Call;
|
||||
import com.nhncorp.lucy.net.call.DefaultReturnValue;
|
||||
import com.nhncorp.lucy.net.call.Reply;
|
||||
import com.nhncorp.lucy.net.call.ReturnValue;
|
||||
import com.nhncorp.lucy.net.invoker.InvocationFuture;
|
||||
import com.nhncorp.lucy.net.invoker.Invoker;
|
||||
import com.nhncorp.lucy.nimm.connector.NimmConnector;
|
||||
import com.nhncorp.lucy.nimm.connector.NimmSocket;
|
||||
import com.nhncorp.lucy.nimm.connector.bloc.NimmInvoker;
|
||||
import com.nhncorp.lucy.nimm.connector.message.NimmMessage;
|
||||
import com.nhncorp.lucy.nimm.connector.worker.NimmAbstractWorkerMock;
|
||||
import com.nhncorp.lucy.npc.DefaultNpcMessage;
|
||||
import com.nhncorp.lucy.npc.NpcMessage;
|
||||
import com.nhncorp.lucy.npc.decoder.NpcHessianDecoder;
|
||||
import com.nhncorp.lucy.npc.encoder.NpcHessianEncoder;
|
||||
|
||||
import external.org.apache.mina.filter.codec.ProtocolEncoderException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* original source : com.nhncorp.lucy.nimm.connector.bloc.NimmInvokerTest
|
||||
* </pre>
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class NimmInvokerTest extends AbstractNimmTest {
|
||||
|
||||
private Logger log = Logger.getLogger(getClass().getName());
|
||||
|
||||
private Invoker invoker;
|
||||
|
||||
private NimmSocket sendSocket;
|
||||
private NimmSocket receiveSocket;
|
||||
|
||||
private static int SEND_SOCKET_DOMAIN_ID = 101;
|
||||
private static int SEND_SOCKET_SOCKET_ID = 13;
|
||||
|
||||
private static int RECEIVE_SOCKET_DOMAIN_ID = 103;
|
||||
private static int RECEIVE_SOCKET_SOCKET_ID = 15;
|
||||
|
||||
public NimmInvokerTest() {
|
||||
try {
|
||||
initialize("/NimmMockupServer.xml");
|
||||
|
||||
sendSocket = NimmConnector.createNimmSocket(SEND_SOCKET_DOMAIN_ID, SEND_SOCKET_SOCKET_ID);
|
||||
receiveSocket = NimmConnector.createNimmSocket(RECEIVE_SOCKET_DOMAIN_ID, RECEIVE_SOCKET_SOCKET_ID);
|
||||
invoker = new NimmInvoker(receiveSocket.getAddress(), sendSocket);
|
||||
|
||||
NimmInvoker nimmInvoker = (NimmInvoker) invoker;
|
||||
long currentTimeout = nimmInvoker.getTimeout();
|
||||
nimmInvoker.setTimeout(currentTimeout + 1000L);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void tearDown() {
|
||||
if (sendSocket != null) {
|
||||
sendSocket.dispose();
|
||||
}
|
||||
if (receiveSocket != null) {
|
||||
receiveSocket.dispose();
|
||||
}
|
||||
if (invoker != null) {
|
||||
invoker.dispose();
|
||||
// Assert.assertFalse(invoker.isValid());
|
||||
if (!invoker.isValid()) {
|
||||
throw new RuntimeException("invokoer is not valid.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testInvoke() throws Exception {
|
||||
log.info("setWorker");
|
||||
|
||||
receiveSocket.setWorker(new NimmAbstractWorkerMock() {
|
||||
@Override
|
||||
protected ByteBuffer responseMessage(NimmMessage request) throws Exception {
|
||||
log.info("message response");
|
||||
|
||||
ByteBuffer npcHessianByteBuffer = request.getMessage();
|
||||
NpcMessage decodeCall = NpcHessianDecoder.decodeCall(npcHessianByteBuffer);
|
||||
Call call = (Call) decodeCall.getPayload();
|
||||
log.info("Call:" + call);
|
||||
|
||||
DefaultReturnValue result = null;
|
||||
if (decodeCall.getNamespace() == null) {
|
||||
result = new DefaultReturnValue("response without namespace");
|
||||
} else {
|
||||
result = new DefaultReturnValue("response");
|
||||
}
|
||||
|
||||
DefaultNpcMessage reply = new DefaultNpcMessage();
|
||||
reply.setNamespace(decodeCall.getNamespace());
|
||||
reply.setTransactionId(decodeCall.getTransactionId());
|
||||
reply.setPayloadCharset(decodeCall.getPayloadCharset());
|
||||
reply.setPayload(result);
|
||||
return NpcHessianEncoder.encodeReply(reply);
|
||||
}
|
||||
});
|
||||
|
||||
InvocationFuture future = invoker.invoke("objectName", "methodName", "params");
|
||||
log.info("await");
|
||||
future.await();
|
||||
Reply reply = (Reply) future.getReturnValue();
|
||||
if (reply instanceof ReturnValue) {
|
||||
ReturnValue value = (ReturnValue) reply;
|
||||
String message = (String) value.get();
|
||||
|
||||
if (!"response".equals(message)) {
|
||||
throw new RuntimeException("invalid response, " + message);
|
||||
}
|
||||
// Assert.assertEquals("response", message);
|
||||
} else {
|
||||
throw new RuntimeException("reply retrun type=" + reply);
|
||||
// Assert.fail("reply retrun type=" + reply);
|
||||
}
|
||||
|
||||
// Without object name
|
||||
future = invoker.invoke(null, "methodName", "params");
|
||||
log.info("await");
|
||||
future.await();
|
||||
reply = (Reply) future.getReturnValue();
|
||||
if (reply instanceof ReturnValue) {
|
||||
ReturnValue value = (ReturnValue) reply;
|
||||
String message = (String) value.get();
|
||||
|
||||
if (!"response without namespace".equals(message)) {
|
||||
throw new RuntimeException("invalid response, " + message);
|
||||
}
|
||||
// Assert.assertEquals("response without namespace", message);
|
||||
} else {
|
||||
throw new RuntimeException("reply retrun type=" + reply);
|
||||
// Assert.fail("reply retrun type=" + reply);
|
||||
}
|
||||
|
||||
// Assert.assertTrue(invoker.isValid());
|
||||
if (!invoker.isValid()) {
|
||||
throw new RuntimeException("invokoer is not valid.");
|
||||
}
|
||||
|
||||
invoker.dispose();
|
||||
}
|
||||
|
||||
public void testConstructorWithInvalidParams() throws Exception {
|
||||
Invoker invalidInvoker = null;
|
||||
|
||||
// First parameters
|
||||
try {
|
||||
invalidInvoker = new NimmInvoker(null, sendSocket);
|
||||
} catch (NullPointerException ex) {
|
||||
// TODO make the tested code have a better exception like
|
||||
// NimmRuntimeException
|
||||
String msg = ex.getMessage();
|
||||
|
||||
if (msg.indexOf("nimmBlocAddress") == -1) {
|
||||
throw new RuntimeException("Invalid NullPointerException for nimmBlocAddress");
|
||||
// Assert.fail("Invalid NullPointerException for nimmBlocAddress");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Invaid Exception for nimmBlocAddress", ex);
|
||||
// Assert.fail("Invaid Exception for nimmBlocAddress - " +
|
||||
// ex.getMessage());
|
||||
}
|
||||
|
||||
// Second parameters
|
||||
try {
|
||||
invalidInvoker = new NimmInvoker(receiveSocket.getAddress(), null);
|
||||
} catch (NullPointerException ex) {
|
||||
// TODO make the tested code have a better exception like
|
||||
// NimmRuntimeException
|
||||
String msg = ex.getMessage();
|
||||
if (msg.indexOf("nimmLocalSocket") == -1) {
|
||||
throw new RuntimeException("Invalid NullPointerException for nimmLocalSocket");
|
||||
// Assert.fail("Invalid NullPointerException for nimmLocalSocket");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Invaid Exception for nimmLocalSocket", ex);
|
||||
// Assert.fail("Invaid Exception for nimmLocalSocket - " +
|
||||
// ex.getMessage());
|
||||
}
|
||||
|
||||
// Third parameters
|
||||
try {
|
||||
invalidInvoker = new NimmInvoker(receiveSocket.getAddress(), sendSocket, -1000L);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
String msg = ex.getMessage();
|
||||
if (msg.indexOf("timeoutMillis") == -1) {
|
||||
throw new RuntimeException("Invalid IllegalArgumentException for timeoutMillis");
|
||||
// Assert.fail("Invalid IllegalArgumentException for timeoutMillis");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Invaid Exception for timeoutMillis - " + ex.getMessage());
|
||||
// Assert.fail("Invaid Exception for timeoutMillis - " +
|
||||
// ex.getMessage());
|
||||
}
|
||||
|
||||
if (invalidInvoker != null) {
|
||||
invalidInvoker.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void testInvokeWithInvalidParams() throws Exception {
|
||||
// methodName
|
||||
try {
|
||||
invoker.invoke("objectName", null, "params");
|
||||
} catch (NullPointerException ex) {
|
||||
// TODO make the tested code have a better exception like
|
||||
// NimmRuntimeException
|
||||
String msg = ex.getMessage();
|
||||
if (msg.indexOf("methodName") == -1) {
|
||||
throw new RuntimeException("Invalid NullPointerException for methodName");
|
||||
// Assert.fail("Invalid NullPointerException for methodName");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Invaid Exception for methodName - " + ex.getMessage());
|
||||
// Assert.fail("Invaid Exception for methodName - " +
|
||||
// ex.getMessage());
|
||||
}
|
||||
|
||||
// timeoutMillis
|
||||
try {
|
||||
NimmInvoker nimmInvoker = (NimmInvoker) invoker;
|
||||
nimmInvoker.invoke(-1000L, "objectName", "methodName", "params");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
String msg = ex.getMessage();
|
||||
if (msg.indexOf("timeoutMillis") == -1) {
|
||||
throw new RuntimeException("Invalid IllegalArgumentException for timeoutMillis");
|
||||
// Assert.fail("Invalid IllegalArgumentException for timeoutMillis");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Invaid Exception for timeoutMillis - " + ex.getMessage());
|
||||
// Assert.fail("Invaid Exception for timeoutMillis - " +
|
||||
// ex.getMessage());
|
||||
}
|
||||
|
||||
// setTimeoutMillis
|
||||
try {
|
||||
NimmInvoker nimmInvoker = (NimmInvoker) invoker;
|
||||
nimmInvoker.setTimeout(-1000L);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
String msg = ex.getMessage();
|
||||
if (msg.indexOf("timeoutMillis") == -1) {
|
||||
throw new RuntimeException("Invalid IllegalArgumentException for timeoutMillis");
|
||||
// Assert.fail("Invalid IllegalArgumentException for timeoutMillis");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Invaid Exception for timeoutMillis - " + ex.getMessage());
|
||||
// Assert.fail("Invaid Exception for timeoutMillis - " +
|
||||
// ex.getMessage());
|
||||
}
|
||||
|
||||
// params : java.lang.Class cannot be encoded.
|
||||
InvocationFuture future = invoker.invoke("objectName", "methodName", Integer.class);
|
||||
log.info("await");
|
||||
future.await();
|
||||
Exception ex = (Exception) future.getException();
|
||||
|
||||
if (!(ex instanceof ProtocolEncoderException)) {
|
||||
throw new RuntimeException("!(ex instanceof ProtocolEncoderException)");
|
||||
}
|
||||
// Assert.assertTrue(ex instanceof ProtocolEncoderException);
|
||||
|
||||
invoker.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.nhn.pinpoint.testweb.repository;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface CubridDao {
|
||||
int selectOne();
|
||||
|
||||
void createStatement();
|
||||
|
||||
void createErrorStatement();
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.nhn.pinpoint.testweb.repository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.orm.ibatis.SqlMapClientTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public class CubridDaoIbatis implements CubridDao {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("cubridSqlMapClientTemplate")
|
||||
private SqlMapClientTemplate sqlMapClientTemplate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("cubridDatasource")
|
||||
private DataSource datasource;
|
||||
|
||||
@Override
|
||||
public int selectOne() {
|
||||
return (Integer) sqlMapClientTemplate.queryForObject("selectOne");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createStatement() {
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
try {
|
||||
connection = datasource.getConnection();
|
||||
statement = connection.createStatement();
|
||||
statement.execute("select 1");
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (statement != null) {
|
||||
try {
|
||||
statement.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createErrorStatement() {
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
try {
|
||||
connection = datasource.getConnection();
|
||||
statement = connection.createStatement();
|
||||
statement.execute("SELECT * FROM NOT_EXISTS_TABLE");
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (statement != null) {
|
||||
try {
|
||||
statement.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.nhn.pinpoint.testweb.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
|
||||
public interface MemberDao {
|
||||
|
||||
void add(Member member);
|
||||
|
||||
void addStatement(Member member);
|
||||
|
||||
void update(Member member);
|
||||
|
||||
Member get(int id);
|
||||
|
||||
List<Member> list();
|
||||
|
||||
void delete(int id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.nhn.pinpoint.testweb.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.orm.ibatis.SqlMapClientTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
|
||||
@Repository
|
||||
public class MemberDaoIbatis implements MemberDao {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mysqlSqlMapClientTemplate")
|
||||
private SqlMapClientTemplate sqlMapClientTemplate;
|
||||
|
||||
public void add(Member member) {
|
||||
sqlMapClientTemplate.insert("add", member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatement(Member member) {
|
||||
sqlMapClientTemplate.insert("addStatement", member);
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
sqlMapClientTemplate.delete("delete", id);
|
||||
}
|
||||
|
||||
public Member get(int id) {
|
||||
return (Member) sqlMapClientTemplate.queryForObject("get", id);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Member> list() {
|
||||
return sqlMapClientTemplate.queryForList("list");
|
||||
}
|
||||
|
||||
public void update(Member member) {
|
||||
sqlMapClientTemplate.update("update", member);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.nhn.pinpoint.testweb.repository;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
|
||||
@Repository
|
||||
public class MemberDaoJdbc implements MemberDao {
|
||||
|
||||
@Autowired
|
||||
SimpleJdbcTemplate jdbcTemplateMysql;
|
||||
|
||||
public void setMemberMapper(RowMapper<Member> memberMapper) {
|
||||
this.memberMapper = memberMapper;
|
||||
}
|
||||
|
||||
RowMapper<Member> memberMapper = new RowMapper<Member>() {
|
||||
public Member mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
Member member = new Member();
|
||||
member.setId(rs.getInt("id"));
|
||||
member.setName(rs.getString("name"));
|
||||
member.setJoined(rs.getDate("joined"));
|
||||
return member;
|
||||
}
|
||||
};
|
||||
|
||||
public void add(Member member) {
|
||||
jdbcTemplateMysql.update("/* testquery */ insert into member(id, name, joined) values (?, ?, ?)", member.getId(), member.getName(), member.getJoined());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatement(Member member) {
|
||||
jdbcTemplateMysql.update("/* testquery */ insert into member(id, name, joined) values ('" + member.getId() + "', '" + member.getName() + "', ?)", member.getJoined());
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
jdbcTemplateMysql.update("/* testquery */ delete from member where id = ?", id);
|
||||
}
|
||||
|
||||
public Member get(int id) {
|
||||
return jdbcTemplateMysql.queryForObject("/* testquery */ select * from member where id = ?", memberMapper, id);
|
||||
}
|
||||
|
||||
public List<Member> list() {
|
||||
return jdbcTemplateMysql.query("/* testquery */ select * from member", memberMapper);
|
||||
}
|
||||
|
||||
public void update(Member member) {
|
||||
jdbcTemplateMysql.update("/* testquery */ update member set name = :name, joined = :joined where id = :id", new BeanPropertySqlParameterSource(member));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.nhn.pinpoint.testweb.repository;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface MySqlDao {
|
||||
|
||||
int selectOne();
|
||||
|
||||
void createStatement();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.nhn.pinpoint.testweb.repository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.orm.ibatis.SqlMapClientTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public class MySqlDaoIbatis implements MySqlDao {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mysqlSqlMapClientTemplate")
|
||||
private SqlMapClientTemplate sqlMapClientTemplate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mysqlDatasource")
|
||||
private DataSource datasource;
|
||||
|
||||
@Override
|
||||
public int selectOne() {
|
||||
return (Integer) sqlMapClientTemplate.queryForObject("selectOne");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createStatement() {
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
try {
|
||||
connection = datasource.getConnection();
|
||||
statement = connection.createStatement();
|
||||
statement.execute("select 1");
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (statement != null) {
|
||||
try {
|
||||
statement.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.nhn.pinpoint.testweb.repository;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface OracleDao {
|
||||
int selectOne();
|
||||
|
||||
void createStatement();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.nhn.pinpoint.testweb.repository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.orm.ibatis.SqlMapClientTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public class OracleDaoIbatis implements OracleDao {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("oracleSqlMapClientTemplate")
|
||||
private SqlMapClientTemplate sqlMapClientTemplate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("oracleDatasource")
|
||||
private DataSource datasource;
|
||||
|
||||
@Override
|
||||
public int selectOne() {
|
||||
return (Integer) sqlMapClientTemplate.queryForObject("selectOne");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createStatement() {
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
try {
|
||||
connection = datasource.getConnection();
|
||||
statement = connection.createStatement();
|
||||
statement.execute("select 1 from dual");
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (statement != null) {
|
||||
try {
|
||||
statement.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.nhn.pinpoint.testweb.repository.ibatis;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.orm.ibatis.SqlMapClientTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
import com.nhn.pinpoint.testweb.repository.MemberDao;
|
||||
|
||||
/**
|
||||
* @author Hyun Jeong
|
||||
*/
|
||||
@Repository("sqlMapClientMemberDao")
|
||||
public class SqlMapClientMemberDao implements MemberDao {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mysqlSqlMapClientTemplate")
|
||||
protected SqlMapClientTemplate sqlMapClientTemplate;
|
||||
|
||||
@Override
|
||||
public void add(Member member) {
|
||||
try {
|
||||
this.sqlMapClientTemplate.getSqlMapClient().insert("add", member);
|
||||
} catch (SQLException e) {
|
||||
throw translateSqlException("SqlMapClient add", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatement(Member member) {
|
||||
try {
|
||||
this.sqlMapClientTemplate.getSqlMapClient().insert("addStatement", member);
|
||||
} catch (SQLException e) {
|
||||
throw translateSqlException("SqlMapClient addStatement", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Member member) {
|
||||
try {
|
||||
this.sqlMapClientTemplate.getSqlMapClient().update("update", member);
|
||||
} catch (SQLException e) {
|
||||
throw translateSqlException("SqlMapClient addStatement", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Member get(int id) {
|
||||
try {
|
||||
return (Member)this.sqlMapClientTemplate.getSqlMapClient().queryForObject("get", id);
|
||||
} catch (SQLException e) {
|
||||
throw translateSqlException("SqlMapClient get", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Member> list() {
|
||||
try {
|
||||
return this.sqlMapClientTemplate.getSqlMapClient().queryForList("list");
|
||||
} catch (SQLException e) {
|
||||
throw translateSqlException("SqlMapClient list", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(int id) {
|
||||
try {
|
||||
this.sqlMapClientTemplate.getSqlMapClient().delete("delete", id);
|
||||
} catch (SQLException e) {
|
||||
throw translateSqlException("SqlMapClient delete", e);
|
||||
}
|
||||
}
|
||||
|
||||
private DataAccessException translateSqlException(String task, SQLException e) {
|
||||
return this.sqlMapClientTemplate.getExceptionTranslator().translate(task, null, e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.nhn.pinpoint.testweb.repository.ibatis;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.orm.ibatis.SqlMapClientTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
import com.nhn.pinpoint.testweb.repository.MemberDao;
|
||||
|
||||
/**
|
||||
* @author Hyun Jeong
|
||||
*/
|
||||
@Repository("sqlMapSessionMemberDao")
|
||||
public class SqlMapSessionMemberDao implements MemberDao {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mysqlSqlMapClientTemplate")
|
||||
private SqlMapClientTemplate sqlMapClientTemplate;
|
||||
|
||||
@Override
|
||||
public void add(Member member) {
|
||||
this.sqlMapClientTemplate.insert("add", member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatement(Member member) {
|
||||
this.sqlMapClientTemplate.insert("addStatement", member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Member member) {
|
||||
this.sqlMapClientTemplate.update("update", member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Member get(int id) {
|
||||
return (Member)this.sqlMapClientTemplate.queryForObject("get", id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Member> list() {
|
||||
return this.sqlMapClientTemplate.queryForList("list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(int id) {
|
||||
this.sqlMapClientTemplate.delete("delete", id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.nhn.pinpoint.testweb.repository.mybatis;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
|
||||
/**
|
||||
* @author Hyun Jeong
|
||||
*/
|
||||
@Repository("memberMapper")
|
||||
public interface MemberMapper {
|
||||
|
||||
public Member selectUser(@Param("id") int id);
|
||||
|
||||
public List<Member> selectAllUsersInvalid();
|
||||
|
||||
public int insertUser(Member member);
|
||||
|
||||
public int updateUser(Member member);
|
||||
|
||||
public int deleteUser(@Param("id") int id);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.nhn.pinpoint.testweb.service;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public interface CacheService {
|
||||
|
||||
public void arcus();
|
||||
|
||||
public void memcached();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.nhn.pinpoint.testweb.service;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.spy.memcached.AddrUtil;
|
||||
import net.spy.memcached.ArcusClient;
|
||||
import net.spy.memcached.ConnectionFactoryBuilder;
|
||||
import net.spy.memcached.MemcachedClient;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public class CacheServiceImpl implements CacheService, DisposableBean {
|
||||
|
||||
private ArcusClient arcus;
|
||||
private MemcachedClient memcached;
|
||||
|
||||
public CacheServiceImpl() {
|
||||
try {
|
||||
arcus = ArcusClient.createArcusClient("dev.arcuscloud.nhncorp.com:17288", "dev", new ConnectionFactoryBuilder());
|
||||
memcached = new MemcachedClient(AddrUtil.getAddresses("10.25.149.80:11244,10.25.149.80:11211,10.25.149.79:11211"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arcus() {
|
||||
int rand = new Random().nextInt(100);
|
||||
String key = "pinpoint:testkey-" + rand;
|
||||
|
||||
// set
|
||||
Future<Boolean> setFuture = null;
|
||||
try {
|
||||
setFuture = arcus.set(key, 10, "Hello, pinpoint." + rand);
|
||||
setFuture.get(1000L, TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
if (setFuture != null)
|
||||
setFuture.cancel(true);
|
||||
}
|
||||
|
||||
// get
|
||||
Future<Object> getFuture = null;
|
||||
try {
|
||||
getFuture = arcus.asyncGet(key);
|
||||
getFuture.get(1000L, TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
if (getFuture != null)
|
||||
getFuture.cancel(true);
|
||||
}
|
||||
|
||||
// del
|
||||
Future<Boolean> delFuture = null;
|
||||
try {
|
||||
delFuture = arcus.delete(key);
|
||||
delFuture.get(1000L, TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
if (delFuture != null)
|
||||
delFuture.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memcached() {
|
||||
int rand = new Random().nextInt(100);
|
||||
String key = "pinpoint:testkey-" + rand;
|
||||
|
||||
// set
|
||||
Future<Boolean> setFuture = null;
|
||||
try {
|
||||
setFuture = memcached.set(key, 10, "Hello, pinpoint." + rand);
|
||||
setFuture.get(1000L, TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
if (setFuture != null)
|
||||
setFuture.cancel(true);
|
||||
}
|
||||
|
||||
// get
|
||||
Future<Object> getFuture = null;
|
||||
try {
|
||||
getFuture = memcached.asyncGet(key);
|
||||
getFuture.get(1000L, TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
if (getFuture != null)
|
||||
getFuture.cancel(true);
|
||||
}
|
||||
|
||||
// del
|
||||
Future<Boolean> delFuture = null;
|
||||
try {
|
||||
delFuture = memcached.delete(key);
|
||||
delFuture.get(1000L, TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
if (delFuture != null)
|
||||
delFuture.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
arcus.shutdown();
|
||||
memcached.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.nhn.pinpoint.testweb.service;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface CubridService {
|
||||
|
||||
int selectOne();
|
||||
|
||||
void createStatement();
|
||||
|
||||
void createErrorStatement();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.nhn.pinpoint.testweb.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.nhn.pinpoint.testweb.repository.CubridDao;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
@Transactional("cubridTransactionManager")
|
||||
public class CubridServiceImpl implements CubridService {
|
||||
@Autowired
|
||||
private CubridDao cubridDao;
|
||||
|
||||
@Override
|
||||
public int selectOne() {
|
||||
return cubridDao.selectOne();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createStatement() {
|
||||
cubridDao.createStatement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createErrorStatement() {
|
||||
cubridDao.createErrorStatement();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.nhn.pinpoint.testweb.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.HttpConnectorOptions;
|
||||
import com.nhn.pinpoint.testweb.connector.apachehttp4.ApacheHttpClient4;
|
||||
|
||||
@Service
|
||||
public class DummyService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* doSomething(); // 2
|
||||
* a(); // 3
|
||||
* b(); // 3
|
||||
* ba(); // 4
|
||||
* baa(); // 5
|
||||
* bb(); // 4
|
||||
* c(); // 3
|
||||
* ca(); // 4
|
||||
* </pre>
|
||||
*/
|
||||
public void doSomething() {
|
||||
System.out.println("do something.");
|
||||
a();
|
||||
b();
|
||||
c();
|
||||
}
|
||||
|
||||
private void a() {
|
||||
System.out.println("a");
|
||||
}
|
||||
|
||||
private void b() {
|
||||
System.out.println("b");
|
||||
ba();
|
||||
bb();
|
||||
}
|
||||
|
||||
private void ba() {
|
||||
System.out.println("ba");
|
||||
baa();
|
||||
}
|
||||
|
||||
private void bb() {
|
||||
System.out.println("bb");
|
||||
}
|
||||
|
||||
private void baa() {
|
||||
System.out.println("baa");
|
||||
}
|
||||
|
||||
private void c() {
|
||||
System.out.println("c");
|
||||
ca();
|
||||
}
|
||||
|
||||
private void ca() {
|
||||
System.out.println("ca");
|
||||
ApacheHttpClient4 client = new ApacheHttpClient4(new HttpConnectorOptions());
|
||||
client.execute("http://localhost:8080/mysqlsimple.pinpoint", new HashMap<String, Object>());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.nhn.pinpoint.testweb.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
|
||||
public interface MemberService {
|
||||
|
||||
void add(Member member);
|
||||
|
||||
void addStatement(Member member);
|
||||
|
||||
void update(Member member);
|
||||
|
||||
Member get(int id);
|
||||
|
||||
List<Member> list();
|
||||
|
||||
void delete(int id);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.nhn.pinpoint.testweb.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
import com.nhn.pinpoint.testweb.repository.MemberDao;
|
||||
|
||||
@Service("memberService")
|
||||
@Transactional("mysqlTransactionManager")
|
||||
public class MemberServiceImpl implements MemberService {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("memberDaoJdbc")
|
||||
private MemberDao dao;
|
||||
|
||||
public MemberDao getDao() {
|
||||
return dao;
|
||||
}
|
||||
|
||||
public void setDao(MemberDao dao) {
|
||||
this.dao = dao;
|
||||
}
|
||||
|
||||
public void add(Member member) {
|
||||
dao.add(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatement(Member member) {
|
||||
dao.addStatement(member);
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
dao.delete(id);
|
||||
}
|
||||
|
||||
public Member get(int id) {
|
||||
return dao.get(id);
|
||||
}
|
||||
|
||||
public List<Member> list() {
|
||||
return dao.list();
|
||||
}
|
||||
|
||||
public void update(Member member) {
|
||||
dao.update(member);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.nhn.pinpoint.testweb.service;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface MySqlService {
|
||||
|
||||
int selectOne();
|
||||
|
||||
void createStatement();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.nhn.pinpoint.testweb.service;
|
||||
|
||||
import com.nhn.pinpoint.testweb.repository.MySqlDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
@Transactional("mysqlTransactionManager")
|
||||
public class MySqlServiceImpl implements MySqlService {
|
||||
|
||||
@Autowired
|
||||
private MySqlDao mysqlDao;
|
||||
|
||||
@Override
|
||||
public int selectOne() {
|
||||
return mysqlDao.selectOne();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createStatement() {
|
||||
mysqlDao.createStatement();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.nhn.pinpoint.testweb.service;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface OracleService {
|
||||
|
||||
int selectOne();
|
||||
|
||||
void createStatement();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.nhn.pinpoint.testweb.service;
|
||||
|
||||
import com.nhn.pinpoint.testweb.repository.OracleDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
@Transactional("oracleTransactionManager")
|
||||
public class OracleServiceImpl implements OracleService {
|
||||
@Autowired
|
||||
private OracleDao oracleDao;
|
||||
|
||||
@Override
|
||||
public int selectOne() {
|
||||
return oracleDao.selectOne();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createStatement() {
|
||||
oracleDao.createStatement();
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.nhn.pinpoint.testweb.service.orm.ibatis;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
import com.nhn.pinpoint.testweb.repository.MemberDao;
|
||||
import com.nhn.pinpoint.testweb.service.MemberService;
|
||||
|
||||
/**
|
||||
* @author Hyun Jeong
|
||||
*/
|
||||
@Service("sqlMapClientMemberService")
|
||||
@Transactional("mysqlTransactionManager")
|
||||
public class SqlMapClientMemberService implements MemberService {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("sqlMapClientMemberDao")
|
||||
private MemberDao sqlMapClientMemberDao;
|
||||
|
||||
@Override
|
||||
public void add(Member member) {
|
||||
this.sqlMapClientMemberDao.add(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatement(Member member) {
|
||||
this.sqlMapClientMemberDao.addStatement(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Member member) {
|
||||
this.sqlMapClientMemberDao.update(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Member get(int id) {
|
||||
return this.sqlMapClientMemberDao.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Member> list() {
|
||||
return this.sqlMapClientMemberDao.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(int id) {
|
||||
this.sqlMapClientMemberDao.delete(id);
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.nhn.pinpoint.testweb.service.orm.ibatis;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
import com.nhn.pinpoint.testweb.repository.MemberDao;
|
||||
import com.nhn.pinpoint.testweb.service.MemberService;
|
||||
|
||||
/**
|
||||
* @author Hyun Jeong
|
||||
*/
|
||||
@Service("sqlMapSessionMemberService")
|
||||
@Transactional("mysqlTransactionManager")
|
||||
public class SqlMapSessionMemberService implements MemberService {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("sqlMapSessionMemberDao")
|
||||
private MemberDao sqlMapSessionMemberDao;
|
||||
|
||||
@Override
|
||||
public void add(Member member) {
|
||||
this.sqlMapSessionMemberDao.add(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatement(Member member) {
|
||||
this.sqlMapSessionMemberDao.addStatement(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Member member) {
|
||||
this.sqlMapSessionMemberDao.update(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Member get(int id) {
|
||||
return this.sqlMapSessionMemberDao.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Member> list() {
|
||||
return this.sqlMapSessionMemberDao.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(int id) {
|
||||
this.sqlMapSessionMemberDao.delete(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.nhn.pinpoint.testweb.service.orm.mybatis;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.nhn.pinpoint.testweb.domain.Member;
|
||||
import com.nhn.pinpoint.testweb.repository.mybatis.MemberMapper;
|
||||
import com.nhn.pinpoint.testweb.service.MemberService;
|
||||
|
||||
/**
|
||||
* @author Hyun Jeong
|
||||
*/
|
||||
@Service("myBatisMemberService")
|
||||
@Transactional("mysqlTransactionManager")
|
||||
public class MyBatisMemberService implements MemberService {
|
||||
|
||||
@Autowired
|
||||
private MemberMapper memberMapper;
|
||||
|
||||
@Override
|
||||
public void add(Member member) {
|
||||
this.memberMapper.insertUser(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatement(Member member) {
|
||||
this.memberMapper.insertUser(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Member member) {
|
||||
this.memberMapper.updateUser(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Member get(int id) {
|
||||
return this.memberMapper.selectUser(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Member> list() {
|
||||
return this.memberMapper.selectAllUsersInvalid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(int id) {
|
||||
this.memberMapper.deleteUser(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.nhn.pinpoint.testweb.util;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Description {
|
||||
String value();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.nhn.pinpoint.testweb.vo;
|
||||
|
||||
public class RequestMappingInfo {
|
||||
private String url;
|
||||
private String description;
|
||||
|
||||
public RequestMappingInfo(String url, String description) {
|
||||
this.url = url;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RequestMappingInfo [url=" + url + ", description=" + description + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.nhncorp.lucy.nimm.connector.agent;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.MessageFuture;
|
||||
import com.nhncorp.lucy.nimm.connector.NimmSocket;
|
||||
import com.nhncorp.lucy.nimm.connector.agent.provider.AgentInfo;
|
||||
import com.nhncorp.lucy.nimm.connector.agent.provider.NimmAgentArchetype;
|
||||
import com.nhncorp.lucy.nimm.connector.message.NimmMessage;
|
||||
import com.nhncorp.lucy.nimm.connector.worker.NimmAbstractWorker;
|
||||
import com.nhncorp.lucy.nimm.connector.worker.NimmWorker;
|
||||
|
||||
@AgentInfo( domainId = 7, socketId = 1)
|
||||
public class AnnotatedMgmtAgent extends NimmAgentArchetype implements ManagementAgentAPI {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(AnnotatedMgmtAgent.class.getName());
|
||||
|
||||
private final NimmWorker worker;
|
||||
|
||||
public AnnotatedMgmtAgent() {
|
||||
this.worker = new AnnotatedMgmtWorker();
|
||||
}
|
||||
@Override
|
||||
public void destroy() {
|
||||
LOGGER.info("AnnotatedMgmtAgent.destroy()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NimmWorker getNimmWorker() {
|
||||
return worker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
LOGGER.info("AnnotatedMgmtAgent.init()");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "AnnotatedMgmtAgent";
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
private class AnnotatedMgmtWorker extends NimmAbstractWorker {
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
LOGGER.info("AnnotatedMgmtWorker.destroy()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
LOGGER.info("AnnotatedMgmtWorker.init()");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processMessage(NimmMessage message) throws Exception {
|
||||
getMySocket().send(message.getSourceAddress(), message.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ByteBuffer responseMessage(NimmMessage request)
|
||||
throws Exception {
|
||||
return request.getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean loopMessage() throws Exception {
|
||||
NimmSocket localSocket = createSocket();
|
||||
|
||||
byte[] msg = "UlaUlaWowWow".getBytes();
|
||||
MessageFuture future = localSocket.request(getMySocket(), msg);
|
||||
|
||||
future.await();
|
||||
|
||||
return Arrays.equals(future.getResponse().getMessageAsArray(),msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.nhncorp.lucy.nimm.connector.agent;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.MessageFuture;
|
||||
import com.nhncorp.lucy.nimm.connector.NimmSocket;
|
||||
import com.nhncorp.lucy.nimm.connector.agent.provider.AgentInfo;
|
||||
import com.nhncorp.lucy.nimm.connector.agent.provider.NimmAgentArchetype;
|
||||
import com.nhncorp.lucy.nimm.connector.message.NimmMessage;
|
||||
import com.nhncorp.lucy.nimm.connector.worker.NimmAbstractWorker;
|
||||
import com.nhncorp.lucy.nimm.connector.worker.NimmWorker;
|
||||
|
||||
@AgentInfo(domainId = 7, socketId = 1)
|
||||
public class ManagementAgent extends NimmAgentArchetype implements ManagementAgentAPI {
|
||||
private Logger logger = Logger.getLogger(getClass().getName());
|
||||
|
||||
private final NimmWorker worker;
|
||||
|
||||
public ManagementAgent() {
|
||||
this.worker = new ManagementWorker();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// ManagementAgentTest.initMethodCallCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// ManagementAgentTest.destoryMethodCallCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NimmWorker getNimmWorker() {
|
||||
return this.worker;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "MGMTAgentTest";
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
public void setRala(int value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setWRala(Integer value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setCooKoo(String value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setYoYo(float value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setWYoYo(Float value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setOhoo(double value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setWohoo(Double value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setAwesome(char value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setWawesome(Character value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setActive(boolean value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setWactive(Boolean value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setBinary(byte value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setWbinary(Byte value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setShortint(short value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setWshortint(Short value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setLongint(long value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setWlongint(Long value) {
|
||||
logger.fine(String.valueOf(value));
|
||||
}
|
||||
|
||||
private class ManagementWorker extends NimmAbstractWorker {
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processMessage(NimmMessage message) throws Exception {
|
||||
getMySocket().send(message.getSourceAddress(), message.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ByteBuffer responseMessage(NimmMessage request) throws Exception {
|
||||
return request.getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean loopMessage() throws Exception {
|
||||
|
||||
NimmSocket localSocket = createSocket();
|
||||
|
||||
byte[] msg = "UlaUlaWowWow".getBytes();
|
||||
MessageFuture future = localSocket.request(getMySocket(), msg);
|
||||
|
||||
future.await();
|
||||
|
||||
return Arrays.equals(future.getResponse().getMessageAsArray(), msg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.nhncorp.lucy.nimm.connector.agent;
|
||||
|
||||
interface ManagementAgentAPI {
|
||||
|
||||
boolean loopMessage() throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.nhncorp.lucy.nimm.connector.agent;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress;
|
||||
import com.nhncorp.lucy.nimm.connector.agent.provider.NimmAgentArchetype;
|
||||
import com.nhncorp.lucy.nimm.connector.message.NimmMessage;
|
||||
import com.nhncorp.lucy.nimm.connector.worker.NimmAbstractWorker;
|
||||
import com.nhncorp.lucy.nimm.connector.worker.NimmWorker;
|
||||
|
||||
public class ServiceAgent extends NimmAgentArchetype implements ServiceAgentAPI {
|
||||
|
||||
private final Worker worker = new Worker();
|
||||
|
||||
ServiceAgent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// ServiceAgentTest.initMethodCalled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// ServiceAgentTest.destoryMethodCalled = true;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return "ComicSexy";
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "MyNameWillBeForgotten";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NimmWorker getNimmWorker() {
|
||||
return this.worker;
|
||||
}
|
||||
|
||||
|
||||
private class Worker extends NimmAbstractWorker {
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processMessage(NimmMessage message) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ByteBuffer responseMessage(NimmMessage request)
|
||||
throws Exception {
|
||||
return request.getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void sendMessage(NimmAddress targetAddress, byte[] message) {
|
||||
getMySocket().send(targetAddress,message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.nhncorp.lucy.nimm.connector.agent;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress;
|
||||
|
||||
interface ServiceAgentAPI {
|
||||
|
||||
|
||||
void sendMessage(NimmAddress targetAddress, byte[] message);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.nhncorp.lucy.nimm.connector.record;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.record.NimmControlRecord;
|
||||
import com.nhncorp.lucy.nimm.connector.record.NimmRecordHeader;
|
||||
|
||||
import external.org.apache.mina.common.IoBuffer;
|
||||
|
||||
|
||||
/**
|
||||
* NimmMockupServer에서 사용하는 NimmControlRecordFactory를 생성
|
||||
*
|
||||
* @author nhn
|
||||
*
|
||||
*/
|
||||
public final class NimmControlRecordFactory {
|
||||
|
||||
/**
|
||||
* Blank private constructor
|
||||
*/
|
||||
private NimmControlRecordFactory() {
|
||||
// Blank private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* create NimmControlRecord by given header and payload
|
||||
*
|
||||
* @param header header of NIMM control message
|
||||
* @param payload payload of NIMM control message
|
||||
* @return NIMM control message
|
||||
*/
|
||||
public static NimmControlRecord create(NimmRecordHeader header, byte[] payload) {
|
||||
return NimmControlRecord.recordCreationFactory(header, IoBuffer.wrap(payload));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.nhncorp.lucy.nimm.connector.record;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress;
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmIndividual;
|
||||
import com.nhncorp.lucy.nimm.connector.record.NimmControlRecord.ControlCode;
|
||||
|
||||
/**
|
||||
* NimmMockupServer에서 사용하는 NimmRecordHeader를 생성
|
||||
*
|
||||
* @author nhn
|
||||
*
|
||||
*/
|
||||
public final class NimmRecordHeaderFactory {
|
||||
|
||||
/**
|
||||
* Blank private constructor
|
||||
*/
|
||||
private NimmRecordHeaderFactory() {
|
||||
// Blank private constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* create NimmRecordHeader
|
||||
* (NIMM Control Message, BYE, Duplicated Address)
|
||||
*
|
||||
* @param remoteAddress remote NIMM address
|
||||
* @param localAddress local NIMM address
|
||||
* @return BYE control message header with duplicated address
|
||||
*/
|
||||
public static NimmRecordHeader createBYEwithDuplicatedAddr(NimmAddress remoteAddress, NimmAddress localAddress) {
|
||||
NimmIndividual[] blankPathThrogh = new NimmIndividual[0];
|
||||
int messageId = NimmRecordUtilities.getNextId();
|
||||
|
||||
NimmRecordHeader header = new NimmRecordHeader.Normal(Constants.HEADER.VERSION,
|
||||
ControlCode.BYE.getCodeNumber(), 12,
|
||||
Constants.HEADER.OPTION.FLAG_NONE,
|
||||
Constants.HEADER.CONTROLPARAMETER.NACK_DUPLICATED_ADDRESS_LIST, 0, 0, messageId, 0,
|
||||
remoteAddress, localAddress, blankPathThrogh);
|
||||
|
||||
return header;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.nhncorp.lucy.nimm.connector.worker;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.message.NimmMessage;
|
||||
|
||||
/**
|
||||
* User: emeroad Date: 2009. 2. 27 Time: 오후 10:34:23
|
||||
*/
|
||||
public class NimmAbstractWorkerMock extends NimmAbstractWorker {
|
||||
private Exception ex;
|
||||
|
||||
public void init() {
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
protected void processMessage(NimmMessage message) throws Exception {
|
||||
ex = new UnsupportedOperationException("processMessage");
|
||||
}
|
||||
|
||||
protected ByteBuffer responseMessage(NimmMessage request) throws Exception {
|
||||
ex = new UnsupportedOperationException("responseMessage");
|
||||
return ByteBuffer.allocate(0);
|
||||
}
|
||||
|
||||
public void checkException() {
|
||||
if (ex == null) {
|
||||
return;
|
||||
}
|
||||
// Assert.fail(ex.getMessage());
|
||||
}
|
||||
|
||||
protected void setException(Exception ex) {
|
||||
this.ex = ex;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.nhncorp.lucy.nimm.mockupserver;
|
||||
|
||||
public class AnycastKey {
|
||||
|
||||
private final int domainId;
|
||||
private final int idcId;
|
||||
|
||||
AnycastKey(int domainId, int idcId) {
|
||||
this.domainId = domainId;
|
||||
this.idcId = idcId;
|
||||
}
|
||||
|
||||
int getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
int getIdcId() {
|
||||
return idcId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (null == o) return true;
|
||||
if (!(o instanceof AnycastKey)) return false;
|
||||
|
||||
AnycastKey that = (AnycastKey) o;
|
||||
|
||||
if (domainId != that.domainId) return false;
|
||||
if (idcId != that.idcId) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = domainId;
|
||||
result = 31 * result + idcId;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.nhncorp.lucy.nimm.mockupserver;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* User: emeroad
|
||||
* Date: 2010. 3. 24
|
||||
* Time: 오전 11:52:07
|
||||
*
|
||||
* @author Middleware Platform Dev. Team
|
||||
*/
|
||||
public class AnycastRoutingTable {
|
||||
private Logger logger = Logger.getLogger(getClass().getName());
|
||||
|
||||
private final ConcurrentMap<AnycastKey, List<IoSessionPair>> routingTable = new ConcurrentHashMap<AnycastKey, List<IoSessionPair>>();
|
||||
private final AtomicInteger rrKey = new AtomicInteger(0);
|
||||
|
||||
public List<IoSessionPair> register(AnycastKey anycastKey, IoSessionPair pair) {
|
||||
List<IoSessionPair> list = this.routingTable.get(anycastKey);
|
||||
if (list == null) {
|
||||
// 약간의 동시성 문제가 있나? 생각좀 해봐야 할듯.
|
||||
list = new CopyOnWriteArrayList<IoSessionPair>();
|
||||
}
|
||||
list.add(pair);
|
||||
return this.routingTable.put(anycastKey, list);
|
||||
}
|
||||
|
||||
public List<IoSessionPair> select(AnycastKey key) {
|
||||
return this.routingTable.get(key);
|
||||
}
|
||||
|
||||
public IoSessionPair roundRobinSelect(AnycastKey key, boolean routingCheck) {
|
||||
List<IoSessionPair> ioSessionPairList = select(key);
|
||||
if(ioSessionPairList == null) {
|
||||
return null;
|
||||
}
|
||||
int size = ioSessionPairList.size();
|
||||
if (size == 0) {
|
||||
// anycast로 roundRobin할 키가 없음.
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
try {
|
||||
IoSessionPair sessionPair = ioSessionPairList.get(rrKey.incrementAndGet() % size);
|
||||
if(routingCheck) {
|
||||
RoutingState routingState = RoutingState.getRoutingState(sessionPair.getIoSession());
|
||||
if(routingState.isAnycastRouting(key.getDomainId())) {
|
||||
return sessionPair;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
return sessionPair;
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
logger.log(Level.WARNING, "index select error", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.nhncorp.lucy.nimm.mockupserver;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.NimmRunTimeException;
|
||||
import com.nhncorp.lucy.nimm.connector.address.AbnormalNimmAddressException;
|
||||
import com.nhncorp.lucy.nimm.connector.address.AddressAdmin;
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress;
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress.Species;
|
||||
|
||||
class ClientInformation {
|
||||
|
||||
private final int domainId;
|
||||
private final int idcId;
|
||||
private final int serverId;
|
||||
private NimmAddress representativeAddress;
|
||||
private Set<Integer> domainIdSet;
|
||||
|
||||
private final AddressAdmin addressAdmin = NimmAddress.getHandle();
|
||||
|
||||
|
||||
ClientInformation(Species species, int domainId, int idcId, int serverId) {
|
||||
this.domainId = domainId;
|
||||
this.idcId = idcId;
|
||||
this.serverId = serverId;
|
||||
this.domainIdSet = Collections.synchronizedSet(new TreeSet<Integer>());
|
||||
|
||||
try {
|
||||
this.representativeAddress = addressAdmin.retrieveAddressInstance(species,0,
|
||||
this.idcId, this.serverId, 0, 0);
|
||||
} catch (AbnormalNimmAddressException e) {
|
||||
throw new NimmRunTimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void addDomainId(int domainId) {
|
||||
this.domainIdSet.add(domainId);
|
||||
}
|
||||
|
||||
|
||||
int getIdcId() {
|
||||
return idcId;
|
||||
}
|
||||
|
||||
int getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
|
||||
int getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
|
||||
NimmAddress getRepresentativeAddress() {
|
||||
return this.representativeAddress;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.nhncorp.lucy.nimm.mockupserver;
|
||||
|
||||
/**
|
||||
* User: emeroad
|
||||
* Date: 2010. 3. 24
|
||||
* Time: 오전 11:56:13
|
||||
*
|
||||
* @author Middleware Platform Dev. Team
|
||||
*/
|
||||
public class ClientKey {
|
||||
private final int domainId;
|
||||
private final int idcId;
|
||||
private final int serverId;
|
||||
|
||||
ClientKey(int domainId, int idcId, int serverId) {
|
||||
this.domainId = domainId;
|
||||
this.idcId = idcId;
|
||||
this.serverId = serverId;
|
||||
}
|
||||
|
||||
int getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
int getIdcId() {
|
||||
return idcId;
|
||||
}
|
||||
|
||||
int getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + domainId;
|
||||
result = prime * result + idcId;
|
||||
result = prime * result + serverId;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final ClientKey other = (ClientKey) obj;
|
||||
if (domainId != other.domainId)
|
||||
return false;
|
||||
if (idcId != other.idcId)
|
||||
return false;
|
||||
if (serverId != other.serverId)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ClientKey{" +
|
||||
"domainId=" + domainId +
|
||||
", idcId=" + idcId +
|
||||
", serverId=" + serverId +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.nhncorp.lucy.nimm.mockupserver;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress;
|
||||
import external.org.apache.mina.common.IoSession;
|
||||
|
||||
/**
|
||||
* User: emeroad
|
||||
* Date: 2010. 3. 24
|
||||
* Time: 오전 11:57:46
|
||||
*
|
||||
* @author Middleware Platform Dev. Team
|
||||
*/
|
||||
public class IoSessionPair {
|
||||
private IoSession ioSession;
|
||||
private NimmAddress address;
|
||||
|
||||
|
||||
public IoSessionPair(IoSession session, NimmAddress address){
|
||||
this.ioSession = session;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public IoSession getIoSession() {
|
||||
return ioSession;
|
||||
}
|
||||
|
||||
public NimmAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package com.nhncorp.lucy.nimm.mockupserver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.NimmRunTimeException;
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress;
|
||||
import com.nhncorp.lucy.nimm.connector.config.ConfigManager;
|
||||
import com.nhncorp.lucy.nimm.connector.config.NimmConnector20Config;
|
||||
import com.nhncorp.lucy.nimm.connector.config.NimmDivisionInfo;
|
||||
import com.nhncorp.lucy.nimm.connector.config.ServerInformation;
|
||||
|
||||
public class MockUpServerSettler {
|
||||
|
||||
private Logger log = Logger.getLogger(getClass().getName());
|
||||
|
||||
private final Map<ServerInformation, NimmMockupServer> serverMap;
|
||||
|
||||
private final MockupServerFactory serverFactory;
|
||||
|
||||
public MockUpServerSettler(String resourceName) {
|
||||
|
||||
NimmConnector20Config configuration = null;
|
||||
try {
|
||||
URL configURL = MockUpServerSettler.class.getResource(resourceName);
|
||||
ConfigManager configManager = new ConfigManager();
|
||||
configuration = configManager.getConfig(configURL, true);
|
||||
} catch (Exception e) {
|
||||
throw new NimmRunTimeException("Configuration couldn't be loaded", e);
|
||||
}
|
||||
|
||||
this.serverFactory = new MockupServerFactory(1);
|
||||
|
||||
NimmDivisionInfo mgmtInfo = configuration.getNimmMgmtInfo();
|
||||
NimmDivisionInfo svcInfo = configuration.getNimmServiceInfo();
|
||||
this.serverMap = new HashMap<ServerInformation, NimmMockupServer>();
|
||||
|
||||
verifyThenAddServerInfo(NimmAddress.Species.Management, mgmtInfo);
|
||||
verifyThenAddServerInfo(NimmAddress.Species.Service, svcInfo);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void verifyThenAddServerInfo(NimmAddress.Species species, NimmDivisionInfo divisionInfo) {
|
||||
|
||||
if(divisionInfo == null) {
|
||||
throw new RuntimeException("There isn't" + species.toString() + "Info");
|
||||
}
|
||||
|
||||
if (validateServerInformation(divisionInfo.getNimmServerAddress())) {
|
||||
throw new RuntimeException(species.toString() + " Server Infos are wrong.");
|
||||
}
|
||||
|
||||
for(Map.Entry<String, List<ServerInformation>> catalogEntry : divisionInfo.getNimmServerAddress().entrySet()) {
|
||||
for(ServerInformation serverInfo : catalogEntry.getValue()) {
|
||||
|
||||
int port = serverInfo.getInetSocketAddress().getPort();
|
||||
NimmMockupServer mockupServer = serverFactory.createMockUpServer(species, port);
|
||||
this.serverMap.put(serverInfo, mockupServer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
|
||||
|
||||
for(Map.Entry<ServerInformation, NimmMockupServer> entry : serverMap.entrySet()) {
|
||||
try {
|
||||
NimmMockupServer mockupServer = entry.getValue();
|
||||
mockupServer.start();
|
||||
} catch (IOException e) {
|
||||
if (log.isLoggable(Level.WARNING)) {
|
||||
log.log(Level.WARNING, "Can't Activate MockUpServer " + entry.getKey(), e);
|
||||
}
|
||||
throw new RuntimeException("mockupServer start error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setDown() {
|
||||
boolean error = false;
|
||||
for (Map.Entry<ServerInformation, NimmMockupServer> entry : this.serverMap.entrySet()) {
|
||||
try {
|
||||
ServerInformation serverInfo = entry.getKey();
|
||||
NimmMockupServer mockupServer = entry.getValue();
|
||||
mockupServer.stop();
|
||||
if(log.isLoggable(Level.INFO)) {
|
||||
log.info(serverInfo + " has been stopped.");
|
||||
}
|
||||
} catch(Throwable th){
|
||||
log.log(Level.WARNING, "MockUPServer setDown error", th);
|
||||
}
|
||||
}
|
||||
if(error) {
|
||||
throw new RuntimeException("check log down error");
|
||||
}
|
||||
}
|
||||
|
||||
public void setGracefulDown() {
|
||||
boolean error = false;
|
||||
for (Map.Entry<ServerInformation, NimmMockupServer> entry : this.serverMap.entrySet()) {
|
||||
try {
|
||||
ServerInformation serverInfo = entry.getKey();
|
||||
NimmMockupServer mockupServer = entry.getValue();
|
||||
mockupServer.gracefulStop();
|
||||
if(log.isLoggable(Level.INFO)) {
|
||||
log.info(serverInfo + " has been graceful stopped.");
|
||||
}
|
||||
} catch(Throwable th){
|
||||
log.log(Level.WARNING, "MockUPServer setGracefulDown error", th);
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
if(error) {
|
||||
throw new RuntimeException("check log gracefuldown error");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validateServerInformation(Map<String, List<ServerInformation>> serverCatalog) {
|
||||
|
||||
|
||||
if(serverCatalog == null || serverCatalog.isEmpty())
|
||||
return false;
|
||||
|
||||
Set<Integer> portSet = new HashSet<Integer>();
|
||||
InetAddress localHost = null;
|
||||
try {
|
||||
localHost = InetAddress.getLocalHost();
|
||||
} catch (UnknownHostException e) {
|
||||
// don't need to handle exception
|
||||
}
|
||||
byte[] loopbackIP = new byte[4];
|
||||
loopbackIP[0] = 127;
|
||||
loopbackIP[1] = loopbackIP[2] = 0;
|
||||
loopbackIP[3] = 1;
|
||||
|
||||
|
||||
for(Map.Entry<String, List<ServerInformation>> catalogEntry : serverCatalog.entrySet()) {
|
||||
|
||||
for(ServerInformation serverInfo : catalogEntry.getValue()) {
|
||||
InetSocketAddress inetAddress = serverInfo.getInetSocketAddress();
|
||||
if (!portSet.add(inetAddress.getPort()))
|
||||
return false;
|
||||
byte[] serverIP = inetAddress.getAddress().getAddress();
|
||||
// TODO array를 잘못비교하고 있는것으로 보임. equals수정해야 되는지 검토
|
||||
if (localHost != null && (localHost.getAddress().equals(serverIP)))
|
||||
continue;
|
||||
else if (!serverIP.equals(loopbackIP))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add pre-registered NimmConnector Address
|
||||
*
|
||||
* @param domainId Domain Id of pre-registered NimmConnector
|
||||
* @param serverId Server Id of pre-registered NimmConnector
|
||||
*/
|
||||
public void addPreRegisteredConnector(int domainId, int serverId) {
|
||||
for (Map.Entry<ServerInformation, NimmMockupServer> serverEntry : serverMap.entrySet()) {
|
||||
NimmMockupServer server = serverEntry.getValue();
|
||||
server.addDummyClientManually(domainId, serverId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove pre-registered NimmConnector Address
|
||||
*
|
||||
* @param domainId Domain Id of pre-registered NimmConnector
|
||||
* @param serverId Server Id of pre-registered NimmConnector
|
||||
*/
|
||||
public void removePreRegisteredConnector(int domainId, int serverId) {
|
||||
for (Map.Entry<ServerInformation, NimmMockupServer> serverEntry : serverMap.entrySet()) {
|
||||
NimmMockupServer server = serverEntry.getValue();
|
||||
server.removeDummyClientManually(domainId, serverId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.nhncorp.lucy.nimm.mockupserver;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.address.AddressAdmin;
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress;
|
||||
import com.nhncorp.lucy.nimm.connector.address.AbnormalNimmAddressException;
|
||||
|
||||
class MockupServerFactory {
|
||||
|
||||
private volatile int idcId;
|
||||
|
||||
private final Map<NimmAddress.Species, AtomicInteger> serverIds;
|
||||
|
||||
private AddressAdmin addressAdmin = NimmAddress.getHandle();
|
||||
|
||||
public static int serverDomainId = 1;
|
||||
|
||||
public static int serverSocketId = 0;
|
||||
|
||||
MockupServerFactory(int idcId) {
|
||||
this.idcId = idcId;
|
||||
this.serverIds = new HashMap<NimmAddress.Species, AtomicInteger>();
|
||||
|
||||
for (NimmAddress.Species species : NimmAddress.Species.values()) {
|
||||
this.serverIds.put(species, new AtomicInteger(1));
|
||||
}
|
||||
}
|
||||
|
||||
int getIdcId() {
|
||||
return this.idcId;
|
||||
}
|
||||
|
||||
void setIdcId(int idcId) {
|
||||
this.idcId = idcId;
|
||||
}
|
||||
|
||||
NimmMockupServer createMockUpServer(NimmAddress.Species species, int portNo) {
|
||||
|
||||
if (species == null)
|
||||
throw new NullPointerException("species");
|
||||
|
||||
NimmMockupServer mockupServer = null;
|
||||
|
||||
NimmAddress serverAddress = null;
|
||||
try {
|
||||
serverAddress = addressAdmin.retrieveAddressInstance(
|
||||
NimmAddress.Species.Management, serverDomainId, this.idcId,
|
||||
this.serverIds.get(species).getAndIncrement(), serverSocketId,
|
||||
0);
|
||||
}
|
||||
catch (AbnormalNimmAddressException e) {
|
||||
throw new RuntimeException("address create error", e);
|
||||
}
|
||||
|
||||
switch (species) {
|
||||
case Management:
|
||||
mockupServer = new NimmMGMTMockupServer(portNo, serverAddress);
|
||||
break;
|
||||
case Service:
|
||||
mockupServer = new NimmSvcMockupServer(portNo, serverAddress);
|
||||
break;
|
||||
}
|
||||
|
||||
return mockupServer;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.nhncorp.lucy.nimm.mockupserver;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.address.AbnormalNimmAddressException;
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress;
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress.Species;
|
||||
|
||||
class NimmMGMTMockupServer extends NimmMockupServer {
|
||||
|
||||
NimmMGMTMockupServer(int portNo, NimmAddress serverAddress) {
|
||||
super(portNo, serverAddress);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NimmAddress createAddress(byte[] binform) throws AbnormalNimmAddressException {
|
||||
return createAddress(Species.Management, binform);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Species getSpecies() {
|
||||
return Species.Management;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,480 @@
|
||||
package com.nhncorp.lucy.nimm.mockupserver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.NimmRunTimeException;
|
||||
import com.nhncorp.lucy.nimm.connector.util.NimmLoggingFilter;
|
||||
import com.nhncorp.lucy.nimm.connector.address.AbnormalNimmAddressException;
|
||||
import com.nhncorp.lucy.nimm.connector.address.AddressAdmin;
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress;
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress.Species;
|
||||
import com.nhncorp.lucy.nimm.connector.record.NimmApplicationRecord;
|
||||
import com.nhncorp.lucy.nimm.connector.record.NimmControlRecord;
|
||||
import com.nhncorp.lucy.nimm.connector.record.NimmControlRecordFactory;
|
||||
import com.nhncorp.lucy.nimm.connector.record.NimmRecord;
|
||||
import com.nhncorp.lucy.nimm.connector.record.NimmRecordDecoder;
|
||||
import com.nhncorp.lucy.nimm.connector.record.NimmRecordEncoder;
|
||||
import com.nhncorp.lucy.nimm.connector.record.NimmRecordHeader;
|
||||
import com.nhncorp.lucy.nimm.connector.record.NimmRecordHeaderFactory;
|
||||
import com.nhncorp.lucy.nimm.connector.record.NimmControlRecord.ControlCode;
|
||||
|
||||
import external.org.apache.mina.common.DummySession;
|
||||
import external.org.apache.mina.common.IdleStatus;
|
||||
import external.org.apache.mina.common.IoBuffer;
|
||||
import external.org.apache.mina.common.IoHandlerAdapter;
|
||||
import external.org.apache.mina.common.IoSession;
|
||||
import external.org.apache.mina.filter.codec.ProtocolCodecFilter;
|
||||
import external.org.apache.mina.transport.socket.nio.NioSocketAcceptor;
|
||||
|
||||
abstract class NimmMockupServer {
|
||||
private final Logger logger = Logger.getLogger(getClass().getName());
|
||||
|
||||
private final int portNo;
|
||||
private final IoHandler ioHandler;
|
||||
private final NioSocketAcceptor socketAcceptor;
|
||||
|
||||
private final NimmAddress serverNimmAddress;
|
||||
|
||||
private final ConcurrentMap<ClientKey, IoSession> ioSessionLookUpMap;
|
||||
// private final ConcurrentMap<AnycastKey, List<IoSessionPair>> ioSessionAnycastLookUpMap;
|
||||
private final AnycastRoutingTable anycastTable;
|
||||
|
||||
private final Set<IoSession> connectedIoSession = new CopyOnWriteArraySet<IoSession>();
|
||||
|
||||
private final ConcurrentMap<IoSession, NimmAddress> representAddress;
|
||||
|
||||
protected AddressAdmin addressAdmin = NimmAddress.getHandle();
|
||||
|
||||
// private final String ROUTING_STATE = "_ROUTING_STATE";
|
||||
|
||||
protected NimmMockupServer(int portNo, NimmAddress serverAddress) {
|
||||
this.portNo = portNo;
|
||||
this.serverNimmAddress = serverAddress;
|
||||
|
||||
this.ioSessionLookUpMap = new ConcurrentHashMap<ClientKey, IoSession>();
|
||||
// this.ioSessionAnycastLookUpMap = new ConcurrentHashMap<AnycastKey, List<IoSessionPair>>();
|
||||
this.anycastTable = new AnycastRoutingTable();
|
||||
|
||||
this.representAddress = new ConcurrentHashMap<IoSession, NimmAddress>();
|
||||
|
||||
this.ioHandler = new IoHandler();
|
||||
|
||||
this.socketAcceptor = new NioSocketAcceptor();
|
||||
this.socketAcceptor.setDefaultLocalAddress(new InetSocketAddress(portNo));
|
||||
this.socketAcceptor.setHandler(this.ioHandler);
|
||||
|
||||
this.socketAcceptor.getFilterChain().addLast("raw-log", new NimmLoggingFilter("mockup-server"));
|
||||
this.socketAcceptor.getFilterChain().addLast(
|
||||
"nimm-record-codec",
|
||||
new ProtocolCodecFilter(new NimmRecordEncoder(),
|
||||
new NimmRecordDecoder()));
|
||||
|
||||
}
|
||||
|
||||
public void start() throws IOException {
|
||||
this.socketAcceptor.bind();
|
||||
}
|
||||
|
||||
public void gracefulStop() {
|
||||
broadcast(new IoSessionTask(){
|
||||
public void execute(IoSession ioSession) {
|
||||
sendStopSending(ioSession);
|
||||
}
|
||||
});
|
||||
|
||||
broadcast(new IoSessionTask(){
|
||||
public void execute(IoSession ioSession) {
|
||||
sendBye(ioSession);
|
||||
}
|
||||
});
|
||||
try {
|
||||
Thread.sleep(1000*2);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
logger.log(Level.WARNING, "InterruptedException", e);
|
||||
}
|
||||
stop();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
this.socketAcceptor.dispose();
|
||||
}
|
||||
|
||||
public int getPortNo() {
|
||||
return this.portNo;
|
||||
}
|
||||
|
||||
protected abstract NimmAddress createAddress(byte[] binform) throws AbnormalNimmAddressException;
|
||||
|
||||
protected abstract Species getSpecies();
|
||||
|
||||
protected NimmAddress createAddress(Species species, byte[] bytesForm) throws AbnormalNimmAddressException {
|
||||
|
||||
if (species == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (bytesForm == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (bytesForm.length != 12) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
ByteBuffer bb = ByteBuffer.wrap(bytesForm);
|
||||
int domainId = bb.getInt();
|
||||
int idcId = (int) bb.getShort();
|
||||
int serverId = (int) bb.getShort();
|
||||
int socketId = (int) bb.getShort();
|
||||
int checkSum = (int) bb.getShort();
|
||||
|
||||
return addressAdmin.retrieveAddressInstance(species, domainId, idcId, serverId, socketId, checkSum);
|
||||
}
|
||||
|
||||
private void processControlRecord(NimmControlRecord controlRecord, IoSession ioSession) throws Exception {
|
||||
|
||||
ControlCode controlCode = controlRecord.getControlCode();
|
||||
|
||||
switch (controlCode) {
|
||||
case HELLO:
|
||||
handleHello(controlRecord, ioSession);
|
||||
break;
|
||||
case LEAVE:
|
||||
hadleLeave(ioSession);
|
||||
break;
|
||||
case START_ROUTING:
|
||||
handleStartRouting(controlRecord, ioSession);
|
||||
break;
|
||||
case STOP_ROUTING:
|
||||
handleStopRouting(controlRecord, ioSession);
|
||||
break;
|
||||
default:
|
||||
if(logger.isLoggable(Level.INFO)){
|
||||
logger.info("controlCode:" + controlCode);
|
||||
}
|
||||
// BEGIN_LARGE_MESSAGE 등의 controlmessage는 target NimmConnector까지 전달되어야 하므로 그대로 라우팅한다.
|
||||
routeNimmRecord(controlRecord, ioSession);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleHello(NimmControlRecord controlRecord, IoSession ioSession) throws AbnormalNimmAddressException {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("HELLO received source:" + controlRecord.getSourceAddress()
|
||||
+ " destination:" + controlRecord.getDestinationAddress());
|
||||
}
|
||||
IoBuffer payloadBuffer = controlRecord.getPayloadBuffer();
|
||||
int numberOfAddresses = controlRecord.getControlParameterAsNumber();
|
||||
int addressSize = NimmAddress.getSizeOfBinForm();
|
||||
|
||||
// To find duplicated address
|
||||
boolean isDuplicated = false;
|
||||
NimmAddress firstDuplicated = null;
|
||||
|
||||
for (int i = 0; i < numberOfAddresses; ++i) {
|
||||
byte[] binFormAddress = new byte[addressSize];
|
||||
payloadBuffer.get(binFormAddress);
|
||||
NimmAddress address = createAddress(binFormAddress);
|
||||
if(logger.isLoggable(Level.FINE)){
|
||||
logger.fine("Hello payload address:" + address);
|
||||
}
|
||||
int domainId = address.getDomainId();
|
||||
int idcId = this.serverNimmAddress.getIdcId();
|
||||
int serverId = address.getServerId();
|
||||
|
||||
if (i == 0) {
|
||||
NimmAddress representAddress = NimmAddress.getHandle().retrieveAddressInstance(address.getSpecies(),
|
||||
0, idcId, serverId, 0, 0);
|
||||
this.representAddress.put(ioSession, representAddress);
|
||||
}
|
||||
|
||||
RoutingState routingState = RoutingState.getRoutingState(ioSession);
|
||||
routingState.register(domainId);
|
||||
|
||||
ClientKey key = new ClientKey(domainId, idcId, serverId);
|
||||
// Duplicated address check
|
||||
if (this.ioSessionLookUpMap.containsKey(key)) {
|
||||
logger.warning("Duplicated detected:" + key);
|
||||
isDuplicated = true;
|
||||
if (firstDuplicated == null) {
|
||||
firstDuplicated = address;
|
||||
}
|
||||
}
|
||||
|
||||
this.ioSessionLookUpMap.put(key, ioSession);
|
||||
|
||||
AnycastKey anyKey = new AnycastKey(domainId, idcId);
|
||||
// List<IoSessionPair> list = this.ioSessionAnycastLookUpMap.get(anyKey);
|
||||
// if (list == null) {
|
||||
// list = new CopyOnWriteArrayList<IoSessionPair>();
|
||||
// }
|
||||
// list.add(new IoSessionPair(ioSession, address));
|
||||
// this.ioSessionAnycastLookUpMap.put(anyKey, list);
|
||||
this.anycastTable.register(anyKey, new IoSessionPair(ioSession, address));
|
||||
}
|
||||
|
||||
if (isDuplicated) {
|
||||
// Duplicated address BYE message
|
||||
NimmRecordHeader header = NimmRecordHeaderFactory.createBYEwithDuplicatedAddr(firstDuplicated,
|
||||
this.serverNimmAddress);
|
||||
byte[] payload = new byte[12];
|
||||
ByteBuffer buf = ByteBuffer.wrap(payload);
|
||||
buf.putInt(firstDuplicated.getDomainId());
|
||||
buf.putShort((short)this.serverNimmAddress.getIdcId());
|
||||
buf.putShort((short)firstDuplicated.getServerId());
|
||||
buf.putShort((short)0);
|
||||
buf.putShort((short)0);
|
||||
NimmControlRecord byeRecord = NimmControlRecordFactory.create(header, payload);
|
||||
|
||||
ioSession.write(byeRecord);
|
||||
ioSession.close();
|
||||
} else {
|
||||
NimmControlRecord welcomeRecord = NimmControlRecord.createControlMessage(this.serverNimmAddress,
|
||||
this.representAddress.get(ioSession),
|
||||
ControlCode.WELCOME, null);
|
||||
|
||||
ioSession.write(welcomeRecord);
|
||||
|
||||
sendStartSending(ioSession);
|
||||
}
|
||||
}
|
||||
|
||||
private void hadleLeave(IoSession ioSession) {
|
||||
if(logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("LEAVE(Control) received IoSession:" + ioSession);
|
||||
}
|
||||
Iterator<Map.Entry<ClientKey, IoSession>> iter = this.ioSessionLookUpMap.entrySet().iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<ClientKey, IoSession> entry = iter.next();
|
||||
|
||||
if (entry.getValue().equals(ioSession)) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
NimmControlRecord byeRecord = NimmControlRecord.createControlMessage(this.serverNimmAddress,
|
||||
this.representAddress.get(ioSession),
|
||||
ControlCode.BYE, null);
|
||||
|
||||
ioSession.write(byeRecord);
|
||||
this.representAddress.remove(ioSession);
|
||||
}
|
||||
|
||||
private void handleStopRouting(NimmControlRecord controlRecord, IoSession ioSession) {
|
||||
final NimmAddress destination = controlRecord.getDestinationAddress();
|
||||
final NimmAddress source = controlRecord.getSourceAddress();
|
||||
// TODO 추가 처리 필요.
|
||||
if(logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("STOP_ROUTING received source:" + source + " destination:" + destination);
|
||||
}
|
||||
RoutingState routingState = RoutingState.getRoutingState(ioSession);
|
||||
routingState.routingEnable(source.getDomainId(), false);
|
||||
|
||||
}
|
||||
|
||||
private void handleStartRouting(NimmControlRecord controlRecord, IoSession ioSession) {
|
||||
final NimmAddress destination = controlRecord.getDestinationAddress();
|
||||
final NimmAddress source = controlRecord.getSourceAddress();
|
||||
// TODO 추가 처리 필요.
|
||||
if(logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("START_ROUTING received source:" + source + " destination:" + destination);
|
||||
}
|
||||
RoutingState routingState = RoutingState.getRoutingState(ioSession);
|
||||
routingState.routingEnable(source.getDomainId(), true);
|
||||
|
||||
}
|
||||
|
||||
private void sendStartSending(IoSession ioSession) {
|
||||
NimmControlRecord startSending = NimmControlRecord.createControlMessage(this.serverNimmAddress,
|
||||
this.representAddress.get(ioSession), NimmControlRecord.ControlCode.START_SENDING, null);
|
||||
ioSession.write(startSending);
|
||||
}
|
||||
|
||||
private void sendStopSending(IoSession ioSession) {
|
||||
NimmControlRecord startSending = NimmControlRecord.createControlMessage(this.serverNimmAddress,
|
||||
this.representAddress.get(ioSession), NimmControlRecord.ControlCode.STOP_SENDING, null);
|
||||
if(logger.isLoggable(Level.INFO)) {
|
||||
logger.info("sendStopSending:" + ioSession + " IoSession:" + ioSession);
|
||||
}
|
||||
ioSession.write(startSending);
|
||||
}
|
||||
|
||||
private void sendBye(IoSession ioSession) {
|
||||
NimmControlRecord bye = NimmControlRecord.createControlMessage(this.serverNimmAddress,
|
||||
this.representAddress.get(ioSession), NimmControlRecord.ControlCode.BYE, null);
|
||||
if(logger.isLoggable(Level.INFO)) {
|
||||
logger.info("sendBye:" + ioSession + " IoSession:" + ioSession);
|
||||
}
|
||||
ioSession.write(bye);
|
||||
}
|
||||
|
||||
private interface IoSessionTask {
|
||||
void execute(IoSession ioSession);
|
||||
}
|
||||
|
||||
private void broadcast(IoSessionTask task) {
|
||||
for(IoSession ioSession: connectedIoSession) {
|
||||
task.execute(ioSession);
|
||||
}
|
||||
}
|
||||
|
||||
private void routeNimmRecord(NimmRecord nimmRecord, IoSession ioSession) throws AbnormalNimmAddressException {
|
||||
|
||||
final NimmAddress destionationAddress = nimmRecord.getDestinationAddress();
|
||||
|
||||
int idcId = destionationAddress.getIdcId();
|
||||
int domainId = destionationAddress.getDomainId();
|
||||
int serverId = destionationAddress.getServerId();
|
||||
|
||||
if (idcId != 0 && serverId != 0) {
|
||||
ClientKey ioSessionLookUpKey = new ClientKey(domainId, idcId, serverId);
|
||||
IoSession targetIoSession = this.ioSessionLookUpMap.get(ioSessionLookUpKey);
|
||||
if (targetIoSession == null) {
|
||||
throw new NimmRunTimeException("idcId:" + idcId + " domainId:" + domainId + " serverId:" + serverId);
|
||||
} else {
|
||||
targetIoSession.write(nimmRecord);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (idcId == 0 && serverId != 0) {
|
||||
final int connectorid = serverNimmAddress.getIdcId();
|
||||
final ClientKey ioSessionLookUpKey = new ClientKey(domainId, connectorid, serverId);
|
||||
final IoSession targetIoSession = this.ioSessionLookUpMap.get(ioSessionLookUpKey);
|
||||
if (targetIoSession == null) {
|
||||
throw new NimmRunTimeException("idcId:" + idcId + " domainId:" + domainId + " serverId:" + serverId);
|
||||
} else {
|
||||
NimmAddress unicastAddress = NimmAddress.createUnicastAddress(destionationAddress.getDomainId(), connectorid,
|
||||
destionationAddress.getServerId(), destionationAddress.getSocketId());
|
||||
nimmRecord.setDestinationAddress(unicastAddress);
|
||||
targetIoSession.write(nimmRecord);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (serverId == 0) {
|
||||
if(idcId == 0) {
|
||||
idcId = serverNimmAddress.getIdcId();
|
||||
}
|
||||
AnycastKey key = new AnycastKey(domainId, idcId);
|
||||
IoSessionPair pair = null;
|
||||
|
||||
if(nimmRecord instanceof NimmApplicationRecord) {
|
||||
pair = this.anycastTable.roundRobinSelect(key, true);
|
||||
} else {
|
||||
if(nimmRecord instanceof NimmControlRecord.TypeLarge) {
|
||||
// LARGE_SESSION은 ??
|
||||
pair = this.anycastTable.roundRobinSelect(key, true);
|
||||
} else {
|
||||
pair = this.anycastTable.roundRobinSelect(key, false);
|
||||
}
|
||||
}
|
||||
if(pair == null) {
|
||||
//TODO TARGET_SERVER_NO_EXIST?? NACK을 던저야 한다.
|
||||
throw new NimmRunTimeException("idcId:" + idcId + " domainId:" + domainId + " serverId:" + serverId + " Record:" + nimmRecord);
|
||||
}
|
||||
NimmAddress address = pair.getAddress();
|
||||
NimmAddress uniAddress = NimmAddress.createUnicastAddress(address.getDomainId(), address.getIdcId(),
|
||||
address.getServerId(), destionationAddress.getSocketId());
|
||||
nimmRecord.setDestinationAddress(uniAddress);
|
||||
pair.getIoSession().write(nimmRecord);
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException("serverid:" + serverId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 주어진 주소를 가진 Client (NimmConnector) 가 이미 연결되어 있는 것으로 만드는 메소드
|
||||
* 중복 주소 오류를 체크하기 위해 사용한다.
|
||||
* IoSession은 DummySession이 사용된다.
|
||||
*
|
||||
* @param domainId dummy client Domain Id
|
||||
* @param serverId dummy client Server Id
|
||||
*/
|
||||
void addDummyClientManually(int domainId, int serverId) {
|
||||
int idcId = this.serverNimmAddress.getIdcId();
|
||||
ClientKey key = new ClientKey(domainId, idcId, serverId);
|
||||
IoSession session = new DummySession();
|
||||
this.ioSessionLookUpMap.put(key, session);
|
||||
}
|
||||
|
||||
/**
|
||||
* 주어진 주소를 가진 Client (NimmConnector) 가 이미 연결되어 있는 것을 삭제 하기 위한 메소드
|
||||
* IoSession은 DummySession이 사용된다.
|
||||
*
|
||||
* @param domainId dummy client Domain Id
|
||||
* @param serverId dummy client Server Id
|
||||
*/
|
||||
void removeDummyClientManually(int domainId, int serverId) {
|
||||
int idcId = this.serverNimmAddress.getIdcId();
|
||||
ClientKey key = new ClientKey(domainId, idcId, serverId);
|
||||
this.ioSessionLookUpMap.remove(key);
|
||||
}
|
||||
|
||||
private class IoHandler extends IoHandlerAdapter {
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
super.exceptionCaught(session, cause);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void messageReceived(IoSession session, Object message) throws Exception {
|
||||
|
||||
NimmRecord nimmRecord = (NimmRecord) message;
|
||||
if (nimmRecord instanceof NimmControlRecord) {
|
||||
processControlRecord((NimmControlRecord) nimmRecord, session);
|
||||
} else if (nimmRecord instanceof NimmApplicationRecord) {
|
||||
routeNimmRecord(nimmRecord, session);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageSent(IoSession session, Object message) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
super.messageSent(session, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionClosed(IoSession session) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
connectedIoSession.remove(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionCreated(IoSession session) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
super.sessionCreated(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
super.sessionIdle(session, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionOpened(IoSession session) throws Exception {
|
||||
|
||||
InetSocketAddress[] socketAddresses = new InetSocketAddress[1];
|
||||
socketAddresses[0] = (InetSocketAddress)session.getRemoteAddress();
|
||||
// TODO 전역공유객체
|
||||
addressAdmin.addInetAddressSpecies(getSpecies(), socketAddresses);
|
||||
connectedIoSession.add(session);
|
||||
|
||||
// session.setAttribute(ROUTING_STATE, new ConcurrentHashMap<Integer, AtomicBoolean>());
|
||||
RoutingState.createRoutingState(session);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.nhncorp.lucy.nimm.mockupserver;
|
||||
|
||||
import com.nhncorp.lucy.nimm.connector.address.AbnormalNimmAddressException;
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress;
|
||||
import com.nhncorp.lucy.nimm.connector.address.NimmAddress.Species;
|
||||
|
||||
class NimmSvcMockupServer extends NimmMockupServer {
|
||||
|
||||
NimmSvcMockupServer(int portNo, NimmAddress serverAddress) {
|
||||
super(portNo, serverAddress);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NimmAddress createAddress(byte[] binform)
|
||||
throws AbnormalNimmAddressException {
|
||||
return createAddress(Species.Management, binform);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Species getSpecies() {
|
||||
return Species.Service;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.nhncorp.lucy.nimm.mockupserver;
|
||||
|
||||
import external.org.apache.mina.common.IoSession;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* User: emeroad
|
||||
* Date: 2010. 3. 25
|
||||
* Time: 오후 4:08:32
|
||||
*
|
||||
* @author Middleware Platform Dev. Team
|
||||
*/
|
||||
public class RoutingState {
|
||||
|
||||
private ConcurrentMap<Integer, AtomicBoolean> routingState;
|
||||
private static final String ROUTING_STATE = "_ROUTING_STATE";
|
||||
|
||||
public static RoutingState getRoutingState(IoSession ioSession) {
|
||||
return (RoutingState) ioSession.getAttribute(ROUTING_STATE);
|
||||
}
|
||||
|
||||
public static void createRoutingState(IoSession ioSession) {
|
||||
ioSession.setAttribute(ROUTING_STATE, new RoutingState());
|
||||
}
|
||||
|
||||
private RoutingState() {
|
||||
this.routingState = new ConcurrentHashMap<Integer, AtomicBoolean>();
|
||||
}
|
||||
|
||||
public boolean register(int domainId) {
|
||||
AtomicBoolean before = this.routingState.putIfAbsent(domainId, new AtomicBoolean());
|
||||
return before == null;
|
||||
}
|
||||
|
||||
public void routingEnable(int domainId, boolean enable) {
|
||||
AtomicBoolean routing = this.routingState.get(domainId);
|
||||
if(routing == null) {
|
||||
throw new RuntimeException("domainId not found:" + domainId);
|
||||
}
|
||||
boolean success = routing.compareAndSet(!enable, enable);
|
||||
if(!success) {
|
||||
throw new RuntimeException("Invalid RoutingState:" + domainId + " enable:" + enable);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAnycastRouting(int domainId) {
|
||||
AtomicBoolean routing = this.routingState.get(domainId);
|
||||
if(routing == null) {
|
||||
throw new RuntimeException("domainId not found:" + domainId);
|
||||
}
|
||||
return routing.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package perftest;
|
||||
|
||||
public class Level {
|
||||
|
||||
String id;
|
||||
int score;
|
||||
Level up, down;
|
||||
|
||||
public Level(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Level(String id, Level up, Level down) {
|
||||
this.id = id;
|
||||
this.up = up;
|
||||
this.down = down;
|
||||
}
|
||||
|
||||
public String enter(String id, int score) {
|
||||
String hello = id + "_" + score;
|
||||
return hello;
|
||||
}
|
||||
|
||||
public void down() {
|
||||
if (down != null) {
|
||||
down.enter(this.id, ++score);
|
||||
}
|
||||
}
|
||||
|
||||
public void up() {
|
||||
if (up != null) {
|
||||
up.enter(this.id, ++score);
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(int score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public Level getUp() {
|
||||
return up;
|
||||
}
|
||||
|
||||
public void setUp(Level up) {
|
||||
this.up = up;
|
||||
}
|
||||
|
||||
public Level getDown() {
|
||||
return down;
|
||||
}
|
||||
|
||||
public void setDown(Level down) {
|
||||
this.down = down;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package perftest;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class LevelManager {
|
||||
|
||||
LinkedList<Level> levels = new LinkedList<Level>();
|
||||
|
||||
public LevelManager() {
|
||||
Level topLevel = new Level("toplevel");
|
||||
levels.add(topLevel);
|
||||
for (int i = 1; i < 10; i++) {
|
||||
Level prev = levels.get(i - 1);
|
||||
Level curr = new Level("level" + i);
|
||||
curr.setUp(prev);
|
||||
prev.setDown(curr);
|
||||
levels.add(curr);
|
||||
}
|
||||
}
|
||||
|
||||
public void traverse() {
|
||||
for (Level each : levels) {
|
||||
each.down();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<nimm-connector>
|
||||
<management>
|
||||
<server-list>
|
||||
<server ip="127.0.0.1" port="21111"/>
|
||||
</server-list>
|
||||
<agent-list>
|
||||
<agent className="com.nhncorp.lucy.nimm.connector.agent.ManagementAgent" domain-id="100" socket-id="1">
|
||||
|
||||
<properties>
|
||||
<property name="rala" type="int" value="5"/>
|
||||
<property name="wrala" type="Integer" value="55"/>
|
||||
<property name="cookoo" type="String" value="chichi"/>
|
||||
<property name="yoyo" type="float" value="10.0"/>
|
||||
<property name="wyoyo" type="Float" value="11.11"/>
|
||||
<property name="ohoo" type="double" value="10.8"/>
|
||||
<property name="wohoo" type="Double" value="1010.88"/>
|
||||
<property name="awesome" type="char" value="t"/>
|
||||
<property name="wawesome" type="Character" value="T"/>
|
||||
<property name="active" type="boolean" value="false"/>
|
||||
<property name="wactive" type="Boolean" value="true"/>
|
||||
<property name="binary" type="byte" value="92"/>
|
||||
<property name="wbinary" type="Byte" value="93"/>
|
||||
<property name="shortint" type="short" value="0"/>
|
||||
<property name="wshortint" type="Short" value="1"/>
|
||||
<property name="longint" type="long" value="65536"/>
|
||||
<property name="wlongint" type="Long" value="6553665536"/>
|
||||
</properties>
|
||||
</agent>
|
||||
<agent className="com.nhncorp.lucy.nimm.connector.agent.ManagementAgent"/>
|
||||
</agent-list>
|
||||
<representative-address>
|
||||
<address domain-id="100" server-id="40"/>
|
||||
</representative-address>
|
||||
|
||||
<allowed-address-list>
|
||||
<address domain-id="7" server-id="30"/>
|
||||
<address domain-id="100" server-id="40"/>
|
||||
<address domain-id="101" server-id="40"/>
|
||||
<address domain-id="102" server-id="42"/>
|
||||
</allowed-address-list>
|
||||
</management>
|
||||
|
||||
<service>
|
||||
<agent-list>
|
||||
<agent className="com.nhncorp.lucy.nimm.connector.agent.ServiceAgent" domain-id="47" socket-id="1"
|
||||
name="Santana"/>
|
||||
</agent-list>
|
||||
<representative-address>
|
||||
<address domain-id="101" server-id="50"/>
|
||||
</representative-address>
|
||||
|
||||
<allowed-address-list>
|
||||
<address domain-id="103" server-id="50"/>
|
||||
<address domain-id="47" server-id="50"/>
|
||||
<address domain-id="123" server-id="52"/>
|
||||
</allowed-address-list>
|
||||
|
||||
<bus-segmentation>
|
||||
<segment-list default-seg-id="Default">
|
||||
|
||||
<segment id="Default">
|
||||
<server ip="127.0.0.1" port="25555"/>
|
||||
</segment>
|
||||
|
||||
<segment id="Rala">
|
||||
<server ip="127.0.0.1" port="25556"/>
|
||||
</segment>
|
||||
</segment-list>
|
||||
|
||||
<transmission-policy>
|
||||
<rule sender-domain-id="103" receiver-domain-id="2001" seg-id="Rala"/>
|
||||
<rule sender-domain-id="47" receiver-domain-id="2002" seg-id="Rala"/>
|
||||
<rule sender-domain-id="123" receiver-domain-id="2003" seg-id="Rala"/>
|
||||
</transmission-policy>
|
||||
|
||||
</bus-segmentation>
|
||||
</service>
|
||||
|
||||
<operation>
|
||||
<sessionTimeout unit="ms">3000</sessionTimeout>
|
||||
<workerThreadPool>256</workerThreadPool>
|
||||
<defaultSocketTimeout>0</defaultSocketTimeout>
|
||||
</operation>
|
||||
|
||||
</nimm-connector>
|
||||
@@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:lang="http://www.springframework.org/schema/lang"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:util="http://www.springframework.org/schema/util" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
|
||||
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
|
||||
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<!--
|
||||
<bean id="mysql" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
|
||||
<property name="driverClass" value="com.mysql.jdbc.Driver" />
|
||||
-->
|
||||
|
||||
<bean id="mysqlDatasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
|
||||
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
|
||||
|
||||
<!--<property name="url" value="jdbc:mysql://localhost:3306/hippo?characterEncoding=UTF-8"/>-->
|
||||
<!--<property name="username" value="root"/>-->
|
||||
<!--<property name="password" value="skdnsnfl"/>-->
|
||||
|
||||
<property name="url" value="jdbc:mysql://10.25.149.61:3306/MySQL?characterEncoding=UTF-8"/>
|
||||
<property name="username" value="pinpoint"/>
|
||||
<property name="password" value="nhn!@#123"/>
|
||||
|
||||
<property name="initialSize" value="30"></property>
|
||||
<property name="maxActive" value="30"></property>
|
||||
<property name="maxIdle" value="30"></property>
|
||||
<property name="minIdle" value="30"></property>
|
||||
<property name="maxWait" value="3000"></property>
|
||||
|
||||
<property name="testOnBorrow" value="false"></property>
|
||||
<property name="testOnReturn" value="false"></property>
|
||||
<!-- 원래는 true가 맞으나. 연결이 오래 지속되면 끊기는 상황에서 정상동작하는지 보기 위해서 false로 남겨두자.-->
|
||||
<property name="testWhileIdle" value="false"></property>
|
||||
|
||||
<property name="timeBetweenEvictionRunsMillis" value="30000"></property>
|
||||
<property name="numTestsPerEvictionRun" value="6"></property>
|
||||
<property name="minEvictableIdleTimeMillis" value="-1"></property>
|
||||
<property name="validationQuery" value="select 1 from db_root"></property>
|
||||
|
||||
<property name="poolPreparedStatements" value="true"></property>
|
||||
<property name="maxOpenPreparedStatements" value="50"></property>
|
||||
|
||||
</bean>
|
||||
|
||||
<bean id="oracleDatasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
|
||||
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
|
||||
|
||||
<!--<property name="url" value="jdbc:mysql://localhost:3306/pinpoint?characterEncoding=UTF-8"/>-->
|
||||
<!--<property name="username" value="root"/>-->
|
||||
<!--<property name="password" value="skdnsnfl"/>-->
|
||||
|
||||
<property name="url" value="jdbc:oracle:thin:@10.98.133.174:1725:INDEV"/>
|
||||
<property name="username" value="lucy"/>
|
||||
<property name="password" value="lucy"/>
|
||||
|
||||
<property name="initialSize" value="30"></property>
|
||||
<property name="maxActive" value="30"></property>
|
||||
<property name="maxIdle" value="30"></property>
|
||||
<property name="minIdle" value="30"></property>
|
||||
<property name="maxWait" value="3000"></property>
|
||||
|
||||
<property name="testOnBorrow" value="false"></property>
|
||||
<property name="testOnReturn" value="false"></property>
|
||||
<!-- 원래는 true가 맞으나. 연결이 오래 지속되면 끊기는 상황에서 정상동작하는지 보기 위해서 false로 남겨두자.-->
|
||||
<property name="testWhileIdle" value="false"></property>
|
||||
|
||||
<property name="timeBetweenEvictionRunsMillis" value="30000"></property>
|
||||
<property name="numTestsPerEvictionRun" value="6"></property>
|
||||
<property name="minEvictableIdleTimeMillis" value="-1"></property>
|
||||
|
||||
<property name="validationQuery" value="select 1 from dual"></property>
|
||||
|
||||
<property name="poolPreparedStatements" value="true"></property>
|
||||
<property name="maxOpenPreparedStatements" value="50"></property>
|
||||
</bean>
|
||||
|
||||
<bean id="mssql" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
|
||||
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
|
||||
<property name="url" value="jdbc:sqlserver://10.64.80.37:1433;DatabaseName=test"/>
|
||||
<property name="username" value="netspider"/>
|
||||
<property name="password" value="chitty!!"/>
|
||||
</bean>
|
||||
|
||||
<bean id="cubridDatasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
|
||||
<property name="driverClassName" value="cubrid.jdbc.driver.CUBRIDDriver"/>
|
||||
<property name="url" value="jdbc:cubrid:10.101.57.233:30102:pinpoint:::"/>
|
||||
<property name="username" value="dba"/>
|
||||
<property name="password" value="nhn!@#123"/>
|
||||
</bean>
|
||||
</beans>
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE IF NOT EXISTS member (
|
||||
id varchar(11) primary key,
|
||||
name varchar(20) not null,
|
||||
joined date
|
||||
);
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE sqlMapConfig
|
||||
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
|
||||
|
||||
<sqlMapConfig>
|
||||
<settings defaultStatementTimeout="3"/>
|
||||
|
||||
<sqlMap resource="cubrid/sql-member.xml" />
|
||||
<sqlMap resource="cubrid/test-sql.xml" />
|
||||
</sqlMapConfig>
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE sqlMap
|
||||
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
|
||||
|
||||
<sqlMap namespace="Member">
|
||||
<typeAlias alias="Member" type="com.nhn.pinpoint.testweb.domain.Member" />
|
||||
|
||||
<delete id="delete" parameterClass="int">
|
||||
delete from member where id = #id#
|
||||
</delete>
|
||||
|
||||
<insert id="add" parameterClass="Member">
|
||||
insert into member (id, name, joined) values(#id#, #name#, #joined#)
|
||||
</insert>
|
||||
|
||||
<insert id="addStatement" parameterClass="Member">
|
||||
insert into member (id, name, joined) values($id$, $name$, #joined#);
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="update" parameterClass="Member">
|
||||
update member set name = #name#, joined = #joined# where id = #id#
|
||||
</update>
|
||||
|
||||
<select id="get" parameterClass="int" resultClass="Member">
|
||||
select * from member where id = #id#
|
||||
</select>
|
||||
|
||||
<select id="list" resultClass="Member">
|
||||
select * from member order by id
|
||||
</select>
|
||||
</sqlMap>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE sqlMap
|
||||
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
|
||||
|
||||
<sqlMap namespace="Cubrid">
|
||||
|
||||
|
||||
<select id="selectOne" resultClass="int" >
|
||||
select 1
|
||||
</select>
|
||||
|
||||
</sqlMap>
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
hibernate.dialect=org.hibernate.dialect.HSQLDialect
|
||||
@@ -0,0 +1,166 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<!-- Authors: Chris Taylor, Ceki Gulcu. -->
|
||||
|
||||
<!-- Version: 1.2 -->
|
||||
|
||||
<!-- A configuration element consists of optional renderer
|
||||
elements,appender elements, categories and an optional root
|
||||
element. -->
|
||||
|
||||
<!ELEMENT log4j:configuration (renderer*, appender*,(category|logger)*,root?,
|
||||
categoryFactory?)>
|
||||
|
||||
<!-- The "threshold" attribute takes a level value such that all -->
|
||||
<!-- logging statements with a level equal or below this value are -->
|
||||
<!-- disabled. -->
|
||||
|
||||
<!-- Setting the "debug" enable the printing of internal log4j logging -->
|
||||
<!-- statements. -->
|
||||
|
||||
<!-- By default, debug attribute is "null", meaning that we not do touch -->
|
||||
<!-- internal log4j logging settings. The "null" value for the threshold -->
|
||||
<!-- attribute can be misleading. The threshold field of a repository -->
|
||||
<!-- cannot be set to null. The "null" value for the threshold attribute -->
|
||||
<!-- simply means don't touch the threshold field, the threshold field -->
|
||||
<!-- keeps its old value. -->
|
||||
|
||||
<!ATTLIST log4j:configuration
|
||||
xmlns:log4j CDATA #FIXED "http://jakarta.apache.org/log4j/"
|
||||
threshold (all|debug|info|warn|error|fatal|off|null) "null"
|
||||
debug (true|false|null) "null"
|
||||
>
|
||||
|
||||
<!-- renderer elements allow the user to customize the conversion of -->
|
||||
<!-- message objects to String. -->
|
||||
|
||||
<!ELEMENT renderer EMPTY>
|
||||
<!ATTLIST renderer
|
||||
renderedClass CDATA #REQUIRED
|
||||
renderingClass CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!-- Appenders must have a name and a class. -->
|
||||
<!-- Appenders may contain an error handler, a layout, optional parameters -->
|
||||
<!-- and filters. They may also reference (or include) other appenders. -->
|
||||
<!ELEMENT appender (errorHandler?, param*, layout?, filter*, appender-ref*)>
|
||||
<!ATTLIST appender
|
||||
name ID #REQUIRED
|
||||
class CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT layout (param*)>
|
||||
<!ATTLIST layout
|
||||
class CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT filter (param*)>
|
||||
<!ATTLIST filter
|
||||
class CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!-- ErrorHandlers can be of any class. They can admit any number of -->
|
||||
<!-- parameters. -->
|
||||
|
||||
<!ELEMENT errorHandler (param*, root-ref?, logger-ref*, appender-ref?)>
|
||||
<!ATTLIST errorHandler
|
||||
class CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT root-ref EMPTY>
|
||||
|
||||
<!ELEMENT logger-ref EMPTY>
|
||||
<!ATTLIST logger-ref
|
||||
ref IDREF #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT param EMPTY>
|
||||
<!ATTLIST param
|
||||
name CDATA #REQUIRED
|
||||
value CDATA #REQUIRED
|
||||
>
|
||||
|
||||
|
||||
<!-- The priority class is org.apache.log4j.Level by default -->
|
||||
<!ELEMENT priority (param*)>
|
||||
<!ATTLIST priority
|
||||
class CDATA #IMPLIED
|
||||
value CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!-- The level class is org.apache.log4j.Level by default -->
|
||||
<!ELEMENT level (param*)>
|
||||
<!ATTLIST level
|
||||
class CDATA #IMPLIED
|
||||
value CDATA #REQUIRED
|
||||
>
|
||||
|
||||
|
||||
<!-- If no level element is specified, then the configurator MUST not -->
|
||||
<!-- touch the level of the named category. -->
|
||||
<!ELEMENT category (param*,(priority|level)?,appender-ref*)>
|
||||
<!ATTLIST category
|
||||
class CDATA #IMPLIED
|
||||
name CDATA #REQUIRED
|
||||
additivity (true|false) "true"
|
||||
>
|
||||
|
||||
<!-- If no level element is specified, then the configurator MUST not -->
|
||||
<!-- touch the level of the named logger. -->
|
||||
<!ELEMENT logger (level?,appender-ref*)>
|
||||
<!ATTLIST logger
|
||||
name ID #REQUIRED
|
||||
additivity (true|false) "true"
|
||||
>
|
||||
|
||||
|
||||
<!ELEMENT categoryFactory (param*)>
|
||||
<!ATTLIST categoryFactory
|
||||
class CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT appender-ref EMPTY>
|
||||
<!ATTLIST appender-ref
|
||||
ref IDREF #REQUIRED
|
||||
>
|
||||
|
||||
<!-- If no priority element is specified, then the configurator MUST not -->
|
||||
<!-- touch the priority of root. -->
|
||||
<!-- The root category always exists and cannot be subclassed. -->
|
||||
<!ELEMENT root (param*, (priority|level)?, appender-ref*)>
|
||||
|
||||
|
||||
<!-- ==================================================================== -->
|
||||
<!-- A logging event -->
|
||||
<!-- ==================================================================== -->
|
||||
<!ELEMENT log4j:eventSet (log4j:event*)>
|
||||
<!ATTLIST log4j:eventSet
|
||||
xmlns:log4j CDATA #FIXED "http://jakarta.apache.org/log4j/"
|
||||
version (1.1|1.2) "1.2"
|
||||
includesLocationInfo (true|false) "true"
|
||||
>
|
||||
|
||||
|
||||
|
||||
<!ELEMENT log4j:event (log4j:message, log4j:NDC?, log4j:throwable?,
|
||||
log4j:locationInfo?) >
|
||||
|
||||
<!-- The timestamp format is application dependent. -->
|
||||
<!ATTLIST log4j:event
|
||||
logger CDATA #REQUIRED
|
||||
level CDATA #REQUIRED
|
||||
thread CDATA #REQUIRED
|
||||
timestamp CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT log4j:message (#PCDATA)>
|
||||
<!ELEMENT log4j:NDC (#PCDATA)>
|
||||
|
||||
<!ELEMENT log4j:throwable (#PCDATA)>
|
||||
|
||||
<!ELEMENT log4j:locationInfo EMPTY>
|
||||
<!ATTLIST log4j:locationInfo
|
||||
class CDATA #REQUIRED
|
||||
method CDATA #REQUIRED
|
||||
file CDATA #REQUIRED
|
||||
line CDATA #REQUIRED
|
||||
>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE log4j:configuration PUBLIC "" "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
|
||||
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="org.apache.log4j.EnhancedPatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-35c{1.}:%-3L) %m%n" />
|
||||
<!-- %L 옵션은 라인넘버가 출력되나 속도저하가 심하다. -->
|
||||
<!--<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-30c{1}) %m%n" />-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="general" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="org.apache.log4j.EnhancedPatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss}[%-5p](%-35c{1.}:%-3L) %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
|
||||
<logger name="com.nhn.pinpoint" additivity="false">
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="console" />
|
||||
</logger>
|
||||
|
||||
<logger name="com.ibatis" additivity="false">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="console" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework" additivity="false">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="console" />
|
||||
</logger>
|
||||
|
||||
<root>
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
</log4j:configuration>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE sqlMapConfig
|
||||
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
|
||||
|
||||
<sqlMapConfig>
|
||||
<settings defaultStatementTimeout="3"/>
|
||||
|
||||
<sqlMap resource="mysql/sql-member.xml" />
|
||||
<sqlMap resource="mysql/test-sql.xml" />
|
||||
</sqlMapConfig>
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE sqlMap
|
||||
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
|
||||
|
||||
<sqlMap namespace="Member">
|
||||
<typeAlias alias="Member" type="com.nhn.pinpoint.testweb.domain.Member" />
|
||||
|
||||
<delete id="delete" parameterClass="int">
|
||||
delete from member where id = #id#
|
||||
</delete>
|
||||
|
||||
<insert id="add" parameterClass="Member">
|
||||
insert into member (id, name, joined) values(#id#, #name#, #joined#)
|
||||
</insert>
|
||||
|
||||
<insert id="addStatement" parameterClass="Member">
|
||||
insert into member (id, name, joined) values($id$, $name$, #joined#);
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="update" parameterClass="Member">
|
||||
update member set name = #name#, joined = #joined# where id = #id#
|
||||
</update>
|
||||
|
||||
<select id="get" parameterClass="int" resultClass="Member">
|
||||
select * from member where id = #id#
|
||||
</select>
|
||||
|
||||
<select id="list" resultClass="Member">
|
||||
select * from member order by id
|
||||
</select>
|
||||
</sqlMap>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE sqlMap
|
||||
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
|
||||
|
||||
<sqlMap namespace="MySql">
|
||||
|
||||
|
||||
<select id="selectOne" resultClass="int" >
|
||||
select 1
|
||||
</select>
|
||||
|
||||
</sqlMap>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE sqlMapConfig
|
||||
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
|
||||
|
||||
<sqlMapConfig>
|
||||
<sqlMap resource="oracle/test-sql.xml" />
|
||||
</sqlMapConfig>
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE sqlMap
|
||||
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
|
||||
|
||||
<sqlMap namespace="Oracle">
|
||||
|
||||
|
||||
<select id="selectOne" resultClass="int" >
|
||||
select 1 from dual
|
||||
</select>
|
||||
|
||||
</sqlMap>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.2//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.nhn.pinpoint.testweb.repository.mybatis.MemberMapper">
|
||||
|
||||
<select id="selectUser" parameterType="int" resultType="Member">
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
joined
|
||||
FROM member
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectAllUsersInvalid" resultType="Member">
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
joined,
|
||||
invalid_column
|
||||
FROM member
|
||||
</select>
|
||||
|
||||
<insert id="insertUser" parameterType="Member">
|
||||
INSERT INTO member (
|
||||
id, name, joined
|
||||
) VALUES (
|
||||
#{id}, #{name}, #{joined}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateUser" parameterType="Member">
|
||||
UPDATE member
|
||||
SET name = #{name},
|
||||
joined = #{joined}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteUser" parameterType="int">
|
||||
DELETE FROM member
|
||||
WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
|
||||
<configuration>
|
||||
|
||||
<!-- default 옵션을 설정한다. -->
|
||||
<settings>
|
||||
<setting name="cacheEnabled" value="true" />
|
||||
|
||||
<!-- lazy로딩 수행여부 -->
|
||||
<setting name="lazyLoadingEnabled" value="true" />
|
||||
<setting name="aggressiveLazyLoading" value="true" />
|
||||
|
||||
<setting name="useGeneratedKeys" value="true" />
|
||||
|
||||
<!-- dbcp에서 preparedStatement cache 를 수행하므로 REUSE를 사용할 필요는 없음. -->
|
||||
<setting name="defaultExecutorType" value="SIMPLE" />
|
||||
|
||||
<!--defaultQueryTiemout을 설정한다. 초단위 -->
|
||||
<setting name="defaultStatementTimeout" value="5" />
|
||||
</settings>
|
||||
|
||||
<typeAliases>
|
||||
<typeAlias alias="Member" type="com.nhn.pinpoint.testweb.domain.Member" />
|
||||
</typeAliases>
|
||||
|
||||
</configuration>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
|
||||
">
|
||||
|
||||
<!-- Transaction manager for a single JDBC DataSource -->
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="mysqlDatasource"/>
|
||||
</bean>
|
||||
|
||||
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
|
||||
<tx:attributes>
|
||||
<tx:method name="select*" read-only="true" />
|
||||
<tx:method name="read*" read-only="true" />
|
||||
<tx:method name="get*" read-only="true" />
|
||||
<tx:method name="view*"/>
|
||||
<tx:method name="list*"/>
|
||||
<tx:method name="add*"/>
|
||||
<tx:method name="create*"/>
|
||||
<tx:method name="delete*"/>
|
||||
<tx:method name="update*"/>
|
||||
</tx:attributes>
|
||||
</tx:advice>
|
||||
|
||||
|
||||
<!-- SqlsessionFactory setup for MyBatis Database Layer -->
|
||||
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
|
||||
<property name="dataSource" ref="mysqlDatasource"/>
|
||||
|
||||
<!-- mybatis 기본설정 -->
|
||||
<property name="configLocation" value="classpath:orm/mybatis/mybatis-config.xml"/>
|
||||
|
||||
<!-- mapper 의 위치를 설정한다.-->
|
||||
<property name="mapperLocations" value="classpath:orm/mybatis/mapper/*Mapper.xml"/>
|
||||
|
||||
<!-- statement 선언의 오류를 좀 더 빠르게 파악하기 위해서 true로 설정 -->
|
||||
<property name="failFast" value="true"/>
|
||||
|
||||
<property name="plugins">
|
||||
<list>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
|
||||
<property name="basePackage" value="com.nhn.pinpoint.testweb.repository.mybatis" />
|
||||
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
|
||||
<constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
|
||||
<property name="transactionManager" ref="transactionManager"/>
|
||||
</bean>
|
||||
|
||||
|
||||
</beans>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user