Tag: vert.x

gRPC gradle:generateProto在导入其他原型定义时找不到目录

我试图编译一些protobuf定义为gradle任务,但得到以下错误,没有源代: * What went wrong: Execution failed for task ':generateProto'. > protoc: stdout: . stderr: /Users/ash/IdeaProjects/kotlin/grpc/build/extracted-protos/main: warning: directory does not exist. service-definitions.proto:10:17: "Empty" is not defined. service-definitions.proto:10:33: "Empty" is not defined. service-definitions.proto:15:17: "SimpleRequest" is not defined. service-definitions.proto:15:41: "SimpleResponse" is not defined. service-definitions.proto:21:27: "StreamingOutputCallRequest" is not defined. service-definitions.proto:21:71: "StreamingOutputCallResponse" is not defined. service-definitions.proto:27:33: "StreamingInputCallRequest" is not […]

用VertX服务favicon.ico和其他静态文件

我正在尝试提供一个favicon和一些字体。 object Lion : AbstractVerticle() { @JvmStatic @Throws(IOException::class) fun main(args: Array<String>) { val vertx = Vertx.vertx() val router = Router.router(vertx) router.route().handler(CorsHandler.create("*") .allowedMethod(HttpMethod.GET) .allowedMethod(HttpMethod.POST) .allowedMethod(HttpMethod.OPTIONS) .allowedHeader("X-PINGARUNER") .allowedHeader("Content-Type")) // some json GET / POST routes here router.route().handler(FaviconHandler.create()); router.route().handler(StaticHandler.create()) vertx.createHttpServer().requestHandler { router.accept(it) }.listen(9090) } 当我转到http://localhost:9090/favicon.ico时, FaviconHandler抛出一个导致“内部服务器错误”的异常。我的图标位于src/main/resources/webroot/favicon.ico Oct 22, 2016 11:16:42 PM io.vertx.ext.web.impl.RoutingContextImplBase SEVERE: Unexpected exception in route java.lang.RuntimeException: […]

在Vertx中,我需要将所有HTTP请求重定向到相同的URL,但HTTPS

我已经在Koltin中编写了一个Vertx-web处理程序,它将任何接收到的HTTP请求重定向到HTTPS,并且使用context.request().isSSL来确定请求是否不是SSL,并且直到我把我的代码在负载平衡器后面。 如果负载均衡器使用HTTPS与我的Vertx-web服务器通信,则认为所有用户请求都是HTTPS,即使它们不是。 如果我更改负载平衡器以与HTTP上的Vertx-web进行通信,那么即使用户已经使用HTTPS,每个请求也会被无限重定向。 然后,我也看到另一个问题,即使用context.request().absoluteURI()的重定向转到私有地址,而不是用户实际与之通信的公用地址。 在Vertx-web中是否有一个处理程序,我错过了这个,或者一些惯用的方法来解决这个问题? 我应该从JavaScript做到这一点,因为它看到的是真正的用户地址,而不是尝试服务器端重定向? 我在Kotlin编码,所以这个语言的例子都很棒! 注意: 这个问题是由作者故意编写和回答的( 自我回答问题 ),所以在SO中共享有趣问题的解决方案。

通过Vert.x托管WebSocket,通过Socket.IO连接

我在Web服务(在Vert.x的Kotlin上编写)上设置了一个简单的WebSocket,然后通过Mocha / Socket.IO进行测试。 我的网络服务片段非常简单: httpServer.websocketHandler({ socket -> LOGGER.info("Websocket event!") LOGGER.info(" Path: ${socket.path()}") LOGGER.info(" Query: ${socket.query()}") LOGGER.info(" Headers: ${socket.headers()}") LOGGER.info(" URI: ${socket.uri()}") if (!socket.path().startsWith("/api/v1/ws/auction/")) { LOGGER.warn("Rejecting WS for lack of proper prefix, path: ${socket.path()}") socket.reject() } val split = socket.path().split("/api/v1/ws/auction/") if (split.size != 2) { LOGGER.warn("Rejecting WS for lack of Auction ID, with split: $split") socket.reject() […]

Vert.x. 如何创建一个真正的多语言JVM应用程序?

我正在检查Vert.x ,一个可以用几种不同的JVM语言运行应用程序的框架。 在vertx-examples中有大量的例子可用。 但问题是,(我还没有找到任何东西),我们如何才能以真正的多语言方式编写Vert.x应用程序(同时使用所有支持的JVM语言)? 例如,我们如何编写使用以下文件的代码: Java.java , Kotlin.kt , Javascript.js , Ruby.rb 。 其中每个人都有一个简单的函数,打印语言名称(例如Ruby.rb打印ruby )。 例如,当使用这个输入时: $vertx run Polyglot.java 我们怎样才能实现以下输出? java, kotlin, javascript, ruby 编辑 ,我的尝试: Polyglot.java import io.vertx.core.AbstractVerticle; import io.vertx.core.Launcher; import java.lang.management.ManagementFactory; public class Polyglot extends AbstractVerticle { public static void main(args: String[]) { Launcher.main(new String[] { "run", Polyglot.class.getName(), "-ha"}); } @Override public void […]

Vertx已经写过“回复”

我是Vertx全新的,并试图创建我的第一个HTTP休息服务器。 但是,我一直在遇到这个问题。 这是我在尝试发送回复时收到的错误。 Jan 07, 2017 3:54:36 AM io.vertx.ext.web.impl.RoutingContextImplBase SEVERE: Unexpected exception in route java.lang.IllegalStateException: Response has already been written at io.vertx.core.http.impl.HttpServerResponseImpl.checkWritten(HttpServerResponseImpl.java:559) at io.vertx.core.http.impl.HttpServerResponseImpl.putHeader(HttpServerResponseImpl.java:156) at io.vertx.core.http.impl.HttpServerResponseImpl.putHeader(HttpServerResponseImpl.java:54) at com.themolecule.utils.Response.sendResponse(Response.kt:25) at com.themolecule.api.UserAPI.addUser(UserAPI.kt:52) at TheMoleculeAPI$main$3.handle(TheMoleculeAPI.kt:50) at TheMoleculeAPI$main$3.handle(TheMoleculeAPI.kt:19) at io.vertx.ext.web.impl.RouteImpl.handleContext(RouteImpl.java:215) at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:78) at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:94) at io.vertx.ext.web.handler.impl.AuthHandlerImpl.authorise(AuthHandlerImpl.java:86) at 这就是我建立我的路线。 // setup verx val vertx = Vertx.vertx() val router = Router.router(vertx) […]

Vert.x使用BLOB和休眠区分数据库中的数据

我尝试使用Hibernate 5.2.11.Final(BLOB类型)和Vert.x 3.4.2在数据库(Postgresql 9.6.5)的响应块中发送二进制数据,但我收到错误的响应(它看起来像我一些位缺失)。 这是我在Kotlin的代码: fun getFile(user: User, messageId: Long, fileId: Short, response: HttpServerResponse) { val mediaContent = mediaContentRepository.getFile(messageId, fileId) when { mediaContent == null -> response.apply { statusCode = 404 }.end() conversationUserRepository.authorize(user.id!!, mediaContent.message!!.conversation!!.id, mediaContent.message!!.created) -> response.setChunked(true) .putHeader("Content-Disposition", "attachment; filename=\"${mediaContent.name}\"") //TODO: prevent injections .putHeader("Content-Type", mediaContent.contentType) //.putHeader("Content-Length", mediaContent.file.length().toString()) .apply { //write(Buffer.buffer().apply { delegate.setBytes(0, mediaContent.file.binaryStream.readAllBytes()) }) val […]

我有一个Vertx请求,我需要计算一个外部可见的(公共)URL

我使用的是Kotlin的Vertx 3,有时我需要从公共URL的角度返回一个特定的URI,这与Vertx-web请求认为我的URL不一样。 这可能是由于我的负载均衡器或代理接收到一个URL,然后通过内部URL转发到我的应用程序。 所以如果我这样做: val publicUrl = context.request().absoluteURI() 我最终得到一个像http://10.10.103.22:8080/some/page而不是https://app.mydomain.com/some/page的URL。 关于该网址的一切都是错误的! 我发现了一个标题,可以告诉我更多关于原始请求的信息,例如X-Forwarded-Host但是它只包含app.mydomain.com ,有时它的端口是app.mydomain:80但是还不足以解决所有问题部分网址,我结束了像http://app.mydomain.com:8080/some/page仍然不是正确的公共URL。 我还需要处理的不仅仅是我当前的URL,而且是对等URL,就像在页面上的“something / page1”一样,在同一台服务器上转到“something / page2”。 当我试图解析到另一个URL,因为公共URL的重要部分是无法获得提到的相同的问题。 Vertx-web中有没有一种方法可以确定这个公共URL,或者一些常用的方法来解决这个问题? 我在Kotlin编码,所以这个语言的例子都很棒! 注意: 这个问题是由作者故意编写和回答的( 自我回答问题 ),所以在SO中共享有趣问题的解决方案。

如何使用Vert.x Web获取当前的Web请求?

我正在写一个使用Hibernate(JPA)+ Vert.x Web(Kotlin)的项目,我需要将EntityManager绑定到Web Request,我的意思是我想要为每个Web请求创建EntityManager。 我需要使用静态方法(Kotlin中的对象)从VertX获得当前的Web请求。 有没有办法做到这一点? 或者我错了,因为VertX是反应?

在VertX中路由静态内容

我正在使用Kotlin使用Vert.X( 通过org.jetbrains.kotlinx:vertx3-lang-kotlin库 ),我试图构建一个自包含在jar中的单页应用程序。 在maven方面,这些是我的依赖: <properties> … <vertx.version>3.3.2</vertx.version> <kotlin.version>1.0.3</kotlin.version> <main.class>Bob</main.class> </properties> <!– Vertx Dependencies –> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-core</artifactId> <version>${vertx.version}</version> </dependency> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-web</artifactId> <version>${vertx.version}</version> </dependency> <!– Kotlin Dependencies –> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib</artifactId> <version>${kotlin.version}</version> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-test</artifactId> <version>${kotlin.version}</version> <scope>test</scope> </dependency> <!– Kotlin Vertx Binding Dependency –> <dependency> <groupId>org.jetbrains.kotlinx</groupId> <artifactId>vertx3-lang-kotlin</artifactId> <version>[0.0.4,0.1.0)</version> </dependency> 在我的主课,我有以下几点: object Bob { val […]