diff --git a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyContextHandler.java b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyContextHandler.java new file mode 100644 index 00000000000..94e96bce859 --- /dev/null +++ b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyContextHandler.java @@ -0,0 +1,62 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.transport.http_jetty; + +import org.eclipse.jetty.server.handler.ContextHandler; + +/** + * The Jetty-specific ContextHandler + */ +class JettyContextHandler extends ContextHandler { + JettyContextHandler() { + super(null, null, null); + _scontext = new JettyContext(); + } + + class JettyContext extends Context { + @Override + public String getRequestCharacterEncoding() { + return getDefaultRequestCharacterEncoding(); + } + + @Override + public void setRequestCharacterEncoding(String encoding) { + if (!isStarting()) { + throw new IllegalStateException(); + } + + setDefaultRequestCharacterEncoding(encoding); + } + + @Override + public String getResponseCharacterEncoding() { + return getDefaultResponseCharacterEncoding(); + } + + @Override + public void setResponseCharacterEncoding(String encoding) { + if (!isStarting()) { + throw new IllegalStateException(); + } + + setDefaultResponseCharacterEncoding(encoding); + } + } +} diff --git a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPHandler.java b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPHandler.java index e4f54d08e07..2be0114cc1c 100644 --- a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPHandler.java +++ b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPHandler.java @@ -43,6 +43,7 @@ public JettyHTTPHandler(JettyHTTPDestination jhd, boolean cmExact) { contextMatchExact = cmExact; jettyHTTPDestination = jhd; } + public JettyHTTPHandler(Bus bus) { this.bus = bus; } @@ -84,7 +85,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques } public ContextHandler createContextHandler() { - return new ContextHandler(); + return new JettyContextHandler(); } public Bus getBus() { diff --git a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java index 8cd8764b31d..57dd88dcfa4 100644 --- a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java +++ b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java @@ -494,6 +494,9 @@ public synchronized void addServant(URL url, JettyHTTPHandler handler) { } String contextName = HttpUriMapper.getContextName(url.getPath()); + if (contextName.isEmpty()) { + contextName = "/"; + } ContextHandler context = handler.createContextHandler(); context.setContextPath(contextName); // bind the jetty http handler with the context handler