<commit_before>// ========================================================================
// Copyright 2008-2009 NEXCOM Systems
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at 
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========================================================================

package org.cipango.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.sip.Address;
import javax.servlet.sip.SipServletMessage;
import javax.servlet.sip.SipServletResponse;
import javax.servlet.sip.SipURI;
import javax.servlet.sip.URI;

import org.cipango.Server;
import org.cipango.SipException;
import org.cipango.SipHandler;
import org.cipango.SipMessage;
import org.cipango.SipRequest;
import org.cipango.SipResponse;
import org.cipango.sip.ServerTransaction;
import org.cipango.sipapp.SipAppContext;
import org.cipango.util.ExceptionUtil;
import org.mortbay.jetty.handler.AbstractHandler;
import org.mortbay.log.Log;

public class SipSessionHandler extends AbstractHandler implements SipHandler
{
	public void handle(String target, HttpServletRequest request,
			HttpServletResponse response, int dispatch) throws IOException,
			ServletException 
	{
		throw new UnsupportedOperationException("sip-only handler");
	}

	@Override
	public Server getServer()
	{
		return (Server) super.getServer();
	}
	
	public void handle(SipServletMessage message) throws IOException,
			ServletException 
	{
		SipMessage baseMessage = (SipMessage) message;
		
		if (baseMessage.isRequest())
		{
			SipRequest request = (SipRequest) message;
			
			// preprocess route

			SipURI paramUri = null;
			
			Address route = request.getTopRoute();
			if (route != null && getServer().getTransportManager().isLocalUri(route.getURI()))
			{
				request.removeTopRoute();
				paramUri = (SipURI) route.getURI();
				request.setPoppedRoute(route);
			}
			else 
			{
				URI uri = request.getRequestURI();
				if (uri.isSipURI())
					paramUri = (SipURI) uri;
			}
			request.setParamUri(paramUri);
			
			Session session = null;
			<commit_msg>Fix CIPANGO-23: Got java.lang.IllegalArgumentException: Multiple getters for attr server when running with JMX<commit_after>// ========================================================================
// Copyright 2008-2009 NEXCOM Systems
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at 
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========================================================================

package org.cipango.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.sip.Address;
import javax.servlet.sip.SipServletMessage;
import javax.servlet.sip.SipServletResponse;
import javax.servlet.sip.SipURI;
import javax.servlet.sip.URI;

import org.cipango.Server;
import org.cipango.SipException;
import org.cipango.SipHandler;
import org.cipango.SipMessage;
import org.cipango.SipRequest;
import org.cipango.SipResponse;
import org.cipango.sip.ServerTransaction;
import org.cipango.sipapp.SipAppContext;
import org.cipango.util.ExceptionUtil;
import org.mortbay.jetty.handler.AbstractHandler;
import org.mortbay.log.Log;

public class SipSessionHandler extends AbstractHandler implements SipHandler
{
	public void handle(String target, HttpServletRequest request,
			HttpServletResponse response, int dispatch) throws IOException,
			ServletException 
	{
		throw new UnsupportedOperationException("sip-only handler");
	}

	
	public void handle(SipServletMessage message) throws IOException,
			ServletException 
	{
		SipMessage baseMessage = (SipMessage) message;
		
		if (baseMessage.isRequest())
		{
			SipRequest request = (SipRequest) message;
			
			// preprocess route

			SipURI paramUri = null;
			
			Address route = request.getTopRoute();
			if (route != null && ((Server) getServer()).getTransportManager().isLocalUri(route.getURI()))
			{
				request.removeTopRoute();
				paramUri = (SipURI) route.getURI();
				request.setPoppedRoute(route);
			}
			else 
			{
				URI uri = request.getRequestURI();
				if (uri.isSipURI())
					paramUri = (SipURI) uri;
			}
			request.setParamUri(paramUri);
			
			Session session = null;
			
{'fraction_non_alphanumeric': 0.16774431923147978, 'fraction_numerical': 0.004803251431738408, 'mean_word_length': 3.9990766389658354, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3635125', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1442, 'n_words': 412}