Archive for the ‘java’ Category

Berkley DB 관리

2016/11/04
DB_HOME=$ODEN_HOME/core/meta
1) db list up
java -jar berkelydb-4.0.103.jar DbDump -h $DB_HOME -l
2) db backup
java -jar berkelydb-4.0.103.jar DbDump -h DB_HOME -p -s RecordInfoDB -f RecordInfoDB.txt
3) db load
java -jar berkelydb-4.0.103.jar DbLoad -h DB_HOME -f recordInfoDB.txt -s RecordInfoDB
3) DbTruncateLog
# show log 
java -jar berkelydb-4.0.103.jar DbPrintLog -h $ODEN_META
java -jar berkelydb-4.0.103.jar DbTruncateLog -h $ODEN_META -f 0x0 -o 0x0 
java -jar berkelydb-4.0.103.jar DbPrintLog -h $ODEN_META
4) DB Verify
java -jar berkelydb-4.0.103.jar DbVerify -h DB_HOME -s RecordInfoDB

[FAQ] Gradle JUnit “Test reports were found but none of them are new. Did tests run?” in Jenkins

2016/10/24

when you run junit test in gradle script at jenkins build server,
you may getting the error “Test reports were found but none of them are new. Did tests run?”
thers is 3 solution to solve it. I prefer 3th solution.

  1. touch every xml files
    touch *.xml
  2. force run
    gradlew test –rerun-tasks
  3. cleanup your test results
    gradlew cleanTest test

reference : http://stackoverflow.com/questions/13879667/how-to-fix-test-reports-were-found-but-none-of-them-are-new-did-tests-run-in

[TIP] java에서 한글 경로 (directory) 인식문제

2016/05/11

공백이 포함된 경로 또는 한글경로를 UTF-8로 인식하기 때문에
문자열로 처리할 경우 제대로 읽어오지 못하는 문제가 발생함.

ex)

String home = “C:\Program%20Files\%ed%95%9c%ea%b8%80″;

solution)

home = java.net.URLDecoder.decode(home ,”UTF-8”);

// C:\Program Files\한글

 

 

logback – remove logback own log

2015/11/27
<configuration>
  <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
  <!-- etc -->
</configuration>

from http://stackoverflow.com/questions/3257154/how-to-prevent-logback-from-outputting-its-own-status-at-the-start-of-every-log

Javascript Parsing with Java, Esprima, JsonPath

2015/06/09

처리흐름

HTML 파싱(jsoup) -> Javascript 파싱(rhino,esprima) -> JsonPath로 관련리소스 추출

/*
하면서 어려웠던 점

– jsonpath가 default로 사용하는 json-smart가 asm library를 쓰는데 기존 사용하는 asm lib버전과 충돌하는 이슈
– JSP가 단순 html, javascript가 아니라 JSTL, JSP Scriptlet, EL 등 다양한 다른 코드를 사용하고 있어 파싱 에러가 빈발
– JsonPath 패턴 사용방법에 익숙하지 않았던 점 (xpath인 듯 xpath 아닌 xpath 같은 너…)
– JsonPath function이 충분하지 않아서 정보 추출을 비효율적으로 우회해서 해결했던 점. (그래서 느려진 속도)

*/

0) dependency (build.gradle)

compile 'org.jsoup:jsoup:+' // for html parsing
compile 'org.mozilla:rhino:1.7R4' // for javascript execute
compile ('com.jayway.jsonpath:json-path:+') // for javascript analyzer</code>

1) html parsing

String content = "alert(1);";
org.jsoup.node.Document doc = Jsoup.parse(String content, String baseUrl);

2) get JavaScripts area

org.jsoup.select.Elements scriptcontent =  doc.getElementsByTag("script");
Set scripts = new HashSet();
for (Element script : scriptcontent) {
    scripts.add(script.html());
}

3) javascript parsing

org.mozilla.javascript.Context context = Context.enter();
org.mozilla.javascript.Scriptable globalScope = context.initStandardObjects();
Reader reader = new InputStreamReader(JavascriptParser.class.getResourceAsStream("esprima.js"));
context.evaluateReader(globalScope, reader, "esprima.js", 1, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
Object wrappedOut = Context.javaToJS(ps, globalScope);
ScriptableObject.putProperty(globalScope, "out", wrappedOut);
String code = "var syntax = esprima.parse('alert(1);',{}); out.print(JSON.stringify(syntax,null,x2));";
context.evaluateString(globalScope, code, "", 1, null);
return baos.toString();
//Context.exit();

4) extract function with json path

ReadContext ctx = JsonPath.parse(jsonString);
List functionNames = ctx.read("$.body[?(@.type=='FunctionDeclaration').id.name]",List.class);
for(String functionName : functionNames ){
  System.out.println(functionName);
}

** reference
http://esprima.org/
http://jsoup.org/
https://github.com/jayway/JsonPath
http://jsonpath.herokuapp.com/

[TroubleShooting] gradle error – A problem occurred evaluating … ShortTypeHandling

2014/12/17

– symptom

>gradlew appstart

FAILURE: Build failed with an exception.

* Where:
Build file ‘build.gradle’ line: 23

* What went wrong:
A problem occurred evaluating root project ‘XXXX’.
> org/codehaus/groovy/runtime/typehandling/ShortTypeHandling

* Try:
Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output.

– cause

gradle version is too lower

– solution

update gradle version ( gradle-wrapper.properties )

ex) distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-bin.zip

[gretty] gradle plugin gretty

2014/12/17

Gretty is a feature-rich gradle plugin for running web-apps on embedded servlet containers

support container : Jetty versions 7, 8 and 9, Tomcat versions 7 and 8

Feature

1. spring boot support

2. jetty, tomcat support

3. multi web-app support ( farm, farms )

4. product generation

version : Gretty 1.1.8 ( Dec 8, 2014: )

License : MIT License

site : https://github.com/akhikhl/gretty

document site : http://akhikhl.github.io/gretty-doc/

[link] lightweight java web server – undertow

2014/12/09

http://undertow.io/

spring multiple context property-placeholder setting

2014/10/16

복수개의 property 파일을 설정할 경우, 뒤에 있는 property파일을 읽지 못하는 문제가 있어 이상하게 생각함…

properties 확장자로 파일을 추가하면 문제가 없는데, xml 파일로 추가하면 제대로 인식을 못하는 것처럼 보임.

해결책은 location attribute 안에 복수개의 값을 주는 것.

거참…

property xml sample


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment/>
<entry key="a"><![CDATA[
<!-- aaa --> <br>
]]></entry>
</properties>

spring context xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
xmlns:context="http://www.springframework.org/schema/context">

<context:property-placeholder location=”classpath:application.xml, classpath:test.xml”/>
</beans>

[IT] SprintBoot log setting ( logback.xml )

2014/08/29

SpringBoot 의 로그 레벨 설정

log4j 는 안되더라..

position : /src/main/resources

file : logback.xml

contents

<?xml version=”1.0″ encoding=”UTF-8″?>

<configuration>

<include resource=”org/springframework/boot/logging/logback/base.xml”/>

<logger name=”org.springframework” level=”ERROR”/>

<logger name=”your.package” level=”DEBUG”/>

</configuration>