private void commandWhere(StringTokenizer t, boolean showPC) throws NoSessionException { ThreadReference current = context.getCurrentThread(); if (!t.hasMoreTokens()) { if (current == null) { env.error("No thread specified."); return; } dumpStack(current, showPC); } else { String token = t.nextToken(); if (token.toLowerCase().equals("all")) { ThreadIterator it = allThreads(); while (it.hasNext()) { ThreadReference thread = it.next(); out.println(thread.name() + ": "); dumpStack(thread, showPC); } } else { ThreadReference thread = findThread(t.nextToken()); // ### Do we want to set current thread here? // ### Should notify user of change. if (thread != null) { context.setCurrentThread(thread); } dumpStack(thread, showPC); } } }
private void commandFrame(StringTokenizer t) throws NoSessionException { ThreadReference current = context.getCurrentThread(); if (current == null) { env.failure("No current thread."); return; } if (!t.hasMoreTokens()) { env.error("usage: frame <frame-index>"); return; } String idToken = t.nextToken(); int n; try { n = Integer.valueOf(idToken).intValue(); } catch (NumberFormatException e) { n = 0; } if (n <= 0) { env.error("use positive frame index"); return; } try { int delta = context.setCurrentFrameIndex(current, n); if (delta == 0) { env.notice("Frame unchanged."); } else if (delta < 0) { env.notice("Moved up " + -delta + " frames."); } else { env.notice("Moved down " + delta + " frames."); } } catch (VMNotInterruptedException e) { env.failure("Target VM must be in interrupted state."); } }
private void commandLocals() throws NoSessionException { ThreadReference current = context.getCurrentThread(); if (current == null) { env.failure("No default thread specified: " + "use the \"thread\" command first."); return; } StackFrame frame; try { frame = context.getCurrentFrame(current); if (frame == null) { env.failure("Thread has not yet created any stack frames."); return; } } catch (VMNotInterruptedException e) { env.failure("Target VM must be in interrupted state."); return; } List<LocalVariable> vars; try { vars = frame.visibleVariables(); if (vars == null || vars.size() == 0) { env.failure("No local variables"); return; } } catch (AbsentInformationException e) { env.failure( "Local variable information not available." + " Compile with -g to generate variable information"); return; } OutputSink out = env.getOutputSink(); out.println("Method arguments:"); for (LocalVariable var : vars) { if (var.isArgument()) { printVar(out, var, frame); } } out.println("Local variables:"); for (LocalVariable var : vars) { if (!var.isArgument()) { printVar(out, var, frame); } } out.show(); return; }
/** * Maps a named servlet to a particular path or extension. If the named servlet is unregistered, * it will be added and subsequently mapped. * * <p>Note that the order of resolution to handle a request is: * * <p>exact mapped servlet (eg /catalog) prefix mapped servlets (eg /foo/bar/*) extension mapped * servlets (eg *jsp) default servlet */ public void addServletMapping(String path, String servletName) throws TomcatException { if (mappings.get(path) != null) { log("Removing duplicate " + path + " -> " + mappings.get(path)); mappings.remove(path); Container ct = (Container) containers.get(path); removeContainer(ct); } ServletWrapper sw = (ServletWrapper) servlets.get(servletName); if (sw == null) { // Workaround for frequent "bug" in web.xmls // Declare a default mapping log("Mapping with unregistered servlet " + servletName); sw = addServlet(servletName, servletName); } if ("/".equals(path)) defaultServlet = sw; mappings.put(path, sw); Container map = new Container(); map.setContext(this); map.setHandler(sw); map.setPath(path); contextM.addContainer(map); containers.put(path, map); }
private void commandPrint(StringTokenizer t, boolean dumpObject) throws NoSessionException { if (!t.hasMoreTokens()) { // ### Probably confused if expresion contains whitespace. env.error("No expression specified."); return; } ThreadReference current = context.getCurrentThread(); if (current == null) { env.failure("No default thread specified: " + "use the \"thread\" command first."); return; } StackFrame frame; try { frame = context.getCurrentFrame(current); if (frame == null) { env.failure("Thread has not yet created any stack frames."); return; } } catch (VMNotInterruptedException e) { env.failure("Target VM must be in interrupted state."); return; } while (t.hasMoreTokens()) { String expr = t.nextToken(""); Value val = null; try { val = runtime.evaluate(frame, expr); } catch (Exception e) { env.error("Exception: " + e); // ### Fix this! } if (val == null) { return; // Error message already printed } OutputSink out = env.getOutputSink(); if (dumpObject && (val instanceof ObjectReference) && !(val instanceof StringReference)) { ObjectReference obj = (ObjectReference) val; ReferenceType refType = obj.referenceType(); out.println(expr + " = " + val.toString() + " {"); dump(out, obj, refType, refType); out.println("}"); } else { out.println(expr + " = " + val.toString()); } out.show(); } }
private void commandNexti() throws NoSessionException { ThreadReference current = context.getCurrentThread(); if (current == null) { env.failure("No current thread."); return; } runtime.stepOverInstruction(current); }
private void commandThread(StringTokenizer t) throws NoSessionException { if (!t.hasMoreTokens()) { env.error("Thread number not specified."); return; } ThreadReference thread = findThread(t.nextToken()); if (thread != null) { // ### Should notify user. context.setCurrentThread(thread); } }
/** Return the absolute path for the docBase, if we are file-system based, null otherwise. */ public String getAbsolutePath() { if (absPath != null) return absPath; if (FileUtil.isAbsolute(docBase)) absPath = docBase; else absPath = contextM.getHome() + File.separator + docBase; try { absPath = new File(absPath).getCanonicalPath(); } catch (IOException npe) { } return absPath; }
public void start() throws Exception { if (con == null) throw new Exception("Invalid ConnectionHandler"); con.setAttribute("context.manager", cm); ep.setPort(port); ep.setAddress(address); if (socketFactory != null) { ep.setServerSocketFactory(socketFactory); } ep.setConnectionHandler(con); ep.startEndpoint(); cm.log("Starting endpoint port=\"" + port + "\" handler=\"" + con.getClass().getName() + "\" "); }
private void commandNext() throws NoSessionException { ThreadReference current = context.getCurrentThread(); if (current == null) { env.failure("No current thread."); return; } try { runtime.stepOverLine(current); } catch (AbsentInformationException e) { env.failure( "No linenumber information available -- " + "Try \"nexti\" to step by instructions."); } }
private void commandDown(StringTokenizer t) throws NoSessionException { ThreadReference current = context.getCurrentThread(); if (current == null) { env.failure("No current thread."); return; } int nLevels = readCount(t); if (nLevels <= 0) { env.error("usage: down [n frames]"); return; } try { int delta = context.moveCurrentFrameIndex(current, nLevels); if (delta == 0) { env.notice("Already at bottom of stack."); } else if (delta < nLevels) { env.notice("Moved down " + delta + " frames to bottom of stack."); } } catch (VMNotInterruptedException e) { env.failure("Target VM must be in interrupted state."); } }
public Context getContext(String path) { if (!path.startsWith("/")) { return null; // according to spec, null is returned // if we can't return a servlet, so it's more probable // servlets will check for null than IllegalArgument } // Return null if cross context lookups are not allowed if (!crossContext) return null; // absolute path Request lr = contextM.createRequest(path); if (vhost != null) lr.setServerName(vhost); getContextManager().processRequest(lr); return lr.getContext(); }
private void commandAttach(StringTokenizer t) { String portName; if (!t.hasMoreTokens()) { portName = context.getRemotePort(); if (!portName.equals("")) { try { runtime.attach(portName); } catch (VMLaunchFailureException e) { env.failure("Attempt to attach to port \"" + portName + "\" failed."); } } else { env.failure("No port specifed and no current default defined."); } } else { portName = t.nextToken(); try { runtime.attach(portName); } catch (VMLaunchFailureException e) { env.failure("Attempt to attach to port \"" + portName + "\" failed."); } context.setRemotePort(portName); } }
/** * Will add a new security constraint: For all paths: if( match(path) && match(method) && match( * transport ) ) then require("roles") * * <p>This is equivalent with adding a Container with the path, method and transport. If the * container will be matched, the request will have to pass the security constraints. */ public void addSecurityConstraint( String path[], String methods[], String roles[], String transport) throws TomcatException { for (int i = 0; i < path.length; i++) { Container ct = new Container(); ct.setContext(this); ct.setTransport(transport); ct.setRoles(roles); ct.setPath(path[i]); ct.setMethods(methods); // XXX check if exists, merge if true. constraints.put(path[i], ct); // contextM.addSecurityConstraint( this, path[i], ct); contextM.addContainer(ct); } }
private void commandStep(StringTokenizer t) throws NoSessionException { ThreadReference current = context.getCurrentThread(); if (current == null) { env.failure("No current thread."); return; } try { if (t.hasMoreTokens() && t.nextToken().toLowerCase().equals("up")) { runtime.stepOut(current); } else { runtime.stepIntoLine(current); } } catch (AbsentInformationException e) { env.failure( "No linenumber information available -- " + "Try \"stepi\" to step by instructions."); } }
/** * @deprecated - use getDocBase and URLUtil if you need it as URL NOT USED INSIDE TOMCAT - ONLY IN * OLD J2EE CONNECTORS ! */ public URL getDocumentBase() { if (documentBase == null) { if (docBase == null) return null; try { String absPath = docBase; // detect absolute path ( use the same logic in all tomcat ) if (FileUtil.isAbsolute(docBase)) absPath = docBase; else absPath = contextM.getHome() + File.separator + docBase; try { absPath = new File(absPath).getCanonicalPath(); } catch (IOException npe) { } documentBase = new URL("file", "", absPath); } catch (MalformedURLException ex) { ex.printStackTrace(); } } return documentBase; }
private boolean doLoad(boolean suspended, StringTokenizer t) throws NoSessionException { String clname; if (!t.hasMoreTokens()) { clname = context.getMainClassName(); if (!clname.equals("")) { // Run from prevously-set class name. try { String vmArgs = context.getVmArguments(); runtime.run(suspended, vmArgs, clname, context.getProgramArguments()); return true; } catch (VMLaunchFailureException e) { env.failure("Attempt to launch main class \"" + clname + "\" failed."); } } else { env.failure("No main class specifed and no current default defined."); } } else { clname = t.nextToken(); StringBuffer sbuf = new StringBuffer(); // Allow VM arguments to be specified here? while (t.hasMoreTokens()) { String tok = t.nextToken(); sbuf.append(tok); if (t.hasMoreTokens()) { sbuf.append(' '); } } String args = sbuf.toString(); try { String vmArgs = context.getVmArguments(); runtime.run(suspended, vmArgs, clname, args); context.setMainClassName(clname); // context.setVmArguments(vmArgs); context.setProgramArguments(args); return true; } catch (VMLaunchFailureException e) { env.failure("Attempt to launch main class \"" + clname + "\" failed."); } } return false; }
public Nomin(Context context, Class<? extends Mapping>... mappingClasses) { contextManager.setSharedContext(context); parse(mappingClasses); }
public <T> T map(Object source, Class<T> targetClass, Context context) { contextManager.replaceShared(context); T target = map(source, targetClass); contextManager.restoreShared(); return target; }
public void stop() throws Exception { cm.log("Stoping endpoint port=\"" + port + "\" handler=\"" + con.getClass().getName() + "\" "); ep.stopEndpoint(); }
public <T> T map(Object source, T target, Context context) { contextManager.replaceShared(context); map(source, target, (Object) null); contextManager.restoreShared(); return target; }
public Nomin(Context context) { contextManager.setSharedContext(context); }
public <T> T map(Object source, T target, Object mappingCase, Context context) { contextManager.replaceShared(context); map(source, target, mappingCase); contextManager.restoreShared(); return target; }
private void commandList(StringTokenizer t) throws NoSessionException { ThreadReference current = context.getCurrentThread(); if (current == null) { env.error("No thread specified."); return; } Location loc; try { StackFrame frame = context.getCurrentFrame(current); if (frame == null) { env.failure("Thread has not yet begun execution."); return; } loc = frame.location(); } catch (VMNotInterruptedException e) { env.failure("Target VM must be in interrupted state."); return; } SourceModel source = sourceManager.sourceForLocation(loc); if (source == null) { if (loc.method().isNative()) { env.failure("Current method is native."); return; } env.failure("No source available for " + Utils.locationString(loc) + "."); return; } ReferenceType refType = loc.declaringType(); int lineno = loc.lineNumber(); if (t.hasMoreTokens()) { String id = t.nextToken(); // See if token is a line number. try { lineno = Integer.valueOf(id).intValue(); } catch (NumberFormatException nfe) { // It isn't -- see if it's a method name. List<Method> meths = refType.methodsByName(id); if (meths == null || meths.size() == 0) { env.failure( id + " is not a valid line number or " + "method name for class " + refType.name()); return; } else if (meths.size() > 1) { env.failure(id + " is an ambiguous method name in" + refType.name()); return; } loc = meths.get(0).location(); lineno = loc.lineNumber(); } } int startLine = (lineno > 4) ? lineno - 4 : 1; int endLine = startLine + 9; String sourceLine = source.sourceLine(lineno); if (sourceLine == null) { env.failure("" + lineno + " is an invalid line number for " + refType.name()); } else { OutputSink out = env.getOutputSink(); for (int i = startLine; i <= endLine; i++) { sourceLine = source.sourceLine(i); if (sourceLine == null) { break; } out.print(i); out.print("\t"); if (i == lineno) { out.print("=> "); } else { out.print(" "); } out.println(sourceLine); } out.show(); } }
public Nomin context(Context context) { contextManager.setSharedContext(context); return this; }