2015년 3월 27일 금요일

아파치에서 403 오류 나올때.

이것저것 했는데 403이 계속 나오면..


chcon -R --reference=/var/www /www/webroot

2015년 3월 24일 화요일

spring junit testcase 작성

maven에 아래 추가.

<dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-test</artifactid>
   <version>4.0.5.RELEASE</version>
   <scope>test</scope>
  </dependency>


test java코드 MemberServiceTest.java

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( {
  "classpath:servlet-context.xml",
  "classpath:config/context-datasource.xml"
}
)
public class MemberServiceTest {

    @Autowired
    MemberService memberService;


    @Test
    public void testSr2002() throws Exception {
        RequestData req = new RequestData(null, new DbMap());
        ResponseData res = new ResponseData(new DbMap());

        memberService.sr2002(req, res);
    }

}



이때 디비를 jndi-lookup 를 이용하는 경우를 위해 test/resources/config/context-datasource.xml 을 넣어서 아래와 같이 기존 id를 덮었다.

test/resources/config/context-datasource.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" xmlns:p="http://www.springframework.org/schema/p" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" p:driverclassname="com.mysql.jdbc.Driver" p:url="jdbc:mysql://server:3306/dbname" p:username="sa" p:password="">


</bean></beans>


2015년 3월 10일 화요일

spring-rabbitmq 연동

설치는 그냥 rpm 으로 설치

# 서버 시작.
sbin/rabbitmq-server start

# 서버 중지
sbin/rabbitmqctl stop




--- spring-rabbit 연동 pom.xml

<dependency>
  <groupid>org.springframework.amqp</groupid>
  <artifactid>spring-rabbit</artifactid>
  <version>1.4.1.RELEASE</version>
</dependency>



context-rabbitmq.xml

<!-- A reference to the org.springframework.amqp.rabbit.connection.ConnectionFactory -->
<rabbit:connection-factory id="connectionFactory" host="localhost" username="worker" password="workerpassword"></rabbit:connection-factory>

<!-- Creates a org.springframework.amqp.rabbit.core.RabbitTemplate for access to the broker -->
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"></rabbit:template>

<!-- Creates a org.springframework.amqp.rabbit.core.RabbitAdmin  to manage exchanges, queues and bindings -->
<rabbit:admin connection-factory="connectionFactory"></rabbit:admin>

<!-- Creates a queue for consumers to retrieve messages -->
<rabbit:queue name="simple_queue"></rabbit:queue>

<rabbit:listener-container connection-factory="connectionFactory">
    <rabbit:listener queues="simple_queue" ref="mqService">
</rabbit:listener></rabbit:listener-container>




MqService.java

@Service
public class MqService implements MessageListener {
    private static final Logger logger = LoggerFactory.getLogger(MqService.class);
    private static final String TASK_QUEUE_NAME = "simple_queue";

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(String message) throws IOException {
        rabbitTemplate.convertAndSend(TASK_QUEUE_NAME, message);

        logger.info("send message={}", message);
    }

    @Override
    public void onMessage(Message message) {
        String msg = null;
        try {
            msg = new String(message.getBody(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        logger.info("recv message=" + msg );
    }
}

2015년 3월 4일 수요일

git 관련 명령어 모음

// svn to git 마이그레이션
$ git svn clone --stdlayout --no-metadata -A users.txt svn://example.com/repository/projectname
$ cd projectname

// 아래 users.txt 만드는건데 perl 이 없어서 그런지.. 안되네요... ㅠ
//$ svn log ^/ --xml | grep -P "^<author" | sort -u | \ perl -pe 's/<author>(.*?)<\/author>/$1 = /' > users.txt

// ignore file처리
$ git svn show-ignore -i trunk > .gitignore

// remote git 지정
$ git remote add origin git@git.example.com:group/projectname.git

// tags 처리
$ git for-each-ref refs/remotes/tags | cut -d / -f 4- | grep -v @ | while read tagname; do git tag "$tagname" "tags/$tagname"; git branch -r -d "tags/$tagname"; done

// branches 처리
$ git for-each-ref refs/remotes | cut -d / -f 3- | grep -v @ | while read branchname; do git branch "$branchname" "refs/remotes/$branchname"; git branch -r -d "$branchname"; done

// push한다.
$ git push origin --all
$ git push origin --tags

// revert local commit
git reset —hard remotes/origin/HEAD


-----------

// backup
$ sudo gitlab-rake gitlab:backup:create

// restore (가장 최근꺼 복원)
$ sudo gitlab-rake gitlab:backup:restore

// restore OPTION (아래 지정한 타임스탬프로 복원시켜준다는건가.. 안해봄..)
BACKUP=timestamp_of_backup (required if more than one backup exists)