<commit_before>package com.oracle.poco.bbhelper;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.oracle.poco.bbhelper.exception.BbhelperBadRequestException;
import com.oracle.poco.bbhelper.exception.BbhelperBeehive4jException;
import com.oracle.poco.bbhelper.exception.BbhelperException;

import jp.gr.java_conf.hhayakawa_jp.beehive4j.BeehiveContext;
import jp.gr.java_conf.hhayakawa_jp.beehive4j.exception.BeehiveApiFaultException;

// TODO このクラスにロギングを実装する
@RestController
@RequestMapping("/api/session")
public class SessionController {

    @Autowired
    private ApplicationProperties properties;

    @Autowired
    private SessionPool sessionPool;

    @Autowired
    private AutowireCapableBeanFactory factory;

    @RequestMapping(path = "/actions/login",
                    method = RequestMethod.GET)
    public ResponseEntity<String> login(HttpServletRequest request) throws BbhelperException {
        final String basicAuthHeader = request.getHeader("Authorization");
        if (basicAuthHeader == null || basicAuthHeader.length() == 0) {
            throw new BbhelperBadRequestException();
        }
        try {
            BeehiveContext context =
                    BeehiveContext.getBeehiveContext(properties.getBeehiveUrl(), basicAuthHeader);
            Session session = new Session(context);
            factory.autowireBean(session);
            String session_id = sessionPool.put(session);
            HttpHeaders headers = new HttpHeaders();
            headers.add(Constants.HEADER_KEY_BBH_AUTHORIZED_SESSION, session_id);
            return new ResponseEntity<>(null, headers, HttpStatus.OK);
        } catch (BeehiveApiFaultException e) {
            throw new BbhelperBeehive4jException();
        }
    }

}<commit_msg>ログイン成功／失敗時のログ出力を追加<commit_after>package com.oracle.poco.bbhelper;

import javax.servlet.http.HttpServletRequest;

import com.oracle.poco.bbhelper.log.BasicMessage;
import com.oracle.poco.bbhelper.log.BbhelperLogger;
import com.oracle.poco.bbhelper.log.Operation;
import com.oracle.poco.bbhelper.log.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.oracle.poco.bbhelper.exception.BbhelperBadRequestException;
import com.oracle.poco.bbhelper.exception.BbhelperBeehive4jException;
import com.oracle.poco.bbhelper.exception.BbhelperException;

import jp.gr.java_conf.hhayakawa_jp.beehive4j.BeehiveContext;
import jp.gr.java_conf.hhayakawa_jp.beehive4j.exception.BeehiveApiFaultException;

@RestController
@RequestMapping("/api/session")
public class SessionController {

    private static final BbhelperLogger logger = BbhelperLogger.getLogger(SessionController.class);

    @Autowired
    private ApplicationProperties properties;

    @Autowired
    private SessionPool sessionPool;

    @Autowired
    private AutowireCapableBeanFactory factory;

    @RequestMapping(path = "/actions/login",
            method = RequestMethod.GET)
    public ResponseEntity<String> login(HttpServletRequest request) throws BbhelperException {
        final String basicAuthHeader = request.getHeader("Authorization");
        if (basicAuthHeader == null || basicAuthHeader.length() == 0) {
            this.logger.info(new BasicMessage(Operation.LOGIN, Result.FAIL, "no credential."));
            throw new BbhelperBadRequestException();
        }
        String session_id;
        try {
            BeehiveContext context =
                    BeehiveContext.getBeehiveContext(properties.getBeehiveUrl(), basicAuthHeader);
            Session session = new Session(context);
            factory.autowireBean(session);
            session_id = sessionPool.put(session);
            this.logger.info(new BasicMessage(Operation.LOGIN, Result.SUCCESS, "login"));
        } catch (BeehiveApiFaultException e) {
            // TODO エラーの原因をログに残す
            this.logger.info(new BasicMessage(Operation.LOGIN, Result.FAIL, "login failed."));
            // TODO 失敗の原因に合わせた例外を上げる
            throw new BbhelperBeehive4jException(e);
        }
        HttpHeaders headers = new HttpHeaders();
        headers.add(Constants.HEADER_KEY_BBH_AUTHORIZED_SESSION, session_id);
        return new ResponseEntity<>(null, headers, HttpStatus.OK);
    }

}
{'fraction_non_alphanumeric': 0.08980153271762625, 'fraction_numerical': 0.0019650225977598744, 'mean_word_length': 4.014778325123153, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1695055', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1469, 'n_words': 233}