标签: embedded-jetty

Java 嵌入式码头正在接受 HTTP TRACE 方法

我正在尝试在嵌入式 Jetty 中禁用 HTTP TRACE 方法。在 Jetty 文档的信息中,HTTP 跟踪在默认情况下是禁用的,但对于嵌入式,它仍处于启用状态。我试图禁用跟踪作为安全约束,就像在 jetty.xml 中所做的那样。

    ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS | ServletContextHandler.SECURITY);
    servletHandler.setClassLoader(Server.class.getClassLoader());
    servletHandler.setContextPath("/");
    servletHandler.addEventListener(new ContextLoaderListener());
    servletHandler.addServlet(new ServletHolder(new CXFServlet()), "/*");
    servletHandler.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
    servletHandler.setInitParameter("contextConfigLocation", BeansConfig.class.getName());
    servletHandler.setInitParameter("javax.ws.rs.Application", DispatcherConfig.class.getName());

     /*
     * <security-constraint>
     * <web-resource-collection>
     * <web-resource-name>Disable TRACE</web-resource-name>
     * <url-pattern>/</url-pattern>
     * <http-method>TRACE</http-method>
     * </web-resource-collection>
     * <auth-constraint/>
     * </security-constraint>
     */
     Constraint constraint = new Constraint();
     constraint.setName("Disable TRACE");

     ConstraintMapping mapping = new ConstraintMapping();
     mapping.setConstraint(constraint);
     mapping.setMethod("TRACE");
     mapping.setPathSpec("/"); // this did not work same this mapping.setPathSpec("/*");

     ConstraintSecurityHandler securityHandler = (ConstraintSecurityHandler) servletHandler.getSecurityHandler();
     securityHandler.addConstraintMapping(mapping); …
Run Code Online (Sandbox Code Playgroud)

spring trace http jetty embedded-jetty

6
推荐指数
2
解决办法
1万
查看次数

作为嵌入式服务器运行时Jetty自定义错误页面

在将Jetty作为嵌入式服务器运行时,如何覆盖默认错误页面(以"Powered by Jetty"为后缀)?

Server server = new Server(8080);
server.setHandler(new Handler());

/* configure custom error pages? */

server.start();
server.join();
Run Code Online (Sandbox Code Playgroud)

jetty embedded-jetty

6
推荐指数
1
解决办法
3404
查看次数

如何在 ODL 控制器中配置拒绝服务过滤器

我是 ODL 控制器和嵌入式码头的新手。如果有请求泛滥,我想在 jetty.xml 中添加 DoSFilter 来限制 REST 请求。

我尝试在互联网上搜索,但在 web.xml DoSFilter 中有很多配置它的示例,但没有找到对 jetty.xml 的太多帮助

在 jetty.xml 中配置 DoSFilter 的任何帮助都会有很大帮助。

ODL - 氮气版本

码头 - 9.2.21.X 版本

以下是我迄今为止尝试过的选项。

在 jetty.xml 中配置的过滤器:

    <Get name="handler">
        <Call name="addHandler">
            <Arg>
                <New class="org.eclipse.jetty.servlet.ServletContextHandler">
                    <Set name="contextPath">/</Set>
                    <Set name="resourceBase">../</Set>
                    <Call name="addFilter">
                        <Arg>
                            <New class="org.eclipse.jetty.servlet.FilterHolder">
                                <Arg>
                                    <New class="org.eclipse.jetty.servlets.DoSFilter" />
                                </Arg>
                                <Call name="setInitParameter">
                                    <Arg>maxRequestsPerSec</Arg>
                                    <Arg>30</Arg>
                                </Call>
                                <Call name="setInitParameter">
                                    <Arg>delayMs</Arg>
                                    <Arg>100</Arg>
                                </Call>
                                <Call name="setInitParameter">
                                    <Arg>maxRequestMs</Arg>
                                    <Arg>0</Arg>
                                </Call>
                                <Call name="setInitParameter">
                                    <Arg>maxIdleTrackerMs</Arg>
                                    <Arg>0</Arg>
                                </Call>
                                <Call name="setInitParameter">
                                    <Arg>ipWhitelist</Arg>
                                    <Arg>127.0.0.1</Arg>
                                </Call>
                            </New>
                        </Arg> …
Run Code Online (Sandbox Code Playgroud)

java servlets jetty embedded-jetty opendaylight

6
推荐指数
1
解决办法
348
查看次数

Jetty:动态删除已注册的servlet

我使用WebAppContext创建并启动了jetty服务器.我还可以使用addServlet方法将servlet添加到WebAppContext.但是我想动态删除这个servlet.我怎样才能做到这一点 ?WebAppContext中未提供类似removeServlet()的内容.

jetty embedded-jetty

5
推荐指数
1
解决办法
2866
查看次数

使用嵌入式jetty创建Web界面

我是网络开发的新手,也是使用嵌入式码头的新手.下面介绍的源代码是使用eclipse IDE开发的.我必须以编程方式启动jetty服务器,我没有通过命令行启动它的选项.它需要是一个极轻量级的Web界面,因为它将从具有低内存/处理速度的系统启动.

我在ECLIPSE中开发了以下目录结构

  JettyExample <Project>
    src 
     sample_package
        HelloWorld.java
     WEB-INF
      index.html
      web.xml
Run Code Online (Sandbox Code Playgroud)

HelloWorld.java的源代码

 public static void main(String[] args) throws Exception
{

    Server server = new Server(8080);
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase(args.length == 2?args[1]:".");
    resource_handler.setWelcomeFiles(new String[]{ "WEB-INF/index.html" });


    System.out.println("serving " + resource_handler.getBaseResource());

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
    server.setHandler(handlers);
    server.start();
    server.join();

}
Run Code Online (Sandbox Code Playgroud)

index.html是

 <html>
<head>
    <title>HTML Generator Sample Page</title>
</head>
<body>
    <h1 style="text-align: center;">
        Agent Management Interface</h1>
    <ol>
        <li>
            Start Platform</li>
        <li>
            Show Agent …
Run Code Online (Sandbox Code Playgroud)

html javascript java embedded-jetty

5
推荐指数
1
解决办法
7346
查看次数

嵌入式Jetty:如何使用Jetty启动的.jar中包含的.war?

我正在尝试生成一个包含main()的.jar ,它将启动Jetty.

我的问题是我希望Jetty加载的.war 包含在同一个.jar中.

我已经能够创建包含.war的.jar:

在POM.xml中:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <finalName>myApp</finalName>
        <appendAssemblyId>false</appendAssemblyId>
        <archive>
            <manifest>
                <mainClass>com.myApp.Server</mainClass>
            </manifest>
        </archive>
        <descriptors>
            <descriptor>src/main/resources/executable-jar-assembly.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
        <execution>
            <id>make-my-jar-with-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

executable-jar-assembly.xml:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">

<id>jar-with-dependencies-and-war</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
    <dependencySet>
        <outputDirectory>/</outputDirectory>
        <useProjectArtifact>false</useProjectArtifact>
        <unpack>true</unpack>
        <scope>runtime</scope>
    </dependencySet>
</dependencySets>
<fileSets>
    <fileSet>
        <directory>target/classes/</directory>
        <outputDirectory>/</outputDirectory>
    </fileSet>
    <fileSet>
        <directory>target/</directory>
        <includes>
            <include>
                myApp.war
            </include>
        </includes>
        <outputDirectory>/</outputDirectory>
    </fileSet>
</fileSets>
Run Code Online (Sandbox Code Playgroud)

在Jetty中设置战争的代码:

handler.setWar("myApp.war");
Run Code Online (Sandbox Code Playgroud)

......我也尝试过:

URL res = Server.class.getResource("myApp.war");
handler.setWar(res.toExternalForm());
Run Code Online (Sandbox Code Playgroud)

......和:

URL res = …
Run Code Online (Sandbox Code Playgroud)

java jetty embedded-jetty maven

5
推荐指数
1
解决办法
2945
查看次数

Jetty 9绝对uri:http://java.sun.com/jsp/jstl/core无法解析

我正在使用

  • Jetty 9嵌入式.
  • Maven的
  • Java 1.7
  • JSTL

当我在Eclipse中运行我的应用程序并浏览到包含JSTL标记的网页时,它可以正常工作.当我将它捆绑在一个可执行的jar中并从cmd提示符运行时,我得到了

org.apache.jasper.JasperException:/jsp/pcReport.jsp(4,62)PWC6188:绝对的uri:http://java.sun.com/jsp/jstl/core无法在web.xml或者使用此应用程序部署的jar文件

我的依赖

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-webapp</artifactId>
        <version>9.0.6.v20130930</version>
    </dependency>
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jsp-2.1-glassfish</artifactId>
        <version>2.1.v20100127</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我的插件

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.pricemon.server.Main</mainClass>
                        <classpathPrefix>webapp/WEB-INF/lib/</classpathPrefix>
                        <addClasspath>true</addClasspath>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>etc/</Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <descriptors>
                    <descriptor>assembly.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup> …
Run Code Online (Sandbox Code Playgroud)

java jstl embedded-jetty maven

5
推荐指数
2
解决办法
4777
查看次数

如何配置嵌入式jetty服务器以记录所有请求?

我想将所有soap请求记录到我的服务器.服务器实例是嵌入式jetty服务器.

有没有办法设置处理程序来执行此操作.我可以访问web.xml文件

java jetty embedded-jetty

5
推荐指数
1
解决办法
9129
查看次数

嵌入式Jetty java.lang.NoClassDefFoundError:org/mortbay/log/Log

我正在尝试为通常部署到Tomcat的应用程序编写一个小型嵌入式Jetty程序.我的应用似乎初始化正常,但Jetty服务器开始抛出与日志记录相关的错误.我的src目录中有一个log4j.properties文件,包括log4j和slf4j-log4j12作为Maven依赖项.我知道我错了吗?

谢谢!

WARN - FAILED org.eclipse.jetty.server.Server@6b0e9064: java.lang.NoClassDefFoundError: org/mortbay/log/Log
java.lang.NoClassDefFoundError: org/mortbay/log/Log
    at com.sun.org.apache.commons.logging.JettyLog.<init>(JettyLog.java:36)
    at com.sun.org.apache.commons.logging.LogFactory.getLog(LogFactory.java:35)
    at org.apache.jasper.servlet.JspServlet.<clinit>(JspServlet.java:116)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at java.lang.Class.newInstance0(Class.java:374)
    at java.lang.Class.newInstance(Class.java:327)
    at org.eclipse.jetty.server.handler.ContextHandler$Context.createInstance(ContextHandler.java:2307)
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createInstance(ServletContextHandler.java:1164)
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createServlet(ServletContextHandler.java:1151)
    at org.eclipse.jetty.servlet.ServletHolder.newInstance(ServletHolder.java:976)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:521)
    at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:349)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:810)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:288)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1346)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:743)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:491)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:99)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117)
    at org.eclipse.jetty.server.Server.start(Server.java:355)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:99)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
    at org.eclipse.jetty.server.Server.doStart(Server.java:324)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
    at com.foo.rscontrolcenter.ControlCenter.main(ControlCenter.java:19)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) …
Run Code Online (Sandbox Code Playgroud)

java jetty embedded-jetty

5
推荐指数
1
解决办法
1万
查看次数

嵌入式Jetty服务器 - 没有JSP支持/,没有找到org.apache.jasper.servlet.JspServlet

我有以下代码使用嵌入式Jetty服务器以及简单的servlet和.jsp网页.但是,在编译并运行代码之后:

javac -cp lib/servlet-api.jar:lib/jetty-all.jar com/test/MyServlet.java 
javac -cp lib/servlet-api.jar:lib/jetty-all.jar com/test/ServerMain.java 
java -cp .:lib/servlet-api.jar:lib/jetty-all.jar com/test/ServerMain
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet
Run Code Online (Sandbox Code Playgroud)

导航到/index.jsp会出现500错误.

HTTP ERROR 500
Problem accessing /index.jsp. 
Reason:
JSP support not configured
Run Code Online (Sandbox Code Playgroud)

我已经阅读过这篇文章,但我不认为解决方案适用于此,因为我正在运行Jetty嵌入式而不是使用start.jar.

如何解决此错误,以便服务器成功运行并提供.jsp页面?

ServerMain.java

package com.test;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

public class ServerMain {

    public static void main(String[] args) throws InterruptedException {

        Server server = new Server(8080);
        WebAppContext webApp = new WebAppContext();
        webApp.setDescriptor("web.xml");
        webApp.setResourceBase("");
        webApp.setParentLoaderPriority(true);
        server.setHandler(webApp);

        try {
            server.start();
        } catch (Exception e) …
Run Code Online (Sandbox Code Playgroud)

java jsp jetty embedded-jetty

5
推荐指数
2
解决办法
4万
查看次数

标签 统计

embedded-jetty ×10

jetty ×8

java ×7

maven ×2

html ×1

http ×1

javascript ×1

jsp ×1

jstl ×1

opendaylight ×1

servlets ×1

spring ×1

trace ×1