org.kohsuke.stapler.StaplerRequest.getHeader()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中org.kohsuke.stapler.StaplerRequest.getHeader()方法的一些代码示例,展示了StaplerRequest.getHeader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StaplerRequest.getHeader()方法的具体详情如下:
包路径:org.kohsuke.stapler.StaplerRequest
类名称:StaplerRequest
方法名:getHeader

StaplerRequest.getHeader介绍

暂无

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * Gets the originating "X-Forwarded-..." header from the request. If there are multiple headers the originating
 * header is the first header. If the originating header contains a comma separated list, the originating entry
 * is the first one.
 * @param req the request
 * @param header the header name
 * @param defaultValue the value to return if the header is absent.
 * @return the originating entry of the header or the default value if the header was not present.
 */
private static String getXForwardedHeader(StaplerRequest req, String header, String defaultValue) {
  String value = req.getHeader(header);
  if (value != null) {
    int index = value.indexOf(',');
    return index == -1 ? value.trim() : value.substring(0,index).trim();
  }
  return defaultValue;
}

代码示例来源:origin: jenkinsci/jenkins

private boolean doesNotSupportPostMessage() {
  StaplerRequest req = Stapler.getCurrentRequest();
  if (req==null)      return false;
  String ua = req.getHeader("User-Agent");
  if (ua==null)       return false;
  // according to http://caniuse.com/#feat=x-doc-messaging, IE <=7 doesn't support pstMessage
  // see http://www.useragentstring.com/pages/Internet%20Explorer/ for user agents
  // we want to err on the cautious side here.
  // Because of JENKINS-15105, we can't serve signed metadata from JSON, which means we need to be
  // using a modern browser as a vehicle to request these data. This check is here to prevent Jenkins
  // from using older browsers that are known not to support postMessage as the vehicle.
  return ua.contains("Windows") && (ua.contains(" MSIE 5.") || ua.contains(" MSIE 6.") || ua.contains(" MSIE 7."));
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Changes the icon size by changing the cookie
 */
public void doIconSize( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
  String qs = req.getQueryString();
  if(qs==null)
    throw new ServletException();
  Cookie cookie = new Cookie("iconSize", Functions.validateIconSize(qs));
  cookie.setMaxAge(/* ~4 mo. */9999999); // #762
  rsp.addCookie(cookie);
  String ref = req.getHeader("Referer");
  if(ref==null)   ref=".";
  rsp.sendRedirect2(ref);
}

代码示例来源:origin: jenkinsci/jenkins

UUID uuid = UUID.fromString(req.getHeader("Session"));
rsp.setHeader("Hudson-Duplex", "true"); // set the header so that the client would know
if (req.getHeader("Side").equals("download")) {
  FullDuplexHttpService service = createService(req, uuid);
  LOGGER.log(Level.FINE, "Processing download side for {0}: {1}", new Object[] {uuid, service});

代码示例来源:origin: jenkinsci/jenkins

private ConsoleAnnotator<T> createAnnotator(StaplerRequest req) throws IOException {
  try {
    String base64 = req!=null ? req.getHeader("X-ConsoleAnnotator") : null;
    if (base64!=null) {
      Cipher sym = PASSING_ANNOTATOR.decrypt();
      ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(
          new CipherInputStream(new ByteArrayInputStream(Base64.decode(base64.toCharArray())),sym)),
          Jenkins.getInstance().pluginManager.uberClassLoader);
      try {
        long timestamp = ois.readLong();
        if (TimeUnit.HOURS.toMillis(1) > abs(System.currentTimeMillis()-timestamp))
          // don't deserialize something too old to prevent a replay attack
          return (ConsoleAnnotator)ois.readObject();
      } finally {
        ois.close();
      }
    }
  } catch (ClassNotFoundException e) {
    throw new IOException(e);
  }
  // start from scratch
  return ConsoleAnnotator.initial(context);
}

代码示例来源:origin: jenkinsci/gitlab-plugin

private WebHookAction onPost(Item project, StaplerRequest request) {
  String eventHeader = request.getHeader("X-Gitlab-Event");
  if (eventHeader == null) {
    LOGGER.log(Level.FINE, "Missing X-Gitlab-Event header");
    return new NoopAction();
  }
  String tokenHeader = request.getHeader("X-Gitlab-Token");
  switch (eventHeader) {
    case "Merge Request Hook":
      return new MergeRequestBuildAction(project, getRequestBody(request), tokenHeader);
    case "Push Hook":
    case "Tag Push Hook":
      return new PushBuildAction(project, getRequestBody(request), tokenHeader);
    case "Note Hook":
      return new NoteBuildAction(project, getRequestBody(request), tokenHeader);
    case "Pipeline Hook":
      return new PipelineBuildAction(project, getRequestBody(request), tokenHeader);
    case "System Hook":
      return onSystemHook(project, getRequestBody(request), tokenHeader);
    default:
      LOGGER.log(Level.FINE, "Unsupported X-Gitlab-Event header: {0}", eventHeader);
      return new NoopAction();
  }
}

代码示例来源:origin: jenkinsci/jenkins

public static void initPageVariables(JellyContext context) {
  StaplerRequest currentRequest = Stapler.getCurrentRequest();
  String rootURL = currentRequest.getContextPath();
  Functions h = new Functions();
  context.setVariable("h", h);
  // The path starts with a "/" character but does not end with a "/" character.
  context.setVariable("rootURL", rootURL);
  /*
    load static resources from the path dedicated to a specific version.
    This "/static/VERSION/abc/def.ghi" path is interpreted by stapler to be
    the same thing as "/abc/def.ghi", but this avoids the stale cache
    problem when the user upgrades to new Jenkins. Stapler also sets a long
    future expiration dates for such static resources.
    see https://wiki.jenkins-ci.org/display/JENKINS/Hyperlinks+in+HTML
   */
  context.setVariable("resURL",rootURL+getResourcePath());
  context.setVariable("imagesURL",rootURL+getResourcePath()+"/images");
  context.setVariable("userAgent", currentRequest.getHeader("User-Agent"));
  IconSet.initPageVariables(context);
}

代码示例来源:origin: org.kohsuke.stapler/stapler

/**
 * Checks if tracing is enabled for the given request. Tracing can be
 * enabled globally with the "stapler.trace=true" system property. Tracing
 * can be enabled per-request by setting "stapler.trace.per-request=true"
 * and sending an "X-Stapler-Trace" header set to "true" with the request.
 */
public static boolean isTraceEnabled(StaplerRequest req) {
  if (TRACE)
    return true;
  if (TRACE_PER_REQUEST && "true".equals(req.getHeader("X-Stapler-Trace")))
    return true;
  return false;
}

代码示例来源:origin: hudson.plugins/project-inheritance

private boolean requestWantsJson(StaplerRequest req) {
  String a = req.getHeader("Accept");
  if (a==null)    return false;
  return !a.contains("text/html") && a.contains("application/json");
}

代码示例来源:origin: i-m-c/jenkins-inheritance-plugin

private boolean requestWantsJson(StaplerRequest req) {
  String a = req.getHeader("Accept");
  if (a==null)    return false;
  return !a.contains("text/html") && a.contains("application/json");
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

private boolean doesNotSupportPostMessage() {
  StaplerRequest req = Stapler.getCurrentRequest();
  if (req==null)      return false;
  String ua = req.getHeader("User-Agent");
  if (ua==null)       return false;
  // according to http://caniuse.com/#feat=x-doc-messaging, IE <=7 doesn't support pstMessage
  // see http://www.useragentstring.com/pages/Internet%20Explorer/ for user agents
  // we want to err on the cautious side here.
  // Because of JENKINS-15105, we can't serve signed metadata from JSON, which means we need to be
  // using a modern browser as a vehicle to request these data. This check is here to prevent Jenkins
  // from using older browsers that are known not to support postMessage as the vehicle.
  return ua.contains("Windows") && (ua.contains(" MSIE 5.") || ua.contains(" MSIE 6.") || ua.contains(" MSIE 7."));
}

代码示例来源:origin: org.hudsonci.stapler/stapler-core

public void forwardToPreviousPage(StaplerRequest request) throws ServletException, IOException {
  String referer = request.getHeader("Referer");
  if(referer==null)   referer=".";
  sendRedirect(referer);
}

代码示例来源:origin: org.kohsuke.stapler/stapler

public void forwardToPreviousPage(StaplerRequest request) throws ServletException, IOException {
  String referer = request.getHeader("Referer");
  if(referer==null)   referer=".";
  sendRedirect(referer);
}

代码示例来源:origin: stapler/stapler

public void forwardToPreviousPage(StaplerRequest request) throws ServletException, IOException {
  String referer = request.getHeader("Referer");
  if(referer==null)   referer=".";
  sendRedirect(referer);
}

代码示例来源:origin: yuzd/coding.net

protected void check(StaplerRequest request) throws InvocationTargetException {
  if (!request.getMethod().equals("POST")) {
    throw new InvocationTargetException(error(SC_METHOD_NOT_ALLOWED, "Method POST required"));
  }
  if (request.getHeader("User-Agent") == null || request.getHeader("User-Agent").toLowerCase().indexOf("coding") == -1 ){
    throw new InvocationTargetException(error(SC_METHOD_NOT_ALLOWED, "From Coding.Net required"));
  }
}

代码示例来源:origin: org.hudsonci.stapler/stapler-core

Object parse(StaplerRequest request, Header a, Class type, String parameterName) throws ServletException {
    String name = a.value();
    if(name.length()==0)    name=parameterName;
    if(name==null)
      throw new IllegalArgumentException("Parameter name unavailable neither in the code nor in annotation");
    String value = request.getHeader(name);
    if(a.required() && value==null)
      throw new ServletException("Required HTTP header "+name+" is missing");
    return convert(type,value);
  }
});

代码示例来源:origin: org.kohsuke.stapler/stapler

public Object parse(StaplerRequest request, Header a, Class type, String parameterName) throws ServletException {
    String name = a.value();
    if(name.length()==0)    name=parameterName;
    if(name==null)
      throw new IllegalArgumentException("Parameter name unavailable neither in the code nor in annotation");
    String value = request.getHeader(name);
    if(a.required() && value==null)
      throw new ServletException("Required HTTP header "+name+" is missing");
    return convert(type,value);
  }
}

代码示例来源:origin: stapler/stapler

public Object parse(StaplerRequest request, Header a, Class type, String parameterName) throws ServletException {
    String name = a.value();
    if(name.length()==0)    name=parameterName;
    if(name==null)
      throw new IllegalArgumentException("Parameter name unavailable neither in the code nor in annotation");
    String value = request.getHeader(name);
    if(a.required() && value==null)
      throw new ServletException("Required HTTP header "+name+" is missing");
    return convert(type,value);
  }
}

代码示例来源:origin: groupon/DotCi

public void doIndex(final StaplerRequest req, final StaplerResponse response) throws IOException {
  String payload = req.getParameter("payload");
  if (StringUtils.isEmpty(payload) && "POST".equalsIgnoreCase(req.getMethod())) {
    payload = getRequestPayload(req);
  }
  if (StringUtils.isEmpty(payload)) {
    throw new IllegalArgumentException("Not intended to be browsed interactively (must specify payload parameter)");
  }
  processGitHubPayload(req.getHeader("X-GitHub-Event"), payload);
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Changes the icon size by changing the cookie
 */
public void doIconSize( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
  String qs = req.getQueryString();
  if(qs==null)
    throw new ServletException();
  Cookie cookie = new Cookie("iconSize", Functions.validateIconSize(qs));
  cookie.setMaxAge(/* ~4 mo. */9999999); // #762
  rsp.addCookie(cookie);
  String ref = req.getHeader("Referer");
  if(ref==null)   ref=".";
  rsp.sendRedirect2(ref);
}

相关文章

微信公众号

最新文章

更多

StaplerRequest类方法