标签: embedded-jetty

使用Maven Jetty插件部署war时获取FileNotFoundException

我正在使用Maven 3.0.3和Jetty插件.我收到以下错误:

java.io.FileNotFoundException:无法打开ServletContext资源[/WEB-INF/applicationContext.xml

我不明白,因为文件存在于target/mywar/WEB-INF/applicationContext.xml.我把这个文件称为web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4">
    <display-name>/jx-production-1.0-SNAPSHOT</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>Any ideas what I'm missing? Here is my Jetty plugin definition in my pom.xml …
    <profile>
        <id>jetty</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>7.2.2.v20101205</version>
                    <configuration>
                        <webAppConfig>
                            <contextPath>/all-new-jx</contextPath>
                            <descriptor>target/jx-1.0-SNAPSHOT/WEB-INF/web.xml</descriptor>
                        </webAppConfig>
                        <jettyConfig>config/jetty7/jetty.xml</jettyConfig>
                        <scanIntervalSeconds>10</scanIntervalSeconds>
                        <contextHandlers>
                            <contextHandler implementation="org.eclipse.jetty.server.handler.ContextHandler">
                                <contextPath>/all-new-jx-web</contextPath>
                                <resourceBase>${project.basedir}/target/web</resourceBase>
                                <handler implementation="org.eclipse.jetty.server.handler.ResourceHandler" />
                            </contextHandler>
                        </contextHandlers>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.eclipse.jetty</groupId>
                            <artifactId>jetty-rewrite</artifactId>
                            <version>7.2.2.v20101205</version>
                            <type>jar</type>
                            <scope>runtime</scope>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </profile>
Run Code Online (Sandbox Code Playgroud)

这是我得到的漫长而令人讨厌的错误:

2011-08-04 14:08:56.677:WARN ::上下文启动失败omjpJettyWebAppContext {/ all-new-jx,file:/ Users/davea/Documents/workspace/NissanUSA2/Technology/nna/mycousa/jx/src/main/webapp /},file:/ …

maven-2 jetty embedded-jetty maven maven-jetty-plugin

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

Spring Boot + Jetty + SSL端口

如何配置Spring Boot以在443处使用HTTPS端口运行Jetty.配置还应注意生成密钥.

简而言之,以下maven插件的等效配置,: -

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>keytool-maven-plugin</artifactId>
  <version>1.3</version>
  <executions>
    <execution>
      <phase>generate-resources</phase>
      <id>clean</id>
      <goals>
        <goal>clean</goal>
      </goals>
    </execution>
    <execution>
      <phase>generate-resources</phase>
      <id>genkey</id>
      <goals>
        <goal>generateKeyPair</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
    <dname>cn=my.hostname.tld</dname>
    <!-- put your CN here -->
    <keypass>jetty6</keypass>
    <storepass>jetty6</storepass>
    <alias>jetty6</alias>
    <keyalg>RSA</keyalg>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

和:-

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>maven-jetty-plugin</artifactId>
  <version>6.1.26</version>
  <configuration>
    <jvmArgs>-Xmx2048m -Xms1536m -XX:PermSize=128m -XX:MaxPermSize=256m</jvmArgs>
    <!-- http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin -->
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <connectors>
      <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
        <port>9999</port>
        <maxIdleTime>60000</maxIdleTime>
      </connector>
      <connector implementation="org.mortbay.jetty.security.SslSocketConnector">
        <port>9993</port>
        <maxIdleTime>60000</maxIdleTime>
        <keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
        <password>jetty6</password>
        <keyPassword>jetty6</keyPassword>
      </connector>
    </connectors>
    <contextPath>/</contextPath>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

embedded-jetty spring-boot

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

RESTEasy支持JAX-RS @RolesAllowed

我花了几个小时在嵌入式Jetty 9.1.0.v20131115和RESTEasy 3.0.5.Final中安装自定义登录服务.我的登录服务将在数据库中查找用户并为其分配角色.它看起来像这样:

final Constraint restConstraint = new Constraint();
restConstraint.setName(Constraint.__BASIC_AUTH);
restConstraint.setRoles(new String[]{"user", "admin");
restConstraint.setAuthenticate(true);
final ConstraintMapping restConstraintMapping = new ConstraintMapping();
restConstraintMapping.setConstraint(restConstraint);
restConstraintMapping.setPathSpec("/api/*");
final ConstraintSecurityHandler restSecurityHandler = new ConstraintSecurityHandler();
final LoginService myLoginService = new MyLoginService();
restSecurityHandler.setAuthenticator(new BasicAuthenticator());
restSecurityHandler.setRealmName(myLoginService.getName());
restSecurityHandler.addConstraintMapping(restConstraintMapping);
restSecurityHandler.setLoginService(myLoginService);
Run Code Online (Sandbox Code Playgroud)

我有用户joe-user谁拥有的角色user,和jane-admin谁既有useradmin角色.我有一个GET名为的REST 资源my-resource:

@RolesAllowed("admin")
Run Code Online (Sandbox Code Playgroud)

当我做一个HTTP GETmy-resource的浏览器中正确请求凭据,我可以登录,无论是joe-userjane-admin.问题是任何一个用户都被允许GET my-resource!!

我已经跟踪了一些Jetty代码,事实上,由于我的登录服务,Jetty要求登录用户支持哪些角色.不幸的是,无论用户如何,Jetty都会接受我指定的任何角色restConstraint.setRoles(new String[]{"user", "admin").

显然,RESTEasy层应该识别@RolesAllowed("admin")注释并验证用户.但是我如何让RESTEasy做到这一点?

jax-rs embedded-jetty resteasy

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

将 Jetty 8 升级到 Jetty 9

我正在从 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?

还有任何自定义的东西在运行时停止工作,这不是很明显可以找到/看到。

java eclipse jetty embedded-jetty

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

Maven Jetty 插件:不支持打包类型 [jar]

我创建了一个使用 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)

jetty embedded-jetty maven spring-boot

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

如何使用jetty8创建代理服务器?

我使用Java套接字创建了一个代理服务器(Fwd和Reverse).

这将听取在浏览器中配置的8080上的传入请求并将它们转发到另一个Proxy Server2.

并读取server2发送的响应并将其写入浏览器.

同时代码将记录请求和响应,并阻止某些预定义的请求类型来自浏览器.

现在我想使用Jetty执行此操作,并且还支持HTTPS请求.

我搜索了一些例子,但没有找到.

这启动服务器在8080,我已在浏览器的代理设置中配置为代理端口.

 import org.eclipse.jetty.server.Server;

import Handler.HelloHandler;

public class StartJetty
{
    public static void main(String[] args) throws Exception
    {
        Server server = new Server(8080);

        server.setHandler(new HelloHandler());
        server.start();
        server.join();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我用来监听请求并将响应写回浏览器的处理程序.

package Handler;

import java.io.IOException;

 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;

 import org.eclipse.jetty.server.Request;
 import org.eclipse.jetty.server.handler.AbstractHandler;

public class HelloHandler extends AbstractHandler
{
    final String _greeting;
          final String _body;

          public HelloHandler()
          {
              _greeting="Hello World";
              _body=null;
          }

          public HelloHandler(String greeting)
          {
              _greeting=greeting;
              _body=null;
          }

          public HelloHandler(String greeting,String body) …
Run Code Online (Sandbox Code Playgroud)

proxy jetty tunnel embedded-jetty

0
推荐指数
1
解决办法
9489
查看次数

jetty 获取 webapp 列表

在执行任何请求之前(在 init 方法中),我需要在 init 方法中从服务器获取一些服务器属性到我的 servlet 。实际上,我需要获取有关此服务器连接器上所有工作的列表、所有工作中的 web 应用程序以及最重要的 - 端口号或连接器。所需的码头版本 - 最多 8 个版本,包括。

所以我需要类似的东西org.eclipse.jetty.server.Server,但不是嵌入式,而是来自现有服务器,我的 servlet 正在运行。就使用此信息操作的 webapp 部署程序而言,此信息应该在码头上。但我找不到在哪里。

java servlets jetty embedded-jetty

0
推荐指数
1
解决办法
1281
查看次数

如何在Jetty中实现拒绝服务攻击最优策略

在Jetty中实现拒绝服务攻击保护的最佳方法是什么?所有类需要扩展或配置需要设置的内容.

java jetty embedded-jetty java-ee-6 jetty-8

0
推荐指数
1
解决办法
738
查看次数

Swagger 与嵌入式 Jetty

有人可以让我知道这是否是使用嵌入式码头配置 Swagger 的正确方法。

public class TestMain {

public static void main(String[] args) throws Exception {
    Server gs = new Server();
    ServletContextHandler sch = gs.getServletContextHandler();

    sch.addFilter(new FilterHolder(new RequestTrackerFilter()), "/*",     EnumSet.of(DispatcherType.REQUEST));
    sch.addFilter(new FilterHolder(new ActionIdFilter()), "/*", EnumSet.of(DispatcherType.REQUEST));

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(false);

    resource_handler.setResourceBase("public/2.0");

    ContextHandler context = new ContextHandler("/apitest");

    context.setHandler(resource_handler);

    ContextHandlerCollection contexts = new ContextHandlerCollection();


   setupSwaggerContextHandler();

  //     context.getServletContext().addListener(new SwaggerInitializer());

    contexts.setHandlers(new Handler[]{sch, context});

    gs.getServer().setHandler(contexts);

    gs.start();
}

private static ServletContextHandler setupSwaggerContextHandler() {
    // Configure Swagger-core
    final ServletHolder swaggerServletHolder = new ServletHolder(new JerseyJaxrsConfig());
    swaggerServletHolder.setName("JerseyJaxrsConfig");
    swaggerServletHolder.setInitParameter("api.version", "1.0.0"); …
Run Code Online (Sandbox Code Playgroud)

java embedded-jetty swagger

0
推荐指数
1
解决办法
4604
查看次数

Jetty:如何嵌套HandlerWrapper、HandlerList、ContextHandlerCollection、ContextHandler

我正在尝试在 Jetty 上构建一个 api 服务器。

我希望在 /apis/api1/endpoint、/apis/api2/endpoint、/apis/api3/endpoint 等路径上有多个 api

本质上我有一个 HandlerWrapper,它包含 ContextHandlerCollections 的 HandlerList,本质上只是做:

public void handle(...) {
    if (uri.startsWith("/apis/")) {
        log.info("This is an api request");
        this.getHandlerList.handle(...)
    } else {
        super.handle()
    }
}

private HandlerList getHandlerList() {
    HandlerList handlerList = new HandlerList();
    ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection();
    ContextHandler api1 = new ContextHandler("/apis/api1/endpoint");
    api1.setHandler(new Api1Handler());
    contextHandlerCollection.addHandler(api1);
    handlerList.addHandler(contextHandlerCollection);
    return handlerList
}
Run Code Online (Sandbox Code Playgroud)

现在当我尝试这样做时:

curl localhost:port/apis/api1/endpoint
Run Code Online (Sandbox Code Playgroud)

我收到 404 not found,但我在日志中看到语句“这是一个 api 请求”。

有什么提示吗?

我基本上希望每个 api1、api2 等都有一个 ContextHandlerCollection。并且 ContextHandlerCollection 应该由一组特定于端点的处理程序组成以供选择。

我缺少什么?

干杯,

java jetty embedded-jetty

0
推荐指数
1
解决办法
1672
查看次数

org.springframework.boot.context.embedded 不存在 - Gradle 构建 Spring Boot Jetty

我正在尝试用 Jetty 替换 Tomcat,作为我的嵌入式 servlet 容器。然后需要使用EmbeddedServletContainerCustomizer()来配置将80端口的请求重定向到443端口(HTTPS)。但是我一开始就被这些gradlew构建错误困住了:

RedirectHttpToHttpsOnJettyConfig.java:7: 错误:包 org.springframework.boot.context.embedded 不存在

导入 org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;

RedirectHttpToHttpsOnJettyConfig.java:8: 错误:包 org.springframework.boot.context.embedded 不存在

导入 org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;

RedirectHttpToHttpsOnJettyConfig.java:9: 错误:包 org.springframework.boot.context.embedded.jetty 不存在

导入 org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;

RedirectHttpToHttpsOnJettyConfig.java:10: 错误:包 org.springframework.boot.context.embedded.jetty 不存在

导入 org.springframework.boot.context.embedded.jetty.JettyServerCustomizer;

...

这是我的 build.gradle:

buildscript {
    ext {
        springBootVersion = '2.0.0.BUILD-SNAPSHOT'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

ext['thymeleaf.version'] = '3.0.9.RELEASE'

war { …
Run Code Online (Sandbox Code Playgroud)

embedded-jetty spring-boot

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