Skip to content

Commit

Permalink
Issue jetty#3165 - Configure the HttpClient via XmlHttpClientProvider
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Feb 18, 2019
1 parent 2c0ef55 commit b72f6c5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//

package org.eclipse.jetty.websocket.javax.server;

import java.net.URI;
Expand All @@ -16,9 +34,6 @@
import javax.websocket.WebSocketContainer;
import javax.websocket.server.ServerContainer;

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.AuthenticationStore;
import org.eclipse.jetty.client.util.BasicAuthentication;
import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.HashLoginService;
Expand All @@ -30,9 +45,6 @@
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.util.security.Credential;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainer;
import org.eclipse.jetty.websocket.javax.server.examples.GetHttpSessionSocket;
import org.eclipse.jetty.websocket.javax.server.examples.MyAuthedSocket;
import org.eclipse.jetty.websocket.javax.server.examples.StreamingEchoSocket;
Expand Down Expand Up @@ -136,12 +148,9 @@ private static SecurityHandler getSecurityHandler(String username, String passwo
@Test
public void testMyAuthedSocket() throws Exception
{
//HttpClient is configured for BasicAuthentication with the XmlHttpClientProvider
URI uri = URI.create("ws://localhost:8080/secured/socket");
HttpClient client = new HttpClient(new SslContextFactory()); // TODO: use HttpClientProvider from issue #3341
AuthenticationStore authenticationStore = client.getAuthenticationStore();
authenticationStore.addAuthentication(new BasicAuthentication(uri, "testRealm", "user", "password"));
JavaxWebSocketClientContainer clientContainer = new JavaxWebSocketClientContainer(new WebSocketCoreClient(client));
clientContainer.start(); // TODO: use container provider
WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer();

ClientSocket clientEndpoint = new ClientSocket();
try(Session session = clientContainer.connectToServer(clientEndpoint, uri))
Expand All @@ -152,8 +161,6 @@ public void testMyAuthedSocket() throws Exception

String msg = clientEndpoint.messageQueue.poll(5, TimeUnit.SECONDS);
assertThat(msg, is("hello world"));

clientContainer.stop();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<Configure class="org.eclipse.jetty.client.HttpClient">
<Arg>
<New class="org.eclipse.jetty.util.ssl.SslContextFactory"/>
</Arg>
<Call name="getAuthenticationStore">
<Call name="addAuthentication">
<Arg>
<New class="org.eclipse.jetty.client.util.BasicAuthentication">
<Arg>
<New class="java.net.URI" arg="ws://localhost:8080/secured/socket"/>
</Arg>
<Arg>testRealm</Arg>
<Arg>user</Arg>
<Arg>password</Arg>
</New>
</Arg>
</Call>
</Call>
</Configure>

0 comments on commit b72f6c5

Please sign in to comment.