<commit_before>package com.bt.controllers;

import com.bt.dao.ImagePostedDao;
import com.bt.dao.ImagePostedDaoImpl;
import com.bt.dao.PhoneNumberDao;
import com.bt.dao.PhoneNumberDaoImpl;
import com.bt.domain.ImagePosted;
import com.bt.domain.PhoneNumber;
import com.bt.domain.User;
import com.bt.util.TwilioUtil;
import com.twilio.Twilio;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Base64;

@RestController
public class TwilioController {

    @Autowired
    TwilioUtil twilioUtil;

    @RequestMapping(value="/twilio/message",method= RequestMethod.POST)
    public void getSMS(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        Twilio.init(twilioUtil.getAccountSid(),twilioUtil.getAuthToken());

        String fromNumber = req.getParameter("From");

        String imageUrl = req.getParameter("MediaUrl0");
        System.out.println(req.getParameter(imageUrl));

        String base64 = null;

        if (imageUrl != null){
            try {

                URLConnection conn = new URL(imageUrl).openConnection();
                conn.setRequestProperty("User-Agent", "Mozilla/5.0");
                byte[] imageBytes = IOUtils.toByteArray(conn);
                base64 = "data:image/jpeg;base64," + Base64.getEncoder().encodeToString(imageBytes);

            } catch (IOException e) {
                System.out.println("image not found" + e);
            }
        }

        System.out.println(base64);


        System.out.println(fromNumber);

        String phoneNumber = fromNumber.substring(2);
        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        PhoneNumberDao phDao = (PhoneNumberDaoImpl) ac.getBean("phoneNumberDaoImpl");
        PhoneNumber ph = phDao.findPhoneNumberByNumber(phoneNumber);
        User user = ph.getUser();
        if(user!=null){
            ImagePosted img = new ImagePosted();
            img.setCaption("Posted from Twilio");
            img.setImage(base64);
            img.setPoster(user);
            ImagePostedDao iDao = (ImagePostedDaoImpl) ac.getBean("imagePostedDaoImpl");
            iDao.persistImagePosted(img);
        }


    }

}
<commit_msg>error with 2 session hibernate<commit_after>package com.bt.controllers;

import com.bt.dao.ImagePostedDao;
import com.bt.dao.ImagePostedDaoImpl;
import com.bt.dao.PhoneNumberDao;
import com.bt.dao.PhoneNumberDaoImpl;
import com.bt.domain.ImagePosted;
import com.bt.domain.PhoneNumber;
import com.bt.domain.User;
import com.bt.util.TwilioUtil;
import com.twilio.Twilio;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Base64;

@RestController
public class TwilioController {

    @Autowired
    TwilioUtil twilioUtil;

    @RequestMapping(value="/twilio/message",method= RequestMethod.POST)
    public void getSMS(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        Twilio.init(twilioUtil.getAccountSid(),twilioUtil.getAuthToken());

        String fromNumber = req.getParameter("From");

        String imageUrl = req.getParameter("MediaUrl0");
        System.out.println(req.getParameter(imageUrl));

        String base64 = null;

        System.out.println(fromNumber);


        if (imageUrl != null){
            URLConnection conn;
            try {
                conn = new URL(imageUrl).openConnection();

                conn.setRequestProperty("User-Agent", "Mozilla/5.0");
                byte[] imageBytes = IOUtils.toByteArray(conn);
                base64 = "data:image/jpeg;base64," + Base64.getEncoder().encodeToString(imageBytes);
            } catch (IOException e) {
                System.out.println("image not found" + e);
            }
        }

        System.out.println(base64);
        postImages(fromNumber, base64);
    }

    public void postImages(String fromNumber, String base64){
        String phoneNumber = fromNumber.substring(2);
        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        PhoneNumberDao phDao = (PhoneNumberDaoImpl) ac.getBean("phoneNumberDaoImpl");
        PhoneNumber ph = phDao.findPhoneNumberByNumber(phoneNumber);
        User user = ph.getUser();
        System.out.println(user.toString());
//        if(user!=null){
//            ImagePosted img = new ImagePosted();
//            img.setCaption("Posted from Twilio");
//            img.setImage(base64);
//            img.setPoster(user);
//            ImagePostedDao iDao = (ImagePostedDaoImpl) ac.getBean("imagePostedDaoImpl");
//            iDao.persistImagePosted(img);
//        }
    }


}

{'fraction_non_alphanumeric': 0.10985517484987636, 'fraction_numerical': 0.007241257506181561, 'mean_word_length': 3.3262032085561497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1688611', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1600, 'n_words': 276}