我在为 Web 应用程序设置处理程序时遇到问题,我想要的是:通过 withHTTPServlet和doGet方法处理一些请求doPost(如何从这些方法中加载 JSP 页面?)并且还能够加载静态内容(html、JS、CSS)。
我现在的设置方式,只能选择其中之一,无法同时使用。
我会解释:
Server server = new Server(5000);
// This is the resource handler for JS & CSS
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(".");
resourceHandler.setDirectoriesListed(false);
// This is the context handler for the HTTPServlet
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addServlet(new ServletHolder(new Main()),"/*");
// this is the Handler list for both handlers
HandlerList handlerList = new HandlerList();
handlerList.setHandlers(new Handler[] { context ,resourceHandler});
/*
If I add them in this …Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用 SolrJ + Solr。问题是我在 Solr/Jetty 方面遇到了不清楚的瓶颈
使用 jvisualvm 我连接到 JVM 实例,Solr 在该实例下启动并看到 77% 的时间花在方法“org.eclipse.jetty.io.ByteArrayBuffer.readFrom()”上,其中一个线程的堆栈跟踪如下:
"qtp64700533-36718" - Thread t@36718
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at org.eclipse.jetty.io.ByteArrayBuffer.readFrom(ByteArrayBuffer.java:391)
at org.eclipse.jetty.io.bio.StreamEndPoint.fill(StreamEndPoint.java:141)
at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.fill(SocketConnector.java:227)
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1040)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:280)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)
at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:745)
Run Code Online (Sandbox Code Playgroud)
所以,花在 I/O 上的时间看起来没问题,但是:
任何帮助/建议表示赞赏,谢谢!
UPD:
确实,伙计们,我忘了提供附加信息。这里是:
硬件:i3770,32gb 内存,根据 iotop,它显示 50-600kb/sec 读取,200-1000kb/sec 写入(几乎与 SOLR 进程相关)
操作系统:Centos 6.6
java:OpenJDK 64 位服务器 VM(1.7.0_71 …
FAILURE:构建失败,出现异常。
出了什么问题:任务 ':project-web:jettyRun' 执行失败。
java.util.concurrent.ExecutionException:java.net.BindException:地址已在使用中:JVM_Bind
尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。
构建失败
我一直在寻找如何让嵌入式码头服务器为包含在同一个 jar 中的少数 html 文件提供服务的方法,但没有成功。这当然有可能吗?
如果不需要的话,我真的不想经历建造和参与战争的麻烦。理想情况下,我也不必创建 WEB-INFO 目录和 web.xml 文件,尽管我读过的所有解决方案似乎都指向这样做并使用 WebAppContext。
我已阅读以下链接,但还没有找到从 jar 运行时设置 ResourceBase 或 BaseResource 属性的方法。
为嵌入式 Jetty 指定 JAR“resources/webapp”文件夹的 ResourceBase 的正确 URL 是什么?
在 DEV 期间通过 IDE 运行很简单,代码工作并且看起来像这样..
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(httpPort);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.setWelcomeFiles(new String[]{"welcome.html"});
server.setHandler(context);
ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
holderPwd.setInitParameter("resourceBase","./Relative/Path/To/Html/Files");
holderPwd.setInitParameter("dirAllowed","true");
context.addServlet(holderPwd,"/");
server.start();
server.join();
Run Code Online (Sandbox Code Playgroud)
那么,我是否必须使用 WebAppContext 而不是 ServletContextHandler?如果是,那么我是否也必须添加 webapp/WEB-INFO/web.xml 目录结构?如果我这样做,那么我是否必须打包成一场战争?
基本上我有这个码头服务器在我的本地运行。但我无法访问我看到的index.jsp 文件
这是我的 web.xml 文件,你看我使用 Apache CXF,还使用 Spring、Hibernate 和 Jetty
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml,classpath:Spring-Security.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring Security Start -->
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<!-- Projenin ana url'inden itibaren spring security aktif ediliyor -->
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring Security End -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
我该如何解决呢。我哪里做错了?
在 Jetty 9 服务器的源代码中有很多有用的调试输出。我使用 Spring 4.3.3(包括 Jetty 作为依赖项)并且愿意启用 Jetty 的调试输出(websocket 部分最重要)我该怎么做?
我正在从 jetty 8 升级到 jetty 9,并且在某些 API 中遇到了一些有关编译失败的问题。
SslSelectChannelConnector 已被删除,从我可以看到带有 secureRequestCustomizer 的 httpConfiguration 替换了它。
但是有很多方法我都找不到。例如
设置请求缓冲区大小
设置响应缓冲区大小
设置接受者
设置最大空闲时间
SessionHandler 不再有 getSessionManager() 方法。
另外 queueThreadPool 不再有 setMaxQueued(int),JettyServer 不再有这两个方法: setThreadPool(QueueThreadPool) setGracefulShutdown(int)
编辑: SslSelectChannelConnector 已弃用。将 SelectChannelConnector 与 SslContextFactory 一起使用。
jettyServer.setThreadPool(threadPool); // --> threadPool is set in the constructor new Server(QueueThreadPool)
jettyServer.setGracefulShutdown(5000); // --> jettyServer.setStopTimeout(5000);
jettyServer.setConnectors(new Connector[] { connector }); // --> ServerConnector which takes https_config
jettyServer.setSendServerVersion(false); // --> https_config.setSendServerVersion(false);
Run Code Online (Sandbox Code Playgroud)
哪里或哪个 API 用于代替上述 API?
还有任何自定义的东西在运行时停止工作,这不是很明显可以找到/看到。
我创建了一个使用 SpringBoot 的项目,项目打包类型是,jar并且我还在项目中添加了 jetty 依赖项,当我尝试使用 构建项目时mvn jetty:run,构建成功,但我收到这样的消息
[INFO] 跳过 keycloak-springboot-demo :不支持打包类型 [jar]
下面是我的 pom.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dasniko</groupId>
<artifactId>keycloak-springboot-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>keycloak-springboot-demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<keycloak.version>3.2.0.Final</keycloak.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
<version>${keycloak.version}</version> …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,其中Servlet有一个方法调用Update(ReqIn, ReqOut).我从doGet&调用它doPost并传递Request和Response变量,然后Update(...)填写以下静态变量:
...
public class Server extends HttpServlet {
public static HttpServletRequest In = null;
public static HttpServletResponse Out = null;
public static boolean isDebug = true;
public static boolean isPost = false;
public static String URL = "";
public static String IP = "0.0.0.0";
public static Cookie[] Cookies = null;
public static UserClass User = null;
public static boolean isLoggedIn = false;
...
}Run Code Online (Sandbox Code Playgroud)
基本上抽象最常用的东西并在每次请求时更新它.这也允许我从网站的任何地方访问IP地址和当前用户数据,只需Server.User.getUsername();编写每次加载页面时使用新的类实例并使用更长的访问代码:Server.getUser().getUsername();
现在的问题是:当在多用户环境(AppEngine上的Jetty)时,这会引入任何问题吗?例如,一些线程/赛车问题使用户看到不正确的IP地址,或者在极端情况下突然以不同的用户身份登录?
或者我应该重写代码并将其更改为 …
有人可以帮我把我的GWT应用程序放在Jetty上.我不是在使用maven.我的构建路径中有库.
首先,我正在将war文件夹展开并将其复制到jetty/webapps中,然后在文件夹上下文中.
我在文件夹web应用程序中放置了一个名为BiddingSystem的folde,它是一个已爆炸的文件夹而不是.war文件
在文件夹jetty/context中,有一个文件test.xml我将文件重命名为BiddingSystem.xml
并且还编辑了BiddingSystem.xml的内容,最后是BiddingSystem.xml的内容
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<configure class="org.mortbay.jetty.webapp.WebAppContext">
<set name="contextPath">/BiddingSystem</set>
<set name="war"><systemproperty name="jetty.home" default="."/>/webapps/BiddingSystem</set>
</configure>
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
