All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.baratine.web.RequestWeb Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
/*
 * Copyright (c) 1998-2015 Caucho Technology -- all rights reserved
 *
 * This file is part of Baratine(TM)
 *
 * Each copy or derived work must preserve the copyright notice and this
 * notice unmodified.
 *
 * Baratine is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Baratine is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
 * of NON-INFRINGEMENT.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Baratine; if not, write to the
 *
 *   Free Software Foundation, Inc.
 *   59 Temple Place, Suite 330
 *   Boston, MA 02111-1307  USA
 *
 * @author Scott Ferguson
 */

package io.baratine.web;

import java.net.InetSocketAddress;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Map;

import io.baratine.config.Config;
import io.baratine.inject.InjectManager;
import io.baratine.io.Buffer;
import io.baratine.service.Result;
import io.baratine.service.ServiceRef;

public interface RequestWeb extends OutWeb, Result
{
  String protocol();
  String version();
  
  String method();
  
  String uri();
  String path();
  String pathInfo();
  String path(String string);
  Map pathMap();
  
  String query();
  String query(String key);
  Map> queryMap();
  
  String header(String string);
  String cookie(String name);
  
  String host();
  int port();
  
  InetSocketAddress ipRemote();
  InetSocketAddress ipLocal();
  String ip();

  boolean secure();
  X509Certificate []certs();
  
   X attribute(Class key);
   void attribute(X value);
  
  ServiceRef session(String name);
   X session(Class type);
  
   X body(Class type);
   void body(BodyReader reader, Result result);
   void body(Class type, Result result);
  
  //
  // resources
  //
  
  // configuration
  
  Config config();
  
  // injection
  
  InjectManager inject();
  //  X instance(Class type, Annotation ...anns);

  //ServiceManager services();
  
  ServiceRef service(String address);
   X service(Class type);
   X service(Class type, String id);

  //
  // response
  //
  
  RequestWeb status(HttpStatus status);
  
  RequestWeb header(String key, String value);
  RequestWeb cookie(String key, String value);
  RequestWeb length(long length);
  RequestWeb type(String contentType);
  RequestWeb encoding(String contentType);

  void ok();
  @Override
  void ok(Object value);
  void ok(Object result, Throwable exn);
  
  @Override
  void fail(Throwable exn);
  
  void halt();
  void halt(HttpStatus status);
  
  void forward(String address);

  @Override
  default void handle(Object value, Throwable exn)
  {
    if (exn != null) {
      fail(exn);
    }
    else {
      ok(value);
    }
  }
}