PayloadRequestImpl.java [src/csip] Revision:   Date:
/*
 * $Id$
 *
 * This file is part of the Cloud Services Integration Platform (CSIP),
 * a Model-as-a-Service framework, API and application suite.
 *
 * 2012-2022, Olaf David and others, OMSLab, Colorado State University.
 *
 * OMSLab licenses this file to you under the MIT license.
 * See the LICENSE file in the project root for more information.
 */
package csip;

import csip.api.server.PayloadRequest;
import org.codehaus.jettison.json.JSONObject;

/**
 * Payload Request Access.
 *
 * @author od
 */
class PayloadRequestImpl implements PayloadRequest {

  String reqRemoteIp;
  String reqUrl;
  String reqHost;
  String reqContext;
  String reqScheme;
  String reqAuth;
  JSONObject reqObj;
  ModelDataService mds;


  PayloadRequestImpl(String reqRemoteIp, String reqUrl,
      String reqHost, String reqContext, String reqScheme, String reqAuth,
      JSONObject reqObj,
      ModelDataService mds) {
    this.reqRemoteIp = reqRemoteIp;
    this.reqUrl = reqUrl;
    this.reqHost = reqHost;
    this.reqContext = reqContext;
    this.reqScheme = reqScheme;
    this.reqAuth = reqAuth;
    this.reqObj = reqObj;
    this.mds = mds;
  }


  @Override
  public boolean isAsync() {
    return mds.isAsync();
  }


  @Override
  public String getRemoteAddr() {
    return reqRemoteIp;
  }


  @Override
  public String getCodebase() {
    String m = mds.service().getPath();
    String u = getURL();
    return u.substring(0, u.indexOf(m));
  }


  @Override
  public String getURL() {
    return reqUrl;
  }


  @Override
  public String getHost() {
    return reqHost;
  }


  @Override
  public String getContext() {
    return reqContext;
  }


  @Override
  public String getScheme() {
    return reqScheme;
  }


  @Override
  public JSONObject getRequest() {
    return reqObj;
  }


  @Override
  public String getAuthToken() {
    if (reqAuth == null
        || !Config.getTokenAuthentication().isTokenBasedAuthentication(reqAuth))
      return null;

    return Config.getTokenAuthentication().getToken(reqAuth);
  }

}