<commit_before>package org.wcecil.filters;

import java.io.IOException;
import java.util.Collection;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;

import org.wcecil.application.MyApp;
import org.wcecil.beans.BeanBase;

public class ResponseFilter implements ContainerResponseFilter {

	@Override
	public void filter(ContainerRequestContext req,
			ContainerResponseContext resp) throws IOException {
		String token = req.getHeaderString(MyApp.AUTH_TOKEN);
		if (token != null && !token.isEmpty()) {
			resp.getHeaders().add(MyApp.AUTH_TOKEN, token);

			// TODO figure out a better way to do this
			resp.getHeaders().add("Set-Cookie",
					"JSESSIONID=" + token + "; Path=/jerseymoe/");
		}
		
		
		//allow requests from anywhere
		
		resp.getHeaders().add("Access-Control-Allow-Origin:", "*");
		
		resp.getHeaders().add("X-Powered-By:", "JerseyMoe");
		
		if (resp.getEntity() == null) {
			return;
		}
		if (resp.getEntity() instanceof BeanBase) {
			BeanBase bean = (BeanBase) resp.getEntity();
			resp.setEntity(bean.getObjectAsJsonString(true));
		}

		if (resp.getEntity() instanceof Collection) {
			String json = null;<commit_msg>MyApp.JSESSIONID over reaw string incase i change it<commit_after>package org.wcecil.filters;

import java.io.IOException;
import java.util.Collection;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;

import org.wcecil.application.MyApp;
import org.wcecil.beans.BeanBase;

public class ResponseFilter implements ContainerResponseFilter {

	@Override
	public void filter(ContainerRequestContext req,
			ContainerResponseContext resp) throws IOException {
		String token = req.getHeaderString(MyApp.AUTH_TOKEN);
		if (token != null && !token.isEmpty()) {
			resp.getHeaders().add(MyApp.AUTH_TOKEN, token);

			// TODO figure out a better way to do this
			resp.getHeaders().add("Set-Cookie",
					MyApp.JSESSIONID+"=" + token + "; Path=/jerseymoe/");
		}
		
		
		//allow requests from anywhere
		
		resp.getHeaders().add("Access-Control-Allow-Origin:", "*");
		
		resp.getHeaders().add("X-Powered-By:", "JerseyMoe");
		
		
		//get as json if possible
		if (resp.getEntity() == null) {
			return;
		}
		if (resp.getEntity() instanceof BeanBase) {
			BeanBase bean = (BeanBase) resp.getEntity();
			resp.setEntity(bean.getObjectAsJsonString(true));
		}

		if (resp.getEntity() instanceof Collection) {
			String json = null;
{'fraction_non_alphanumeric': 0.12909441233140656, 'fraction_numerical': 0.0, 'mean_word_length': 4.453781512605042, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6035285', 'n_tokens_mistral': 882, 'n_tokens_neox': 779, 'n_words': 169}