HBASE-14471 Thrift - HTTP Error 413 full HEAD if using kerberos authentication (huaxiang sun)

This commit is contained in:
tedyu 2015-09-25 09:07:16 -07:00
parent a33adf2f0b
commit 36f6eb139d
2 changed files with 45 additions and 3 deletions

View File

@ -401,6 +401,7 @@ public class ThriftServerRunner implements Runnable {
String host = getBindAddress(conf).getHostAddress(); String host = getBindAddress(conf).getHostAddress();
connector.setPort(listenPort); connector.setPort(listenPort);
connector.setHost(host); connector.setHost(host);
connector.setHeaderBufferSize(1024 * 64);
httpServer.addConnector(connector); httpServer.addConnector(connector);
if (doAsEnabled) { if (doAsEnabled) {

View File

@ -34,10 +34,15 @@ import org.apache.hadoop.hbase.util.IncrementingEnvironmentEdge;
import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.THttpClient; import org.apache.thrift.transport.THttpClient;
import org.apache.thrift.transport.TTransportException;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
@ -98,8 +103,31 @@ public class TestThriftHttpServer {
httpServerThread.start(); httpServerThread.start();
} }
@Rule
public ExpectedException exception = ExpectedException.none();
@Test(timeout=600000)
public void testRunThriftServerWithHeaderBufferLength() throws Exception {
// Test thrift server with HTTP header length less than 64k
try {
runThriftServer(1024 * 63);
} catch (TTransportException tex) {
assertFalse(tex.getMessage().equals("HTTP Response code: 413"));
}
// Test thrift server with HTTP header length more than 64k, expect an exception
exception.expect(TTransportException.class);
exception.expectMessage("HTTP Response code: 413");
runThriftServer(1024 * 64);
}
@Test(timeout=600000) @Test(timeout=600000)
public void testRunThriftServer() throws Exception { public void testRunThriftServer() throws Exception {
runThriftServer(0);
}
private void runThriftServer(int customHeaderSize) throws Exception {
List<String> args = new ArrayList<String>(); List<String> args = new ArrayList<String>();
port = HBaseTestingUtility.randomFreePort(); port = HBaseTestingUtility.randomFreePort();
args.add("-" + ThriftServer.PORT_OPTION); args.add("-" + ThriftServer.PORT_OPTION);
@ -117,7 +145,7 @@ public class TestThriftHttpServer {
} }
try { try {
talkToThriftServer(); talkToThriftServer(customHeaderSize);
} catch (Exception ex) { } catch (Exception ex) {
clientSideException = ex; clientSideException = ex;
} finally { } finally {
@ -126,16 +154,29 @@ public class TestThriftHttpServer {
if (clientSideException != null) { if (clientSideException != null) {
LOG.error("Thrift client threw an exception " + clientSideException); LOG.error("Thrift client threw an exception " + clientSideException);
if (clientSideException instanceof TTransportException) {
throw clientSideException;
} else {
throw new Exception(clientSideException); throw new Exception(clientSideException);
} }
} }
}
private static volatile boolean tableCreated = false; private static volatile boolean tableCreated = false;
private void talkToThriftServer() throws Exception { private void talkToThriftServer(int customHeaderSize) throws Exception {
THttpClient httpClient = new THttpClient( THttpClient httpClient = new THttpClient(
"http://"+ HConstants.LOCALHOST + ":" + port); "http://"+ HConstants.LOCALHOST + ":" + port);
httpClient.open(); httpClient.open();
if (customHeaderSize > 0) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < customHeaderSize; i++) {
sb.append("a");
}
httpClient.setCustomHeader("User-Agent", sb.toString());
}
try { try {
TProtocol prot; TProtocol prot;
prot = new TBinaryProtocol(httpClient); prot = new TBinaryProtocol(httpClient);