org.kohsuke.stapler.HttpResponse Java Examples
The following examples show how to use
org.kohsuke.stapler.HttpResponse.
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: GithubOauthLoginAction.java From DotCi with MIT License | 6 votes |
public HttpResponse doFinishLogin(StaplerRequest request, StaplerResponse rsp) throws IOException { String code = request.getParameter("code"); if (code == null || code.trim().length() == 0) { Log.info("doFinishLogin: missing code."); return HttpResponses.redirectToContextRoot(); } String content = postForAccessToken(code); String accessToken = extractToken(content); updateOfflineAccessTokenForUser(accessToken); request.getSession().setAttribute("access_token", accessToken); String newProjectSetupUrl = getJenkinsRootUrl() + "/" + GithubReposController.URL; return HttpResponses.redirectTo(newProjectSetupUrl); }
Example #2
Source File: OicSession.java From oic-auth-plugin with MIT License | 6 votes |
/** * When the identity provider is done with its thing, the user comes back here. * @return an {@link HttpResponse} */ public HttpResponse doFinishLogin(StaplerRequest request) { StringBuffer buf = request.getRequestURL(); if (request.getQueryString() != null) { buf.append('?').append(request.getQueryString()); } AuthorizationCodeResponseUrl responseUrl = new AuthorizationCodeResponseUrl(buf.toString()); if (!state.equals(responseUrl.getState())) { return new Failure("State is invalid"); } String code = responseUrl.getCode(); if (responseUrl.getError() != null) { return new Failure( "Error from provider: " + responseUrl.getError() + ". Details: " + responseUrl.getErrorDescription() ); } else if (code == null) { return new Failure("Missing authorization code"); } else { return onSuccess(code); } }
Example #3
Source File: GitLabSecurityRealm.java From gitlab-oauth-plugin with MIT License | 6 votes |
public HttpResponse doCommenceLogin(StaplerRequest request, @QueryParameter String from, @Header("Referer") final String referer) throws IOException { // 2. Requesting authorization : // http://doc.gitlab.com/ce/api/oauth2.html String redirectOnFinish; if (from != null && Util.isSafeToRedirectTo(from)) { redirectOnFinish = from; } else if (referer != null && (referer.startsWith(Jenkins.getInstance().getRootUrl()) || Util.isSafeToRedirectTo(referer))) { redirectOnFinish = referer; } else { redirectOnFinish = Jenkins.getInstance().getRootUrl(); } List<NameValuePair> parameters = new ArrayList<>(); parameters.add(new BasicNameValuePair("redirect_uri", buildRedirectUrl(request, redirectOnFinish))); parameters.add(new BasicNameValuePair("response_type", "code")); parameters.add(new BasicNameValuePair("client_id", clientID)); return new HttpRedirect(gitlabWebUri + "/oauth/authorize?" + URLEncodedUtils.format(parameters, StandardCharsets.UTF_8)); }
Example #4
Source File: AddLabelToField.java From jira-ext-plugin with Apache License 2.0 | 6 votes |
public HttpResponse doQueryJiraFields(@QueryParameter String issueKey) { try { if (!Config.getGlobalConfig().isJiraConfigComplete()) { return FormValidation.error("JIRA settings are not set in global config"); } final Map<String, String> jiraFields = getJiraClientSvc().getJiraFields(issueKey); return new ForwardToView(this, "/org/jenkinsci/plugins/jiraext/view/AddLabelToField/jiraFields.jelly") .with("jiraFieldMap", jiraFields); } catch (Throwable t) { String message = "Error finding FieldIds for issueKey: " + issueKey; logger.log(Level.WARNING, message, t); return FormValidation.error(t, message); } }
Example #5
Source File: BitbucketServerEndpoint.java From blueocean-plugin with MIT License | 6 votes |
/** * Validates this server endpoint. Checks availability and version requirement. * @return If valid HttpStatus 200, if unsupported version then 428 and if unreachable then 400 error code is returned. */ @GET @WebMethod(name="validate") public HttpResponse validate(){ String version = BitbucketServerApi.getVersion(apiUrl); if(!BitbucketServerApi.isSupportedVersion(version)){ throw new ServiceException.PreconditionRequired( Messages.bbserver_version_validation_error( version, BitbucketServerApi.MINIMUM_SUPPORTED_VERSION)); } return new HttpResponse(){ @Override public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.setStatus(200); } }; }
Example #6
Source File: UpdateField.java From jira-ext-plugin with Apache License 2.0 | 6 votes |
public HttpResponse doQueryJiraFields(@QueryParameter String issueKey) { try { if (!Config.getGlobalConfig().isJiraConfigComplete()) { return FormValidation.error("JIRA settings are not set in global config"); } final Map<String, String> jiraFields = getJiraClientSvc().getJiraFields(issueKey); return new ForwardToView(this, "/org/jenkinsci/plugins/jiraext/view/UpdateField/jiraFields.jelly") .with("jiraFieldMap", jiraFields); } catch (Throwable t) { String message = "Error finding FieldIds for issueKey: " + issueKey; logger.log(Level.WARNING, message, t); return FormValidation.error(t, message); } }
Example #7
Source File: DockerTraceabilityRootAction.java From docker-traceability-plugin with MIT License | 6 votes |
/** * Retrieves the latest container status via API. * The output will be retrieved in JSON. Supports filers. Missing * "since" and "until" * @param id ID of the container, for which the info should be retrieved. * Short container IDs are not supported. * @throws IOException Processing error * @throws ServletException Servlet error * @return Raw JSON output compatible with docker inspect */ public HttpResponse doRawContainerInfo(@QueryParameter(required = true) String id) throws IOException, ServletException { checkPermission(DockerTraceabilityPlugin.READ_DETAILS); //TODO: check containerID format final DockerTraceabilityReport report = DockerTraceabilityHelper.getLastReport(id); if (report == null) { return HttpResponses.error(404, "No info available for the containerId=" + id); } final InspectContainerResponse inspectInfo = report.getContainer(); if (inspectInfo == null) { assert false : "Input logic should reject such cases"; return HttpResponses.error(500, "Cannot retrieve the container's status"); } // Return raw JSON in the response InspectContainerResponse[] out = {inspectInfo}; return toJSONResponse(out); }
Example #8
Source File: DockerTraceabilityRootAction.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Retrieves the latest raw status via API. * The output will be retrieved in JSON. * @param id ID of the image, for which the info should be retrieved. * Short container IDs are not supported. * @throws IOException Processing error * @throws ServletException Servlet error * @return {@link HttpResponse} */ public HttpResponse doRawImageInfo(@QueryParameter(required = true) String id) throws IOException, ServletException { checkPermission(DockerTraceabilityPlugin.READ_DETAILS); final InspectImageResponse report = DockerTraceabilityHelper.getLastInspectImageResponse(id); if (report == null) { return HttpResponses.error(404, "No info available for the imageId=" + id); } // Return raw JSON in the response InspectImageResponse[] out = {report}; return toJSONResponse(out); }
Example #9
Source File: GitLabWebHookAction.java From gitlab-branch-source-plugin with MIT License | 5 votes |
public HttpResponse doPost(StaplerRequest request) throws IOException, GitLabApiException { if (!request.getMethod().equals("POST")) { return HttpResponses .error(HttpServletResponse.SC_BAD_REQUEST, "Only POST requests are supported, this was a " + request.getMethod() + " request"); } if (!"application/json".equals(request.getContentType())) { return HttpResponses .error(HttpServletResponse.SC_BAD_REQUEST, "Only application/json content is supported, this was " + request .getContentType()); } String type = request.getHeader("X-Gitlab-Event"); if (StringUtils.isBlank(type)) { return HttpResponses.error(HttpServletResponse.SC_BAD_REQUEST, "Expecting a GitLab event, missing expected X-Gitlab-Event header"); } String secretToken = request.getHeader("X-Gitlab-Token"); if(!isValidToken(secretToken)) { return HttpResponses.error(HttpServletResponse.SC_UNAUTHORIZED, "Expecting a valid secret token"); } String origin = SCMEvent.originOf(request); WebHookManager webHookManager = new WebHookManager(); webHookManager.addListener(new GitLabWebHookListener(origin)); webHookManager.handleEvent(request); return HttpResponses.ok(); // TODO find a better response }
Example #10
Source File: OicSecurityRealm.java From oic-auth-plugin with MIT License | 5 votes |
/** * This is where the user comes back to at the end of the OpenID redirect ping-pong. * @param request The user's request * @return an HttpResponse */ public HttpResponse doFinishLogin(StaplerRequest request) { OicSession currentSession = OicSession.getCurrent(); if(currentSession==null) { LOGGER.fine("No session to resume (perhaps jenkins was restarted?)"); return HttpResponses.errorWithoutStack(401, "Unauthorized"); } return currentSession.doFinishLogin(request); }
Example #11
Source File: TestRealm.java From oic-auth-plugin with MIT License | 5 votes |
@Override public HttpResponse doFinishLogin(StaplerRequest request) { try { Field field = OicSession.class.getDeclaredField("state"); field.setAccessible(true); field.set(OicSession.getCurrent(), "state"); } catch (Exception e) { throw new RuntimeException("can't fudge state",e); } return super.doFinishLogin(request); }
Example #12
Source File: DockerTraceabilityRootAction.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Submits a new event through Jenkins API. * @param inspectData JSON output of docker inspect container (array of container infos) * @param hostName Optional name of the host, which submitted the event * "unknown" by default * @param hostId Optional host ID. * "unknown" by default * @param status Optional status of the container. * By default, an artificial {@link DockerEventType#NONE} will be used. * @param time Optional time when the event happened. * The time is specified in seconds since January 1, 1970, 00:00:00 GMT * Default value - current time * @param environment Optional field, which describes the environment * @param imageName Optional field, which provides the name of the image * @return {@link HttpResponse} * @throws IOException Request processing error * @throws ServletException Servlet error */ //TODO: parameters check @RequirePOST public HttpResponse doSubmitContainerStatus( @QueryParameter(required = true) String inspectData, @QueryParameter(required = false) String hostId, @QueryParameter(required = false) String hostName, @QueryParameter(required = false) String status, @QueryParameter(required = false) long time, @QueryParameter(required = false) @CheckForNull String environment, @QueryParameter(required = false) @CheckForNull String imageName ) throws IOException, ServletException { checkPermission(DockerTraceabilityPlugin.SUBMIT); final ObjectMapper mapper = new ObjectMapper(); final InspectContainerResponse[] inspectContainerResponses = mapper.readValue(inspectData, InspectContainerResponse[].class); final long eventTime = time != 0 ? time : System.currentTimeMillis()/1000; final String effectiveHostName = StringUtils.isNotBlank(hostName) ? hostName : "unknown"; final String effectiveHostId = StringUtils.isNotBlank(hostId) ? hostId : "unknown"; final String effectiveStatus = StringUtils.isNotBlank(status) ? status.toUpperCase(Locale.ENGLISH) : DockerEventType.NONE.toString(); final String effectiveImageName = hudson.Util.fixEmpty(imageName); final String effectiveEnvironment = hudson.Util.fixEmpty(environment); for (InspectContainerResponse inspectContainerResponse : inspectContainerResponses) { final Event event = new DockerEvent(effectiveStatus, inspectContainerResponse.getImageId(), effectiveHostId, eventTime).toDockerEvent(); final Info hostInfo = new DockerInfo(effectiveHostId, effectiveHostName).toInfo(); DockerTraceabilityReport res = new DockerTraceabilityReport(event, hostInfo, inspectContainerResponse, inspectContainerResponse.getImageId(), effectiveImageName, /* InspectImageResponse */ null, new LinkedList<String>(), effectiveEnvironment); DockerTraceabilityReportListener.fire(res); } return HttpResponses.ok(); }
Example #13
Source File: DockerTraceabilityRootAction.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Submits a new {@link DockerTraceabilityReport} via API. * @param json String representation of {@link DockerTraceabilityReport} * @return {@link HttpResponse} * @throws ServletException Servlet error * @throws IOException Processing error */ @RequirePOST public HttpResponse doSubmitReport(@QueryParameter(required = true) String json) throws IOException, ServletException { checkPermission(DockerTraceabilityPlugin.SUBMIT); ObjectMapper mapper = new ObjectMapper(); final DockerTraceabilityReport report = mapper.readValue(json, DockerTraceabilityReport.class); DockerTraceabilityReportListener.fire(report); return HttpResponses.ok(); }
Example #14
Source File: DockerTraceabilityRootAction.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Removes the container reference from the registry. * @param id Container ID. Method supports full 64-char IDs only. * @throws IOException Cannot save the updated {@link DockerTraceabilityRootAction} * @throws ServletException Servlet exception * @return response */ @RequirePOST public HttpResponse doDeleteContainer(@QueryParameter(required = true) String id) throws IOException, ServletException { checkPermission(DockerTraceabilityPlugin.DELETE); removeContainerID(id); return HttpResponses.ok(); }
Example #15
Source File: OicSecurityRealm.java From oic-auth-plugin with MIT License | 5 votes |
public HttpResponse doEscapeHatch(@QueryParameter("j_username") String username, @QueryParameter("j_password") String password) { randomWait(); // to slowdown brute forcing if(!isEscapeHatchEnabled()) { return HttpResponses.redirectViaContextPath("loginError"); } if(this.escapeHatchUsername == null || this.escapeHatchSecret == null) { return HttpResponses.redirectViaContextPath("loginError"); } if(escapeHatchUsername.equalsIgnoreCase(username) && escapeHatchSecret.getPlainText().equals(password)) { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY); if(isNotBlank(escapeHatchGroup)) { authorities.add(new GrantedAuthorityImpl(escapeHatchGroup)); } String userName = "escape-hatch-admin"; GrantedAuthority[] grantedAuthorities = authorities.toArray(new GrantedAuthority[authorities.size()]); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( userName, "", grantedAuthorities ); SecurityContextHolder.getContext().setAuthentication(token); OicUserDetails userDetails = new OicUserDetails(userName, grantedAuthorities); SecurityListener.fireAuthenticated(userDetails); return HttpRedirect.CONTEXT_ROOT; } return HttpResponses.redirectViaContextPath("loginError"); }
Example #16
Source File: DockerTraceabilityRootAction.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Serves the JSON response. * @param item Data to be serialized to JSON * @return HTTP response with application/json MIME type */ private static HttpResponse toJSONResponse(final Object item) { return new HttpResponse() { @Override public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { ObjectMapper mapper = new ObjectMapper(); rsp.setContentType("application/json;charset=UTF-8"); mapper.writeValue(rsp.getWriter(), item); } }; }
Example #17
Source File: DockerTraceabilityRootActionTest.java From docker-traceability-plugin with MIT License | 5 votes |
@Test @Bug(28656) public void createFingerPrintsOnDemand() throws Exception { // Read data from resources String inspectData = JSONSamples.inspectContainerData.readString(); InspectContainerResponse inspectResponse = JSONSamples.inspectContainerData. readObject(InspectContainerResponse[].class)[0]; final String containerId = inspectResponse.getId(); final String imageId = inspectResponse.getImageId(); // Retrieve instances final DockerTraceabilityRootAction action = DockerTraceabilityRootAction.getInstance(); assertNotNull(action); // Enable automatic fingerprints creation DockerTraceabilityPluginConfiguration config = new DockerTraceabilityPluginConfiguration(true, false); DockerTraceabilityPluginTest.configure(config); DockerTraceabilityPlugin plugin = DockerTraceabilityPlugin.getInstance(); assertTrue(plugin.getConfiguration().isCreateImageFingerprints()); // Submit JSON HttpResponse res = action.doSubmitContainerStatus(inspectData, null, null, null, 0, null, null); // Ensure that both container and images have been created with proper facets Fingerprint imageFP = DockerFingerprints.of(imageId); Fingerprint containerFP = DockerFingerprints.of(containerId); assertNotNull(imageFP); assertNotNull(DockerFingerprints.getFacet(imageFP, DockerDeploymentRefFacet.class)); assertNotNull(containerFP); assertNotNull(DockerFingerprints.getFacet(containerFP, DockerDeploymentFacet.class)); // TODO: JENKINS-28655 (Fingerprints cleanup) // Check original references - Docker Traceability Manager should create runs // assertNotNull(imageFP.getOriginal().getJob()); // assertNotNull(containerFP.getOriginal().getJob()); }
Example #18
Source File: TemplateDrivenMultiBranchProject.java From multi-branch-project-plugin with MIT License | 5 votes |
@SuppressWarnings(UNUSED) @CLIMethod(name = "disable-job") @RequirePOST public HttpResponse doDisable() throws IOException, ServletException { // NOSONAR checkPermission(CONFIGURE); makeDisabled(true); return new HttpRedirect("."); }
Example #19
Source File: TemplateDrivenMultiBranchProject.java From multi-branch-project-plugin with MIT License | 5 votes |
@SuppressWarnings(UNUSED) @CLIMethod(name = "enable-job") @RequirePOST public HttpResponse doEnable() throws IOException, ServletException { // NOSONAR checkPermission(CONFIGURE); makeDisabled(false); return new HttpRedirect("."); }
Example #20
Source File: PublicCoverageAction.java From jenkins-status-badges-plugin with MIT License | 5 votes |
public HttpResponse doIcon( StaplerRequest req, StaplerResponse rsp, @QueryParameter String job, @QueryParameter String style ) throws IOException, FontFormatException { Job<?, ?> project = coverageStatus.getProject( job, req, rsp ); int coverage = coverageStatus.getCoverage( project ); return iconResolver.getCoverageImage( coverage, style ); }
Example #21
Source File: PublicGradeAction.java From jenkins-status-badges-plugin with MIT License | 5 votes |
public HttpResponse doIcon( StaplerRequest req, StaplerResponse rsp, @QueryParameter String job, @QueryParameter String style ) throws IOException, FontFormatException { Job<?, ?> project = gradeStatus.getProject( job, req, rsp ); double grade = gradeStatus.getGrade( project ); return iconResolver.getGradeImage( grade, style ); }
Example #22
Source File: PublicBuildAction.java From jenkins-status-badges-plugin with MIT License | 5 votes |
public HttpResponse doIcon( StaplerRequest req, StaplerResponse rsp, @QueryParameter String job, @QueryParameter String style ) throws IOException, FontFormatException { Job<?, ?> project = buildStatus.getProject( job, req, rsp ); return iconResolver.getBuildImage( project.getIconColor(), style ); }
Example #23
Source File: GithubOauthLoginActionTest.java From DotCi with MIT License | 5 votes |
@Test public void should_set_access_token_in_the_session() throws IOException { final StaplerRequest request = mock(StaplerRequest.class); final HttpSession httpSession = mock(HttpSession.class); when(request.getSession()).thenReturn(httpSession); when(request.getParameter("code")).thenReturn("code"); when(this.httpPoster.post(anyString(), anyMap())).thenReturn("access_token=meow_token"); final HttpResponse response = this.githubOauthLoginAction.doFinishLogin(request, null); verify(httpSession).setAttribute("access_token", "meow_token"); assertNotNull(response); }
Example #24
Source File: RepositoryCloneProgressEndpoint.java From blueocean-plugin with MIT License | 5 votes |
@GET @WebMethod(name="") public HttpResponse getProgress(StaplerRequest req) { String repositoryUrl = req.getOriginalRestOfPath(); CloneProgressMonitor progress = CloneProgressMonitor.get(repositoryUrl); if (progress == null) { return null; } return HttpResponses.okJSON(ImmutableMap.of("progress", progress.getPercentComplete())); }
Example #25
Source File: GitLabSystemHookAction.java From gitlab-branch-source-plugin with MIT License | 5 votes |
public HttpResponse doPost(StaplerRequest request) throws GitLabApiException { if (!request.getMethod().equals("POST")) { return HttpResponses .error(HttpServletResponse.SC_BAD_REQUEST, "Only POST requests are supported, this was a " + request.getMethod() + " request"); } if (!"application/json".equals(request.getContentType())) { return HttpResponses .error(HttpServletResponse.SC_BAD_REQUEST, "Only application/json content is supported, this was " + request .getContentType()); } String type = request.getHeader("X-Gitlab-Event"); if (StringUtils.isBlank(type)) { return HttpResponses.error(HttpServletResponse.SC_BAD_REQUEST, "Expecting a GitLab event, missing expected X-Gitlab-Event header"); } String secretToken = request.getHeader("X-Gitlab-Token"); if(!isValidToken(secretToken)) { return HttpResponses.error(HttpServletResponse.SC_UNAUTHORIZED, "Expecting a valid secret token"); } String origin = SCMEvent.originOf(request); SystemHookManager systemHookManager = new SystemHookManager(); systemHookManager.addListener(new GitLabSystemHookListener(origin)); systemHookManager.handleEvent(request); return HttpResponses.ok(); // TODO find a better response }
Example #26
Source File: AbstractBitbucketScm.java From blueocean-plugin with MIT License | 5 votes |
/** * Request payload: * { * "userName": "joe", * "password":"****", * "apiUrl":"mybitbucketserver.com" * } * @param request userName and password of bitbucket server * * @return credential id */ @Override public HttpResponse validateAndCreate(@JsonBody JSONObject request) { User authenticatedUser = User.current(); if(authenticatedUser == null){ throw new ServiceException.UnauthorizedException("No logged in user found"); } String userName = (String) request.get("userName"); String password = (String) request.get("password"); String apiUrl = (String) request.get("apiUrl"); validate(userName, password, apiUrl); final StandardUsernamePasswordCredentials credential = new UsernamePasswordCredentialsImpl(CredentialsScope.USER, createCredentialId(apiUrl), "Bitbucket server credentials", userName, password); //if credentials are wrong, this call will fail with 401 error validateCredential(apiUrl, credential); StandardUsernamePasswordCredentials bbCredentials = CredentialsUtils.findCredential(createCredentialId(apiUrl), StandardUsernamePasswordCredentials.class, new BlueOceanDomainRequirement()); try { if (bbCredentials == null) { CredentialsUtils.createCredentialsInUserStore( credential, authenticatedUser, getDomainId(), ImmutableList.<DomainSpecification>of(new BlueOceanDomainSpecification())); } else { CredentialsUtils.updateCredentialsInUserStore( bbCredentials, credential, authenticatedUser, getDomainId(), ImmutableList.<DomainSpecification>of(new BlueOceanDomainSpecification())); } return createResponse(credential.getId()); }catch (IOException e){ throw new ServiceException.UnexpectedErrorException(e.getMessage()); } }
Example #27
Source File: RepositoryCloneProgressEndpoint.java From blueocean-plugin with MIT License | 5 votes |
@DELETE @WebMethod(name="") public HttpResponse cancelClone(StaplerRequest req) { String repositoryUrl = req.getOriginalRestOfPath(); CloneProgressMonitor progress = CloneProgressMonitor.get(repositoryUrl); if (progress != null) { progress.cancel(); } return HttpResponses.ok(); }
Example #28
Source File: AbstractScm.java From blueocean-plugin with MIT License | 5 votes |
protected HttpResponse createResponse(final String credentialId) { return new HttpResponse() { @Override public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.setStatus(200); rsp.getWriter().print(JsonConverter.toJson(ImmutableMap.of("credentialId", credentialId))); } }; }
Example #29
Source File: OicSession.java From oic-auth-plugin with MIT License | 5 votes |
/** * Starts the login session. * @return an {@link HttpResponse} */ @SuppressFBWarnings("J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION") public HttpResponse doCommenceLogin() { // remember this in the session Stapler.getCurrentRequest().getSession().setAttribute(SESSION_NAME, this); AuthorizationCodeRequestUrl authorizationCodeRequestUrl = flow.newAuthorizationUrl().setState(state).setRedirectUri(redirectUrl); return new HttpRedirect(authorizationCodeRequestUrl.toString()); }
Example #30
Source File: BlueI18n.java From blueocean-plugin with MIT License | 4 votes |
/** * Get a localised resource bundle. * <p> * URL: {@code blueocean-i18n/$PLUGIN_NAME/$PLUGIN_VERSION/$BUNDLE_NAME/$LOCALE} (where {@code $LOCALE} is optional). * * @param request The request. * @return The JSON response. */ public HttpResponse doDynamic(StaplerRequest request) { String path = request.getOriginalRequestURI(); String contextPath = request.getContextPath(); BundleParams bundleParams; path = path.substring(contextPath.length()); bundleParams = getBundleParameters(path); if (bundleParams == null) { return HttpResponses.errorJSON("All mandatory bundle identification parameters not specified: '$PLUGIN_NAME/$PLUGIN_VERSION/$BUNDLE_NAME' (and optional $LOCALE)."); } try { Locale locale = bundleParams.getLocale(); if (locale == null) { locale = request.getLocale(); } BundleCacheEntry bundleCacheEntry = bundleCache.get(bundleParams); JSONObject bundle; if (bundleCacheEntry == null) { bundle = getBundle(bundleParams, locale); if (bundle == null) { bundle = BUNDLE_404; } bundleCacheEntry = new BundleCacheEntry(bundle, bundleParams); bundleCache.put(bundleParams, bundleCacheEntry); } if (bundleCacheEntry.bundleData == BUNDLE_404) { return JSONObjectResponse.errorJson("Unknown plugin or resource bundle: " + bundleParams.toString(), HttpServletResponse.SC_NOT_FOUND); } else { return JSONObjectResponse.okJson(bundleCacheEntry); } } catch (Exception e) { return HttpResponses.errorJSON(e.getMessage()); } }