/// <summary> /// Creates a ServletResponse adaptor wrapping the given response object. /// </summary> /// <param name="response"></param> /// <exception cref="ArgumentException">if the response is null</exception> public ServletResponseWrapper(IServletResponse response) { if (response == null) { throw new ArgumentException("Response cannot be null"); } this.response = response; }
// --------------------------------------------------------- Public methods /// <exception cref="System.IO.IOException"/> /// <exception cref="Javax.Servlet.ServletException"/> public void DoFilter(IServletRequest servletRequest, IServletResponse servletResponse, IFilterChain filterChain) { if (!(servletRequest is IHttpServletRequest) || !(servletResponse is IHttpServletResponse)) { string message = "CORS doesn't support non-HTTP request or response."; throw new ServletException(message); } // Safe to downcast at this point. IHttpServletRequest request = (IHttpServletRequest)servletRequest; IHttpServletResponse response = (IHttpServletResponse)servletResponse; // Determines the CORS request type. CORSFilter.CORSRequestType requestType = CheckRequestType(request); // Adds CORS specific attributes to request. if (decorateRequest) { Edu.Stanford.Nlp.Naturalli.Demo.CORSFilter.DecorateCORSProperties(request, requestType); } switch (requestType) { case CORSFilter.CORSRequestType.Simple: { // Handles a Simple CORS request. this.HandleSimpleCORS(request, response, filterChain); break; } case CORSFilter.CORSRequestType.Actual: { // Handles an Actual CORS request. this.HandleSimpleCORS(request, response, filterChain); break; } case CORSFilter.CORSRequestType.PreFlight: { // Handles a Pre-flight CORS request. this.HandlePreflightCORS(request, response, filterChain); break; } case CORSFilter.CORSRequestType.NotCors: { // Handles a Normal request that is not a cross-origin request. this.HandleNonCORS(request, response, filterChain); break; } default: { // Handles a CORS request that violates specification. this.HandleInvalidCORS(request, response, filterChain); break; } } }
/// <summary> /// Dispatches client requests to the protected /// Service method. There's no need to /// override this method. /// </summary> /// <param name="req"> /// the IHttpServletRequest object that /// contains the request the client made of /// the servlet /// </param> /// <param name="res"> /// the IHttpServletResponse object that /// contains the response the servlet returns /// to the client /// </param> /// <exception cref="IOException"> /// if an input or output error occurs /// while the servlet is handling the /// HTTP request /// </exception> /// <exception cref="ServletException"> /// if the HTTP request cannot be handled /// </exception> public override void Service(IServletRequest req, IServletResponse res) { IHttpServletRequest request; IHttpServletResponse response; try { request = (IHttpServletRequest)req; response = (IHttpServletResponse)res; } catch (InvalidCastException) { throw new ServletException("non-HTTP request or response"); } Service(request, response); }
/// <summary> /// Called by the servlet container to allow the servlet to respond to /// a request. See {@link Servlet#Service}. /// /// This method is declared abstract so subclasses, such as /// <code>HttpServlet</code>, must override it. /// </summary> /// <param name="req">the IServletRequest object that contains the client's request</param> /// <param name="res">the IServletResponse object that will contain the servlet's response</param> /// <exception cref="ServletException"> /// if an exception occurs that /// interferes with the servlet's /// normal operation occurred /// </exception> /// <exception cref="System.IO.IOException"> /// if an input or output /// exception occurs /// </exception> public abstract void Service(IServletRequest req, IServletResponse res);
/// <summary> /// The default behavior of this method is to return StartAsync(IServletRequest request, IServletResponse response) /// on the wrapped request object. /// </summary> /// <param name="request"></param> /// <param name="response"></param> /// <returns></returns> public IAsyncContext StartAsync(IServletRequest request, IServletResponse response) { return request.StartAsync(request, response); }
/// <summary> /// The default behavior of this method is to return AddAsyncListener(IAsyncListener listener, IServletRequest request, IServletResponse response) /// on the wrapped request object. /// </summary> /// <param name="listener"></param> /// <param name="request"></param> /// <param name="response"></param> public void AddAsyncListener(IAsyncListener listener, IServletRequest request, IServletResponse response) { request.AddAsyncListener(listener, request, response); }
public AsyncEvent(IServletRequest request, IServletResponse response) { this.request = request; this.response = response; }
/// <summary> /// The default behavior of this method is to return StartAsync(IServletRequest request, IServletResponse response) /// on the wrapped request object. /// </summary> /// <param name="request"></param> /// <param name="response"></param> /// <returns></returns> public IAsyncContext StartAsync(IServletRequest request, IServletResponse response) { return(request.StartAsync(request, response)); }