Generic request handler
324979
function makeRequest(url, handler) {
  const xhr = new XMLHttpRequest();

  xhr.open('GET', url, true);
  xhr.responseType = handler.type;

  xhr.onload = function onLoad(e) {
    if (this.status === 200 || this.status === 0) {
      handler.fn(null, xhr);
      return;
    }
    handler.fn(e, xhr);
  };
  xhr.onerror = function onError(e) {
    handler.fn(e, xhr);
  };
  xhr.send();
}
624921
function () {

                var that = this,
                    paramHandler = this.params.handler,
                    params = util.mixin({}, this.params);

                //wrap the handler callbacks in a cancel check
                function handler(responseCode, data, ioArgs) {
                    that.xhr = ioArgs.xhr;
                    that.statusCode = that.xhr && !that.xhr.timedOut && that.xhr.status || 0;
                    if (that.canceled) {
                        logger.debug("Request [" + that.id + "] was canceled, not calling handler");
                    } else {
                        that.pending = false;
                        that.complete = true;
                        paramHandler(responseCode, data, ioArgs);
                    }
                }

                if (this.canceled) {
                    logger.debug("Request [" + that.id + "] was canceled, not executing");
                } else {
                    this.pending = true;
                    this.fn(util.mixin(params, {
                        handler: handler
                    }));
                }
            }
1043621
function invokeHTTPHandler(handler, args, req, res, done) {
  // inject parsed parameters into request
  req.params = args;
  // call handler with typical HTTP request/response parameters
  let result = handler(req, res);
  // handle results that are not a trusted Promise with Promise.resolve()
  // which also supports other then-ables
  if (result instanceof Promise === false) {
    result = Promise.resolve(result);
  }
  return result.then(() => done()).catch(done);
}
1259529
@Override
    public void handleRequest(HttpServletRequest request, HttpServletResponse response) {
        handleRequest(request, response, null, null, false);
    }
1213570
function onServerPreRequestHandler (ctx, err, value) {
  if (err) {
    if (err instanceof SuperError) {
      ctx._response.error = err.rootCause || err.cause || err;
    } else {
      ctx._response.error = err;
    }

    return ctx.finish();
  }

  // reply value from extension
  if (value) {
    ctx._response.payload = value;
    return ctx.finish();
  }

  // check if a handler is registered with this pattern
  if (ctx._actMeta) {
    ctx._extensions.onServerPreHandler.dispatch(ctx, (err, val) => {
      return onServerPreHandler(ctx, err, val);
    });
  } else {
    const internalError = new Errors.PatternNotFound(Constants.PATTERN_NOT_FOUND, ctx.errorDetails);
    ctx.log.error(internalError);
    ctx._response.error = internalError;

    // send error back to callee
    ctx.finish();
  }
}
1060783
private void handleRequest(
		ChainWriter out,
		WebSiteRequest req,
		HttpServletResponse resp,
		List<? extends TreePageData> tree,
		int scrollToX,
		int scrollToY,
		boolean[] opened
	) throws IOException, SQLException {
		WebPageLayout layout=getWebPageLayout(req);
		layout.startContent(out, req, resp, 1, getPreferredContentWidth(req));
		layout.printContentTitle(out, req, resp, this, 1);
		layout.printContentHorizontalDivider(out, req, resp, 1, false);
		layout.startContentLine(out, req, resp, 1, null, null);
		try {
			// Get the tree data
			int treeLen = tree.size();

			// Break apart each line
			String[][] paths = getLines(tree);

			if (opened == null) {
				// Default to opened for first item
				opened = new boolean[treeLen];
				if (treeLen > 0) opened[0] = true;
			}

			// Write the javascript that controls the form
			out.print("<script type='text/javascript'>\n"
					+ "  // <![CDATA[\n"
					+ "  function openNode(index) {\n"
					+ "    eval('document.forms[\"tree_form\"].opened_'+index+'.value=\"true\";');\n"
					+ "    document.forms[\"tree_form\"].scroll_to_x.value=getPageXOffset(window);\n"
					+ "    document.forms[\"tree_form\"].scroll_to_y.value=getPageYOffset(window);\n"
					+ "    document.forms[\"tree_form\"].submit();\n"
					+ "  }\n"
					+ "\n"
					+ "  function closeNode(index) {\n"
					+ "    eval('document.forms[\"tree_form\"].opened_'+index+'.value=\"false\";');\n"
					+ "    document.forms[\"tree_form\"].scroll_to_x.value=getPageXOffset(window);\n"
					+ "    document.forms[\"tree_form\"].scroll_to_y.value=getPageYOffset(window);\n"
					+ "    document.forms[\"tree_form\"].submit();\n"
					+ "  }\n"
					+ "  // ]]>\n"
					+ "</script>\n");

			// Write the form containing the current settings
			out.print("<form action='' id='tree_form' method='post'><div>\n");
			req.printFormFields(out, 1);
			out.print("  <input type='hidden' name='scroll_to_x' value='").print(scrollToX).print("' />\n"
					+ "  <input type='hidden' name='scroll_to_y' value='").print(scrollToY).print("' />\n");
			for(int c=0; c<treeLen; c++) {
				out.print("  <input type='hidden' name='opened_").print(c).print("' value='").print(opened[c]).print("' />\n");
			}

			// Display the tree in a table with links for opening/closing the different parts
			out.print("  <table cellspacing='0' cellpadding='0'>\n");

			String[] last = AoArrays.EMPTY_STRING_ARRAY;
			for (int c = 0; c < treeLen; c++) {
				String[] path = paths[c];
				int pathLen = path.length;

				// Every parent must be open for this to be visible
				boolean visible = true;
				Loop2 :
					for (int d = 0; d < (pathLen - 1); d++) {
						// Find the first row that has all the path up to current step
						for (int e = 0; e < c; e++) {
							String[] parentpath = paths[e];
							if (parentpath.length > d) {
								boolean isParent = true;
								for (int f = 0; f <= d; f++) {
									if (!parentpath[f].equals(path[f])) {
										isParent = false;
										break;
									}
								}
								if (isParent) {
									if (!opened[e]) {
										visible = false;
										break Loop2;
									}
									break;
								}
							}
						}
					}
					if (visible) {
						out.print("    <tr>\n"
								+ "      <td style='white-space:nowrap; border:0px;'><table cellspacing='0' cellpadding='0'><tr><td style='white-space:nowrap; border:0px;'>");

						int max = Math.min(pathLen - 1, last.length);
						int pos = 0;

						// Skip the part of the path that is already displayed by the parent
						for (; pos < max; pos++) {
							if (last[pos].equals(path[pos])) {
								boolean hasMore = false;
								for (int d = c + 1; d < treeLen; d++) {
									int end = pos;
									for (int e = 0; e < end; e++) {
										if (paths[d][e].equals(path[e])) {
											if (e == (end - 1) && !paths[d][end].equals(path[end])) {
												hasMore = true;
												break;
											}
										} else break;
									}
								}
								out.print("<img src='").encodeXmlAttribute(resp.encodeURL(req.getContextPath()+req.getURL(this, "image_num="+(hasMore?1:0)))).print("' style='border:0px; display:inline; vertical-align:bottom;' width='"+IMAGE_WIDTH+"' height='"+IMAGE_HEIGHT+"' alt='' />");
							} else break;
						}

						// Display the remaining part of the path
						for(; pos < pathLen; pos++) {
							if(path[pos].length()>0) {
								// Determine has sub items
								boolean hasSub = false;
								if (c < (treeLen - 1)) {
									String[] next_path = paths[c + 1];
									if (next_path.length >= pathLen) {
										hasSub = true;
										for (int e = 0; e < pathLen; e++) {
											String tempPath=path[e];
											if(tempPath.length()>0 && !tempPath.equals(next_path[e])) {
												hasSub = false;
												break;
											}
										}
									}
								}

								// Determine if the line continues farther down
								boolean hasMore = false;
								for (int d = c; d < treeLen; d++) {
									int end = pos;
									for (int e = 0; e < end; e++) {
										if (paths[d][e].equals(path[e])) {
											if (e == (end - 1) && !paths[d][end].equals(path[end])) {
												hasMore = true;
												break;
											}
										} else break;
									}
								}

								if(hasSub) {
									out
										.print("<a href='javascript:")
										.print(opened[c] ? "closeNode(" : "openNode(")
										.print(c)
										.print(");'><img alt='").print(opened[c] ? "Close" : "Open")
										.print("' src='")
										.encodeXmlAttribute(
											resp.encodeURL(
												req.getContextPath()+req.getURL(
													this,
													"image_num="+(
														opened[c]
														? (hasMore ? 4 : (c > 0 ? 5 : 9))
														: (hasMore ? 6 : (c > 0 ? 7 : 8))
													)
												)
											)
										).print("' style='vertical-align:bottom; border:0px; display:inline;' width='"+IMAGE_WIDTH+"' height='"+IMAGE_HEIGHT+"' /></a>");
								} else {
									out
										.print("<img src='")
										.encodeXmlAttribute(
											resp.encodeURL(
												req.getContextPath()+req.getURL(
													this,
													"image_num="+(hasMore ? 2 : 3)
												)
											)
										).print("' style='vertical-align:bottom; border:0px; display:inline;' width='"+IMAGE_WIDTH+"' height='"+IMAGE_HEIGHT+"' alt='' />");
								}
								out.print("<img src='").encodeXmlAttribute(resp.encodeURL(req.getContextPath()+req.getURL(this, "image_num=0"))).print("' style='vertical-align:bottom; border:0px; display:inline;' width='4' height='"+IMAGE_HEIGHT+"' alt='' /></td><td style='white-space:nowrap'>");
							}

							boolean useCodeFont=useCodeFont(req);
							if (useCodeFont) out.print("<code>");
							String href;
							if(
								(
									(pathLen>=2 && pos==(pathLen-2) && path[pathLen-1].length()==0)
									|| (pos==(pathLen-1) && path[pathLen-1].length()>0)
								) && (href = tree.get(c).getUrl()) != null
							) {
								out.print("<a class='aoLightLink' href='").encodeXmlAttribute(resp.encodeURL(href)).print("'>").print(path[pos]).print("</a>");
							} else if(path[pos].length()>0) out.print(path[pos]);
							if(useCodeFont) out.print("</code>");
						}

						out.print("</td></tr></table></td>\n"
								+ "      <td style='white-space:nowrap; width:20px'><img src='").encodeXmlAttribute(resp.encodeURL(req.getContextPath()+req.getURL(this, "image_num=0"))).print("' style='vertical-align:bottom; border:0px; display:inline;' width='20' height='1' alt='' /></td>\n"
								+ "      <td style='white-space:nowrap'>");
						String description=tree.get(c).getDescription();
						if(description!=null) out.print(description);
						out.print("</td>\n"
								+ "    </tr>\n");
						last = path;
					}
			}

			out.print("  </table>\n"
					+ "</div></form>\n");
		} finally {
			layout.endContentLine(out, req, resp, 1, false);
			layout.endContent(this, out, req, resp, 1);
		}
	}
94861
function Handler() {
    if (this.constructor === Handler) {
        throw new Error("Can't instantiate abstract class!");
    }

    /**
     * @var {Object}
     * @protected
     */
    this.__inspector;

    /**
     * @var {Object}
     * @protected
     */
    this.__run;

    /**
     * @var {Object}
     * @protected
     */
    this.__request = null;

    /**
     * @var {Object}
     * @protected
     */
    this.__response = null;
}
1299970
function wrapRequestHandler(func) {
  return function handler(req, res, next) {
    try {
      const result = func(req, res, next)
      if (result && result.catch) result.catch(e => next(e))
    } catch(e) {
      next(e)
    }
  }
}
605516
private ApiListType executeRequest(Call call) throws IOException, ApiException {
    return client.handleResponse(call.execute(), listType);
  }
720356
private void handleRequest(ByteBuf request, ChannelHandlerContext context) {
    NettyConnection connection = getConnection(context.channel());
    if (connection != null) {
      connection.handleRequest(request);
    }
  }
715900
def get_handler(self, request):
        
        try:
            f = self._json_rpc_methods[request.method]

        except (AttributeError, KeyError):  # pragma no coverage
            raise RPCMethodError("Received invalid method '{}'".format(request.method))

        return f
726429
function tryCall(handler, data, callback)
{
  try {
    handler(data, callback);
  } catch (e) {
    callback(e);
  }
}
810954
def _generic_signal_handler(self, signal_type):
        
        print("</pre>")
        message = "Got " + signal_type + ". Failing gracefully..."
        self.timestamp(message)
        self.fail_pipeline(KeyboardInterrupt(signal_type), dynamic_recover=True)
        sys.exit(1)
415051
function handleRequest(url, options, callback) {
  let req = {
    url: url,
    headers: {},
    qs: {},
    json: {},
  }

  req = parseOptions(req, options)
  callback(req)
}
1202475
def _request(self, url, **kwargs):
        '''
        '''
        if self.method is None:
            raise NotImplementedError('method must be defined on a subclass')
        response = requests.request(self.method, url, **kwargs)
        return self.response_class(response, sender=self)
1344814
def send_request(req=None, method=None, requires_response=True):
    """"""
    if req is None:
        return functools.partial(send_request, method=method,
                                 requires_response=requires_response)

    @functools.wraps(req)
    def wrapper(self, *args, **kwargs):
        params = req(self, *args, **kwargs)
        _id = self.send(method, params, requires_response)
        return _id
    wrapper._sends = method
    return wrapper
986262
function request(server, config, hooks, keys, request, callback) {
    const start = Date.now();

    if (typeof request === 'function' && typeof callback !== 'function') {
        callback = request;
        request = {};
    }

    // handle argument variations and get Request instance
    const args = Array.from(arguments).slice(4).filter(v => v !== undefined);
    const req = (function() {
        const length = args.length;
        if (length === 0) {
            return new Request(server, keys, config.rejectable);

        } else if (length === 1 && typeof args[0] === 'function') {
            callback = args[0];
            return new Request(server, keys, config.rejectable);

        } else {
            return new Request(server, keys, config.rejectable, request);
        }
    })();

    // event log aggregation
    const queue = config.logs ? [] : null;
    if (queue) req.on('log', event => queue.push(event));

    // if logging enabled then produce the log when the request is fulfilled or rejected
    if (queue) {
        const log = function(state) {
            const events = queue.map((event, index) => {
                const seconds = util.seconds(event.timestamp - (index > 0 ? queue[index - 1].timestamp : start));
                return '[+' + seconds + 's] ' + event.category + ':' + event.type + ' ' + event.data;
            });
            console.log(state.statusCode + ' ' + req.method + ' ' + req.url +
                (state.statusCode === 302 ? '\n  Redirect To: ' + state.headers['location']  : '') +
                '\n  ID: ' + req.id +
                '\n  Start: ' + new Date(start).toISOString() +
                '\n  Duration: ' + prettyPrint.seconds(Date.now() - start) +
                '\n  Events:\n    ' +
                events.join('\n    '));
        };
        req.then(log, () => log(req.res.state));
    }

    // copy hooks into request
    req.log('initialized');
    Object.keys(hooks).forEach(type => {
        hooks[type].forEach(d => {
            req.hook(type, d.weight, d.hook)
        });
    });
    req.log('hooks applied');

    // is using a callback paradigm then execute the callback
    if (typeof callback === 'function') req.then(state => callback(null, state), err => callback(err, req.res.state));

    return req;
}