• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Utils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.vertx.ext.web.impl.Utils的典型用法代码示例。如果您正苦于以下问题:Java Utils类的具体用法?Java Utils怎么用?Java Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Utils类属于io.vertx.ext.web.impl包,在下文中一共展示了Utils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createTenant

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
/**
 * Helper to create a tenant. So it can be done in a one-liner without
 * cluttering real tests. Actually testing the tenant stuff should be in its
 * own test.
 *
 * @return the location, for deleting it later. This has to be urldecoded,
 * because restAssured "helpfully" encodes any urls passed to it.
 */
private String createTenant() {
  final String docTenant = "{" + LS
    + "  \"id\" : \"" + okapiTenant + "\"," + LS
    + "  \"name\" : \"" + okapiTenant + "\"," + LS
    + "  \"description\" : \"" + okapiTenant + " bibliotek\"" + LS
    + "}";
  final String loc = given()
    .header("Content-Type", "application/json")
    .body(docTenant)
    .post("/_/proxy/tenants")
    .then()
    .statusCode(201)
    .header("Location",containsString("/_/proxy/tenants"))
    .log().ifValidationFails()
    .extract().header("Location");
  return Utils.urlDecode(loc, false);
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:26,代码来源:ModuleTest.java


示例2: deployModule

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
/**
 * Helper to deploy a module. Assumes that the ModuleDescriptor has a good
 * LaunchDescriptor.
 *
 * @param modId Id of the module to be deployed.
 * @return url to delete when done
 */
private String deployModule(String modId) {
  final String instId = modId.replace("-module", "") + "-inst";
  final String docDeploy = "{" + LS
    + "  \"instId\" : \"" + instId + "\"," + LS
    + "  \"srvcId\" : \"" + modId + "\"," + LS
    + "  \"nodeId\" : \"localhost\"" + LS
    + "}";
  final String loc = given()
    .header("Content-Type", "application/json")
    .body(docDeploy)
    .post("/_/discovery/modules")
    .then()
    .statusCode(201)
    .header("Location",containsString("/_/discovery/modules"))
    .log().ifValidationFails()
    .extract().header("Location");
  return Utils.urlDecode(loc, false);
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:26,代码来源:ModuleTest.java


示例3: start

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
@Override
public void start() throws Exception {
    VERSION = Utils.readFileToString(vertx, "version");
    HttpServerOptions serverOptions = new HttpServerOptions();
    serverOptions.setCompressionSupported(true);
    HttpServer httpServer = vertx.createHttpServer(serverOptions);
    Router router = Router.router(vertx);

    new SpeechDropApplication(vertx, config(),
            Utils.readFileToString(vertx, "main.html"),
            Utils.readFileToString(vertx, "room.html"),
            Utils.readFileToString(vertx, "about.html")
    ).mount(router);

    httpServer.requestHandler(router::accept).listen(config().getInteger("port"), config().getString("host"));
}
 
开发者ID:yunyu,项目名称:SpeechDrop,代码行数:17,代码来源:SpeechDropVerticle.java


示例4: preHandle

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
@Override
public void preHandle(RoutingContext context) {
  String accept = context.request().getHeader(ACCEPT.toString());
  if (accept == null) {
    context.fail(406);
    return;
  }
  List<String> acceptableTypes = Utils.getSortedAcceptableMimeTypes(accept);
  Optional<String> bestType = acceptableTypes.stream().filter(Arrays.asList(annotation.value())::contains).findFirst();
  if (bestType.isPresent()) {
    ContentTypeProcessor.setContentType(context, bestType.get());
    context.next();
  } else {
    context.fail(406);
  }
}
 
开发者ID:aesteve,项目名称:nubes,代码行数:17,代码来源:ContentTypeProcessor.java


示例5: readFromBuffer

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
@Override
public int readFromBuffer(int pos, Buffer buffer) {
  byte b = buffer.getByte(pos++);
  if (b == (byte)1) {
    int len = buffer.getInt(pos);
    pos += 4;
    byte[] bytes = buffer.getBytes(pos, pos + len);
    pos += len;
    String className = new String(bytes, StandardCharsets.UTF_8);
    try {
      Class clazz = Utils.getClassLoader().loadClass(className);
      ClusterSerializable obj = (ClusterSerializable) clazz.newInstance();
      pos = obj.readFromBuffer(pos, buffer);
      user = (User) obj;
    } catch (Exception e) {
      throw new VertxException(e);
    }
  } else {
    user = null;
  }
  return pos;
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:23,代码来源:UserHolder.java


示例6: handle

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
@Override
public void handle(RoutingContext context) {
  HttpServerRequest request = context.request();
  if (request.method() != HttpMethod.GET && request.method() != HttpMethod.HEAD) {
    if (log.isTraceEnabled()) log.trace("Not GET or HEAD so ignoring request");
    context.next();
  } else {
    String path = Utils.removeDots(Utils.urlDecode(context.normalisedPath(), false));
    // if the normalized path is null it cannot be resolved
    if (path == null) {
      log.warn("Invalid path: " + context.request().path());
      context.next();
      return;
    }

    // only root is known for sure to be a directory. all other directories must be identified as such.
    if (!directoryListing && "/".equals(path)) {
      path = indexPage;
    }

    // can be called recursive for index pages
    sendStatic(context, path);

  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:26,代码来源:StaticHandlerImpl.java


示例7: testDirectoryListingHtmlCustomTemplate

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
private void testDirectoryListingHtmlCustomTemplate(String dirTemplateFile) throws Exception {
  stat.setDirectoryListing(true);


  String directoryTemplate = Utils.readResourceToBuffer(dirTemplateFile).toString();

  String parentLink = "<a href=\"/\">..</a>";
  String files = "<ul id=\"files\"><li><a href=\"/somedir2/foo2.json\" title=\"foo2.json\">foo2.json</a></li>" +
    "<li><a href=\"/somedir2/somepage.html\" title=\"somepage.html\">somepage.html</a></li>" +
    "<li><a href=\"/somedir2/somepage2.html\" title=\"somepage2.html\">somepage2.html</a></li></ul>";

  String expected = directoryTemplate.replace("{directory}", "/somedir2/").replace("{parent}", parentLink).replace("{files}", files);

  testRequest(HttpMethod.GET, "/somedir2", req -> req.putHeader("accept", "text/html"), resp -> resp.bodyHandler(buff -> {
    assertEquals("text/html", resp.headers().get("content-type"));
    String sBuff = buff.toString();
    assertEquals(expected, sBuff);
    testComplete();
  }), 200, "OK", null);
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:22,代码来源:StaticHandlerTest.java


示例8: handleContent

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
private void handleContent(Parameter parameter) {
  Content contents = parameter.getContent();
  ParameterLocation location = resolveLocation(parameter.getIn());
  List<MediaType> jsonsContents = OpenApi3Utils.extractTypesFromMediaTypesMap(contents, Utils::isJsonContentType);
  if (jsonsContents.size() == 1) {
    this.addRule(ParameterValidationRuleImpl.ParameterValidationRuleFactory
      .createValidationRuleWithCustomTypeValidator(parameter.getName(), JsonTypeValidator.JsonTypeValidatorFactory
        .createJsonTypeValidator(OpenApi3Utils.generateSanitizedJsonSchemaNode(jsonsContents.get(0).getSchema(), this.spec)),
        !parameter.getRequired(), OpenApi3Utils.resolveAllowEmptyValue(parameter), location), location);
  } else if (contents.size() > 1 && jsonsContents.size() >= 1) {
    // Mount anyOf
    List<ParameterTypeValidator> validators =
      jsonsContents.stream().map(e -> JsonTypeValidator.JsonTypeValidatorFactory
        .createJsonTypeValidator(OpenApi3Utils.generateSanitizedJsonSchemaNode(e.getSchema(), this.spec))).collect(Collectors.toList());
    validators.add(CONTENT_TYPE_VALIDATOR);
    AnyOfTypeValidator validator = new AnyOfTypeValidator(validators);
    this.addRule(ParameterValidationRuleImpl.ParameterValidationRuleFactory
      .createValidationRuleWithCustomTypeValidator(parameter.getName(), validator, !parameter.getRequired(), OpenApi3Utils.resolveAllowEmptyValue(parameter)
        , location), location);
  } else {
    this.addRule(ParameterValidationRuleImpl.ParameterValidationRuleFactory
      .createValidationRuleWithCustomTypeValidator(parameter.getName(), CONTENT_TYPE_VALIDATOR, !parameter
          .getRequired(), OpenApi3Utils.resolveAllowEmptyValue(parameter),
        location), location);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:27,代码来源:OpenAPI3RequestValidationHandlerImpl.java


示例9: testOthers

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
@Test
public void testOthers() {
    Assert.assertEquals(mountPoint, contextToTest.mountPoint());
    Assert.assertEquals(Utils.normalizePath(mountPoint), contextToTest.normalisedPath());
    Assert.assertEquals(null, contextToTest.currentRoute());
    Assert.assertEquals(-1, contextToTest.statusCode());
    Assert.assertEquals(null, contextToTest.failure());
    Assert.assertEquals(myVertx, contextToTest.vertx());
    Assert.assertEquals(false, contextToTest.failed());

    Session sess = new SessionImpl();
    contextToTest.setSession(sess);
    Assert.assertEquals(sess, contextToTest.session());
}
 
开发者ID:phiz71,项目名称:vertx-swagger,代码行数:15,代码来源:InterceptableRoutingContextImplTest.java


示例10: createModule

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
/**
 * Helper to create a module.
 *
 * @param md A full ModuleDescriptor
 * @return the URL to delete when done
 */
private String createModule(String md) {
  final String loc = given()
    .header("Content-Type", "application/json")
    .body(md)
    .post("/_/proxy/modules")
    .then()
    .statusCode(201)
    .header("Location",containsString("/_/proxy/modules"))
    .log().ifValidationFails()
    .extract().header("Location");
  return Utils.urlDecode(loc, false);
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:19,代码来源:ModuleTest.java


示例11: enableModule

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
/**
 * Helper to enable a module for our test tenant.
 *
 * @param modId The module to enable
 * @return the location, so we can delete it later. Can safely be ignored.
 */
private String enableModule(String modId) {
  final String docEnable = "{" + LS
    + "  \"id\" : \"" + modId + "\"" + LS
    + "}";
  final String location = given()
    .header("Content-Type", "application/json")
    .body(docEnable)
    .post("/_/proxy/tenants/" + okapiTenant + "/modules")
    .then()
    .statusCode(201)
    .header("Location",containsString("/_/proxy/tenants"))
    .extract().header("Location");
  return Utils.urlDecode(location, false);
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:21,代码来源:ModuleTest.java


示例12: getResourceAsStream

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
@Override
public InputStream getResourceAsStream(TemplateProcessingParameters templateProcessingParameters,
		String resourceName) {
	String str = Utils.readFileToString(vertx, resourceName);
	try {
		ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes("UTF-8"));
		return new BufferedInputStream(bis);
	} catch (UnsupportedEncodingException e) {
		throw new VertxException(e);
	}
}
 
开发者ID:quebic-source,项目名称:puppy-io,代码行数:12,代码来源:CustomThymeleafTemplateEngineImpl.java


示例13: findTemplateSource

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
@Override
public Object findTemplateSource(String name) throws IOException {
  try {
    // check if exists on file system
    if (vertx.fileSystem().existsBlocking(name)) {
      String templ = Utils.readFileToString(vertx, name);
      return new StringTemplateSource(name, templ, System.currentTimeMillis());
    } else {
      return null;
    }

  } catch (Exception e) {
    throw new IOException(e);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:16,代码来源:FreeMarkerTemplateLoader.java


示例14: sourceAt

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
@Override
public TemplateSource sourceAt(String location) throws IOException {
  String loc = resolve(location);
  String templ = Utils.readFileToString(vertx, loc);

  if (templ == null) {
    throw new IllegalArgumentException("Cannot find resource " + loc);
  }

  long lastMod = System.currentTimeMillis();

  return new TemplateSource() {
    @Override
    public String content() throws IOException {
      // load from the file system
      return templ;
    }

    @Override
    public String filename() {
      return loc;
    }

    @Override
    public long lastModified() {
      return lastMod;
    }
  };
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:30,代码来源:HandlebarsTemplateEngineImpl.java


示例15: getReader

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
@Override
public Reader getReader(String s) throws LoaderException {
  try {
    final String buffer = Utils.readFileToString(vertx, s, charset);
    return new StringReader(buffer);
  } catch (RuntimeException e) {
    throw new LoaderException(e, e.getMessage());
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:10,代码来源:PebbleVertxLoader.java


示例16: getReader

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
@Override
public Reader getReader(String name) throws IOException {
  // the internal loader will always resolve with .jade extension
  name = adjustLocation(name.endsWith(".jade") ? name.substring(0, name.length() - 5) : name);
  String templ = Utils.readFileToString(vertx, name);
  if (templ == null) {
    throw new IllegalArgumentException("Cannot find resource " + name);
  }
  return new StringReader(templ);
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:11,代码来源:JadeTemplateEngineImpl.java


示例17: render

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
@Override
public void render(RoutingContext context, String templateDirectory, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
  try {
    templateFileName = templateDirectory + templateFileName;
    CompiledTemplate template = isCachingEnabled() ? cache.get(templateFileName) : null;
    if (template == null) {
      // real compile
      String loc = adjustLocation(templateFileName);
      String templateText = Utils.readFileToString(context.vertx(), loc);
      if (templateText == null) {
        throw new IllegalArgumentException("Cannot find template " + loc);
      }
      template = TemplateCompiler.compileTemplate(templateText);
      if (isCachingEnabled()) {
        cache.put(templateFileName, template);
      }
    }
    Map<String, RoutingContext> variables = new HashMap<>(1);
    variables.put("context", context);
    final VertxInternal vertxInternal = (VertxInternal) context.vertx();
    String directoryName = vertxInternal.resolveFile(templateFileName).getParent();
    handler.handle(Future.succeededFuture(
      Buffer.buffer(
        (String) new TemplateRuntime(template.getTemplate(), null, template.getRoot(), directoryName)
          .execute(new StringAppender(), variables, new ImmutableDefaultFactory())
      )
    ));
  } catch (Exception ex) {
    handler.handle(Future.failedFuture(ex));
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:32,代码来源:MVELTemplateEngineImpl.java


示例18: handleSend

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
private void handleSend(RoutingContext rc, SockJSSession session) {
  rc.request().bodyHandler(buff -> {
    String body = buff.toString();

    boolean urlEncoded;
    String ct = rc.request().getHeader("content-type");
    if ("application/x-www-form-urlencoded".equalsIgnoreCase(ct)) {
      urlEncoded = true;
    } else if ("text/plain".equalsIgnoreCase(ct)) {
      urlEncoded = false;
    } else {
      rc.response().setStatusCode(500);
      rc.response().end("Invalid Content-Type");
      return;
    }

    if (body.equals("") || urlEncoded && (!body.startsWith("d=") || body.length() <= 2)) {
      rc.response().setStatusCode(500).end("Payload expected.");
      return;
    }

    if (urlEncoded) {
      body = Utils.urlDecode(body, true).substring(2);
    }

    if (!session.handleMessages(body)) {
      sendInvalidJSON(rc.response());
    } else {
      setJSESSIONID(options, rc);
      rc.response().putHeader("Content-Type", "text/plain; charset=UTF-8");
      setNoCacheHeaders(rc);
      rc.response().end("ok");
      if (log.isTraceEnabled()) log.trace("send handled ok");
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:37,代码来源:JsonPTransport.java


示例19: handle

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
@Override
public void handle(RoutingContext context) {
  String file = Utils.pathOffset(context.normalisedPath(), context);
  if (file.endsWith("/") && null != indexTemplate) {
    file += indexTemplate;
  }
  engine.render(context, templateDirectory, file, res -> {
    if (res.succeeded()) {
      context.response().putHeader(HttpHeaders.CONTENT_TYPE, contentType).end(res.result());
    } else {
      context.fail(res.cause());
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:15,代码来源:TemplateHandlerImpl.java


示例20: init

import io.vertx.ext.web.impl.Utils; //导入依赖的package包/类
private void init(Vertx vertx) {
  try {
    if (path == null) {
      icon = new Icon(Utils.readResourceToBuffer("favicon.ico"));
    } else {
      icon = new Icon(vertx.fileSystem().readFileBlocking(path));
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:12,代码来源:FaviconHandlerImpl.java



注:本文中的io.vertx.ext.web.impl.Utils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java KeyDescription类代码示例发布时间:2022-05-23
下一篇:
Java VariableType类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap