org.eclipse.jetty.http.HttpVersion Java Examples
The following examples show how to use
org.eclipse.jetty.http.HttpVersion.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppEngineAuthenticationTest.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
public void testUserRequired_PreserveQueryParams() throws Exception { String path = "/user/blah"; Request request = new Request(null, null); // request.setServerPort(9999); HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path,"foo=baqr","foo=bar","foo=barff"); HttpFields httpf = new HttpFields(); MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf); request.setMetaData(metadata); MultiMap<String> queryParameters = new MultiMap<> (); queryParameters.add("ffo", "bar"); request.setQueryParameters(queryParameters); request = spy(request); /// request.setAuthority(SERVER_NAME,9999); request.setQueryString("foo=bar"); Response response = mock(Response.class); String output = runRequest2(path, request, response); // Verify that the servlet never was run (there is no output). assertEquals("", output); // Verify that the request was redirected to the login url. String loginUrl = UserServiceFactory.getUserService() .createLoginURL(String.format("http://%s%s?foo=bar", SERVER_NAME + ":9999", path)); verify(response).sendRedirect(loginUrl); }
Example #2
Source File: ReverseProxyServlet.java From logbook-kai with MIT License | 6 votes |
@Override protected void customizeProxyRequest(Request proxyRequest, HttpServletRequest request) { proxyRequest.onRequestContent(new RequestContentListener(request)); if (!AppConfig.get().isUseProxy()) { // アップストリームプロキシがある場合は除外 // HTTP/1.1 ならkeep-aliveを追加します if (proxyRequest.getVersion() == HttpVersion.HTTP_1_1) { proxyRequest.header(HttpHeader.CONNECTION, "keep-alive"); } // Pragma: no-cache はプロキシ用なので Cache-Control: no-cache に変換します String pragma = proxyRequest.getHeaders().get(HttpHeader.PRAGMA); if ((pragma != null) && pragma.equals("no-cache")) { proxyRequest.header(HttpHeader.PRAGMA, null); if (!proxyRequest.getHeaders().containsKey(HttpHeader.CACHE_CONTROL.asString())) { proxyRequest.header(HttpHeader.CACHE_CONTROL, "no-cache"); } } } String queryString = ((org.eclipse.jetty.server.Request) request).getQueryString(); fixQueryString(proxyRequest, queryString); super.customizeProxyRequest(proxyRequest, request); }
Example #3
Source File: JettyService.java From armeria with Apache License 2.0 | 6 votes |
private static MetaData.Request toRequestMetadata(ServiceRequestContext ctx, AggregatedHttpRequest aReq) { // Construct the HttpURI final StringBuilder uriBuf = new StringBuilder(); final RequestHeaders aHeaders = aReq.headers(); uriBuf.append(ctx.sessionProtocol().isTls() ? "https" : "http"); uriBuf.append("://"); uriBuf.append(aHeaders.authority()); uriBuf.append(aHeaders.path()); final HttpURI uri = new HttpURI(uriBuf.toString()); uri.setPath(ctx.mappedPath()); // Convert HttpHeaders to HttpFields final HttpFields jHeaders = new HttpFields(aHeaders.size()); aHeaders.forEach(e -> { final AsciiString key = e.getKey(); if (!key.isEmpty() && key.byteAt(0) != ':') { jHeaders.add(key.toString(), e.getValue()); } }); return new MetaData.Request(aHeaders.get(HttpHeaderNames.METHOD), uri, HttpVersion.HTTP_1_1, jHeaders, aReq.content().length()); }
Example #4
Source File: HelixRestServer.java From helix with Apache License 2.0 | 6 votes |
public void setupSslServer(int port, SslContextFactory sslContextFactory) { if (_server != null && port > 0) { try { HttpConfiguration https = new HttpConfiguration(); https.addCustomizer(new SecureRequestCustomizer()); ServerConnector sslConnector = new ServerConnector( _server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https)); sslConnector.setPort(port); _server.addConnector(sslConnector); LOG.info("Helix SSL rest server is ready to start."); } catch (Exception ex) { LOG.error("Failed to setup Helix SSL rest server, " + ex); } } }
Example #5
Source File: AppEngineAuthenticationTest.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
/** * Fire one request at the security handler (and by extension to the AuthServlet behind it). * * @param path The path to hit. * @param request The request object to use. * @param response The response object to use. Must be created by Mockito.mock() * @return Any data written to response.getWriter() * @throws IOException * @throws ServletException */ private String runRequest(String path, Request request, Response response) throws IOException, ServletException { //request.setMethod(/*HttpMethod.GET,*/ "GET"); HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path); HttpFields httpf = new HttpFields(); MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf); request.setMetaData(metadata); // request.setServerName(SERVER_NAME); // request.setAuthority(SERVER_NAME,9999); //// request.setPathInfo(path); //// request.setURIPathQuery(path); request.setDispatcherType(DispatcherType.REQUEST); doReturn(response).when(request).getResponse(); ByteArrayOutputStream output = new ByteArrayOutputStream(); try (PrintWriter writer = new PrintWriter(output)) { when(response.getWriter()).thenReturn(writer); securityHandler.handle(path, request, request, response); } return new String(output.toByteArray()); }
Example #6
Source File: AppEngineAuthenticationTest.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
private String runRequest2(String path, Request request, Response response) throws IOException, ServletException { //request.setMethod(/*HttpMethod.GET,*/ "GET"); HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path); HttpFields httpf = new HttpFields(); MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf); // request.setMetaData(metadata); // request.setServerName(SERVER_NAME); // request.setAuthority(SERVER_NAME,9999); //// request.setPathInfo(path); //// request.setURIPathQuery(path); request.setDispatcherType(DispatcherType.REQUEST); doReturn(response).when(request).getResponse(); ByteArrayOutputStream output = new ByteArrayOutputStream(); try (PrintWriter writer = new PrintWriter(output)) { when(response.getWriter()).thenReturn(writer); securityHandler.handle(path, request, request, response); } return new String(output.toByteArray()); }
Example #7
Source File: EventServer.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
private SslConnectionFactory getSSLConnectionFactory() { Resource keyStoreResource = null; try { keyStoreResource = Resource.newClassPathResource("localhost"); System.out.println(keyStoreResource); } catch (Exception ex) { Logger.getLogger(EventServer.class.getName()).log(Level.SEVERE, null, ex); } SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStoreResource(keyStoreResource); String secret = readresource(); sslContextFactory.setKeyStorePassword(Encrypt.getInstance().decrypt(secret)); sslContextFactory.setKeyManagerPassword(Encrypt.getInstance().decrypt(secret)); return new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()); }
Example #8
Source File: JettySeverTools.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
protected static void addHttpsConnector(Server server, Integer port) throws Exception { SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(Config.sslKeyStore().getAbsolutePath()); sslContextFactory.setKeyStorePassword(Config.token().getSslKeyStorePassword()); sslContextFactory.setKeyManagerPassword(Config.token().getSslKeyManagerPassword()); sslContextFactory.setTrustAll(true); HttpConfiguration config = new HttpConfiguration(); config.setSecureScheme("https"); config.setOutputBufferSize(32768); config.setRequestHeaderSize(8192 * 2); config.setResponseHeaderSize(8192 * 2); config.setSendServerVersion(true); config.setSendDateHeader(false); ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(config)); sslConnector.setPort(port); server.addConnector(sslConnector); }
Example #9
Source File: AppEngineAuthenticationTest.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
public void testUserRequired_NoUser() throws Exception { String path = "/user/blah"; Request request = spy(new Request(null, null)); //request.setServerPort(9999); HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path); HttpFields httpf = new HttpFields(); MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf); request.setMetaData(metadata); // request.setAuthority(SERVER_NAME,9999); Response response = mock(Response.class); String output = runRequest(path, request, response); // Verify that the servlet never was run (there is no output). assertEquals("", output); // Verify that the request was redirected to the login url. String loginUrl = UserServiceFactory.getUserService() .createLoginURL(String.format("http://%s%s", SERVER_NAME + ":9999", path)); verify(response).sendRedirect(loginUrl); }
Example #10
Source File: SystemInfoServiceClient.java From java-11-examples with Apache License 2.0 | 6 votes |
@Override public SystemInfo getSystemInfo() { try { Session session = createSession(); HttpFields requestFields = new HttpFields(); requestFields.put(USER_AGENT, USER_AGENT_VERSION); MetaData.Request request = new MetaData.Request("GET", getSystemInfoURI, HttpVersion.HTTP_2, requestFields); HeadersFrame headersFrame = new HeadersFrame(request, null, true); GetListener getListener = new GetListener(); session.newStream(headersFrame, new FuturePromise<>(), getListener); SystemInfo response = getListener.get(SystemInfo.class); session.close(0, null, new Callback() {}); return response; } catch (Exception e) { throw new HttpAccessException(e); } }
Example #11
Source File: AppEngineAuthenticationTest.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
public void testAdminRequired_NoUser() throws Exception { String path = "/admin/blah"; Request request = spy(new Request(null, null)); //request.setServerPort(9999); HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path); HttpFields httpf = new HttpFields(); MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf); request.setMetaData(metadata); // request.setAuthority(SERVER_NAME,9999); Response response = mock(Response.class); String output = runRequest(path, request, response); // Verify that the servlet never was run (there is no output). assertEquals("", output); // Verify that the request was redirected to the login url. String loginUrl = UserServiceFactory.getUserService() .createLoginURL(String.format("http://%s%s", SERVER_NAME + ":9999", path)); verify(response).sendRedirect(loginUrl); }
Example #12
Source File: TlsCertificateAuthorityService.java From localization_nifi with Apache License 2.0 | 6 votes |
private static Server createServer(Handler handler, int port, KeyStore keyStore, String keyPassword) throws Exception { Server server = new Server(); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setIncludeProtocols("TLSv1.2"); sslContextFactory.setKeyStore(keyStore); sslContextFactory.setKeyManagerPassword(keyPassword); HttpConfiguration httpsConfig = new HttpConfiguration(); httpsConfig.addCustomizer(new SecureRequestCustomizer()); ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig)); sslConnector.setPort(port); server.addConnector(sslConnector); server.setHandler(handler); return server; }
Example #13
Source File: TlsCertificateAuthorityService.java From nifi with Apache License 2.0 | 6 votes |
private static Server createServer(Handler handler, int port, KeyStore keyStore, String keyPassword) throws Exception { Server server = new Server(); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setIncludeProtocols(CertificateUtils.getHighestCurrentSupportedTlsProtocolVersion()); sslContextFactory.setKeyStore(keyStore); sslContextFactory.setKeyManagerPassword(keyPassword); // Need to set SslContextFactory's endpointIdentificationAlgorithm to null; this is a server, // not a client. Server does not need to perform hostname verification on the client. // Previous to Jetty 9.4.15.v20190215, this defaulted to null, and now defaults to "HTTPS". sslContextFactory.setEndpointIdentificationAlgorithm(null); HttpConfiguration httpsConfig = new HttpConfiguration(); httpsConfig.addCustomizer(new SecureRequestCustomizer()); ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig)); sslConnector.setPort(port); server.addConnector(sslConnector); server.setHandler(handler); return server; }
Example #14
Source File: ErrorCases.java From scheduling with GNU Affero General Public License v3.0 | 6 votes |
@BeforeClass public static void startHttpsServer() throws Exception { skipIfHeadlessEnvironment(); server = new Server(); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(ErrorCases.class.getResource("keystore").getPath()); sslContextFactory.setKeyStorePassword("activeeon"); HttpConfiguration httpConfig = new HttpConfiguration(); HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig); httpsConfig.addCustomizer(new SecureRequestCustomizer()); ServerConnector sslConnector = new ServerConnector(server, new ConnectionFactory[] { new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig) }); server.addConnector(sslConnector); server.start(); serverUrl = "https://localhost:" + sslConnector.getLocalPort() + "/rest"; }
Example #15
Source File: AssetServletTest.java From dropwizard-configurable-assets-bundle with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { servletTester.addServlet(DummyAssetServlet.class, DUMMY_SERVLET + '*'); servletTester.addServlet(NoIndexAssetServlet.class, NOINDEX_SERVLET + '*'); servletTester.addServlet(NoCharsetAssetServlet.class, NOCHARSET_SERVLET + '*'); servletTester.addServlet(RootAssetServlet.class, ROOT_SERVLET + '*'); servletTester.addServlet(MimeMappingsServlet.class, MIME_SERVLET + '*'); servletTester.addServlet(CachingServlet.class, CACHE_SERVLET + '*'); ServletHolder servlet = new ServletHolder(MultipleMappingsServlet.class); servletTester.addServlet(servlet, MM_ASSET_SERVLET + '*'); servletTester.addServlet(servlet, MM_JSON_SERVLET + '*'); servletTester.start(); servletTester.getContext().getMimeTypes().addMimeMapping("mp4", "video/mp4"); servletTester.getContext().getMimeTypes().addMimeMapping("m4a", "audio/mp4"); request.setMethod("GET"); request.setURI(DUMMY_SERVLET + "example.txt"); request.setVersion(HttpVersion.HTTP_1_0); }
Example #16
Source File: AsyncHttpExecutableTest.java From cougar with Apache License 2.0 | 6 votes |
private void fireResponse(CapturingRequest request, int errorCode, String responseText, int resultSize, ObservableObserver observer, boolean successfulResponse) throws InterruptedException { Response.CompleteListener listener = request.awaitSend(1000, TimeUnit.MILLISECONDS); assertNotNull(listener); InputStreamResponseListener responseListener = (InputStreamResponseListener) listener; Result result = mock(Result.class); Response response = mock(Response.class); when(result.getResponse()).thenReturn(response); when(result.isSucceeded()).thenReturn(successfulResponse); when(result.isFailed()).thenReturn(!successfulResponse); HttpFields headers = mock(HttpFields.class); when(response.getHeaders()).thenReturn(headers); when(headers.get(HttpHeader.CONTENT_LENGTH)).thenReturn(String.valueOf(resultSize)); when(response.getStatus()).thenReturn(errorCode); when(response.getVersion()).thenReturn(HttpVersion.HTTP_1_1); // fire that event responseListener.onHeaders(response); responseListener.onContent(response, ByteBuffer.allocate(0)); responseListener.onComplete(result); assertTrue(observer.getLatch().await(1000, TimeUnit.MILLISECONDS)); }
Example #17
Source File: ZeppelinServer.java From zeppelin with Apache License 2.0 | 5 votes |
private static void configureRequestHeaderSize( ZeppelinConfiguration conf, ServerConnector connector) { HttpConnectionFactory cf = (HttpConnectionFactory) connector.getConnectionFactory(HttpVersion.HTTP_1_1.toString()); int requestHeaderSize = conf.getJettyRequestHeaderSize(); cf.getHttpConfiguration().setRequestHeaderSize(requestHeaderSize); }
Example #18
Source File: ProxyServlet.java From logbook-kai with MIT License | 5 votes |
private Request createProxyRequest(HttpServletRequest request, HttpServletResponse response, URI targetUri, ContentProvider contentProvider) { final Request proxyRequest = this._client.newRequest(targetUri) .method(HttpMethod.fromString(request.getMethod())) .version(HttpVersion.fromString(request.getProtocol())); // Copy headers for (Enumeration<String> headerNames = request.getHeaderNames(); headerNames.hasMoreElements();) { String headerName = headerNames.nextElement(); String lowerHeaderName = headerName.toLowerCase(Locale.ENGLISH); // Remove hop-by-hop headers if (HOP_HEADERS.contains(lowerHeaderName)) continue; if ((this._hostHeader != null) && lowerHeaderName.equals("host")) continue; for (Enumeration<String> headerValues = request.getHeaders(headerName); headerValues.hasMoreElements();) { String headerValue = headerValues.nextElement(); if (headerValue != null) proxyRequest.header(headerName, headerValue); } } // Force the Host header if configured if (this._hostHeader != null) proxyRequest.header(HttpHeader.HOST, this._hostHeader); proxyRequest.content(contentProvider); this.customizeProxyRequest(proxyRequest, request); proxyRequest.timeout(this.getTimeout(), TimeUnit.MILLISECONDS); return proxyRequest; }
Example #19
Source File: HttpServer2.java From hadoop-ozone with Apache License 2.0 | 5 votes |
private ServerConnector createHttpsChannelConnector( Server server, HttpConfiguration httpConfig) { httpConfig.setSecureScheme(HTTPS_SCHEME); httpConfig.addCustomizer(new SecureRequestCustomizer()); ServerConnector conn = createHttpChannelConnector(server, httpConfig); SslContextFactory.Server sslContextFactory = new SslContextFactory.Server(); sslContextFactory.setNeedClientAuth(needsClientAuth); if (keyPassword != null) { sslContextFactory.setKeyManagerPassword(keyPassword); } if (keyStore != null) { sslContextFactory.setKeyStorePath(keyStore); sslContextFactory.setKeyStoreType(keyStoreType); if (keyStorePassword != null) { sslContextFactory.setKeyStorePassword(keyStorePassword); } } if (trustStore != null) { sslContextFactory.setTrustStorePath(trustStore); sslContextFactory.setTrustStoreType(trustStoreType); if (trustStorePassword != null) { sslContextFactory.setTrustStorePassword(trustStorePassword); } } if (null != excludeCiphers && !excludeCiphers.isEmpty()) { sslContextFactory.setExcludeCipherSuites( StringUtils.getTrimmedStrings(excludeCiphers)); LOG.info("Excluded Cipher List: {}", excludeCiphers); } conn.addFirstConnectionFactory(new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString())); return conn; }
Example #20
Source File: HttpServer2.java From knox with Apache License 2.0 | 5 votes |
private ServerConnector createHttpsChannelConnector( Server server, HttpConfiguration httpConfig) { httpConfig.setSecureScheme(HTTPS_SCHEME); httpConfig.addCustomizer(new SecureRequestCustomizer()); ServerConnector conn = createHttpChannelConnector(server, httpConfig); SslContextFactory.Server sslContextFactory = new SslContextFactory.Server(); sslContextFactory.setNeedClientAuth(needsClientAuth); sslContextFactory.setKeyManagerPassword(keyPassword); if (keyStore != null) { sslContextFactory.setKeyStorePath(keyStore); sslContextFactory.setKeyStoreType(keyStoreType); sslContextFactory.setKeyStorePassword(keyStorePassword); } if (trustStore != null) { sslContextFactory.setTrustStorePath(trustStore); sslContextFactory.setTrustStoreType(trustStoreType); sslContextFactory.setTrustStorePassword(trustStorePassword); } if(null != excludeCiphers && !excludeCiphers.isEmpty()) { sslContextFactory.setExcludeCipherSuites( StringUtils.getTrimmedStrings(excludeCiphers)); LOG.info("Excluded Cipher List:" + excludeCiphers); } conn.addFirstConnectionFactory(new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString())); return conn; }
Example #21
Source File: HttpServer2.java From knox with Apache License 2.0 | 5 votes |
private ServerConnector createHttpsChannelConnector( Server server, HttpConfiguration httpConfig) { httpConfig.setSecureScheme(HTTPS_SCHEME); httpConfig.addCustomizer(new SecureRequestCustomizer()); ServerConnector conn = createHttpChannelConnector(server, httpConfig); SslContextFactory.Server sslContextFactory = new SslContextFactory.Server(); sslContextFactory.setNeedClientAuth(needsClientAuth); sslContextFactory.setKeyManagerPassword(keyPassword); if (keyStore != null) { sslContextFactory.setKeyStorePath(keyStore); sslContextFactory.setKeyStoreType(keyStoreType); sslContextFactory.setKeyStorePassword(keyStorePassword); } if (trustStore != null) { sslContextFactory.setTrustStorePath(trustStore); sslContextFactory.setTrustStoreType(trustStoreType); sslContextFactory.setTrustStorePassword(trustStorePassword); } if(null != excludeCiphers && !excludeCiphers.isEmpty()) { sslContextFactory.setExcludeCipherSuites( StringUtils.getTrimmedStrings(excludeCiphers)); LOG.info("Excluded Cipher List:" + excludeCiphers); } conn.addFirstConnectionFactory(new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString())); return conn; }
Example #22
Source File: JettyAppServer.java From selenium with Apache License 2.0 | 5 votes |
@Override public void start() { HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSecureScheme("https"); httpConfig.setSecurePort(securePort); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig)); http.setPort(port); http.setIdleTimeout(500000); Path keystore = getKeyStore(); if (!Files.exists(keystore)) { throw new RuntimeException( "Cannot find keystore for SSL cert: " + keystore.toAbsolutePath()); } SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(keystore.toAbsolutePath().toString()); sslContextFactory.setKeyStorePassword("password"); sslContextFactory.setKeyManagerPassword("password"); HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig); httpsConfig.addCustomizer(new SecureRequestCustomizer()); ServerConnector https = new ServerConnector( server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig)); https.setPort(securePort); https.setIdleTimeout(500000); server.setConnectors(new Connector[]{http, https}); try { server.start(); } catch (Exception e) { throw new RuntimeException(e); } }
Example #23
Source File: FakeGoServer.java From gocd with Apache License 2.0 | 5 votes |
private void start() throws Exception { server = new Server(); ServerConnector connector = new ServerConnector(server); server.addConnector(connector); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setCertAlias("cruise"); sslContextFactory.setKeyStoreResource(Resource.newClassPathResource("testdata/fake-server-keystore")); sslContextFactory.setKeyStorePassword("serverKeystorepa55w0rd"); ServerConnector secureConnnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(new HttpConfiguration()) ); server.addConnector(secureConnnector); WebAppContext wac = new WebAppContext(".", "/go"); ServletHolder holder = new ServletHolder(); holder.setServlet(new HttpServlet() { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.getOutputStream().println("Hello"); } }); wac.addServlet(holder, "/hello"); addFakeAgentBinaryServlet(wac, "/admin/agent", TEST_AGENT, this); addFakeAgentBinaryServlet(wac, "/admin/agent-launcher.jar", TEST_AGENT_LAUNCHER, this); addFakeAgentBinaryServlet(wac, "/admin/agent-plugins.zip", TEST_AGENT_PLUGINS, this); addFakeAgentBinaryServlet(wac, "/admin/tfs-impl.jar", TEST_TFS_IMPL, this); addlatestAgentStatusCall(wac); addDefaultServlet(wac); server.setHandler(wac); server.setStopAtShutdown(true); server.start(); port = connector.getLocalPort(); securePort = secureConnnector.getLocalPort(); }
Example #24
Source File: HttpClientSetUp.java From product-private-paas with Apache License 2.0 | 5 votes |
public HttpClientSetUp() { // Create Server ServletContextHandler context = new ServletContextHandler(); server.setHandler(context); ServletHolder jerseyServlet = context .addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/stratos/*"); jerseyServlet.setInitOrder(0); jerseyServlet .setInitParameter("jersey.config.server.provider.classnames", StratosV400Mock.class.getCanonicalName()); ServletHolder jerseyServlet2 = context .addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/migration/*"); jerseyServlet2.setInitOrder(0); jerseyServlet2 .setInitParameter("jersey.config.server.provider.classnames", StratosV400Mock.class.getCanonicalName()); server.setHandler(context); HttpConfiguration https_config = new HttpConfiguration(); https_config.setSecureScheme("https"); https_config.setSecurePort(Integer.getInteger("https.port")); https_config.setOutputBufferSize(TestConstants.BUFFER_SIZE); https_config.addCustomizer(new SecureRequestCustomizer()); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(TestConstants.KEYSTORE_PATH); sslContextFactory.setKeyStorePassword("wso2carbon"); sslContextFactory.setKeyManagerPassword("wso2carbon"); ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config)); https.setPort(Integer.getInteger("https.port")); https.setIdleTimeout(TestConstants.IDLE_TIMEOUT); // Set the connectors server.setConnectors(new Connector[] { https }); }
Example #25
Source File: MockServer.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
public MockServer() throws IOException { server = new Server(); connector = new ServerConnector(server); connector.setPort(httpPort); HttpConfiguration https = new HttpConfiguration(); https.addCustomizer(new SecureRequestCustomizer()); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setTrustAll(true); sslContextFactory.setValidateCerts(false); sslContextFactory.setNeedClientAuth(false); sslContextFactory.setWantClientAuth(false); sslContextFactory.setValidatePeerCerts(false); sslContextFactory.setKeyStorePassword("password"); sslContextFactory.setKeyStorePath(MockServer.class.getResource("mock-keystore.jks").toExternalForm()); sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https)); sslConnector.setPort(httpsPort); server.setConnectors(new Connector[] {connector, sslConnector}); ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS); context.addServlet(new ServletHolder(new AlwaysSuccessServlet()), "/*"); server.setHandler(context); }
Example #26
Source File: SubmarineServer.java From submarine with Apache License 2.0 | 5 votes |
private static void configureRequestHeaderSize( SubmarineConfiguration conf, ServerConnector connector) { HttpConnectionFactory cf = (HttpConnectionFactory) connector.getConnectionFactory(HttpVersion.HTTP_1_1.toString()); int requestHeaderSize = conf.getJettyRequestHeaderSize(); cf.getHttpConfiguration().setRequestHeaderSize(requestHeaderSize); }
Example #27
Source File: HttpChannelOverHttpCustom.java From sofa-registry with Apache License 2.0 | 5 votes |
@Override public boolean startRequest(String method, String uri, HttpVersion version) { if (uri != null && !uri.isEmpty() && uri.charAt(0) == QUESTION_MARK) { /* HTTP/1.1 spec says in 5.1.2. about Request-URI: * "Note that the absolute path cannot be empty; if * none is present in the original URI, it MUST be * given as "/" (the server root)." So if the file * name here has only a query string, the path is * empty and we also have to add a "/". */ uri = "/" + uri; } return super.startRequest(method, uri, version); }
Example #28
Source File: ExchangeSocketServer.java From conga with Apache License 2.0 | 5 votes |
public void init() { // connector configuration SslContextFactory sslContextFactory = new SslContextFactory(); if (null != keyStorePath) { sslContextFactory.setKeyStorePath(keyStorePath); } if (null != keyStorePassword) { sslContextFactory.setKeyStorePassword(keyStorePassword); } if (null != keyManagerPassword) { sslContextFactory.setKeyManagerPassword(keyManagerPassword); } SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()); HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(new HttpConfiguration()); ServerConnector sslConnector = new ServerConnector(server, sslConnectionFactory, httpConnectionFactory); sslConnector.setHost(host); sslConnector.setPort(port); server.addConnector(sslConnector); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletHolder servletHolder = new ServletHolder(new ExchangeServlet(sessions, ringBuffer)); context.addServlet(servletHolder, "/trade/*"); // context.addServlet(DefaultServlet.class, "/"); server.setHandler(context); }
Example #29
Source File: ReporterFactoryTest.java From apm-agent-java with Apache License 2.0 | 5 votes |
@BeforeEach void setUp() throws Exception { server = new Server(); Path keyStorePath = Paths.get(ReporterFactoryTest.class.getResource("/keystore").toURI()); final SslContextFactory sslContextFactory = new SslContextFactory(keyStorePath.toAbsolutePath().toString()); sslContextFactory.setKeyStorePassword("password"); sslContextFactory.getSslContext(); final HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.setSecureScheme("https"); httpConfiguration.setSecurePort(0); final HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration); httpsConfiguration.addCustomizer(new SecureRequestCustomizer()); final ServerConnector httpsConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfiguration)); httpsConnector.setPort(0); server.addConnector(httpsConnector); server.setHandler(new AbstractHandler() { @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) { baseRequest.setHandled(true); requestHandled.set(true); } }); server.start(); configuration = SpyConfiguration.createSpyConfig(); reporterConfiguration = configuration.getConfig(ReporterConfiguration.class); when(reporterConfiguration.getServerUrls()).thenReturn(Collections.singletonList(new URL("https://localhost:" + getPort()))); }
Example #30
Source File: RestClient20.java From java-11-examples with Apache License 2.0 | 5 votes |
public Stream createStream(Session session, HttpURI uri, Stream.Listener listener) throws Exception { HttpFields requestFields = new HttpFields(); requestFields.put(USER_AGENT, USER_AGENT_VERSION); MetaData.Request request = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, requestFields); HeadersFrame headersFrame = new HeadersFrame(request, null, false); FuturePromise<Stream> streamPromise = new FuturePromise<>(); session.newStream(headersFrame, streamPromise, listener); return streamPromise.get(); }