标签: embedded-jetty

使用嵌入式Jetty 7发布JAX-WS端点

任何人都可以帮忙吗?

我想使用嵌入式Jetty 7作为端点.这是我试过的:

public class MiniTestJetty {

@WebService(targetNamespace = "http")
public static class Calculator {

    @Resource
    WebServiceContext context;

    public int add(int a, int b) {
        return a + b;
    }
}


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

    Calculator calculator = new Calculator();
    Endpoint.publish("http://localhost:" + port + "/calc", calculator);

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

}

但我无法确定这是否真的使用Jetty而不是默认的sun HttpServer.

一篇博客提到

 System.setProperty("com.sun.net.httpserver.HttpServerProvider",
       "org.mortbay.jetty.j2se6.JettyHttpServerProvider");
Run Code Online (Sandbox Code Playgroud)

但是在Jetty 7中似乎没有这样的HttpServerProvider.

感谢任何帮助,Axel.

java jax-ws embedded-jetty

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

我在哪里将jetty.xml文件与Jetty嵌入?

我刚刚开始使用Jetty(Jetty 6 w/Java 6).使用Jetty 6的示例文件,我放置了我的xml配置文件.在与我的java文件相同的目录中.但是当我运行项目时,我得到了这个错误.

Exception in thread "main" java.lang.NullPointerException at net.test.FileServerXml.main(FileServerXml.java:13
Run Code Online (Sandbox Code Playgroud)

这是示例代码:

`package net.test;


import org.mortbay.jetty.Server;
import org.mortbay.resource.Resource;
import org.mortbay.xml.XmlConfiguration;

public class FileServerXml
{
    public static void main(String[] args) throws Exception
    {
        Resource fileserver_xml = Resource.newSystemResource("fileserver.xml");
        XmlConfiguration configuration = new XmlConfiguration(fileserver_xml.getInputStream());
        Server server = (Server)configuration.configure();
        server.start();
        server.join();

    }
 }
Run Code Online (Sandbox Code Playgroud)

构建文件系统的正确方法是什么,以便找到我的xml文件?

eclipse jetty embedded-jetty

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

如何在嵌入式Jetty中启动Lift?

我有一个服务器,它将作为其职责的一部分提供一些Web内容.它使用嵌入式Jetty,我想为它添加一些Lift的美感(模板,演员等).

问题是所有电梯示例都使用Jetty作为容器.有没有办法在我的嵌入式Jetty中启动Lift?如果是,怎么样?

scala jetty lift embedded-jetty

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

嵌入式Jetty是否能够设置过滤器的init-params?

假设我使用以下代码运行嵌入式jetty.我想将一些参数传递给我的过滤器.当我查看Jetty API添加过滤器时 - 没有设置init-params的选项.我的问题是嵌入式Jetty能否设置过滤器的init-params?

import java.io.IOException;
import java.util.EnumSet;

import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;

public class JettyFilter {

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

    ServletHandler handler = new ServletHandler();
    server.setHandler(handler);

    handler.addServletWithMapping(HelloServlet.class, "/*");
    handler.addFilterWithMapping(HelloPrintingFilter.class, "/*",
        EnumSet.of(DispatcherType.REQUEST));

    server.start();
    server.join();
  }

  public static class HelloServlet extends HttpServlet {
    private static final long serialVersionUID = …
Run Code Online (Sandbox Code Playgroud)

java servlets jetty filter embedded-jetty

8
推荐指数
2
解决办法
5516
查看次数

Jetty ConnectHandler与上游代理

我正在使用Jetty的ConnectHandler通过CONNECT代理SSL.

现在,我想配置ConnectHandler将请求转发给另一个代理,该代理将为我处理CONNECT.

有没有办法配置ConnectHandler来执行此操作?我检查了ConnectHandler源代码,但找不到这样做的方法.

ssl proxy jetty embedded-jetty

8
推荐指数
0
解决办法
168
查看次数

启动JettyRun时排除Gradle类路径运行时

我有你的磨机Gradle web应用程序项目的基本运行,它工作正常,但我注意到Gradle的运行时类路径被包含在可能与Web应用程序冲突的jetty中.

请注意,gradle使用的是较旧版本的logback,并且SL4J警告它在类路径中发现了多个绑定.

:jettyRun
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/dev/java/tools/gradle-1.0-milestone-5/lib/logback-classic-0.9.29.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/kirk.rasmussen/.gradle/caches/artifacts-3/ch.qos.logback/logback-classic/fd9fe39e28f1bd54eee47f04ca040f2b/jars/logback-classic-0.9.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Run Code Online (Sandbox Code Playgroud)

有没有办法在运行jettyRun任务时排除gradle运行时类路径?我正在使用最新的1.0里程碑5版Gradle.

我正在寻找Ant中javac任务中'includeAntRuntime'的内容.

http://ant.apache.org/manual/Tasks/javac.html

includeAntRuntime是否在类路径中包含Ant运行时库; 默认为yes,除非设置了build.sysclasspath.通常最好将其设置为false,以便脚本的行为对运行它的环境不敏感.

剥离build.gradle:

apply plugin: 'groovy'
apply plugin: 'war'
apply plugin: 'jetty'

jettyRun {
    contextPath = ''
}
Run Code Online (Sandbox Code Playgroud)

jetty embedded-jetty gradle

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

嵌入式Jetty - Spring MVC - 视图解析器 - 无XML - HTTP错误:404

我正在尝试使用嵌入式Jetty建立一个简单的Spring MVC服务器.我已经设置了服务器,启用了spring并为.jsp文件配置了一个视图解析器.控制器给我404以下消息:

Problem accessing /jsp/test.jsp. Reason:
Not Found
Run Code Online (Sandbox Code Playgroud)

有谁知道问题是什么?我一直在谷歌上搜索两天.

服务器:

private static final int DEFAULT_PORT = 8080;
private static final String CONTEXT_PATH = "/";
private static final String CONFIG_LOCATION = "spring.config";
private static final String MAPPING_URL = "/*";

private EmbeddedJettyServer(){
}

public static void main(String[] args) throws Exception {
    Server server = new Server(DEFAULT_PORT);
    server.setHandler(getServletContextHandler(getContext()));
    server.start();
    server.join();
}

private static ServletContextHandler getServletContextHandler(WebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    contextHandler.setErrorHandler(null);
    contextHandler.setContextPath(CONTEXT_PATH);
    contextHandler.addServlet(new ServletHolder(new DispatcherServlet(context)), MAPPING_URL);
    contextHandler.addEventListener(new ContextLoaderListener(context));
    contextHandler.setResourceBase(new …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc embedded-jetty

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

泽西岛:如何将杰克逊添加到Servlet Holder

我正在使用Jersey创建一个嵌入式Jetty webapp.我不知道如何在这里添加杰克逊自动JSON serde:

    ServletHolder jerseyServlet = context.addServlet(
       org.glassfish.jersey.servlet.ServletContainer.class, "/*");
    jerseyServlet.setInitOrder(0);

    jerseyServlet.setInitParameter(
        ServerProperties.PROVIDER_CLASSNAMES,
        StringUtils.join(
            Arrays.asList(
                HealthCheck.class.getCanonicalName(),
                Rest.class.getCanonicalName()),
            ";"));

    // Create JAX-RS application.
    final Application application = new ResourceConfig()
        .packages("com.example.application")
        .register(JacksonFeature.class);

    // what do I do now to tie this to the ServletHolder?
Run Code Online (Sandbox Code Playgroud)

如何ResourceConfig在ServletHolder中注册这个,以便在使用注释的地方使用Jackson @Produces(MediaType.APPLICATION_JSON)?这是嵌入式Jetty应用程序的完整主类

package com.example.application.web;

import com.example.application.api.HealthCheck;
import com.example.application.api.Rest;
import com.example.application.api.Frontend;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.ServerProperties;

import javax.ws.rs.core.Application;
import java.util.Arrays;

public class JettyStarter {

public static void main(String[] …
Run Code Online (Sandbox Code Playgroud)

java jetty jersey embedded-jetty jackson

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

如何优雅地关闭嵌入式码头

我有一个应用程序在嵌入式jetty服务器上运行.现在我想启动/停止服务器作为服务.我使用脚本启动服务器.

java $JAVA_OPTS -DREQ_JAVA_VERSION=$JAVA_VERSION -jar myjetty.jar
Run Code Online (Sandbox Code Playgroud)

主类

Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(PORT);
server.addConnector(connector);
HandlerCollection handlers = new HandlerCollection();
NCSARequestLog requestLog = new NCSARequestLog();
requestLog.setFilename(home + "/logs/access_" + logFileDateFormat
            + ".log");
requestLog.setFilenameDateFormat(logFileDateFormat);
requestLog.setRetainDays(10);
requestLog.setAppend(true);
requestLog.setExtended(false);
requestLog.setLogCookies(false);
requestLog.setLogTimeZone(TimeZone.getDefault().getID());
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
handlers.addHandler(requestLogHandler);
server.setHandler(handlers);
server.start();
server.join();
Run Code Online (Sandbox Code Playgroud)

这启动了服务器.通过Web调用停止和/或重新启动嵌入式Jetty实例可用于停止服务器但是,如何从脚本中停止服务器?我应该做些什么来改变主类中的服务器.

java jetty embedded-jetty

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

以编程方式设置Jetty配置以增加允许的URL长度

我们正在使用嵌入式Jetty 9.3.1.v20150714,并遇到了我们的长查询URL与其他标头相结合的问题比允许的长.

解决方案看起来很简单:增加requestHeaderSizeHttpConfiguration.但是我该如何轻松地做到这一点?我正在创建一个Server,一个ServletContextHandler和一个ServletHolder.但是,在一个自定义的混合HttpConfiguration,我必须创建一个新的ServerConnectorHttpConnectionFactory?我是否必须覆盖HTTP和HTTPS配置?如何在requestHeaderSize不重新配置所有默认值的情况下轻松更改?

java url embedded-jetty http-headers httpconfiguration

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