Merge lp:~tjoneslo/akiban-server/add-http-session-table into lp:~akiban-technologies/akiban-server/trunk

Proposed by Thomas Jones-Low
Status: Merged
Approved by: Mike McMahon
Approved revision: 2646
Merged at revision: 2653
Proposed branch: lp:~tjoneslo/akiban-server/add-http-session-table
Merge into: lp:~akiban-technologies/akiban-server/trunk
Diff against target: 536 lines (+400/-8)
5 files modified
src/main/java/com/akiban/http/HttpConductorImpl.java (+81/-6)
src/main/java/com/akiban/http/SimpleHandlerList.java (+14/-0)
src/test/java/com/akiban/http/HttpMonitorVerifyIT.java (+106/-0)
src/test/java/com/akiban/http/HttpMonitorVerifySSLIT.java (+199/-0)
src/test/java/com/akiban/http/HttpThreadedLoginIT.java (+0/-2)
To merge this branch: bzr merge lp:~tjoneslo/akiban-server/add-http-session-table
Reviewer Review Type Date Requested Status
Mike McMahon Approve
Review via email: mp+161259@code.launchpad.net

Description of the change

Per the demo today, add the ability for the HttpConnections to be seen in the IS.SERVER_SESSIONS table. This allows both the REST and Postgres server connections to be tracked and some accounting performed.

This is still mostly infrastructure. There are some basic statistics capture, but a further review of the business requirements should drive design of more statistics capture.

Also add test to verify this.

To post a comment you must log in.
Revision history for this message
Mike McMahon (mmcm) wrote :

This gives the HTTP server connection a Session, but it isn't otherwise used. Would it be feasible for REST resources, many of which create new sessions each request today, to get access to this one?

review: Needs Information
Revision history for this message
Thomas Jones-Low (tjoneslo) wrote :

It is possible to allow the REST processing to use the session created for the HTTP connection.

It requires a chunk of refactoring that I'd prefer to do in a separate commit.

Revision history for this message
Thomas Jones-Low (tjoneslo) wrote :

It's possible, but is it ok to use the same Session across multiple threads?

The interaction of the HTTP connection (jetty) and the Servlet processing (Jersey) is via a (theoretical) thread pool. As each request comes across the wire into the connection, it gets packaged into the Request/Response and given to the servlet to process on its own thread. When the Servlet finishes, the the Response it picked up by the connection thread and sent back across the wire.

So the safe thing to do is to create a new session for each Servlet request (i.e. as we do now). Nathan and I had a discussion on the wiki page regarding the REST processing not mapping directly to the Postgres processing, and this is one of those points.

Revision history for this message
Mike McMahon (mmcm) wrote :

Okay, seems that at the least more throught is required to do anything there.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/main/java/com/akiban/http/HttpConductorImpl.java'
--- src/main/java/com/akiban/http/HttpConductorImpl.java 2013-04-22 22:58:39 +0000
+++ src/main/java/com/akiban/http/HttpConductorImpl.java 2013-04-26 23:40:34 +0000
@@ -22,8 +22,15 @@
22import com.akiban.server.service.monitor.MonitorService;22import com.akiban.server.service.monitor.MonitorService;
23import com.akiban.server.service.monitor.ServerMonitor;23import com.akiban.server.service.monitor.ServerMonitor;
24import com.akiban.server.service.security.SecurityService;24import com.akiban.server.service.security.SecurityService;
25import com.akiban.sql.embedded.EmbeddedJDBCService;25import com.akiban.server.service.session.Session;
26import com.akiban.server.service.session.SessionService;
27import com.akiban.sql.server.ServerSessionMonitor;
26import com.google.inject.Inject;28import com.google.inject.Inject;
29
30import org.eclipse.jetty.io.AsyncEndPoint;
31import org.eclipse.jetty.io.Connection;
32import org.eclipse.jetty.io.nio.AsyncConnection;
33import org.eclipse.jetty.io.nio.SslConnection;
27import org.eclipse.jetty.servlets.CrossOriginFilter;34import org.eclipse.jetty.servlets.CrossOriginFilter;
28import org.eclipse.jetty.util.security.Constraint;35import org.eclipse.jetty.util.security.Constraint;
29import org.eclipse.jetty.security.Authenticator;36import org.eclipse.jetty.security.Authenticator;
@@ -32,6 +39,7 @@
32import org.eclipse.jetty.security.LoginService;39import org.eclipse.jetty.security.LoginService;
33import org.eclipse.jetty.security.authentication.BasicAuthenticator;40import org.eclipse.jetty.security.authentication.BasicAuthenticator;
34import org.eclipse.jetty.security.authentication.DigestAuthenticator;41import org.eclipse.jetty.security.authentication.DigestAuthenticator;
42import org.eclipse.jetty.server.AsyncHttpConnection;
35import org.eclipse.jetty.server.Connector;43import org.eclipse.jetty.server.Connector;
36import org.eclipse.jetty.server.Server;44import org.eclipse.jetty.server.Server;
37import org.eclipse.jetty.server.handler.ContextHandler;45import org.eclipse.jetty.server.handler.ContextHandler;
@@ -44,6 +52,8 @@
4452
45import javax.servlet.FilterRegistration;53import javax.servlet.FilterRegistration;
46import javax.servlet.ServletException;54import javax.servlet.ServletException;
55
56import java.nio.channels.SocketChannel;
47import java.util.Collections;57import java.util.Collections;
48import java.util.HashSet;58import java.util.HashSet;
49import java.util.Set;59import java.util.Set;
@@ -66,10 +76,12 @@
66 private static final String CONFIG_XORIGIN_CREDENTIALS = CONFIG_XORIGIN_PREFIX + "allow_credentials";76 private static final String CONFIG_XORIGIN_CREDENTIALS = CONFIG_XORIGIN_PREFIX + "allow_credentials";
6777
68 private static final String REST_ROLE = "rest-user";78 private static final String REST_ROLE = "rest-user";
79 public static final String SERVER_TYPE = "REST";
6980
70 private final ConfigurationService configurationService;81 private final ConfigurationService configurationService;
71 private final SecurityService securityService;82 private final SecurityService securityService;
72 private final MonitorService monitorService;83 private final MonitorService monitorService;
84 private final SessionService sessionService;
7385
74 private final Object lock = new Object();86 private final Object lock = new Object();
75 private SimpleHandlerList handlerList;87 private SimpleHandlerList handlerList;
@@ -84,10 +96,12 @@
84 @Inject96 @Inject
85 public HttpConductorImpl(ConfigurationService configurationService,97 public HttpConductorImpl(ConfigurationService configurationService,
86 SecurityService securityService,98 SecurityService securityService,
87 MonitorService monitor) {99 MonitorService monitor,
100 SessionService session) {
88 this.configurationService = configurationService;101 this.configurationService = configurationService;
89 this.securityService = securityService;102 this.securityService = securityService;
90 this.monitorService = monitor;103 this.monitorService = monitor;
104 this.sessionService = session;
91105
92 jerseyLogging = java.util.logging.Logger.getLogger("com.sun.jersey");106 jerseyLogging = java.util.logging.Logger.getLogger("com.sun.jersey");
93 jerseyLogging.setLevel(java.util.logging.Level.OFF);107 jerseyLogging.setLevel(java.util.logging.Level.OFF);
@@ -182,14 +196,14 @@
182 Server localServer = new Server();196 Server localServer = new Server();
183 SelectChannelConnector connector;197 SelectChannelConnector connector;
184 if (!ssl) {198 if (!ssl) {
185 connector = new SelectChannelConnector();199 connector = new SelectChannelConnectorExtended();
186 }200 }
187 else {201 else {
188 // Share keystore configuration with PSQL.202 // Share keystore configuration with PSQL.
189 SslContextFactory sslFactory = new SslContextFactory();203 SslContextFactory sslFactory = new SslContextFactory();
190 sslFactory.setKeyStorePath(System.getProperty("javax.net.ssl.keyStore"));204 sslFactory.setKeyStorePath(System.getProperty("javax.net.ssl.keyStore"));
191 sslFactory.setKeyStorePassword(System.getProperty("javax.net.ssl.keyStorePassword"));205 sslFactory.setKeyStorePassword(System.getProperty("javax.net.ssl.keyStorePassword"));
192 connector = new SslSelectChannelConnector(sslFactory);206 connector = new SslSelectChannelConnectorExtended(sslFactory);
193 }207 }
194 connector.setPort(portLocal);208 connector.setPort(portLocal);
195 connector.setThreadPool(new QueuedThreadPool(200));209 connector.setThreadPool(new QueuedThreadPool(200));
@@ -262,7 +276,7 @@
262 @Override276 @Override
263 public void stop() {277 public void stop() {
264 Server localServer;278 Server localServer;
265 monitorService.deregisterServerMonitor(monitorService.getServerMonitors().get(ConnectionMonitor.SERVER_TYPE));279 monitorService.deregisterServerMonitor(monitorService.getServerMonitors().get(SERVER_TYPE));
266 synchronized (lock) {280 synchronized (lock) {
267 xOriginFilterEnabled = false;281 xOriginFilterEnabled = false;
268 localServer = server;282 localServer = server;
@@ -313,7 +327,6 @@
313 }327 }
314328
315 private class ConnectionMonitor implements ServerMonitor {329 private class ConnectionMonitor implements ServerMonitor {
316 public static final String SERVER_TYPE = "REST";
317 private final SelectChannelConnector connector;330 private final SelectChannelConnector connector;
318 private final AtomicLong _statsStartedAt = new AtomicLong(System.currentTimeMillis());331 private final AtomicLong _statsStartedAt = new AtomicLong(System.currentTimeMillis());
319 332
@@ -341,4 +354,66 @@
341 return connector.getConnections();354 return connector.getConnections();
342 }355 }
343 }356 }
357
358 private class SelectChannelConnectorExtended extends SelectChannelConnector {
359 private Session session;
360 @Override
361 protected AsyncConnection newConnection(SocketChannel channel,final AsyncEndPoint endpoint)
362 {
363 AsyncHttpConnection conn = (AsyncHttpConnection)super.newConnection(channel, endpoint);
364 ServerSessionMonitor sessionMonitor = new ServerSessionMonitor(SERVER_TYPE,
365 monitorService.allocateSessionId());
366
367 conn.setAssociatedObject(sessionMonitor);
368 this.session = sessionService.createSession();
369 monitorService.registerSessionMonitor(sessionMonitor, session);
370 return conn;
371 }
372
373 @Override
374 protected void connectionClosed(Connection connection) {
375 if (connection instanceof AsyncHttpConnection) {
376 AsyncHttpConnection conn = (AsyncHttpConnection)connection;
377 ServerSessionMonitor monitor = (ServerSessionMonitor)conn.getAssociatedObject();
378 if (monitor != null) {
379 monitorService.deregisterSessionMonitor(monitor, session);
380 conn.setAssociatedObject(null);
381 }
382 }
383 super.connectionClosed(connection);
384 }
385 }
386
387 private class SslSelectChannelConnectorExtended extends SslSelectChannelConnector {
388 private Session session;
389 public SslSelectChannelConnectorExtended(SslContextFactory sslFactory) {
390 super(sslFactory);
391 }
392
393 @Override
394 protected AsyncConnection newConnection(SocketChannel channel,final AsyncEndPoint endpoint)
395 {
396 AsyncHttpConnection conn = (AsyncHttpConnection)((SslConnection)super.newConnection(channel, endpoint)).getSslEndPoint().getConnection();
397 ServerSessionMonitor sessionMonitor = new ServerSessionMonitor(SERVER_TYPE,
398 monitorService.allocateSessionId());
399
400 conn.setAssociatedObject(sessionMonitor);
401 this.session = sessionService.createSession();
402 monitorService.registerSessionMonitor(sessionMonitor, session);
403 return conn;
404 }
405
406 @Override
407 protected void connectionClosed (Connection connection) {
408 if (connection instanceof SslConnection) {
409 AsyncHttpConnection conn = (AsyncHttpConnection)((SslConnection) connection).getSslEndPoint().getConnection();
410 ServerSessionMonitor monitor = (ServerSessionMonitor)conn.getAssociatedObject();
411 if (monitor != null) {
412 monitorService.deregisterSessionMonitor(monitor, session);
413 conn.setAssociatedObject(null);
414 }
415 }
416 super.connectionClosed(connection);
417 }
418 }
344}419}
345420
=== modified file 'src/main/java/com/akiban/http/SimpleHandlerList.java'
--- src/main/java/com/akiban/http/SimpleHandlerList.java 2013-04-22 22:37:46 +0000
+++ src/main/java/com/akiban/http/SimpleHandlerList.java 2013-04-26 23:40:34 +0000
@@ -22,6 +22,8 @@
22import org.eclipse.jetty.server.handler.AbstractHandler;22import org.eclipse.jetty.server.handler.AbstractHandler;
23import org.eclipse.jetty.util.MultiException;23import org.eclipse.jetty.util.MultiException;
2424
25import com.akiban.server.service.monitor.MonitorStage;
26import com.akiban.sql.server.ServerSessionMonitor;
25import com.akiban.util.tap.InOutTap;27import com.akiban.util.tap.InOutTap;
26import com.akiban.util.tap.Tap;28import com.akiban.util.tap.Tap;
2729
@@ -53,10 +55,18 @@
53 Request baseRequest,55 Request baseRequest,
54 HttpServletRequest request,56 HttpServletRequest request,
55 HttpServletResponse response) throws IOException, ServletException {57 HttpServletResponse response) throws IOException, ServletException {
58 ServerSessionMonitor monitor = null;
56 if(!isStarted()) {59 if(!isStarted()) {
57 return;60 return;
58 }61 }
59 REST_TAP.in();62 REST_TAP.in();
63 Object obj = baseRequest.getConnection().getAssociatedObject();
64 if (obj instanceof ServerSessionMonitor) {
65 monitor = (ServerSessionMonitor)obj;
66 monitor.setRemoteAddress(request.getRemoteAddr());
67 monitor.startStatement(request.getMethod(), request.getRequestURI());
68 monitor.enterStage(MonitorStage.EXECUTE);
69 }
60 try {70 try {
61 for(Handler h : handlers) {71 for(Handler h : handlers) {
62 h.handle(target,baseRequest, request, response);72 h.handle(target,baseRequest, request, response);
@@ -70,6 +80,10 @@
70 }80 }
71 }finally {81 }finally {
72 REST_TAP.out();82 REST_TAP.out();
83 if (monitor != null) {
84 monitor.leaveStage();
85 monitor.endStatement(1);
86 }
73 }87 }
74 }88 }
7589
7690
=== added file 'src/test/java/com/akiban/http/HttpMonitorVerifyIT.java'
--- src/test/java/com/akiban/http/HttpMonitorVerifyIT.java 1970-01-01 00:00:00 +0000
+++ src/test/java/com/akiban/http/HttpMonitorVerifyIT.java 2013-04-26 23:40:34 +0000
@@ -0,0 +1,106 @@
1/**
2 * Copyright (C) 2009-2013 Akiban Technologies, Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17package com.akiban.http;
18
19import static org.junit.Assert.assertEquals;
20
21import java.net.URI;
22import java.util.Arrays;
23import java.util.HashMap;
24import java.util.Map;
25
26import org.apache.http.HttpResponse;
27import org.apache.http.client.HttpClient;
28import org.apache.http.client.methods.HttpGet;
29import org.apache.http.impl.client.DefaultHttpClient;
30import org.apache.http.util.EntityUtils;
31import org.junit.Before;
32import org.junit.Test;
33import org.slf4j.Logger;
34import org.slf4j.LoggerFactory;
35
36import com.akiban.rest.RestService;
37import com.akiban.rest.RestServiceImpl;
38import com.akiban.server.service.monitor.MonitorService;
39import com.akiban.server.service.security.SecurityService;
40import com.akiban.server.service.security.SecurityServiceImpl;
41import com.akiban.server.service.servicemanager.GuicedServiceManager;
42import com.akiban.server.test.it.ITBase;
43import com.akiban.sql.embedded.EmbeddedJDBCService;
44import com.akiban.sql.embedded.EmbeddedJDBCServiceImpl;
45
46public class HttpMonitorVerifyIT extends ITBase {
47
48 private static final Logger LOG = LoggerFactory.getLogger(HttpMonitorVerifyIT.class);
49
50 @Override
51 protected GuicedServiceManager.BindingsConfigurationProvider serviceBindingsProvider() {
52 return super.serviceBindingsProvider()
53 .bindAndRequire(SecurityService.class, SecurityServiceImpl.class)
54 .bindAndRequire(EmbeddedJDBCService.class, EmbeddedJDBCServiceImpl.class)
55 .bindAndRequire(RestService.class, RestServiceImpl.class);
56 }
57
58 @Before
59 public void setUp() {
60 SecurityService securityService = securityService();
61 securityService.addRole("rest-user");
62 securityService.addUser("user1", "password", Arrays.asList("rest-user"));
63 }
64
65 protected SecurityService securityService() {
66 return serviceManager().getServiceByClass(SecurityService.class);
67 }
68
69 protected HttpConductor httpConductor() {
70 return serviceManager().getServiceByClass(HttpConductor.class);
71 }
72
73 protected MonitorService monitorService () {
74 return serviceManager().getServiceByClass(MonitorService.class);
75 }
76
77 @Override
78 protected Map<String, String> startupConfigProperties() {
79 Map<String, String> properties = new HashMap<>();
80 properties.put("akserver.http.login", "basic"); // "digest"
81 properties.put("akserver.restrict_user_schema", "true");
82 return properties;
83 }
84
85 private static int openRestURL(HttpClient client, String userInfo, int port, String path) throws Exception {
86 URI uri = new URI("http", userInfo, "localhost", port, path, null, null);
87 HttpGet get = new HttpGet(uri);
88 HttpResponse response = client.execute(get);
89 int code = response.getStatusLine().getStatusCode();
90 EntityUtils.consume(response.getEntity());
91 return code;
92 }
93
94 @Test
95 public void runTest () throws Exception {
96 MonitorService monitor = monitorService();
97
98 HttpClient client = new DefaultHttpClient();
99 openRestURL(client, "user1:password", httpConductor().getPort(), "/version");
100
101 assertEquals(monitor.getSessionMonitors().size(), 1);
102
103 client.getConnectionManager().shutdown();
104 }
105
106}
0107
=== added file 'src/test/java/com/akiban/http/HttpMonitorVerifySSLIT.java'
--- src/test/java/com/akiban/http/HttpMonitorVerifySSLIT.java 1970-01-01 00:00:00 +0000
+++ src/test/java/com/akiban/http/HttpMonitorVerifySSLIT.java 2013-04-26 23:40:34 +0000
@@ -0,0 +1,199 @@
1/**
2 * Copyright (C) 2009-2013 Akiban Technologies, Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17package com.akiban.http;
18
19import static org.junit.Assert.assertEquals;
20
21import java.net.URI;
22import java.security.cert.CertificateException;
23import java.security.cert.X509Certificate;
24import java.util.Arrays;
25import java.util.HashMap;
26import java.util.Map;
27import java.util.Properties;
28
29import javax.net.ssl.SSLContext;
30import javax.net.ssl.TrustManager;
31import javax.net.ssl.X509TrustManager;
32
33import org.apache.http.HttpResponse;
34import org.apache.http.client.HttpClient;
35import org.apache.http.client.methods.HttpGet;
36import org.apache.http.conn.ClientConnectionManager;
37import org.apache.http.conn.scheme.Scheme;
38import org.apache.http.conn.scheme.SchemeRegistry;
39import org.apache.http.conn.ssl.SSLSocketFactory;
40import org.apache.http.impl.client.DefaultHttpClient;
41import org.apache.http.util.EntityUtils;
42import org.junit.Before;
43import org.junit.Ignore;
44import org.junit.Test;
45import org.slf4j.Logger;
46import org.slf4j.LoggerFactory;
47
48import com.akiban.rest.RestService;
49import com.akiban.rest.RestServiceImpl;
50import com.akiban.server.service.monitor.MonitorService;
51import com.akiban.server.service.security.SecurityService;
52import com.akiban.server.service.security.SecurityServiceImpl;
53import com.akiban.server.service.servicemanager.GuicedServiceManager;
54import com.akiban.server.test.it.ITBase;
55import com.akiban.sql.embedded.EmbeddedJDBCService;
56import com.akiban.sql.embedded.EmbeddedJDBCServiceImpl;
57
58/**
59 * In order to run this test, you need to generate a key store, then update the
60 * javax.net.ssl.keyStore system property (set below), to the path where you put the
61 * keystore file.
62 * <pre>
63 * $ keytool -keystore keystore -alias akiban -genkey -keyalg RSA
64 * Enter keystore password: password
65 * Re-enter new password: password
66 * What is your first and last name?
67 * [Unknown]: akiban.com
68 * What is the name of your organizational unit?
69 * [Unknown]: akiban.com
70 * What is the name of your organization?
71 * [Unknown]: akiban
72 * What is the name of your City or Locality?
73 * [Unknown]:
74 * What is the name of your State or Province?
75 * [Unknown]:
76 * What is the two-letter country code for this unit?
77 * [Unknown]:
78 * Is CN=akiban.com, OU=akiban.com, O=akiban, L=Unknown, ST=Unknown, C=Unknown correct?
79 * [no]: yes
80 * </pre>
81 * Because we don't want to be shipping a half completed SSL certificate with the source
82 * code, This is a manual step required for this (otherwise) disabled test.
83 * @author tjoneslo
84 *
85 */
86public class HttpMonitorVerifySSLIT extends ITBase {
87 private static final Logger LOG = LoggerFactory.getLogger(HttpMonitorVerifySSLIT.class);
88
89 @Override
90 protected GuicedServiceManager.BindingsConfigurationProvider serviceBindingsProvider() {
91 return super.serviceBindingsProvider()
92 .bindAndRequire(SecurityService.class, SecurityServiceImpl.class)
93 .bindAndRequire(EmbeddedJDBCService.class, EmbeddedJDBCServiceImpl.class)
94 .bindAndRequire(RestService.class, RestServiceImpl.class);
95 }
96
97 @Before
98 public void setUp() {
99 SecurityService securityService = securityService();
100 securityService.addRole("rest-user");
101 securityService.addRole("admin");
102 securityService.addUser("user1", "password", Arrays.asList("rest-user"));
103 securityService.addUser("akiban", "topsecret", Arrays.asList("rest-user", "admin"));
104 }
105
106 protected SecurityService securityService() {
107 return serviceManager().getServiceByClass(SecurityService.class);
108 }
109
110 protected HttpConductor httpConductor() {
111 return serviceManager().getServiceByClass(HttpConductor.class);
112 }
113
114 protected MonitorService monitorService () {
115 return serviceManager().getServiceByClass(MonitorService.class);
116 }
117
118 @Override
119 protected Map<String, String> startupConfigProperties() {
120 Map<String, String> properties = new HashMap<>();
121 properties.put("akserver.http.login", "digest"); // "digest"
122 properties.put("akserver.http.ssl", "true");
123 properties.put("akserver.restrict_user_schema", "true");
124
125 Properties p = new Properties(System.getProperties());
126 p.put("javax.net.ssl.keyStore", "./keystore");
127 p.put("javax.net.ssl.keyStorePassword", "password");
128 System.setProperties(p);
129 return properties;
130 }
131
132 private static int openRestURL(HttpClient client, String userInfo, int port, String path) throws Exception {
133 URI uri = new URI("https", userInfo, "localhost", port, path, null, null);
134 HttpGet get = new HttpGet(uri);
135 HttpResponse response = client.execute(get);
136 int code = response.getStatusLine().getStatusCode();
137 EntityUtils.consume(response.getEntity());
138 return code;
139 }
140
141 @Ignore ("need setup")
142 @Test
143 public void runTest () throws Exception {
144 MonitorService monitor = monitorService();
145
146 HttpClient client = new DefaultHttpClient();
147 client = wrapClient(client);
148
149 openRestURL(client, "user1:password", httpConductor().getPort(), "/version");
150
151 assertEquals(monitor.getSessionMonitors().size(), 1);
152
153 client.getConnectionManager().shutdown();
154 }
155
156
157 /**
158 * This code sets up the httpclient to accept any SSL certificate. The
159 * SSL certificate generated by the instructions above is not correctly
160 * signed, so we need ignore the problem.
161 * This code should not, under any circumstances, be allowed anywhere
162 * the production code.
163 * @param base
164 * @return
165 */
166 private HttpClient wrapClient (HttpClient base) {
167 try {
168 SSLContext ctx = SSLContext.getInstance("TLS");
169
170 ctx.init(null, new TrustManager[]{getTrustManager()}, null);
171 SSLSocketFactory ssf = new SSLSocketFactory(ctx);
172 ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
173 ClientConnectionManager ccm = base.getConnectionManager();
174 SchemeRegistry sr = ccm.getSchemeRegistry();
175 sr.register(new Scheme("https", ssf, 8091));
176 return new DefaultHttpClient(ccm, base.getParams());
177 } catch (Exception ex) {
178 ex.printStackTrace();
179 return null;
180 }
181 }
182
183 private X509TrustManager getTrustManager() {
184 return new X509TrustManager() {
185
186 public X509Certificate[] getAcceptedIssuers() {
187 return null;
188 }
189
190 @Override
191 public void checkClientTrusted(X509Certificate[] arg0, String arg1)
192 throws CertificateException { }
193
194 @Override
195 public void checkServerTrusted(X509Certificate[] arg0, String arg1)
196 throws CertificateException { }
197 };
198 }
199}
0200
=== modified file 'src/test/java/com/akiban/http/HttpThreadedLoginIT.java'
--- src/test/java/com/akiban/http/HttpThreadedLoginIT.java 2013-04-22 22:51:14 +0000
+++ src/test/java/com/akiban/http/HttpThreadedLoginIT.java 2013-04-26 23:40:34 +0000
@@ -21,8 +21,6 @@
21import com.akiban.rest.RestServiceImpl;21import com.akiban.rest.RestServiceImpl;
22import com.akiban.server.service.servicemanager.GuicedServiceManager;22import com.akiban.server.service.servicemanager.GuicedServiceManager;
23import com.akiban.server.test.it.ITBase;23import com.akiban.server.test.it.ITBase;
24import com.akiban.sql.embedded.EmbeddedJDBCService;
25import com.akiban.sql.embedded.EmbeddedJDBCServiceImpl;
2624
27import org.apache.http.HttpResponse;25import org.apache.http.HttpResponse;
28import org.apache.http.HttpStatus;26import org.apache.http.HttpStatus;

Subscribers

People subscribed via source and target branches