Java Code Examples for org.kohsuke.stapler.Stapler#getCurrentResponse()

The following examples show how to use org.kohsuke.stapler.Stapler#getCurrentResponse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiHead.java    From blueocean-plugin with MIT License 6 votes vote down vote up
/**
 * Exposes all {@link ApiRoutable}s to URL space.
 *
 * @param route current URL route handled by ApiHead
 * @return {@link ApiRoutable} object
 */
public ApiRoutable getDynamic(String route) {
    setApis();
    StaplerRequest request = Stapler.getCurrentRequest();
    String m = request.getMethod();
    if(m.equalsIgnoreCase("POST") || m.equalsIgnoreCase("PUT") || m.equalsIgnoreCase("PATCH")) {
        String header = request.getHeader("Content-Type");
        if(header == null || !header.contains("application/json")) {
            throw new ServiceException(415, "Content-Type: application/json required");
        }
    }

    ApiRoutable apiRoutable = apis.get(route);

    //JENKINS-46025 - Avoid caching REST API responses for IE
    StaplerResponse response = Stapler.getCurrentResponse();
    if (response != null && !response.containsHeader("Cache-Control")) {
        response.setHeader("Cache-Control", "no-cache, no-store, no-transform");
    }

    return apiRoutable;
}
 
Example 2
Source File: APIHeadTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Iterator<String> iterator() {
    StaplerResponse response = Stapler.getCurrentResponse();
    response.setHeader("Cache-Control", "max-age=10");
    return new ArrayList<String>().iterator();
}
 
Example 3
Source File: OrganizationFolderPipelineImpl.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
public void getUrl() {
    StaplerRequest req = Stapler.getCurrentRequest();
    String s = req.getParameter("s");
    if (s == null) {
        s = Integer.toString(DEFAULT_ICON_SIZE);
    }
    StaplerResponse resp = Stapler.getCurrentResponse();
    try {
        resp.setHeader("Cache-Control", "max-age=" + TimeUnit.DAYS.toDays(7));
        resp.sendRedirect(action.getAvatarImageOf(s));
    } catch (IOException e) {
        throw new UnexpectedErrorException("Could not provide icon", e);
    }
}