/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sip.RequestEvent;
import javax.sip.header.AllowHeader;
import javax.sip.header.CSeqHeader;
import javax.sip.header.CallIdHeader;
import javax.sip.header.FromHeader;
import javax.sip.header.HeaderFactory;
import javax.sip.header.SupportedHeader;
import javax.sip.header.ToHeader;
import javax.sip.header.ViaHeader;
import javax.sip.message.MessageFactory;
import javax.sip.message.Response;
import logger.OhmLogger;

/**
 * Erstellt den Trying Header, wird als erstes gesendet sobald man einen Anruf bekommt
 * @author Jan
 */
public class SIP100Trying
{
  private Response tryResponse;
  private static final Logger lgTry = OhmLogger.getLogger();

  public SIP100Trying(MessageFactory messageFactory, RequestEvent requestEvent,
                      HeaderFactory headerFactory)
  {
    try
    { //
      tryResponse = messageFactory.createResponse(100, requestEvent.getRequest());
      tryResponse.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via"));
      tryResponse.addHeader((FromHeader) requestEvent.getRequest().getHeader("From"));
      tryResponse.addHeader((ToHeader) requestEvent.getRequest().getHeader("To"));
      tryResponse.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID"));
      tryResponse.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq"));
      SupportedHeader supp = headerFactory.createSupportedHeader("replace,path,timer"); //nachschauen
      AllowHeader allow = headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE");
      tryResponse.addHeader(supp);
      tryResponse.addHeader(allow);
      lgTry.info("100-Trying Header erstellt");
    }
    catch (Exception ex)
    {
      lgTry.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
    }

  }

  /**
   * @return the tryResponse
   */
  public Response getTryResponse()
  {
    return tryResponse;
  }
}
