ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/net/TestXxxEndpoint.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/net/TestXxxEndpoint.java
Status
scanned
Type
file
Name
TestXxxEndpoint.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
4394 (4.3 KB)
MD5
40238e64c29f7405eb0e5697753f0456
SHA1
b0d432911b9d4e18b18fe01b44d31a2eeb040348
SHA256
0831bc4815457589116bdf10118e312b0e84d95844a5722cee8363a6eeebe453
SHA512

      
    
SHA1_git
7295d88118d72a4fa54e68478aeb21db1d862157
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestXxxEndpoint.java | 4.3 KB |

/* * 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.tomcat.util.net; import java.io.File; import java.net.InetAddress; import java.net.ServerSocket; import java.net.SocketAddress; import java.net.StandardProtocolFamily; import java.net.UnixDomainSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import org.junit.Assert; import org.junit.Test; import org.apache.catalina.connector.Connector; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; /** * Test case for the Endpoint implementations. The testing framework will ensure * that each implementation is tested. */ public class TestXxxEndpoint extends TomcatBaseTest { @Test public void testStartStopBindOnInit() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File(getBuildDirectory(), "webapps/examples"); tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath()); tomcat.start(); int port = getPort(); tomcat.getConnector().stop(); Exception e = null; try (@SuppressWarnings("unused") ServerSocket s = new ServerSocket(port, 100, InetAddress.getByName("localhost"))){ } catch (Exception e1) { e = e1; } if (e != null) { log.info("Exception was", e); } Assert.assertNotNull(e); tomcat.getConnector().start(); } @Test public void testStartStopBindOnStart() throws Exception { Tomcat tomcat = getTomcatInstance(); Connector c = tomcat.getConnector(); Assert.assertTrue(c.setProperty("bindOnInit", "false")); File appDir = new File(getBuildDirectory(), "webapps/examples"); tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath()); tomcat.start(); int port = getPort(); tomcat.getConnector().stop(); Exception e = null; try (@SuppressWarnings("unused") ServerSocket s = new ServerSocket(port, 100, InetAddress.getByName("localhost"))) { // This should not throw an Exception } catch (Exception e1) { e = e1; } Assert.assertNull(e); tomcat.getConnector().start(); } @Test public void testUnixDomainSocket() throws Exception { Tomcat tomcat = getTomcatInstance(); Connector c = tomcat.getConnector(); if (!c.getProtocolHandlerClassName().contains("NioProtocol")) { // Only the NIO connector supports UnixDomainSockets return; } File tempPath = File.createTempFile("uds-tomcat-test-", ".sock"); String unixDomainSocketPath = tempPath.getAbsolutePath(); // Need to delete the file to make way for the actual socket Assert.assertTrue(tempPath.delete()); Assert.assertTrue(c.setProperty("unixDomainSocketPath", unixDomainSocketPath)); tomcat.start(); // Connect to the domain socket as a client SocketAddress sa = UnixDomainSocketAddress.of(unixDomainSocketPath); ByteBuffer response = ByteBuffer.allocate(1024); try (SocketChannel socket = SocketChannel.open(StandardProtocolFamily.UNIX)) { socket.connect(sa); socket.write(ByteBuffer.wrap("OPTIONS * HTTP/1.0 ".getBytes())); socket.read(response); } Assert.assertTrue((new String(response.array(), 0, response.position()).startsWith("HTTP/1.1 200"))); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
26.21
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9