@Override public Route postWithRegex(String regex) { return router.postWithRegex(regex); }
private void registerHandler(Router router, Handler<SockJSSocket> sockHandler, String re, boolean streaming, SockJSHandlerOptions options) { router.postWithRegex(re).handler(rc -> { if (log.isTraceEnabled()) log.trace("XHR, post, " + rc.request().uri()); setNoCacheHeaders(rc); String sessionID = rc.request().getParam("param0"); SockJSSession session = getSession(rc, options.getSessionTimeout(), options.getHeartbeatInterval(), sessionID, sockHandler); HttpServerRequest req = rc.request(); session.register(req, streaming? new XhrStreamingListener(options.getMaxBytesStreaming(), rc, session) : new XhrPollingListener(rc, session)); }); }
@Test public void testPostWithRegex() throws Exception { router.postWithRegex("\\/somepath\\/.*").handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.POST, "/somepath/whatever", 200, "foo"); testRequest(HttpMethod.POST, "/otherpath/whatever", 404, "Not Found"); testRequest(HttpMethod.GET, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.PUT, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.DELETE, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/somepath/whatever", 404, "Not Found"); }
router.postWithRegex(jsonpSendRE).handler(rc -> { if (log.isTraceEnabled()) log.trace("JsonP, post: " + rc.request().uri()); String sessionID = rc.request().getParam("param0");
/** * Add a route that matches a HTTP POST request and the specified path regex * @param regex URI paths that begin with a match for this regex will match * @return the route */ public io.vertx.rxjava.ext.web.Route postWithRegex(String regex) { io.vertx.rxjava.ext.web.Route ret = io.vertx.rxjava.ext.web.Route.newInstance(delegate.postWithRegex(regex)); return ret; }
/** * Add a route that matches a HTTP POST request and the specified path regex * @param regex URI paths that begin with a match for this regex will match * @return the route */ public io.vertx.rxjava.ext.web.Route postWithRegex(String regex) { io.vertx.rxjava.ext.web.Route ret = io.vertx.rxjava.ext.web.Route.newInstance(delegate.postWithRegex(regex)); return ret; }
@Override public io.vertx.ext.web.Route postWithRegex(String regex) { return delegate.postWithRegex(getFullPath(regex)); }
XhrTransport(Vertx vertx, Router router, LocalMap<String, SockJSSession> sessions, SockJSHandlerOptions options, Handler<SockJSSocket> sockHandler) { super(vertx, sessions, options); String xhrBase = COMMON_PATH_ELEMENT_RE; String xhrRE = xhrBase + "xhr"; String xhrStreamRE = xhrBase + "xhr_streaming"; Handler<RoutingContext> xhrOptionsHandler = createCORSOptionsHandler(options, "OPTIONS, POST"); router.optionsWithRegex(xhrRE).handler(xhrOptionsHandler); router.optionsWithRegex(xhrStreamRE).handler(xhrOptionsHandler); registerHandler(router, sockHandler, xhrRE, false, options); registerHandler(router, sockHandler, xhrStreamRE, true, options); String xhrSendRE = COMMON_PATH_ELEMENT_RE + "xhr_send"; router.optionsWithRegex(xhrSendRE).handler(xhrOptionsHandler); router.postWithRegex(xhrSendRE).handler(rc -> { if (log.isTraceEnabled()) log.trace("XHR send, post, " + rc.request().uri()); String sessionID = rc.request().getParam("param0"); final SockJSSession session = sessions.get(sessionID); if (session != null && !session.isClosed()) { handleSend(rc, session); } else { rc.response().setStatusCode(404); setJSESSIONID(options, rc); rc.response().end(); } }); }
private void installMethodForwarder(io.vertx.ext.web.Router newRouter, Rule rule, Handler<RoutingContext> forwarder) { for (String method : rule.getMethods()) { log.info("Installing " + rule.getScheme().toUpperCase() + " forwarder for methods " + method + " to " + rule.getUrlPattern()); switch (method) { case "GET": newRouter.getWithRegex(rule.getUrlPattern()).handler(forwarder); break; case "PUT": newRouter.putWithRegex(rule.getUrlPattern()).handler(forwarder); break; case "POST": newRouter.postWithRegex(rule.getUrlPattern()).handler(forwarder); break; case "DELETE": newRouter.deleteWithRegex(rule.getUrlPattern()).handler(forwarder); break; } } }
@Test public void testPostWithRegex() throws Exception { router.postWithRegex("\\/somepath\\/.*").handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.POST, "/somepath/whatever", 200, "foo"); testRequest(HttpMethod.POST, "/otherpath/whatever", 404, "Not Found"); testRequest(HttpMethod.GET, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.PUT, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.DELETE, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/somepath/whatever", 404, "Not Found"); }
private void registerHandler(Router router, Handler<SockJSSocket> sockHandler, String re, boolean streaming, SockJSHandlerOptions options) { router.postWithRegex(re).handler(rc -> { if (log.isTraceEnabled()) log.trace("XHR, post, " + rc.request().uri()); setNoCacheHeaders(rc); String sessionID = rc.request().getParam("param0"); SockJSSession session = getSession(rc, options.getSessionTimeout(), options.getHeartbeatInterval(), sessionID, sockHandler); HttpServerRequest req = rc.request(); session.register(req, streaming? new XhrStreamingListener(options.getMaxBytesStreaming(), rc, session) : new XhrPollingListener(rc, session)); }); }
router.postWithRegex(jsonpSendRE).handler(rc -> { if (log.isTraceEnabled()) log.trace("JsonP, post: " + rc.request().uri()); String sessionID = rc.request().getParam("param0");
XhrTransport(Vertx vertx, Router router, LocalMap<String, SockJSSession> sessions, SockJSHandlerOptions options, Handler<SockJSSocket> sockHandler) { super(vertx, sessions, options); String xhrBase = COMMON_PATH_ELEMENT_RE; String xhrRE = xhrBase + "xhr"; String xhrStreamRE = xhrBase + "xhr_streaming"; Handler<RoutingContext> xhrOptionsHandler = createCORSOptionsHandler(options, "OPTIONS, POST"); router.optionsWithRegex(xhrRE).handler(xhrOptionsHandler); router.optionsWithRegex(xhrStreamRE).handler(xhrOptionsHandler); registerHandler(router, sockHandler, xhrRE, false, options); registerHandler(router, sockHandler, xhrStreamRE, true, options); String xhrSendRE = COMMON_PATH_ELEMENT_RE + "xhr_send"; router.optionsWithRegex(xhrSendRE).handler(xhrOptionsHandler); router.postWithRegex(xhrSendRE).handler(rc -> { if (log.isTraceEnabled()) log.trace("XHR send, post, " + rc.request().uri()); String sessionID = rc.request().getParam("param0"); final SockJSSession session = sessions.get(sessionID); if (session != null && !session.isClosed()) { handleSend(rc, session); } else { rc.response().setStatusCode(404); setJSESSIONID(options, rc); rc.response().end(); } }); }
router.postWithRegex(prefix + "/queues/([^/]+)/").handler(ctx -> { final String queue = part(ctx.request().path(), "/", 1); ctx.request().bodyHandler(buffer -> {
router.postWithRegex(prefix + "/queues/([^/]+)/").handler(ctx -> { final String queue = part(ctx.request().path(), "/", 1); ctx.request().bodyHandler(buffer -> {
router.postWithRegex(prefix + "/queues/([^/]+)/").handler(this::addQueueItem);