@Test public void testPrintGotoFormWritesValidXML() throws IOException, ParserConfigurationException, SAXException { JspWriter mockJspWriter = mock(JspWriter.class); ArgumentCaptor<String> arg = ArgumentCaptor.forClass(String.class); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invok) { Object[] args = invok.getArguments(); jspWriterOutput += (String) args[0]; return null; } }).when(mockJspWriter).print(arg.capture()); jspWriterOutput = ""; JspHelper.printGotoForm(mockJspWriter, 424242, "a token string", "foobar/file", "0.0.0.0"); DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(jspWriterOutput)); parser.parse(is); }
public static void printGotoForm(JspWriter out, int namenodeInfoPort, String tokenString, String file, String nnAddress) throws IOException { out.print("<form action=\"browseDirectory.jsp\" method=\"get\" name=\"goto\">"); out.print("Goto : "); out.print("<input name=\"dir\" type=\"text\" width=\"50\" id=\"dir\" value=\""+ HtmlQuoting.quoteHtmlChars(file)+"\"/>"); out.print("<input name=\"go\" type=\"submit\" value=\"go\"/>"); out.print("<input name=\"namenodeInfoPort\" type=\"hidden\" " + "value=\"" + namenodeInfoPort + "\"/>"); if (UserGroupInformation.isSecurityEnabled()) { out.print("<input name=\"" + DELEGATION_PARAMETER_NAME + "\" type=\"hidden\" value=\"" + tokenString + "\"/>"); } out.print("<input name=\""+ NAMENODE_ADDRESS +"\" type=\"hidden\" " + "value=\"" + nnAddress + "\"/>"); out.print("</form>"); }
JspHelper { public static void printGotoForm(JspWriter out, int namenodeInfoPort, String tokenString, String file, String nnAddress) throws IOException { out.print("<form action=\"browseDirectory.jsp\" method=\"get\" name=\"goto\">"); out.print("Goto : "); out.print("<input name=\"dir\" type=\"text\" width=\"50\" id=\"dir\" value=\""+ HtmlQuoting.quoteHtmlChars(file)+"\"/>"); out.print("<input name=\"go\" type=\"submit\" value=\"go\"/>"); out.print("<input name=\"namenodeInfoPort\" type=\"hidden\" " + "value=\"" + namenodeInfoPort + "\"/>"); if (UserGroupInformation.isSecurityEnabled()) { out.print("<input name=\"" + DELEGATION_PARAMETER_NAME + "\" type=\"hidden\" value=\"" + tokenString + "\"/>"); } out.print("<input name=\""+ NAMENODE_ADDRESS +"\" type=\"hidden\" " + "value=\"" + nnAddress + "\"/>"); out.print("</form>"); } }
JspHelper { public static void printGotoForm(JspWriter out, int namenodeInfoPort, String tokenString, String file, String nnAddress) throws IOException { out.print("<form action=\"browseDirectory.jsp\" method=\"get\" name=\"goto\">"); out.print("Goto : "); out.print("<input name=\"dir\" type=\"text\" width=\"50\" id=\"dir\" value=\""+ HtmlQuoting.quoteHtmlChars(file)+"\"/>"); out.print("<input name=\"go\" type=\"submit\" value=\"go\"/>"); out.print("<input name=\"namenodeInfoPort\" type=\"hidden\" " + "value=\"" + namenodeInfoPort + "\"/>"); if (UserGroupInformation.isSecurityEnabled()) { out.print("<input name=\"" + DELEGATION_PARAMETER_NAME + "\" type=\"hidden\" value=\"" + tokenString + "\"/>"); } out.print("<input name=\""+ NAMENODE_ADDRESS +"\" type=\"hidden\" " + "value=\"" + nnAddress + "\"/>"); out.print("</form>"); } private  JspHelper(); }
JspHelper { public static void printGotoForm(JspWriter out, int namenodeInfoPort, String tokenString, String file, String nnAddress) throws IOException { out.print("<form action=\"browseDirectory.jsp\" method=\"get\" name=\"goto\">"); out.print("Goto : "); out.print("<input name=\"dir\" type=\"text\" width=\"50\" id=\"dir\" value=\""+ HtmlQuoting.quoteHtmlChars(file)+"\"/>"); out.print("<input name=\"go\" type=\"submit\" value=\"go\"/>"); out.print("<input name=\"namenodeInfoPort\" type=\"hidden\" " + "value=\"" + namenodeInfoPort + "\"/>"); if (UserGroupInformation.isSecurityEnabled()) { out.print("<input name=\"" + DELEGATION_PARAMETER_NAME + "\" type=\"hidden\" value=\"" + tokenString + "\"/>"); } out.print("<input name=\""+ NAMENODE_ADDRESS +"\" type=\"hidden\" " + "value=\"" + nnAddress + "\"/>"); out.print("</form>"); } private  JspHelper(); static String canonicalize(String addr); static DatanodeInfo bestNode(LocatedBlocks blks, Configuration conf); static DatanodeInfo bestNode(LocatedBlock blk, Configuration conf); static void streamBlockInAscii(InetSocketAddress addr, String poolId,
      long blockId, final Token<BlockTokenIdentifier> blockToken, long genStamp,
      long blockSize, long offsetIntoBlock, long chunkSizeToView,
      JspWriter out, final Configuration conf, DFSClient.Conf dfsConf,
      final DFSClient dfs, final SaslDataTransferClient saslClient); static void addTableHeader(JspWriter out); static void addTableRow(JspWriter out, String[] columns); static void addTableRow(JspWriter out, String[] columns, int row); static void addTableFooter(JspWriter out); static void sortNodeList(final List<DatanodeDescriptor> nodes,
                           String field, String order); static void printPathWithLinks(String dir, JspWriter out, 
                                        int namenodeInfoPort,
                                        String tokenString,
                                        String nnAddress
                                        ); static void printGotoForm(JspWriter out,
                                   int namenodeInfoPort,
                                   String tokenString,
                                   String file,
                                   String nnAddress); static void createTitle(JspWriter out, 
                                 HttpServletRequest req, 
                                 String  file); static int string2ChunkSizeToView(String s, int defaultValue); static String getVersionTable(); static String validatePath(String p); static Long validateLong(String value); static String validateURL(String value); static UserGroupInformation getDefaultWebUser(Configuration conf
                                                       ); static UserGroupInformation getUGI(HttpServletRequest request,
      Configuration conf); static UserGroupInformation getUGI(ServletContext context,
      HttpServletRequest request, Configuration conf); static UserGroupInformation getUGI(ServletContext context,
      HttpServletRequest request, Configuration conf,
      final AuthenticationMethod secureAuthMethod,
      final boolean tryUgiParameter); static String getRemoteAddr(HttpServletRequest request); static String getDelegationTokenUrlParam(String tokenString); static String getUrlParam(String name, String val, String paramSeparator); static String getUrlParam(String name, String val, boolean firstParam); static String getUrlParam(String name, String val); }
JspHelper { public static void printGotoForm(JspWriter out, int namenodeInfoPort, String tokenString, String file, String nnAddress) throws IOException { out.print("<form action=\"browseDirectory.jsp\" method=\"get\" name=\"goto\">"); out.print("Goto : "); out.print("<input name=\"dir\" type=\"text\" width=\"50\" id=\"dir\" value=\""+ HtmlQuoting.quoteHtmlChars(file)+"\"/>"); out.print("<input name=\"go\" type=\"submit\" value=\"go\"/>"); out.print("<input name=\"namenodeInfoPort\" type=\"hidden\" " + "value=\"" + namenodeInfoPort + "\"/>"); if (UserGroupInformation.isSecurityEnabled()) { out.print("<input name=\"" + DELEGATION_PARAMETER_NAME + "\" type=\"hidden\" value=\"" + tokenString + "\"/>"); } out.print("<input name=\""+ NAMENODE_ADDRESS +"\" type=\"hidden\" " + "value=\"" + nnAddress + "\"/>"); out.print("</form>"); } private  JspHelper(); static String canonicalize(String addr); static DatanodeInfo bestNode(LocatedBlocks blks, Configuration conf); static DatanodeInfo bestNode(LocatedBlock blk, Configuration conf); static void streamBlockInAscii(InetSocketAddress addr, String poolId,
      long blockId, final Token<BlockTokenIdentifier> blockToken, long genStamp,
      long blockSize, long offsetIntoBlock, long chunkSizeToView,
      JspWriter out, final Configuration conf, DFSClient.Conf dfsConf,
      final DFSClient dfs, final SaslDataTransferClient saslClient); static void addTableHeader(JspWriter out); static void addTableRow(JspWriter out, String[] columns); static void addTableRow(JspWriter out, String[] columns, int row); static void addTableFooter(JspWriter out); static void sortNodeList(final List<DatanodeDescriptor> nodes,
                           String field, String order); static void printPathWithLinks(String dir, JspWriter out, 
                                        int namenodeInfoPort,
                                        String tokenString,
                                        String nnAddress
                                        ); static void printGotoForm(JspWriter out,
                                   int namenodeInfoPort,
                                   String tokenString,
                                   String file,
                                   String nnAddress); static void createTitle(JspWriter out, 
                                 HttpServletRequest req, 
                                 String  file); static int string2ChunkSizeToView(String s, int defaultValue); static String getVersionTable(); static String validatePath(String p); static Long validateLong(String value); static String validateURL(String value); static UserGroupInformation getDefaultWebUser(Configuration conf
                                                       ); static UserGroupInformation getUGI(HttpServletRequest request,
      Configuration conf); static UserGroupInformation getUGI(ServletContext context,
      HttpServletRequest request, Configuration conf); static UserGroupInformation getUGI(ServletContext context,
      HttpServletRequest request, Configuration conf,
      final AuthenticationMethod secureAuthMethod,
      final boolean tryUgiParameter); static String getRemoteAddr(HttpServletRequest request); static String getDelegationTokenUrlParam(String tokenString); static String getUrlParam(String name, String val, String paramSeparator); static String getUrlParam(String name, String val, boolean firstParam); static String getUrlParam(String name, String val); static final String CURRENT_CONF; static final String DELEGATION_PARAMETER_NAME; static final String NAMENODE_ADDRESS; }