126
126
import com .ning .http .client .filter .ResponseFilter ;
127
127
import com .ning .http .client .listener .TransferCompletionHandler ;
128
128
import com .ning .http .client .ntlm .NTLMEngine ;
129
- import com .ning .http .client .ntlm .NTLMEngineException ;
130
129
import com .ning .http .client .websocket .WebSocket ;
131
130
import com .ning .http .client .websocket .WebSocketByteListener ;
132
131
import com .ning .http .client .websocket .WebSocketCloseCodeReasonListener ;
@@ -552,7 +551,7 @@ boolean sendRequest(final FilterChainContext ctx,
552
551
throws IOException {
553
552
554
553
boolean isWriteComplete = true ;
555
- LOGGER . debug ( "@@@@@@@@@@@@@@@@@@@@@ sendRequest sending message .... context = " + ctx + " connection is " + ctx . getConnection ());
554
+
556
555
if (requestHasEntityBody (request )) {
557
556
final HttpTransactionContext context = getHttpTransactionContext (ctx .getConnection ());
558
557
BodyHandler handler = bodyHandlerFactory .getBodyHandler (request );
@@ -840,8 +839,6 @@ private boolean sendAsGrizzlyRequest(final Request request,
840
839
final FilterChainContext ctx )
841
840
throws IOException {
842
841
843
- //LOGGER.debug("@@@@@@@@@@@@@@@@@@@@@ sendAsGrizzlyRequest sending message .... context = "+ctx + " connection is "+ctx.getConnection());
844
-
845
842
final HttpTransactionContext httpCtx = getHttpTransactionContext (ctx .getConnection ());
846
843
if (isUpgradeRequest (httpCtx .handler ) && isWSRequest (httpCtx .requestUrl )) {
847
844
httpCtx .isWSRequest = true ;
@@ -916,7 +913,7 @@ private boolean sendAsGrizzlyRequest(final Request request,
916
913
boolean avoidProxy = ProxyUtils .avoidProxy (proxy , request );
917
914
if (!avoidProxy ) {
918
915
if (!requestPacket .getHeaders ().contains (Header .ProxyConnection )) {
919
- requestPacket .setHeader (Header .ProxyConnection , "Keep-Alive " );
916
+ requestPacket .setHeader (Header .ProxyConnection , "keep-alive " );
920
917
}
921
918
922
919
if (proxy .getNtlmDomain () != null && proxy .getNtlmDomain ().length () > 0 )
@@ -928,10 +925,6 @@ private boolean sendAsGrizzlyRequest(final Request request,
928
925
929
926
}
930
927
}
931
-
932
- String userAgent = "Apache-HttpClient/4.2.2 (java 1.5)" ;
933
- requestPacket .setHeader (Header .UserAgent , userAgent );
934
-
935
928
final AsyncHandler h = httpCtx .handler ;
936
929
if (h != null ) {
937
930
if (TransferCompletionHandler .class .isAssignableFrom (h .getClass ())) {
@@ -940,15 +933,7 @@ private boolean sendAsGrizzlyRequest(final Request request,
940
933
TransferCompletionHandler .class .cast (h ).transferAdapter (new GrizzlyTransferAdapter (map ));
941
934
}
942
935
}
943
-
944
- boolean returnVal = false ;
945
- try {
946
- returnVal = sendRequest (ctx , request , requestPacket );
947
- }catch (RuntimeException e )
948
- {
949
- e .printStackTrace ();
950
- }
951
- return returnVal ;
936
+ return sendRequest (ctx , request , requestPacket );
952
937
953
938
}
954
939
@@ -1005,7 +990,7 @@ private void addHeaders(final Request request,
1005
990
1006
991
final MimeHeaders headers = requestPacket .getHeaders ();
1007
992
if (!headers .contains (Header .Connection )) {
1008
- requestPacket .addHeader (Header .Connection , "Keep-Alive " );
993
+ requestPacket .addHeader (Header .Connection , "keep-alive " );
1009
994
}
1010
995
1011
996
if (!headers .contains (Header .Accept )) {
@@ -1186,10 +1171,7 @@ protected void onHttpContentEncoded(HttpContent content, FilterChainContext ctx)
1186
1171
protected void onInitialLineParsed (HttpHeader httpHeader ,
1187
1172
FilterChainContext ctx ) {
1188
1173
1189
-
1190
1174
super .onInitialLineParsed (httpHeader , ctx );
1191
-
1192
- LOGGER .debug ("printing ..... RESPONSE: {}" , httpHeader );
1193
1175
if (httpHeader .isSkipRemainder ()) {
1194
1176
return ;
1195
1177
}
@@ -1243,10 +1225,7 @@ protected void onInitialLineParsed(HttpHeader httpHeader,
1243
1225
getURI (context .requestUrl ),
1244
1226
provider );
1245
1227
context .responseStatus = responseStatus ;
1246
- LOGGER .debug ("auth header " +httpHeader .getHeader (Header .ProxyAuthenticate ));
1247
- LOGGER .debug ("############### status handler is not null....so returning here " +context .statusHandler );
1248
1228
if (context .statusHandler != null ) {
1249
-
1250
1229
return ;
1251
1230
}
1252
1231
if (context .currentState != AsyncHandler .STATE .ABORT ) {
@@ -1296,7 +1275,6 @@ protected void onHttpHeadersParsed(HttpHeader httpHeader,
1296
1275
final HttpTransactionContext context = provider .getHttpTransactionContext (ctx .getConnection ());
1297
1276
1298
1277
if (httpHeader .isSkipRemainder () || (context .establishingTunnel && context .statusHandler ==null )) {
1299
- LOGGER .debug ("returning skipping remainder" );
1300
1278
return ;
1301
1279
}
1302
1280
@@ -1412,7 +1390,6 @@ protected void onHttpHeadersParsed(HttpHeader httpHeader,
1412
1390
protected boolean onHttpPacketParsed (HttpHeader httpHeader , FilterChainContext ctx ) {
1413
1391
1414
1392
boolean result ;
1415
- LOGGER .debug ("onHttpPacketParsed " +ctx + " http header = " +httpHeader );
1416
1393
final String proxy_auth = httpHeader .getHeader (Header .ProxyAuthenticate );
1417
1394
1418
1395
if (httpHeader .isSkipRemainder () ) {
@@ -1422,21 +1399,8 @@ protected boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext c
1422
1399
cleanup (ctx , provider );
1423
1400
return false ;
1424
1401
}else {
1425
- LOGGER .debug ("!!!!!! onHttpPacketParsed this is second handshake so not cleaning up" );
1426
1402
super .onHttpPacketParsed (httpHeader , ctx );
1427
1403
httpHeader .getProcessingState ().setKeepAlive (true );
1428
- /*final HttpTransactionContext context = provider.getHttpTransactionContext(ctx.getConnection());
1429
- final AsyncHandler handler = context.handler;
1430
- if (handler != null) {
1431
- try {
1432
- context.result(handler.onCompleted());
1433
- } catch (Exception e) {
1434
- context.abort(e);
1435
- }
1436
- } else {
1437
- context.done(null);
1438
- }*/
1439
- LOGGER .debug ("!!!!!! onHttpPacketParsed this is second handshake so not cleaning up ctx = " +ctx );
1440
1404
return false ;
1441
1405
}
1442
1406
}
@@ -1548,16 +1512,14 @@ private static final class AuthorizationHandler implements StatusHandler {
1548
1512
1549
1513
1550
1514
public boolean handlesStatus (int statusCode ) {
1551
- LOGGER .debug ("inside handle status returning = " +HttpStatus .UNAUTHORIZED_401 .statusMatches (statusCode ));
1552
1515
return (HttpStatus .UNAUTHORIZED_401 .statusMatches (statusCode ));
1553
1516
}
1554
1517
1555
1518
@ SuppressWarnings ({"unchecked" })
1556
1519
public boolean handleStatus (final HttpResponsePacket responsePacket ,
1557
1520
final HttpTransactionContext httpTransactionContext ,
1558
1521
final FilterChainContext ctx ) {
1559
-
1560
- LOGGER .debug ("inside handle status returning context = " +ctx );
1522
+
1561
1523
final String auth = responsePacket .getHeader (Header .WWWAuthenticate );
1562
1524
if (auth == null ) {
1563
1525
throw new IllegalStateException ("401 response received, but no WWW-Authenticate header was present" );
@@ -1640,16 +1602,14 @@ private static final class ProxyAuthorizationHandler implements StatusHandler {
1640
1602
1641
1603
1642
1604
public boolean handlesStatus (int statusCode ) {
1643
- LOGGER .debug ("inside proxy handle status returning " +HttpStatus .PROXY_AUTHENTICATION_REQUIRED_407 .statusMatches (statusCode ));
1644
1605
return (HttpStatus .PROXY_AUTHENTICATION_REQUIRED_407 .statusMatches (statusCode ));
1645
1606
}
1646
1607
1647
1608
@ SuppressWarnings ({"unchecked" })
1648
1609
public boolean handleStatus (final HttpResponsePacket responsePacket ,
1649
1610
final HttpTransactionContext httpTransactionContext ,
1650
1611
final FilterChainContext ctx ) {
1651
-
1652
- LOGGER .debug ("inside proxy handle status returning context = " +ctx );
1612
+
1653
1613
final String proxy_auth = responsePacket .getHeader (Header .ProxyAuthenticate );
1654
1614
if (proxy_auth == null ) {
1655
1615
throw new IllegalStateException ("407 response received, but no Proxy Authenticate header was present" );
@@ -1689,27 +1649,16 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
1689
1649
1690
1650
req .getHeaders ().remove (Header .ProxyAuthenticate .toString ());
1691
1651
req .getHeaders ().remove (Header .ProxyAuthorization .toString ());
1692
- req .getHeaders ().remove (Header .Accept .toString ());
1693
- req .getHeaders ().remove ("CLIENT_ID" );
1652
+
1694
1653
String msg = null ;
1695
1654
try {
1696
1655
1697
- if (proxy_auth . toLowerCase (). equals ( "ntlm" ))
1656
+ if (isFirstHandShake ( proxy_auth ))
1698
1657
{
1699
-
1700
1658
msg = ntlmEngine .generateType1Msg (proxyServer .getNtlmDomain (), "" );
1701
- //msg = ApacheNTLMWrapper.generateType1Msg(proxyServer.getNtlmDomain(), "");
1702
-
1703
1659
}else {
1704
1660
String serverChallenge = proxy_auth .trim ().substring ("NTLM " .length ());
1705
- //String serverChallenge1 = "TlRMTVNTUAACAAAAEgASADAAAAA1AokgNc3mBXra8i8AAAAAAAAAAIgAiABCAAAAUwBGAEQAQwBQAFIATwBYAFkAAgASAFMARgBEAEMAUABSAE8AWABZAAEAEgBJAFAAQQBTAEUAUgBWAEUAUgAEAB4AcwBmAGQAYwBwAHIAbwB4AHkALgBsAG8AYwBhAGwAAwAyAGkAcABhAHMAZQByAHYAZQByAC4AcwBmAGQAYwBwAHIAbwB4AHkALgBsAG8AYwBhAGwAAAAAAA==";
1706
- //System.out.println("Server Challenge :: " + serverChallenge);
1707
- //System.out.println("Server Challenge1 :: " + serverChallenge1);
1708
-
1709
-
1710
1661
msg = ntlmEngine .generateType3Msg (principal , password , proxyServer .getNtlmDomain (), proxyServer .getHost (), serverChallenge );
1711
- //msg = ApacheNTLMWrapper.generateType3Msg(principal, password, proxyServer.getNtlmDomain(), "", serverChallenge);
1712
- //msg = "TlRMTVNTUAADAAAAGAAYAEAAAAC0ALQAWAAAABIAEgAMAQAACgAKAB4BAAAAAAAAKAEAAAAAAAAoAQAANQIIIGYSPmcl/CPV8YAkN+5e1A1MmwI0Ekz0aS41p9y413TiBLJA82wTL4UBAQAAAAAAAJD+rq/r8s0BTJsCNBJM9GkAAAAAAgASAFMARgBEAEMAUABSAE8AWABZAAEAEgBJAFAAQQBTAEUAUgBWAEUAUgAEAB4AcwBmAGQAYwBwAHIAbwB4AHkALgBsAG8AYwBhAGwAAwAyAGkAcABhAHMAZQByAHYAZQByAC4AcwBmAGQAYwBwAHIAbwB4AHkALgBsAG8AYwBhAGwAAAAAAFMARgBEAEMAUABSAE8AWABZAHUAcwBlAHIANQA=";
1713
1662
}
1714
1663
1715
1664
req .getHeaders ().add (Header .ProxyAuthorization .toString (), "NTLM " + msg );
@@ -1724,14 +1673,7 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
1724
1673
InvocationStatus tempInvocationStatus = InvocationStatus .STOP ;
1725
1674
1726
1675
try {
1727
-
1728
- /*if(proxy_auth.toLowerCase().startsWith("ntlm") && !isSecondHandShake(proxy_auth))
1729
- {
1730
- httpTransactionContext.done(null);
1731
- }*/
1732
-
1733
- if (proxy_auth .toLowerCase ().startsWith ("ntlm" ))
1734
- //if(isSecondHandShake(proxy_auth))
1676
+ if (isFirstHandShake (proxy_auth ))
1735
1677
{
1736
1678
tempInvocationStatus = InvocationStatus .CONTINUE ;
1737
1679
@@ -1742,9 +1684,6 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
1742
1684
final Connection c = ctx .getConnection ();
1743
1685
final HttpTransactionContext newContext = httpTransactionContext .copy (); //httpTransactionContext.copy();
1744
1686
1745
- tempInvocationStatus = InvocationStatus .STOP ;
1746
-
1747
- LOGGER .debug ("is connection cacheable " +m .isConnectionCacheable (c ));
1748
1687
httpTransactionContext .future = null ;
1749
1688
httpTransactionContext .provider .setHttpTransactionContext (c , newContext );
1750
1689
@@ -1763,23 +1702,6 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
1763
1702
return false ;
1764
1703
}
1765
1704
1766
- /*final Connection c = m.obtainConnection(req, httpTransactionContext.future);
1767
- final HttpTransactionContext newContext = httpTransactionContext.copy();
1768
- httpTransactionContext.future = null;
1769
- httpTransactionContext.provider.setHttpTransactionContext(c, newContext);
1770
-
1771
- newContext.invocationStatus = tempInvocationStatus;
1772
-
1773
- try {
1774
- httpTransactionContext.provider.execute(c,
1775
- req,
1776
- httpTransactionContext.handler,
1777
- httpTransactionContext.future);
1778
- return false;
1779
- } catch (IOException ioe) {
1780
- newContext.abort(ioe);
1781
- return false;
1782
- }*/
1783
1705
}
1784
1706
else {
1785
1707
final Connection c = m .obtainConnection (req , httpTransactionContext .future );
@@ -1809,8 +1731,11 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
1809
1731
1810
1732
public static boolean isSecondHandShake (final String proxy_auth ) {
1811
1733
return (proxy_auth .toLowerCase ().startsWith ("ntlm" ) && !proxy_auth .equalsIgnoreCase ("ntlm" ));
1812
- //return proxy_auth.toLowerCase().startsWith("ntlm");
1813
1734
}
1735
+ public static boolean isFirstHandShake (final String proxy_auth ) {
1736
+ return (proxy_auth .equalsIgnoreCase ("ntlm" ));
1737
+ }
1738
+
1814
1739
1815
1740
} // END AuthorizationHandler
1816
1741
@@ -2740,7 +2665,6 @@ public boolean acquire() {
2740
2665
@ Override
2741
2666
public void onClosed (Connection connection , Connection .CloseType closeType ) throws IOException {
2742
2667
2743
- LOGGER .debug ("!!!!!!!!!!!!!!!! close getting invoked..... connection = " +connection +" closetype " +closeType );
2744
2668
if (connections != null ) {
2745
2669
connections .release ();
2746
2670
}
0 commit comments