'ITWeb/개발일반'에 해당되는 글 489건

  1. 2021.11.25 [Java] Snake to Camel 변환
  2. 2021.11.23 [cURL] cURL in Bash Script
  3. 2021.11.23 [Shell] Bash Random Number & Substring
  4. 2021.11.18 [Shell] for loop example
  5. 2021.11.16 [Jackson] AddSlash 출력 결과 포함
  6. 2021.11.10 [Shell] sed 명령어 예제
  7. 2021.10.28 [CURL] proxy 설정에 따른 ERR_ACCESS_DENIED 회피.
  8. 2021.10.27 [Postman] Set Array Variable.
  9. 2021.10.20 [Spring] Intellij Community + Springboot Profile 활용
  10. 2021.10.05 [Logback] JSON Layout Format 적용하기.

[Java] Snake to Camel 변환

ITWeb/개발일반 2021. 11. 25. 16:46

query parameter 로 넘어온 변수가 snake 로 작성 되어 있어서 이걸 camel 로 받도록 해주고 싶을 때 사용 하면 됩니다.

 

- jackson-databind 패키지에 포함 되어 있습니다.

- domain, model 클래스에 아래와 같이 선언 합니다.

// GET /_cluster/settings?flat_settings=true&master_timeout=30s


@Data
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class SettingsModel {
	private String flatSettings;
    private String masterTimeout;
}

참고용으로 기록 합니다.

 

:

[cURL] cURL in Bash Script

ITWeb/개발일반 2021. 11. 23. 15:35

Case 1)
response=`curl -s -X GET 'http://www.kakaopay.com' -H 'Content-Type: application/json' -d '{ "size": 100, "message": "test" }'`

Case 2)
curl -s -X GET 'http://www.kakaopay.com' -H 'Content-Type: application/json' -d '{ "size": 100, "message": "test" }'

Case 3)
size=100
message="test"

response=`curl -s -X GET 'http://www.kakaopay.com' -H 'Content-Type: application/json' -d '{ "size": '$size', "message": "'"$message"'" }'`

Case 4)
size=100
message="test"

curl -s -X GET 'http://www.kakaopay.com' -H 'Content-Type: application/json' -d '{ "size": '$size', "message": "'"$message"'" }'

proxy 를 지정 하고자 한다면 아래 내용 추가 합니다.
curl -x 'http://PROXY-IP:PROXY-PORT' -s -X GET 'http://www.kakaopay.com'

 

:

[Shell] Bash Random Number & Substring

ITWeb/개발일반 2021. 11. 23. 15:33

이런것도 기억력을 돕기 위해 기록해 봅니다.

 

- Bash Random Number
$ echo $(( $RANDOM % 4 ))

 

nodes=( '1' '2' '3' '4' )

i=$(( $RANDOM % 4 ))

node=${nodes[${i}]}

- Bash Substring
${String:Position:length} 문자:인덱스:길이

 

:

[Shell] for loop example

ITWeb/개발일반 2021. 11. 18. 11:25

간혹 서버간 ssh tunneling 을 위해 pub key 를 등록 해야 할 일이 있습니다.

노가다 하기 귀찮으니까 instance 목록만 가지고 쭈욱 돌리면 되겠죠.

 

#!/bin/bash

PUB="abcdefg"
HOSTS=("ip1" "ip2" "ip3" ...)

for host in "${HOSTS[@]}"
do
  echo "ssh -o StrictHostKeychecking=no USER@$host \"echo '$PUB' >> .ssh/authorized_keys\""
  ssh -o StrictHostKeychecking=no USER@$host "echo '$PUB' >> .ssh/authorized_keys"
done

이런것도 맨날 기억을 못해서 기록을 합니다.

:

[Jackson] AddSlash 출력 결과 포함

ITWeb/개발일반 2021. 11. 16. 16:54

jackson 사용 시 writeValueAsString(Object) 에서 간혹 JSON String 에 Addslash 된 결과가 출력

reponse.getEntity() -> EntityUtils.toString 후 writeValueAsString(Object)

하게 되면 의도하지 않게 List value 에 addslash 가 되어서 출력이 되버립니다.
이를 방지 하기 위해서는 아래 단계를 추가해서 구분해 주면 됩니다.

response.getEntity() -> EntityUtils.toString -> readValue(String, new TypeReference<List<Object>>() {}) -> writeValueAsString(Object)

하게 되면 원하는 결과를 얻을 수 있습니다.

Case 1) reponse.getEntity() 가 Object 형일 경우
reponse.getEntity() -> EntityUtils.toString -> writeValueAsString(Object)

Case 2) reponse.getEntity() 가 List 형일 경우
response.getEntity() -> EntityUtils.toString -> readValue(String, new TypeReference<List<Object>>() {}) -> writeValueAsString(Object)

:

[Shell] sed 명령어 예제

ITWeb/개발일반 2021. 11. 10. 13:55

sed - stream editor for filtering and transforming text

예) 파일 내부 컨텐츠 내용을 변경
$ sed -i "s/FIND-VAR/REPLACE-VAR/g" FILE

:

[CURL] proxy 설정에 따른 ERR_ACCESS_DENIED 회피.

ITWeb/개발일반 2021. 10. 28. 15:47

뭐 회피라고 하기도 그렇지만 실행 하는 장비에 proxy 설정이 되어 있어서 발생 하는 문제 입니다.

proxy 를 거치지 않도록 실행 시키면 관련 에러는 없어 질 수 있습니다.

(제 경우를 기록 한거라 다른 환경이면 안될 수도 있으니 참고하세요.)

 

$ curl --noproxy '*' -X POST http://user:token@localhost:8080/job/task/build

 

:

[Postman] Set Array Variable.

ITWeb/개발일반 2021. 10. 27. 12:36

참고문서)

https://learning.postman.com/docs/sending-requests/variables/

 

Pre-request Script

pm.environment.set("KEYWORDS", "삼성", "전자", "삼성전자")

 

Body

{
  "query": {
    "terms": {
      "keywords": [
        "{{KEYWORDS}}"
      ]
    }
  }
}

 Array 로 설정을 해야 할 일이 있어서 또 기억 못할까봐 기록해 봅니다.

:

[Spring] Intellij Community + Springboot Profile 활용

ITWeb/개발일반 2021. 10. 20. 16:43

Intellij Community + Spring Boot Framework Profiles

intellij 에서 바로 springboot application 을 실행 시킬 때 환경 설정 파일을 분리해서 사용하기 위한 내용입니다.
Intellij Community 같은 경우 Ultimate 이랑 다르기 때문에 아래와 같은 방법으로 사용 하시면 됩니다.

application.yml 내 "---" 을 이용한 방식은 검색 해 보시면 많이 나와 있으니 넘어 가겠습니다.
아래 방식이 제가 하고 싶은 방법이라서 기술 합니다.

resources/
  + application.yml
  + application-local.yml

Edit Configuration -> Build and run 에서 Modify options 를 선택해서 add VM options 선택 -> -Dspring.profiles.active=local 입력
또는
Environment variables 에서 아래 key=value 입력 합니다.
spring.profiles.active=local

이와 같이 설정 하고 Application 을 실행 시켜 보시면 동작하는 걸 확인해 볼 수 있습니다.

 

:

[Logback] JSON Layout Format 적용하기.

ITWeb/개발일반 2021. 10. 5. 18:52

Springboot 로 프로젝트 생성 후 로깅 하면서 로그 포멧을 JSON 으로 적용 하기 위한 내용을 기억 차원에서 작성 합니다.

 

[logback.xml]

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds">
  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
        <timestampFormat>yyyy-MM-dd'T'HH:mm:ss.SSS'Z'</timestampFormat>
        <timestampFormatTimezoneId>Asia/Seoul</timestampFormatTimezoneId>
        <appendLineSeparator>true</appendLineSeparator>
        <jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
          <prettyPrint>true</prettyPrint>
        </jsonFormatter>
      </layout>
    </encoder>
  </appender>

  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>application/application.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>application/application-%d{yyyy-MM-dd}.log</fileNamePattern>
      <maxHistory>30</maxHistory>
    </rollingPolicy>

    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
        <timestampFormat>yyyy-MM-dd'T'HH:mm:ss.SSS'Z'</timestampFormat>
        <timestampFormatTimezoneId>Asia/Seoul</timestampFormatTimezoneId>
        <appendLineSeparator>true</appendLineSeparator>
        <jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
          <prettyPrint>true</prettyPrint>
        </jsonFormatter>
      </layout>
    </encoder>
  </appender>

  <logger name="org.springframework" level="error" additivity="false" />
  <logger name="org.apache" level="error" additivity="false" />
  <logger name="com.zaxxer" level="error" additivity="false" />
  <logger name="io.netty" level="error" additivity="false" />
  <logger name="reactor" level="error" additivity="false" />
  <logger name="com.xxxxx" level="debug" additivity="false">
    <appender-ref ref="FILE" />
  </logger>

  <root level="debug">
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>
  </root>
</configuration>

 

[build.gradle]

compile "ch.qos.logback.contrib:logback-jackson:${props.getProperty('logback-jackson')}"
compile "ch.qos.logback.contrib:logback-json-classic:${props.getProperty('logback-json-classic')}"

- 여기서 사용 버전은 0.1.5 입니다.

 

사용한 timezone 은 ETC/UTC 가 아닌 Asia/Seoul 로 설정 했습니다.

: