본문 바로가기

Programing

(393)
[python] BeautifulSoup 로 XML 처리하기 엄밀히 이야기 하면 XML은 아니나 마크업 문서를 처리하기 위함이다. from bs4 import BeautifulSoup with open("user.xml") as fp: soup = BeautifulSoup(fp, 'html.parser') body = soup.grid.body.b for ele in body.find_all("i"): print ele["name"].encode('utf8') 처리하다 발견한 예외 UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) 관련내용: https://ourcstory.tistory.com/39 처리방법: .encode('utf8')
[python] Python의 버전 관리 툴 pyenv 설치 사이트: https://github.com/pyenv/pyenv homebrew가 설치되어 있으면 아래 명령으로 설치 가능 $ brew install pyenv 설치가 가능한 목록 확인 $ pyenv install -l Available versions: 2.1.3 2.2.3 ... 3.8.1 버전 설치 $ pyenv install 3.8.1 pyenv shell 먼저 사용을 위해서는 pyenv init 명령 수행이 필요하다. $ pyenv shell pyenv: shell integration not enabled. Run `pyenv init' for instructions $ pyenv init # Load pyenv automatically by appending # the following to..
[tomcat] HttpServletRequest.getHeader 헤더를 보면 가끔 대소문자를 가리지 않고 동작하는 경우가 있어서 확인을 해보았다. package javax.servlet.http; public interface HttpServletRequest extends ServletRequest { /** * Returns the value of the specified request header as a * String. If the request did not include a header of the * specified name, this method returns null. If there are * multiple headers with the same name, this method returns the first head * in the reque..
[Spring] mvc - DispatcherServlet 1부 서블릿과 스프링 MVC는 밀접하면서 독립적이다. DispatcherServlet 클래스는 HTTP 요청을 처리하는 중심 디스패처 클래스이다. DispatcherServlet 클래스는 아래와 같은 계층 구조를 가진다. Servlet 인터페이스 서블릿의 핵심은 요청과 응답이다. ServletRequest과 ServletResponse가 요청 및 응답을 추상화해놓은 인터페이스이다. public interface Servlet { // .. public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException; HttpServlet 추상 클래스 Servlet 인터페이스의 구현체인 HttpServlet 라는 ..
[Spring] SSE vs WebFlux WebFlux를 쓰지 않을 경우 스레드풀 방식에 의해 매 연결이 계속 연결이 될까 궁금했다. 코드 방법1. Tomcat, MVC 방법.2 Tomcat, WebFlux https://supawer0728.github.io/2018/03/15/spring-http-stereamings/ http://jmlim.github.io/spring/2018/11/27/spring-boot-schedule/ @EnableScheduling 크롬브라우저는 되는데 HttpPie는 -S 옵션을 붙여주어야 한다. 안그러면 마지막 응답 후 한꺼번에 결과를 보여준다.
[Spring] mvc 예외처리 스프링의 mvc에서 예외처리는 실무에서 보면 @ControllerAdvice 을 이용해서 많이 한다. 아래와 같이 밑바닥 부터 예외 처리기를 구현해도 무방하다. @RestControllerAdvice(basePackages = {"com.tistory.namocom.controller"}) public class NamoExceptionHandler { 하지만 편의를 위해 스프링은 미리 ResponseEntityExceptionHandler을 만들어놓았다. public abstract class ResponseEntityExceptionHandler { 추상클래스이므로 상속을 받아 사용이 가능하다. @RestControllerAdvice(basePackages = {"com.tistory.namocom...
[Spring] ServiceLocatorFactoryBean 어떤 기능이 여러 출처에 의해 분기를 해야하는 경우가 실무에서는 자주 생긴다. 주문 도메인이라면 처음에는 카테고리 A에 대해서만 판매를 하다가 카테고리 B라는 것이 생긴다. 결제 도메인이라면 처음에는 카카오페이만 지원을 했더라도 나중에 다른 네이버페이를 추가할 수 있다. 이럴 경우 레이어를 두는 것이 보통 일반적이다. Client -> KakaopayService -> KakaopayExternalAPI 이런식으로 되어 있는데 네이버 페이를 추가한다면 Client -> PaymentService -> KakaopayService -> KakaopayExternalAPI -> NaverpayService -> NaverpayExternalAPI 이런식으로 분기를 할 수 있는 계층(위에서 PaymentSer..
[Spring] Boot 빈 의존성 사례 - Spring Integration (TCP) 하는 방법은 검색해보면 쉽게 찾을 수 있다. 글을 쓰는 이유는 실무에서 어떤 경우에 발생하는지 기록을 하기 위함이다. 스프링이 관리하는 객체, 즉 빈은 의존하고 있는 것이 명시적으로 드러날 때는 초기화 과정에서 필요한 빈들을 먼저 초기화를 해준다. 하지만 간접적으로 빈을 사용하는 경우 초기화 시점에 필요한 빈이 없을 수 있기 때문에 애플리케이션에서 실패가 발생한다. 내가 경험한 사례는 다음과 같다. TCP/IP 전문 통신을 해야해서 Spring Integration프로젝트 중 TCP and UDP Support 기능을 이용했다. Spring Integration 5.0 부터는 Java DSL을 통한 설정이 가능하기에 Configuration은 아래와 같이 구성했다. @Configuration @Enabl..