/*
(non-Javadoc)
@see javax.servlet.sip.SipServletRequest#createResponse(int, java.lang.String)
182073
public SipServletResponse createResponse(final int statusCode, final String reasonPhrase) {
		return createResponse(statusCode, reasonPhrase, true, false);
	}
1034753
@Override
    protected Smb2NegotiateResponse createResponse ( CIFSContext tc, ServerMessageBlock2Request<Smb2NegotiateResponse> req ) {
        return new Smb2NegotiateResponse(tc.getConfig());
    }
998509
public CreatePresetResponse createPreset(CreatePresetRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");
        
        InternalRequest internalRequest = createRequest(HttpMethodName.POST, request, PRESET);

        return invokeHttpClient(internalRequest, CreatePresetResponse.class);
    }
1224159
public void doGet (HttpServletRequest request,
            	   HttpServletResponse response)
    throws ServletException, IOException
    {
    	String access = request.getParameter("access");
    	String callAuthCode = getServletContext().getInitParameter("call.code");
    	if (callAuthCode.equals(access)) {

			String toAddr = "sip:+" + request.getParameter("to").trim() + "@"
					+ getServletContext().getInitParameter("domain.name");

			String fromAddr = "sip:"
					+ getServletContext().getInitParameter("user1") + "@"
					+ getServletContext().getInitParameter("domain.name");

			String secondParty = "sip:+" + request.getParameter("from").trim()
					+ "@" + getServletContext().getInitParameter("domain.name");

			URI to = toAddr == null ? null : sipFactory.createAddress(toAddr)
					.getURI();
			URI from = fromAddr == null ? null : sipFactory.createAddress(
					fromAddr).getURI();

			// Create app session and request
			SipApplicationSession appSession =
			// ((ConvergedHttpSession)request.getSession()).getApplicationSession();
			sipFactory.createApplicationSession();

			SipServletRequest req = sipFactory.createRequest(appSession,
					"INVITE", from, to);

			// Set some attribute
			req.getSession().setAttribute("SecondPartyAddress",
					sipFactory.createAddress(secondParty));
			req.getSession().setAttribute("FromAddr",
					sipFactory.createAddress(fromAddr));
			req.getSession().setAttribute("user",
					getServletContext().getInitParameter("user1"));
			req.getSession().setAttribute("pass",
					getServletContext().getInitParameter("pass1"));

			logger.info("Sending request" + req);
			// Send the INVITE request
			req.send();

		}
        // Write the output html
    	PrintWriter	out;
        response.setContentType("text/html");
        out = response.getWriter();
        
        // Just redirect to the index
        out.println("<HTML><META HTTP-EQUIV=\"Refresh\"CONTENT=\"0; URL=index.jsp\"><HEAD><TITLE></HTML>");
        out.close();
    }
1092561
public void addSipServletResponse(SipServletResponseImpl sipServletResponse) {
		if(sipServletResponses == null) {
			sipServletResponses = new CopyOnWriteArraySet<SipServletResponseImpl>();
		}
		sipServletResponses.add(sipServletResponse);
	}
557019
@Override
    protected Smb2CloseResponse createResponse ( CIFSContext tc, ServerMessageBlock2Request<Smb2CloseResponse> req ) {
        return new Smb2CloseResponse(tc.getConfig(), this.fileId, this.fileName);
    }
745718
@SuppressWarnings("unchecked")
	public Response createResponse(ServerTransaction origServerTransaction, Response receivedResponse) throws SipException {

		final SleeSipProviderImpl provider = ra.getProviderWrapper();
		
		Response forgedResponse = null;
		
		try {
			forgedResponse = provider.getMessageFactory().createResponse(receivedResponse.getStatusCode(), origServerTransaction.getRequest());
		} catch (ParseException e) {
			throw new SipException("Failed to forge message", e);
		}
		
		final DialogState dialogState = getState();
		final String localTag = getLocalTag();
		if ((dialogState == null || dialogState == DialogState.EARLY) && localTag != null && isServer()) {
			// no tag set in the response, since the dialog creating transaction didn't had it
			try {
				((ToHeader)forgedResponse.getHeader(ToHeader.NAME)).setTag(localTag);
			} catch (ParseException e) {
				throw new SipException("Failed to set local tag", e);
			}
		}
		
		// copy headers 
		ListIterator<String> lit = receivedResponse.getHeaderNames();
		String headerName = null;
		ListIterator<Header> headersIterator = null;
		while (lit.hasNext()) {
			headerName = lit.next();
			if (Utils.getHeadersToOmmitOnResponseCopy().contains(headerName)) {
				continue;
			} else {
				forgedResponse.removeHeader(headerName);
				headersIterator = receivedResponse.getHeaders(headerName);
				while (headersIterator.hasNext()) {
					forgedResponse.addLast((Header)headersIterator.next().clone());
				}
			}
		}
		
		// Copy content
		final byte[] rawOriginal = receivedResponse.getRawContent();
		if (rawOriginal != null && rawOriginal.length != 0) {
			final byte[] copy = new byte[rawOriginal.length];
			System.arraycopy(rawOriginal, 0, copy, 0, copy.length);
			try {
				forgedResponse.setContent(copy, (ContentTypeHeader) forgedResponse
						.getHeader(ContentTypeHeader.NAME));
			} catch (ParseException e) {
				tracer.severe("Failed to set content on forged response. To copy value [" + new String(copy) + "] Type ["
						+ receivedResponse.getHeader(ContentTypeHeader.NAME) + "]\n", e);
			}
		}
		
		// set contact if the received response had it
		if (receivedResponse.getHeader(ContactHeader.NAME) != null) {
			final String transport = ((ViaHeader) forgedResponse.getHeader(ViaHeader.NAME)).getTransport();
			forgedResponse.setHeader(((ListeningPointImpl)provider.getListeningPoint(transport)).createContactHeader());
		}
		
		return forgedResponse;
		
	}
633825
public Response createResponse(final String serviceId, final WebApplicationService service) {
        return this.samlObjectBuilder.newResponse(
            this.samlObjectBuilder.generateSecureRandomId(),
            ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(this.skewAllowance), serviceId, service);
    }
478191
private void responseEntity(String html, HttpServletResponse servletResponse)
            throws IOException {
        PrintWriter printWriter = servletResponse.getWriter();
        try {
            printWriter.write(html);
            printWriter.flush();
        } finally {
            closeQuietly(printWriter);
        }
    }
1101063
protected void buildHttpResponse(HttpServletResponse httpServletResponse,
            NaviRpcResponse response, String contentType, String encoding) throws IOException {
        httpServletResponse.setContentType(contentType);
        httpServletResponse.setCharacterEncoding(encoding);
        if (response == null || response.getResponse() == null) {
            httpServletResponse.setContentLength(0);
        } else {
            httpServletResponse.setContentLength(response.getResponse().length);
            httpServletResponse.getOutputStream().write(response.getResponse());
        }
        httpServletResponse.flushBuffer();
    }
775569
public TCResponseRequest createResponse(Dialog d) {
        if (d == null) {
            throw new NullPointerException("Dialog is null");
        }
        TCResponseRequestImpl tcer = new TCResponseRequestImpl();
        tcer.setDialog(d);
        tcer.setOriginatingAddress(d.getLocalAddress());
        return tcer;
    }
253191
public synchronized void create( HttpServletRequest request, HttpServletResponse response, ServletContext servletContext )
        throws Exception
    {
        reinitialize( request, response, servletContext );
        JavaControlUtils.initJavaControls( request, response, servletContext, this );
        onCreate();
    }
434609
private static Response createResponse(Object object) {
    if (object == null) {
      return Response.ok().build();
    }

    if (object instanceof Response) {
      return (Response) object;
    }

    if (object instanceof Response.Status) {
      Response.Status s = (Response.Status) object;
      switch (s) {
        case OK:
          return Response.ok().build();
        case ACCEPTED:
          return Response.accepted().build();
        case NO_CONTENT:
          return Response.noContent().build();
        default:
          return createErrorResponse(
              new S3Exception("Response status is invalid", S3ErrorCode.INTERNAL_ERROR));
      }
    }

    // Need to explicitly encode the string as XML because Jackson will not do it automatically.
    XmlMapper mapper = new XmlMapper();
    try {
      return Response.ok(mapper.writeValueAsString(object)).build();
    } catch (JsonProcessingException e) {
      return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
          .entity("Failed to encode XML: " + e.getMessage()).build();
    }
  }
909592
@Override
    protected Smb2LockResponse createResponse ( CIFSContext tc, ServerMessageBlock2Request<Smb2LockResponse> req ) {
        return new Smb2LockResponse(tc.getConfig());
    }
472199
@Override
    protected Smb2QueryDirectoryResponse createResponse ( CIFSContext tc, ServerMessageBlock2Request<Smb2QueryDirectoryResponse> req ) {
        return new Smb2QueryDirectoryResponse(tc.getConfig(), this.fileInformationClass);
    }
84282
public SipServletRequest createRequest(SipApplicationSession sipAppSession,
			String method, URI from, URI to, String handler) {
		if (logger.isDebugEnabled()) {
			logger
					.debug("Creating new SipServletRequest for SipApplicationSession["
							+ sipAppSession
							+ "] METHOD["
							+ method
							+ "] FROM_URI[" + from + "] TO_URI[" + to + "]");
		}

		validateCreation(method, sipAppSession);

		//javadoc specifies that a copy of the uri should be done hence the clone
		Address toA = this.createAddress(to.clone());
		Address fromA = this.createAddress(from.clone());

		try {
			return createSipServletRequest(sipAppSession, method, fromA, toA, handler, null, null);
		} catch (ServletParseException e) {
			logger.error("Error creating sipServletRequest", e);
			return null;
		}

	}
1337484
@Override
    	protected void doSuccessResponse(SipServletResponse resp)
			throws ServletException, IOException {
		if (resp.getStatus() == SipServletResponse.SC_OK) {
			String audioFilePath = (String)getServletContext().getAttribute("audioFilePath");
			logger.info("audio file path is " + audioFilePath);
			try {
				MsPeer peer = MsPeerFactory.getPeer("org.mobicents.mscontrol.impl.MsPeerImpl");
				MsProvider provider = peer.getProvider();
				MsSession session = provider.createSession();
				MsConnection connection = session.createNetworkConnection(PR_JNDI_NAME);
				MediaConnectionListener listener = new MediaConnectionListener();
				listener.setResponse(resp);
				listener.setAudioFilePath(audioFilePath);
				connection.addConnectionListener(listener);
				Object sdpObj = resp.getContent();
				byte[] sdpBytes = (byte[]) sdpObj;
				String sdp = new String(sdpBytes); 
				connection.modify("$", sdp);
			} catch (ClassNotFoundException e) {
				logger.error("class not found ", e);
			}			
		}
	}