Merge remote-tracking branch 'upstream/jetty-9.4.x' into jetty-10.0.x

This commit is contained in:
olivier lamy 2018-11-30 17:59:42 +10:00
commit 3e1f814674
3 changed files with 109 additions and 30 deletions

View File

@ -110,7 +110,7 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer
_connectors.put(addr.getHostName() + addr.getPort(), connector);
}
protected Server getServer()
{
return _server;
@ -218,8 +218,8 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer
try
{
connector.stop();
}
catch (Exception ex)
}
catch (Exception ex)
{
LOG.warn(ex);
}
@ -237,7 +237,7 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer
HttpSpiContextHandler jettyContextHandler = context.getJettyContextHandler();
ContextHandlerCollection chc = _server.getChildHandlerByClass(ContextHandlerCollection.class);
if (chc == null)
throw new RuntimeException("could not find ContextHandlerCollection, you must configure one");

View File

@ -18,9 +18,9 @@
package org.eclipse.jetty.http.spi;
import java.io.IOException;
import java.net.InetSocketAddress;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsServer;
import com.sun.net.httpserver.spi.HttpServerProvider;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
@ -29,9 +29,8 @@ import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ThreadPool;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsServer;
import com.sun.net.httpserver.spi.HttpServerProvider;
import java.io.IOException;
import java.net.InetSocketAddress;
/**
* Jetty implementation of <a href="http://java.sun.com/javase/6/docs/jre/api/net/httpserver/spec/index.html">Java HTTP Server SPI</a>

View File

@ -18,68 +18,148 @@
package org.eclipse.jetty.http.spi;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Endpoint;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import java.net.URL;
public class TestEndpointMultiplePublishProblem
{
private static String default_impl = System.getProperty("com.sun.net.httpserver.HttpServerProvider");
private static String default_impl = System.getProperty( "com.sun.net.httpserver.HttpServerProvider" );
@BeforeAll
public static void change_Impl()
{
System.setProperty("com.sun.net.httpserver.HttpServerProvider", JettyHttpServerProvider.class.getName());
System.setProperty( "com.sun.net.httpserver.HttpServerProvider", JettyHttpServerProvider.class.getName() );
}
@AfterAll
public static void restore_Impl()
{
if(default_impl != null)
if ( default_impl != null )
{
System.setProperty( "com.sun.net.httpserver.HttpServerProvider", default_impl );
}
}
@Test
public void mainJetty() throws Exception {
public void mainJetty()
throws Exception
{
Server jettyWebServer = new Server(new DelegatingThreadPool(new QueuedThreadPool()));
ServerConnector connector = new ServerConnector(jettyWebServer);
connector.setHost("localhost");
connector.setPort(0);
connector.setReuseAddress(true);
jettyWebServer.addConnector(connector);
jettyWebServer.setHandler(new ContextHandlerCollection());
Server jettyWebServer = new Server( new DelegatingThreadPool( new QueuedThreadPool() ) );
ServerConnector connector = new ServerConnector( jettyWebServer );
connector.setHost( "localhost" );
connector.setPort( 0 );
connector.setReuseAddress( true );
jettyWebServer.addConnector( connector );
jettyWebServer.setHandler( new ContextHandlerCollection() );
JettyHttpServerProvider.setServer(jettyWebServer);
JettyHttpServerProvider.setServer( jettyWebServer );
jettyWebServer.start();
Endpoint.publish(String.format("http://%s:%d/hello", "localhost", 0), new Ws());
// Comment out the below line for success in later java such as java8_u172, works before u151 or so
Endpoint.publish(String.format("http://%s:%d/hello2", "localhost", 0), new Ws());
Endpoint.publish( String.format( "http://%s:%d/hello", "localhost", 0 ), new WsHello() );
Endpoint.publish( String.format( "http://%s:%d/hello2", "localhost", 0 ), new WsHello() );
int port = connector.getLocalPort();
System.out.printf("Started, check: http://localhost:%d/hello?wsdl%n", port);
HttpClient httpClient = new HttpClient();
httpClient.start();
{
String url = String.format( "http://localhost:%d/hello", port );
String urlWsdl = url + "?wsdl";
ContentResponse contentResponse = httpClient.newRequest( url ).send();
Assertions.assertEquals( 200, contentResponse.getStatus() );
HelloMessengerService helloMessengerService = new HelloMessengerService( new URL( urlWsdl ) );
Hello hello = helloMessengerService.getHelloMessengerPort();
( (BindingProvider) hello ).getRequestContext().put( BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url );
String helloResponse = hello.hello();
Assertions.assertEquals( "G'Day mate!", helloResponse );
}
{
String url2 = String.format( "http://localhost:%d/hello2", port );
String url2Wsdl = url2 + "?wsdl";
ContentResponse contentResponse = httpClient.newRequest( url2Wsdl ).send();
Assertions.assertEquals( 200, contentResponse.getStatus() );
HelloMessengerService helloMessengerService = new HelloMessengerService( new URL( url2Wsdl ) );
Hello hello = helloMessengerService.getHelloMessengerPort();
( (BindingProvider) hello ).getRequestContext().put( BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url2 );
String helloResponse = hello.hello();
Assertions.assertEquals( "G'Day mate!", helloResponse );
}
httpClient.stop();
jettyWebServer.stop();
}
@WebService( targetNamespace = "http://org.eclipse.jetty.ws.test", name = "HelloService" )
public interface Hello
{
@WebMethod
String hello();
}
@WebService
public static class Ws {
@WebService( targetNamespace = "http://org.eclipse.jetty.ws.test", name = "HelloService" )
public static class WsHello
implements Hello
{
@WebMethod
public String hello() {
return "Hello";
public String hello()
{
return "G'Day mate!";
}
}
@WebServiceClient( name = "HelloService", targetNamespace = "http://org.eclipse.jetty.ws.test" )
public static class HelloMessengerService
extends Service
{
public HelloMessengerService( URL wsdlLocation )
{
super( wsdlLocation, //
new QName( "http://org.eclipse.jetty.ws.test", "WsHelloService" ) );
}
@WebEndpoint( name = "HelloServicePort" )
public Hello getHelloMessengerPort()
{
return super.getPort( new QName( "http://org.eclipse.jetty.ws.test", "HelloServicePort" ), //
Hello.class );
}
}
private void assertWsdl( String wsdl )
throws Exception
{
}
}