我正在尝试在托管模式下运行时在后端java代码中调用Web服务.一切都很好,GWT RPC调用工作,我可以在服务器上看到它,然后一旦它尝试调用外部Web服务(使用jax-ws),jetty就会出现内部服务器错误(500).
我已经将日志一直转到ALL,但我仍然没有看到任何堆栈跟踪或导致此错误.我只得到一行关于请求标头和响应的500错误.
有没有人知道内部码头是否在某处保存了日志文件,或者我如何调试错误?
我在OS X 10.6.1上运行GWT 1.7
编辑:我知道我可以使用-noserver选项,但我真的很想知道这个东西在哪里生活!
任何人都可以帮忙吗?
我想使用嵌入式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.
我刚刚开始使用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文件?
我想用Java和Web技术创建一个桌面应用程序.选择Java的主要原因是,它是免费的,开源的,因此我们的投资也很少,我们将节省大量的投资相对于许可费用等.此外,选择Web技术最主要的原因是因为我们目前的程序员以及与网络技术,如HTML,CSS,Ajax的精通,我们有在网络技术创造惊人的UI很好的经验.
我会告诉你一些我们想要创建的软件.它将是一个基于桌面的软件,即ERP软件.
关键要求是应该有一个很好的用户界面,它应该是快速的,而不是非常耗费资源.
我听说实现一个很棒的GUI是可能的,但在Java中很难实现.它可以完成但很复杂,而在Visual Studio,Microsoft产品中执行相同操作非常简单.
我还检查了Adobe Air,诺基亚QT等,但它们对我们来说都非常昂贵,我们正在寻找使用Java技术的前端浏览器UI和后端嵌入式服务器/数据库.
是否有可能创建一个桌面软件,其中使用Web技术创建UI,并且有一个嵌入式服务器(如jetty或tomcat)和数据库,后端编程将使用Java.JavaFX如何适应这一点?
基本上,桌面应用程序将有一个嵌入式浏览器(mozilla或一些可以与软件一起打包的java浏览器),但最终用户永远不会意识到这一点.
我期待得到关于同样的反馈.您能否提供一些以类似的java + Web技术组合创建的软件示例.
我确实研究过像PulpTunes和Zimbra这样的软件,它们类似,但它们似乎连接到互联网以显示数据.我们的软件将完全是一个离线桌面应用程序.
我想要做的是构建一个JAR包含我的项目的可执行文件.我已经将它的依赖项包含在它旁边,也包含在JAR文件中,所以我的目录列表看起来像这样:
〜/项目/ Java的/ web应用程序输入/输出:
网络app.jar
dependency1.jar
dependency2.jar
dependency3.jar
我知道并确信我的问题不是来自依赖关系,因为我的应用程序正常运行,直到我启动Jetty嵌入式的那一刻.
我用来启动Jetty的代码是这样的:
public class ServerExecutionGoal implements ExecutionGoal {
private final static Logger logger = Logger.getLogger(ServerExecutionGoal.class);
private WebAppContext getWebAppContext() throws IOException {
WebAppContext context = new WebAppContext();
System.out.println("context = " + context);
context.setResourceBase(new PathMatchingResourcePatternResolver().getResource("classpath:/webapp").getURL().toExternalForm());
context.setContextPath("/");
context.setLogger(new StdErrLog());
return context;
}
@Override
public void execute(Map<String, Object> stringObjectMap) throws ExecutionTargetFailureException {
logger.info("Instantiating target server ...");
final Server server = new Server(8089);
final ContextHandlerCollection handlerCollection = new ContextHandlerCollection();
try {
handlerCollection.setHandlers(new Handler[]{new …Run Code Online (Sandbox Code Playgroud) 今天我有了构建一个非常简单的Web应用程序的想法,该应用程序将由REST后端提供支持.因为我想要一个非常轻量级的服务器,所以我开始关注Jetty.因为我想尝试另一个JAX-RS实现而不是Jersey我看了RestEasy.我认为这两个很容易实现.我错了...
我导入了基本的Jetty服务器和servlet依赖项,因为我认为这是基本(仅限REST)Jetty服务器的唯一服务器要求(我总是尝试使用webapp依赖项;这给出了相同的错误).
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.0.0.RC0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.0.0.RC0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.0.0.RC0</version>
<scope>compile</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
然后我导入了基本的RestEasy依赖项.
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.1.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.0.1.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>async-http-servlet-3.0</artifactId>
<version>3.0.1.Final</version>
<scope>compile</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
主要方法:
public class ExampleActivator {
public static void main(String args[]) throws Exception {
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
ServletHolder h = new ServletHolder(new HttpServlet30Dispatcher());
h.setInitParameter("javax.ws.rs.Application", "packages.ExampleResources");
context.addServlet(h, "/*");
server.setHandler(context);
server.start();
server.join();
}
}
Run Code Online (Sandbox Code Playgroud)
ExampleResources:
public …Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用嵌入式Jetty的项目(不幸的是我只是"继承"了项目的服务器端,并且对Jetty及其配置的使用不是很熟悉).
刚出现一个奇怪的案例 - 我会尽力描述:
基于Web的UI(使用AngularJS,来自不同的域,因此使用CORS)发送POST请求以更改服务器上某些内容的状态.这在过去的某个时刻起作用(它可能是大约一个月前使用过的).
昨天这停止了工作.检查REST调用,我看到首先发出OPTIONS请求.POST的内容类型是application/json,所以基于我读过的内容,这是正确的.我不确定为什么之前没有发送过 - 有可能该公司最近更新了Chrome版本,旧版本没有发送预检请求,但这只是猜测.在任何情况下,我认为这是我的应用程序中为JetS配置CORS的相关代码:
FilterHolder holder = new FilterHolder(new CrossOriginFilter());
holder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
holder.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER, "true");
appHandler.addFilter(holder, "/*", EnumSet.of(DispatcherType.REQUEST));
Run Code Online (Sandbox Code Playgroud)
一切都适用于POST请求.我可以通过使用--disable-web-security标志启动Chrome来验证这一点.没有发送OPTIONS请求,并且POST正常工作.
我的想法是,因为它适用于POST,它不是授权或安全问题 - 它只是没有正确配置Jetty来处理预检请求(它只返回401).
我找不到很多关于嵌入式Jetty的文档,以及哪些CrossOriginFilter常量在调用setInitParameter时用作属性键(而且,因为该方法调用的第二个参数是一个String,我真的不知道如何格式化值).
我应该在CrossOriginFilter上设置哪些参数来处理OPTIONS请求?如果我上面说过任何错误或做出任何错误的假设,请纠正我!我对这方面的经验非常有限.
在我的一个项目中,我已经将Jersey从版本升级2.14到2.23.但是我遇到了一个问题需要花费很多时间.我的项目ExceptionMapper为a 定义了自己的ValidationException,但不幸的是,Jersey已经为这个异常提供了一个内置的异常映射器,我无法覆盖它.
我已正确注册(我检查过)我自己的映射器,如下所示:
@Provider
public class ValidationExceptionMapper implements
ExceptionMapper<ValidationException> {
@Override
public Response toResponse(ValidationException exception) {
return Response.status(Status.BAD_REQUEST).build();
}
}
Run Code Online (Sandbox Code Playgroud)
但它永远不会被召唤.泽西总是拿起来org.glassfish.jersey.server.validation.internal.ValidationExceptionMapper.我也试过@Priority为我的自定义映射器使用 注释,但不幸的是Jersey没有考虑它.
那么发生了什么?它在以前的Jersey版本中运行得非常好,所以它似乎是一个回归错误.
我放弃.有线索吗?
我想能够去
https://localhost:8080/users/pages/profile (没有服务器失败)而不是 https://localhost:8080/users/pages/profile.html
所以我试过了
ServletContextHandler pagesContext = new ServletContextHandler();
pagesContext.setContextPath("/users/pages");
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase("./src/main/webapp/pages");
resourceHandler.setDirectoriesListed(true);
pagesContext.setHandler(resourceHandler);
pagesContext.addServlet(new ServletHolder("default", DefaultServlet.class), "*.html");
// TODO this is not working currently
jettyServer.addHandler(pagesContext);
Run Code Online (Sandbox Code Playgroud)
但它不起作用!它抱怨profile页面不存在但profile.html工作正常
我正在使用Jetty的ConnectHandler通过CONNECT代理SSL.
现在,我想配置ConnectHandler将请求转发给另一个代理,该代理将为我处理CONNECT.
有没有办法配置ConnectHandler来执行此操作?我检查了ConnectHandler源代码,但找不到这样做的方法.