From 38bc686baa40e1888f9c253ce638593716650662 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 14 Jan 2011 15:37:55 -0800 Subject: [PATCH] this code should work even when called from outside the context of request handling. --- core/src/main/java/hudson/console/AnnotatedLargeText.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/console/AnnotatedLargeText.java b/core/src/main/java/hudson/console/AnnotatedLargeText.java index 550f33c8b9..be84a39802 100644 --- a/core/src/main/java/hudson/console/AnnotatedLargeText.java +++ b/core/src/main/java/hudson/console/AnnotatedLargeText.java @@ -114,7 +114,7 @@ public class AnnotatedLargeText extends LargeText { private ConsoleAnnotator createAnnotator(StaplerRequest req) throws IOException { try { - String base64 = req.getHeader("X-ConsoleAnnotator"); + String base64 = req!=null ? req.getHeader("X-ConsoleAnnotator") : null; if (base64!=null) { Cipher sym = Secret.getCipher("AES"); sym.init(Cipher.DECRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128()); @@ -162,7 +162,9 @@ public class AnnotatedLargeText extends LargeText { oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack oos.writeObject(caw.getConsoleAnnotator()); oos.close(); - Stapler.getCurrentResponse().setHeader("X-ConsoleAnnotator",new String(Base64.encode(baos.toByteArray()))); + StaplerResponse rsp = Stapler.getCurrentResponse(); + if (rsp!=null) + rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray()))); } catch (GeneralSecurityException e) { throw new IOException2(e); } -- GitLab