小编Joa*_*elt的帖子

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万
查看次数

获取“x-amzn-Remapped-WWW-Authenticate 而不是 WWW-Authenticate 并且码头客户端无法识别

AWS API 网关将 WWW-Authenticate 标头重新映射为 x-amazn-remapped-WWW-Authenticate。我们的客户使用 java jetty 客户端并且码头客户端失败,因为码头客户端正在寻找 WWW-Authenticate 标头

  1. 如何从 AWS API 网关发送 WWW-Authenticate
  2. Jetty 客户端的任何修复?

我尝试在 1.AWS API 网关响应上使用网关响应 - 处理 400 2. 集成响应 - 处理 400 个请求,然后设置 WWW-authenticate 标头 #set($inputRoot = $input.path('$')) $input.json("$") #if($inputRoot.toString().contains("error")) #set($context.responseOverride.status = 400) #set($context.responseOverride.header.WWW-Authenticate = 'value')

jetty amazon-web-services

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

如何在 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
查看次数

检测运行的servlet容器是否为Eclipse Jetty

我尝试检测应用程序是否在Eclipse Jetty上作为servlet容器运行.我找到了Mortbay Jetty解决方案,但不是Eclipse的实际版本.我修改了现有的检查并将Classpath从"/org/mortbay/jetty/Server.class"替换为"/org/eclipse/jetty/server/Server.class",但是在Jetty 9上检查失败.运行相同的应用程序tomcat很成功.我错了什么?

代码如下:

private boolean detect(final String clazz) {
  try {
    final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
    systemClassLoader.loadClass(clazz);
    return true;
  } catch (final ClassNotFoundException cnfe) {
    final Class<?> classObj = getClass();
      if (classObj.getResource(clazz) != null) {
        return true;
  } else {
        return false;
      }
  }
}
Run Code Online (Sandbox Code Playgroud)

调用函数:

detect("/org/eclipse/jetty/server/Server.class");
Run Code Online (Sandbox Code Playgroud)

eclipse jetty detection

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

杰克逊注释被忽略了

我正在尝试使用Jackson注释来重命名序列化期间生成的一些json标签.所有注释都编译良好,当我运行时,杰克逊序列化工作除了所有杰克逊注释完全被忽略.即使像@JsonIgnore或@JsonProperty这样的基本对json响应也没有影响.我在构建路径中拥有的库是:

jsr311-qpi-1.1.1.jar
jackson-[core|databind|annotations]-2.2.0.jar
Run Code Online (Sandbox Code Playgroud)

我正在Eclipse中运行jetty外部程序,外部程序设置如下:

Location: .../apache-maven-2.2.1/bin/mvnDebug.bat
working Directory: ${workspace_loc:/ohma-rest-svr}
Arguments: jetty:run
Run Code Online (Sandbox Code Playgroud)

将远程Java应用程序配置设置为:

Host: localhost
Port: 8000
Run Code Online (Sandbox Code Playgroud)

没有错误消息可以使用,我有点失去了尝试的东西.任何想法,将不胜感激.

这是我需要序列化的类的一些代码示例:

@XmlRootElement(name="ads-parameter")
public class DefineParameterResponse {

    private Date _createdAt = new Date();

    @JsonProperty("created-at")
    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd,HH:00", timezone="CET")
    @XmlElement
    public String getCreatedAt() {
        return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(_createdAt);
    }

    @JsonProperty("created-at")
    public void setCreatedAt(Date createdAt) {
        this._createdAt = createdAt;
    }


    private String _dataTitle1 = "Default Title1";
    @XmlElement
    @JsonProperty("data-title-1")
    public String getDataTitle1() {
        return _dataTitle1;
    }

    @JsonProperty("data-title-1")
    public void setDataTitle1(String dataTitle1) {
        this._dataTitle1 = dataTitle1;
    }


    @XmlElement
    @JsonProperty("data-title-2")
    public …
Run Code Online (Sandbox Code Playgroud)

java json annotations jetty jackson

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

java.lang.SecurityException 与 javax.servlet.servlet-api jars 的两个冲突版本

我正在努力解决我无法解决的 Java/Maven/Jetty 问题。我有一个 Java Jetty 服务器可以正确启动,但是一旦向它发送 HTTP 请求,它就会中止显示此堆栈跟踪:

2013-09-30 08:40:24,534 [qtp297240915-11 Selector0] WARN  org.eclipse.jetty.io.nio - java.lang.SecurityException: class "javax.servlet.AsyncContext"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:806) ~[na:1.6.0_37]
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:487) ~[na:1.6.0_37]
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:625) ~[na:1.6.0_37]
at java.lang.ClassLoader.defineClass(ClassLoader.java:615) ~[na:1.6.0_37]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) ~[na:1.6.0_37]
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) ~[na:1.6.0_37]
at java.net.URLClassLoader.access$000(URLClassLoader.java:58) ~[na:1.6.0_37]
at java.net.URLClassLoader$1.run(URLClassLoader.java:197) ~[na:1.6.0_37]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_37]
at java.net.URLClassLoader.findClass(URLClassLoader.java:190) ~[na:1.6.0_37]
at java.lang.ClassLoader.loadClass(ClassLoader.java:306) ~[na:1.6.0_37]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) ~[na:1.6.0_37]
at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ~[na:1.6.0_37]
at org.eclipse.jetty.server.AbstractHttpConnection.<init>(AbstractHttpConnection.java:157) ~[jetty-server-8.1.9.v20130131.jar:8.1.9.v20130131]
at org.eclipse.jetty.server.AsyncHttpConnection.<init>(AsyncHttpConnection.java:50) ~[jetty-server-8.1.9.v20130131.jar:8.1.9.v20130131]
at org.eclipse.jetty.server.nio.SelectChannelConnector.newConnection(SelectChannelConnector.java:285) …
Run Code Online (Sandbox Code Playgroud)

java jetty maven

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

!从Jetty 7切换到Jetty 9时出现asyncSupported异常

我们最近升级了我们的码头版本.当我们这样做时,我们的两个遗留的gui war文件,在一段时间内没有人修改过,停止正常工作.我相信我找到了代理的根本原因(用于代理另一个端口上的restful接口),对代理的任何调用都会抛出异常:

 IllegalStateException: !asyncSupported
Run Code Online (Sandbox Code Playgroud)

我不知道为什么会出现这种情况,而不是旧的码头.我目前无法构建war文件,只有一个开发人员可以构建它是一个混乱,但是我使用jetty -x解压缩它并且对web.xml文件的servlet部分进行解压缩:

<async-supported>true</async-supported>
Run Code Online (Sandbox Code Playgroud)

然后使用jar c命令重新解压缩.这似乎没有帮助,虽然现在我在我的码头日志中得到例外情况,而他们只会在浏览器中显示.

任何人都可以告诉我如何激活异步支持和/或为什么jetty中的切换会导致这种情况?

java jetty war

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

如何为Jetty 9启用GZIP

我正在尝试在Jetty 9上启用gzip压缩.我不想在我的web.xml中配置它,因此基于Jetty文档我已经配置了override-web.xml.我不是在嵌入模式下使用Jetty,而是作为容器使用Jetty.

在我的{jetty.home}/webapps文件夹中,我是我的战争档案 - cc.war.我还定义了一个cc.xml如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

<!-- ==================================================================
Configure and deploy the test web application in $(jetty.home)/webapps/test

Note. If this file did not exist or used a context path other that /test
then the default configuration of jetty.xml would discover the test
webapplication with a WebAppDeployer.  By specifying a context in this
directory, additional configuration may be specified and hot deployments
detected.
===================================================================== -->

<Configure class="org.eclipse.jetty.webapp.WebAppContext">

  <!-- - - - - …
Run Code Online (Sandbox Code Playgroud)

java jetty

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

嵌入式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万
查看次数

嵌入式Jetty(访问)请求记录

我正在使用JAX-RS和嵌入式Jetty创建一些rest API.我通过在Server.java文件中添加LogRequestHandler来启用Server日志记录.

问题是为什么码头为每个请求写200 0:0:0:0:0:0:0:1 - - [03/Nov/2016:16:59:57 +0500] "GET /app/check HTTP/1.1" 200 - 4

虽然检查终点未实现但在应用程序中不存在.

源代码:

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    //context.setContextPath("/");

    ResourceConfig config = new ResourceConfig();
    config.packages("server");
    ServletHolder servlet = new ServletHolder(new ServletContainer(config));
    context.addServlet(servlet,"/*");

    NCSARequestLog requestLog = new NCSARequestLog("/var/logs/jetty/log-yyyy_mm_dd.request.log");
    requestLog.setAppend(true);
    requestLog.setExtended(false);
    requestLog.setLogTimeZone("GMT+5");
    requestLog.setLogLatency(true);
    requestLog.setRetainDays(90);
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    requestLogHandler.setRequestLog(requestLog);

    HandlerList topLevelHandlers = new HandlerList();
    topLevelHandlers.addHandler(context);
    topLevelHandlers.addHandler(requestLogHandler);

    try {
        jettyServer.setHandler(topLevelHandlers);
        jettyServer.dumpStdErr();
        jettyServer.start();
    }
Run Code Online (Sandbox Code Playgroud)

jetty jersey-2.0

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