How get http response headers via axis2 stub - java

I access a SOAP service using adb-stubs created by axis2 and I should get sessionId and cookies from response, then send with another request...
I need get this parameters which you may see at the picture
http://www.imageup.ru/img36/1635686/skrinshot-2014-01-23-104646.png
MessageContext msgCtx = serviceStub._getServiceClient().getLastOperationContext().getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
msgCtx.getProperty(HTTPConstants.HTTP_HEADERS);
SOAPHeader soapHeader = msgCtx.getEnvelope().getHeader();
I tried these, but I could get result :(
Also I set manageSession parameters to true.
When I debuged request and response I got following log:
2014/01/23 12:35:55:372 ALMT [DEBUG] header - << "HTTP/1.1 200 OK[\r][\n]"
2014/01/23 12:35:55:372 ALMT [DEBUG] header - << "HTTP/1.1 200 OK[\r][\n]"
2014/01/23 12:35:55:372 ALMT [DEBUG] header - << "Cache-Control: private, max-age=0[\r][\n]"
2014/01/23 12:35:55:372 ALMT [DEBUG] header - << "Content-Length: 505[\r][\n]"
2014/01/23 12:35:55:372 ALMT [DEBUG] header - << "Content-Type: text/xml; charset=utf-8[\r][\n]"
2014/01/23 12:35:55:372 ALMT [DEBUG] header - << "Server: Microsoft-IIS/7.5[\r][\n]"
2014/01/23 12:35:55:382 ALMT [DEBUG] header - << "X-AspNet-Version: 2.0.50727[\r][\n]"
2014/01/23 12:35:55:382 ALMT [DEBUG] header - << "Set-Cookie: ASP.NET_SessionId=agj1njnpvoerup45tqnmsz45; path=/; HttpOnly[\r][\n]"
2014/01/23 12:35:55:382 ALMT [DEBUG] header - << "X-Powered-By: ASP.NET[\r][\n]"
2014/01/23 12:35:55:382 ALMT [DEBUG] header - << "Date: Thu, 23 Jan 2014 06:35:59 GMT[\r][\n]"
2014/01/23 12:35:55:382 ALMT [DEBUG] header - << "[\r][\n]"
2014/01/23 12:35:55:382 ALMT [DEBUG] CookieSpec - Unrecognized cookie attribute: name=HttpOnly, value=null
2014/01/23 12:35:55:382 ALMT [DEBUG] HttpMethodBase - Cookie accepted: "$Version=0; ASP.NET_SessionId=agj1njnpvoerup45tqnmsz45; $Path=/"
Please, help me.

After much anguish, I found the answer ...
I retrieve cookies from axis2 stub response with following code:
CommonsTransportHeaders cth = (CommonsTransportHeaders) msgCtx.getProperty(MessageContext.TRANSPORT_HEADERS);
String cookie = (String) cth.get(WSConstants.SET_COOKIE);
I hope this will help others :)

Related

Removing HttpClient "http-outgoing" log lines

I am using HttpClient 4.5.2 to manage http requests.
By default it sends log lines to my log file in the format of:
http-outgoing-50 >> "0[\r][\n]"
http-outgoing-50 >> "[\r][\n]"
http-outgoing-50 << "HTTP/1.1 200 OK[\r][\n]"
http-outgoing-50 << "Server: Apache-Coyote/1.1[\r][\n]"
http-outgoing-50 << "Content-Type: text/xml[\r][\n]"
http-outgoing-50 << "Content-Length: 163[\r][\n]"
http-outgoing-50 << "Date: Tue, 04 Apr 2017 08:36:40 GMT[\r][\n]"
http-outgoing-50 << "[\r][\n]"
http-outgoing-50 << "<?xml version="1.0" encoding="UTF-8" standalone="yes"?><WbxTSPSchema
http-outgoing-50 << HTTP/1.1 200 OK
http-outgoing-50 << Server: Apache-Coyote/1.1
http-outgoing-50 << Content-Type: text/xml
http-outgoing-50 << Content-Length: 163
http-outgoing-50 << Date: Tue, 04 Apr 2017 08:36:40 GMT
Connection can be kept alive indefinitely
Response Code : 200
Connection [id: 50][route: {}->http://stires-web-a.smst290.att.com:3100] can be kept alive
It multiples the log size by 10 or more!!!
How can I avoid those lines.
My log is log4j based.
Here is the solution: https://hc.apache.org/httpcomponents-client-ga/logging.html
I put the lines for log4j in my app main class constructor.
If you are using Log4j 2.x, then set the org.apache.http Logger to the Info level. This will block the log messages since those are logged at the Debug level.
<Logger name="org.apache.http" level="Info"/>

How to create get request using apache httpclient with "bad" symbols in url (that requere encoding)?

I'm trying to create auto test (java). Service should be able to handle request correctly: return json instead of java stack trace.
In this test i have cases like #host/some/path/?param=%
Ok, % is incorrect symbol and should be encoded. When you are developer and creating service that send requests. But this is a test.
So question is: how can i create get response with url «as is», without encoding? Currently i'm using apache httpclient (4.5.2)
Currently i have nothing really special:
public void fetchGet(String uri) {
HttpGet getRequest = new HttpGet(uri);
HttpClient client = HttpClientBuilder.create().build();
try {
response = client.execute(requestBase);
} catch (IOException e) {
e.printStackTrace();
} finally {
requestBase.abort();
}
}
Use BasicHttpRequest instead of HttpGet to compose a request message
CloseableHttpClient client = HttpClientBuilder.create().build();
BasicHttpRequest request = new BasicHttpRequest("GET", "all kind of c%.p");
try (CloseableHttpResponse response1 = client.execute(new HttpHost("www.google.com"), request)) {
System.out.println(response1.getStatusLine());
EntityUtils.consume(response1.getEntity());
}
This code produces the following message exchange
[DEBUG] ProtocolExec - Unable to parse 'all kind of c%.p' as a valid URI; request URI and Host header may be inconsistent <java.lang.IllegalArgumentException: Illegal character in path at index 3: all kind of c%.p>java.lang.IllegalArgumentException: Illegal character in path at index 3: all kind of c%.p
at java.net.URI.create(URI.java:852)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:120)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118)
at Testing.main(Testing.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.net.URISyntaxException: Illegal character in path at index 3: all kind of c%.p
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.checkChars(URI.java:3021)
at java.net.URI$Parser.parseHierarchical(URI.java:3105)
at java.net.URI$Parser.parse(URI.java:3063)
at java.net.URI.<init>(URI.java:588)
at java.net.URI.create(URI.java:850)
... 11 more
[DEBUG] RequestAddCookies - CookieSpec selected: default
[DEBUG] RequestAuthCache - Auth cache not set in the context
[DEBUG] PoolingHttpClientConnectionManager - Connection request: [route: {}->http://www.google.com:80][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
[DEBUG] PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://www.google.com:80][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
[DEBUG] MainClientExec - Opening connection {}->http://www.google.com:80
[DEBUG] DefaultHttpClientConnectionOperator - Connecting to www.google.com/216.58.213.100:80
[DEBUG] DefaultHttpClientConnectionOperator - Connection established xx.xx.xx.xx:36088<->216.58.213.100:80
[DEBUG] MainClientExec - Executing request GET all kind of c%.p HTTP/1.1
[DEBUG] MainClientExec - Target auth state: UNCHALLENGED
[DEBUG] MainClientExec - Proxy auth state: UNCHALLENGED
[DEBUG] headers - http-outgoing-0 >> GET all kind of c%.p HTTP/1.1
[DEBUG] headers - http-outgoing-0 >> Host: www.google.com
[DEBUG] headers - http-outgoing-0 >> Connection: Keep-Alive
[DEBUG] headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_112)
[DEBUG] headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
[DEBUG] headers - http-outgoing-0 << HTTP/1.1 400 Bad Request
[DEBUG] headers - http-outgoing-0 << Cache-Control: no-cache
[DEBUG] headers - http-outgoing-0 << Pragma: no-cache
[DEBUG] headers - http-outgoing-0 << Content-Type: text/html; charset=utf-8
[DEBUG] headers - http-outgoing-0 << Connection: close
[DEBUG] headers - http-outgoing-0 << Content-Length: 1904
HTTP/1.1 400 Bad Request
[DEBUG] DefaultManagedHttpClientConnection - http-outgoing-0: Close connection
[DEBUG] MainClientExec - Connection discarded
[DEBUG] PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://www.google.com:80][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]

How do I stop appache.commons.logging from spamming System.out?

I am writing a clojure app that uses Amazon S3. It is using the standard amazonaws library, under this wrapper. For some reason, it is logging to System.out a ton of DEBUG info, including but not limited to the entire binary file I am sending to S3.
As of writing this, I have tried setting up a log4j.properties file:
# Direct log messages to NULL gdmnt
log4j.appender.devnull=org.apache.log4j.varia.NullAppender
log4j.rootLogger=fatal, devnull
log4j.logger.httpclient.wire.header=ERROR
log4j.logger.httpclient.wire.content=ERROR
org.appache.http=ERROR
org.appache.http.wire=ERROR
org.appache.http.headers=ERROR
log4j.logger.com.amazonaws=WARN
log4j.logger.com.amazonaws.request=WARN
log4j.logger.com.amazonaws.http=WARN
log4j.logger.org.apache.http.wire = WARN
Yet it still sends DEBUG info. Yes, log4j is on my classpath. Here is a printout of my classpath filtered for log4j
/Users/collinbell/.m2/repository/org/apache/logging/log4j/log4j-api/2.7/log4j-api-2.7.jar
/Users/collinbell/.m2/repository/org/apache/logging/log4j/log4j-core/2.7/log4j-core-2.7.jar
Here is an example of the logs produced when I send just a simple string to an S3 bucket.
17:53:52.092 [nREPL-worker-0] DEBUG c.a.internal.config.InternalConfig - Configuration override awssdk_config_override.json not found.
17:53:52.126 [nREPL-worker-0] DEBUG c.a.services.s3.internal.S3Signer - Calculated string to sign:
"PUT
text/plain; charset=UTF-8
Tue, 10 Jan 2017 22:53:52 GMT
/eden-cybernetics-voice/key"
17:53:52.225 [nREPL-worker-0] DEBUG com.amazonaws.request - Sending Request: PUT https://eden-cybernetics-voice.s3.amazonaws.com /key Headers: (Authorization: AWS YA,FUCKTHAT=, User-Agent: aws-sdk-java/1.7.5 Mac_OS_X/10.11.5 Java_HotSpot(TM)_64-Bit_Server_VM/25.102-b14/1.8.0_102, Content-Length: 3, Date: Tue, 10 Jan 2017 22:53:52 GMT, Content-Type: text/plain; charset=UTF-8, )
17:53:52.326 [nREPL-worker-0] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Connection request: [route: {s}->https://eden-cybernetics-voice.s3.amazonaws.com:443][total kept alive: 0; route allocated: 0 of 50; total allocated: 0 of 50]
17:53:52.356 [nREPL-worker-0] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Connection leased: [id: 0][route: {s}->https://eden-cybernetics-voice.s3.amazonaws.com:443][total kept alive: 0; route allocated: 1 of 50; total allocated: 1 of 50]
17:53:52.889 [nREPL-worker-0] DEBUG o.a.h.i.c.DefaultClientConnectionOperator - Connecting to eden-cybernetics-voice.s3.amazonaws.com:443
17:53:53.145 [nREPL-worker-0] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
17:53:53.147 [nREPL-worker-0] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
17:53:53.148 [nREPL-worker-0] DEBUG o.a.h.c.p.RequestProxyAuthentication - Proxy auth state: UNCHALLENGED
17:53:53.149 [nREPL-worker-0] DEBUG c.a.http.impl.client.SdkHttpClient - Attempt 1 to execute request
17:53:53.150 [nREPL-worker-0] DEBUG o.a.h.i.conn.DefaultClientConnection - Sending request: PUT /key HTTP/1.1
17:53:53.151 [nREPL-worker-0] DEBUG org.apache.http.wire - >> "PUT /key HTTP/1.1[\r][\n]"
17:53:53.153 [nREPL-worker-0] DEBUG org.apache.http.wire - >> "Host: eden-cybernetics-voice.s3.amazonaws.com[\r][\n]"
17:53:53.154 [nREPL-worker-0] DEBUG org.apache.http.wire - >> "Authorization: AWS YA, FUCKTHAT=[\r][\n]"
17:53:53.155 [nREPL-worker-0] DEBUG org.apache.http.wire - >> "User-Agent: aws-sdk-java/1.7.5 Mac_OS_X/10.11.5 Java_HotSpot(TM)_64-Bit_Server_VM/25.102-b14/1.8.0_102[\r][\n]"
17:53:53.155 [nREPL-worker-0] DEBUG org.apache.http.wire - >> "Date: Tue, 10 Jan 2017 22:53:52 GMT[\r][\n]"
17:53:53.156 [nREPL-worker-0] DEBUG org.apache.http.wire - >> "Content-Type: text/plain; charset=UTF-8[\r][\n]"
17:53:53.156 [nREPL-worker-0] DEBUG org.apache.http.wire - >> "Content-Length: 3[\r][\n]"
17:53:53.157 [nREPL-worker-0] DEBUG org.apache.http.wire - >> "Connection: Keep-Alive[\r][\n]"
17:53:53.157 [nREPL-worker-0] DEBUG org.apache.http.wire - >> "Expect: 100-continue[\r][\n]"
17:53:53.157 [nREPL-worker-0] DEBUG org.apache.http.wire - >> "[\r][\n]"
17:53:53.158 [nREPL-worker-0] DEBUG org.apache.http.headers - >> PUT /key HTTP/1.1
17:53:53.158 [nREPL-worker-0] DEBUG org.apache.http.headers - >> Host: eden-cybernetics-voice.s3.amazonaws.com
17:53:53.158 [nREPL-worker-0] DEBUG org.apache.http.headers - >> Authorization: AWS YA, I AM NOT SHOWING YOU THIS=
17:53:53.159 [nREPL-worker-0] DEBUG org.apache.http.headers - >> User-Agent: aws-sdk-java/1.7.5 Mac_OS_X/10.11.5 Java_HotSpot(TM)_64-Bit_Server_VM/25.102-b14/1.8.0_102
17:53:53.159 [nREPL-worker-0] DEBUG org.apache.http.headers - >> Date: Tue, 10 Jan 2017 22:53:52 GMT
17:53:53.159 [nREPL-worker-0] DEBUG org.apache.http.headers - >> Content-Type: text/plain; charset=UTF-8
17:53:53.159 [nREPL-worker-0] DEBUG org.apache.http.headers - >> Content-Length: 3
17:53:53.159 [nREPL-worker-0] DEBUG org.apache.http.headers - >> Connection: Keep-Alive
17:53:53.160 [nREPL-worker-0] DEBUG org.apache.http.headers - >> Expect: 100-continue
17:53:53.209 [nREPL-worker-0] DEBUG org.apache.http.wire - << "HTTP/1.1 100 Continue[\r][\n]"
17:53:53.213 [nREPL-worker-0] DEBUG org.apache.http.wire - << "[\r][\n]"
17:53:53.214 [nREPL-worker-0] DEBUG o.a.h.i.conn.DefaultClientConnection - Receiving response: HTTP/1.1 100 Continue
17:53:53.214 [nREPL-worker-0] DEBUG org.apache.http.headers - << HTTP/1.1 100 Continue
17:53:53.215 [nREPL-worker-0] DEBUG org.apache.http.wire - >> "key"
17:53:53.252 [nREPL-worker-0] DEBUG org.apache.http.wire - << "HTTP/1.1 200 OK[\r][\n]"
17:53:53.253 [nREPL-worker-0] DEBUG org.apache.http.wire - << "x-amz-id-2: KxZ8+cp4/BDEm4hdEjaVI/8tUaz0RRh6hcM041BB5pMlHXGXTAjJS3hA3VojH6H4UlleHmD2HSE=[\r][\n]"
17:53:53.253 [nREPL-worker-0] DEBUG org.apache.http.wire - << "x-amz-request-id: F83687CB8CDEB189[\r][\n]"
17:53:53.254 [nREPL-worker-0] DEBUG org.apache.http.wire - << "Date: Tue, 10 Jan 2017 22:53:54 GMT[\r][\n]"
17:53:53.254 [nREPL-worker-0] DEBUG org.apache.http.wire - << "ETag: "3c6e0b8a9c15224a8228b9a98ca1531d"[\r][\n]"
17:53:53.255 [nREPL-worker-0] DEBUG org.apache.http.wire - << "Content-Length: 0[\r][\n]"
17:53:53.256 [nREPL-worker-0] DEBUG org.apache.http.wire - << "Server: AmazonS3[\r][\n]"
17:53:53.257 [nREPL-worker-0] DEBUG org.apache.http.wire - << "[\r][\n]"
17:53:53.258 [nREPL-worker-0] DEBUG o.a.h.i.conn.DefaultClientConnection - Receiving response: HTTP/1.1 200 OK
17:53:53.258 [nREPL-worker-0] DEBUG org.apache.http.headers - << HTTP/1.1 200 OK
17:53:53.258 [nREPL-worker-0] DEBUG org.apache.http.headers - << x-amz-id-2: KxZ8+cp4/BDEm4hdEjaVI/8tUaz0RRh6hcM041BB5pMlHXGXTAjJS3hA3VojH6H4UlleHmD2HSE=
17:53:53.259 [nREPL-worker-0] DEBUG org.apache.http.headers - << x-amz-request-id: F83687CB8CDEB189
17:53:53.259 [nREPL-worker-0] DEBUG org.apache.http.headers - << Date: Tue, 10 Jan 2017 22:53:54 GMT
17:53:53.259 [nREPL-worker-0] DEBUG org.apache.http.headers - << ETag: "3c6e0b8a9c15224a8228b9a98ca1531d"
17:53:53.259 [nREPL-worker-0] DEBUG org.apache.http.headers - << Content-Length: 0
17:53:53.260 [nREPL-worker-0] DEBUG org.apache.http.headers - << Server: AmazonS3
17:53:53.265 [nREPL-worker-0] DEBUG c.a.http.impl.client.SdkHttpClient - Connection can be kept alive indefinitely
17:53:53.276 [nREPL-worker-0] DEBUG com.amazonaws.request - Received successful response: 200, AWS Request ID: F83687CB8CDEB189
17:53:53.277 [nREPL-worker-0] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Connection [id: 0][route: {s}->https://eden-cybernetics-voice.s3.amazonaws.com:443] can be kept alive indefinitely
17:53:53.278 [nREPL-worker-0] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Connection released: [id: 0][route: {s}->https://eden-cybernetics-voice.s3.amazonaws.com:443][total kept alive: 1; route allocated: 1 of 50; total allocated: 1 of 50]
#object[com.amazonaws.services.s3.model.PutObjectResult 0x3822e74d "com.amazonaws.services.s3.model.PutObjectResult#3822e74d"]
17:54:51.712 [java-sdk-http-connection-reaper] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Closing connections idle longer than 60 SECONDS
17:55:51.793 [java-sdk-http-connection-reaper] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Closing connections idle longer than 60 SECONDS
17:55:51.881 [java-sdk-http-connection-reaper] DEBUG o.a.h.i.conn.DefaultClientConnection - Connection 0.0.0.0:61322<->52.216.80.64:443 closed
17:56:51.896 [java-sdk-http-connection-reaper] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Closing connections idle longer than 60 SECONDS
17:57:51.909 [java-sdk-http-connection-reaper] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Closing connections idle longer than 60 SECONDS
17:58:51.918 [java-sdk-http-connection-reaper] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Closing connections idle longer than 60 SECONDS
17:59:51.929 [java-sdk-http-connection-reaper] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Closing connections idle longer than 60 SECOND
My current strategy is to first find out if appache.commons.logging is even using log4j, but I don't know how to do that.
Next, I want to check that log4j is loading in the log4j.properties file.
Is this a good strategy? How do I accomplish it? Do you know another strategy?
S3 under clojure is unusable as is.
Here is my summarized project.clj:
(defproject voice "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:plugins [[lein-cljsbuild "1.1.5"]
[lein-figwheel "0.5.8"]]
:dependencies [[org.clojure/clojure "1.8.0"]
[org.apache.logging.log4j/log4j-core "2.7"]
[org.apache.logging.log4j/log4j-api "2.7"]
;browser repl
[org.clojure/clojurescript "1.9.293"]
[lein-figwheel "0.5.8"]
[figwheel-sidecar "0.5.8"]
;explicitly get the right version
[instaparse "1.4.0"]
;for the trainer
[org.deeplearning4j/deeplearning4j-core "0.7.1"]
[org.deeplearning4j/deeplearning4j-ui_2.10 "0.7.1"]
;[org.nd4j/nd4j-cuda-7.5 "0.7.1"] ;for cuda
[org.nd4j/nd4j-native "0.7.1"]
;for the sampler
[clojure-opennlp "0.3.3"]
[compojure "1.5.1"]
[hiccup "1.0.5"]
[http-kit "2.2.0"]
[garden "1.3.2"]
;;for the sampler client
[jayq "2.5.4"]
[cljs-ajax "0.5.8"]
;for the database
[korma "0.4.3"]
[org.postgresql/postgresql "9.4.1212"]
[clj-aws-s3 "0.3.10" :exclusions [joda-time]]
[org.clojure/data.json "0.2.6"]]
:profiles {:dev {:dependencies [[alembic "0.3.2"]
[org.clojure/tools.nrepl "0.2.10"]
[com.cemerick/piggieback "0.2.1"]]}}
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
:jvm-opts ["-Dlog4j.debug=true"]
:cljsbuild {
:builds [{
:source-paths ["src/cljs/"]
:id "dev"
:figwheel {:websocket-host "localhost"}
:compiler {
:main "voice.sampler"
:asset-path "js/out"
:output-to "resources/public/js/main.js"
:output-dir "resources/public/js/out"}}]})
Here is my fullish classpath:
/Users/collinbell/voice/test/
/Users/collinbell/voice/src/
/Users/collinbell/voice/dev-resources
/Users/collinbell/voice/resources/
/Users/collinbell/voice/target/classes/
/Users/collinbell/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.4.4/jackson-annotations-2.4.4.jar
/Users/collinbell/.m2/repository/org/nd4j/nd4j-jackson/0.7.1/nd4j-jackson-0.7.1.jar
/Users/collinbell/.m2/repository/net/jodah/typetools/0.4.3/typetools-0.4.3.jar
/Users/collinbell/.m2/repository/org/flatland/classlojure/0.7.0/classlojure-0.7.0.jar
/Users/collinbell/.m2/repository/com/mchange/mchange-commons-java/0.2.11/mchange-commons-java-0.2.11.jar
/Users/collinbell/.m2/repository/org/nd4j/jackson/0.7.1/jackson-0.7.1.jar
/Users/collinbell/.m2/repository/lein-as-resource/lein-as-resource/2.5.0/lein-as-resource-2.5.0.jar
/Users/collinbell/.m2/repository/org/apache/commons/commons-lang3/3.3.1/commons-lang3-3.3.1.jar
/Users/collinbell/.m2/repository/ring-cors/ring-cors/0.1.8/ring-cors-0.1.8.jar
/Users/collinbell/.m2/repository/org/clojure/tools.analyzer/0.6.9/tools.analyzer-0.6.9.jar
/Users/collinbell/.m2/repository/com/amazonaws/aws-java-sdk/1.7.5/aws-java-sdk-1.7.5.jar
/Users/collinbell/.m2/repository/ring/ring-core/1.5.0/ring-core-1.5.0.jar
/Users/collinbell/.m2/repository/org/nd4j/nd4j-common/0.7.1/nd4j-common-0.7.1.jar
/Users/collinbell/.m2/repository/org/bytedeco/javacpp-presets/leptonica/1.73-1.2/leptonica-1.73-1.2-macosx-x86_64.jar
/Users/collinbell/.m2/repository/com/typesafe/play/play-functional_2.10/2.4.6/play-functional_2.10-2.4.6.jar
/Users/collinbell/.m2/repository/com/google/jsinterop/jsinterop-annotations/1.0.0/jsinterop-annotations-1.0.0.jar
/Users/collinbell/.m2/repository/org/eclipse/collections/eclipse-collections-api/7.1.0/eclipse-collections-api-7.1.0.jar
/Users/collinbell/.m2/repository/com/typesafe/config/1.3.0/config-1.3.0.jar
/Users/collinbell/.m2/repository/com/stuartsierra/dependency/0.2.0/dependency-0.2.0.jar
/Users/collinbell/.m2/repository/org/bytedeco/javacpp-presets/leptonica/1.73-1.2/leptonica-1.73-1.2.jar
/Users/collinbell/.m2/repository/com/cemerick/piggieback/0.2.1/piggieback-0.2.1.jar
/Users/collinbell/.m2/repository/javax/inject/javax.inject/1/javax.inject-1.jar
/Users/collinbell/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-cbor/2.5.3/jackson-dataformat-cbor-2.5.3.jar
/Users/collinbell/.m2/repository/org/eclipse/collections/eclipse-collections/7.1.0/eclipse-collections-7.1.0.jar
/Users/collinbell/.m2/repository/org/tukaani/xz/1.5/xz-1.5.jar
/Users/collinbell/.m2/repository/compojure/compojure/1.5.1/compojure-1.5.1.jar
/Users/collinbell/.m2/repository/org/springframework/spring-beans/4.1.6.RELEASE/spring-beans-4.1.6.RELEASE.jar
/Users/collinbell/.m2/repository/com/twelvemonkeys/imageio/imageio-core/3.1.1/imageio-core-3.1.1.jar
/Users/collinbell/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.4.4/jackson-core-2.4.4.jar
/Users/collinbell/.m2/repository/org/slf4j/jul-to-slf4j/1.7.12/jul-to-slf4j-1.7.12.jar
/Users/collinbell/.m2/repository/org/bytedeco/javacpp-presets/opencv/3.1.0-1.2/opencv-3.1.0-1.2-macosx-x86_64.jar
/Users/collinbell/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar
/Users/collinbell/.m2/repository/org/springframework/spring-context/4.1.6.RELEASE/spring-context-4.1.6.RELEASE.jar
/Users/collinbell/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
/Users/collinbell/.m2/repository/net/cgrand/sjacket/0.1.1/sjacket-0.1.1.jar
/Users/collinbell/.m2/repository/org/eclipse/collections/eclipse-collections-forkjoin/7.1.0/eclipse-collections-forkjoin-7.1.0.jar
/Users/collinbell/.m2/repository/org/apache/httpcomponents/httpclient/4.5.1/httpclient-4.5.1.jar
/Users/collinbell/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/3.0.2-1.2/ffmpeg-3.0.2-1.2.jar
/Users/collinbell/.m2/repository/org/agrona/Agrona/0.5.4/Agrona-0.5.4.jar
/Users/collinbell/.m2/repository/com/typesafe/play/play-exceptions/2.4.6/play-exceptions-2.4.6.jar
/Users/collinbell/.m2/repository/commons-codec/commons-codec/1.6/commons-codec-1.6.jar
/Users/collinbell/.m2/repository/com/stuartsierra/component/0.3.1/component-0.3.1.jar
/Users/collinbell/.m2/repository/org/apache/directory/studio/org.apache.commons.codec/1.8/org.apache.commons.codec-1.8.jar
/Users/collinbell/.m2/repository/cider/cider-nrepl/0.15.0-SNAPSHOT/cider-nrepl-0.15.0-SNAPSHOT.jar
/Users/collinbell/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/3.0.2-1.2/ffmpeg-3.0.2-1.2-windows-x86_64.jar
/Users/collinbell/.m2/repository/org/apache/commons/commons-compress/1.8/commons-compress-1.8.jar
/Users/collinbell/.m2/repository/clj-aws-s3/clj-aws-s3/0.3.10/clj-aws-s3-0.3.10.jar
/Users/collinbell/.m2/repository/org/postgresql/postgresql/9.4.1212/postgresql-9.4.1212.jar
/Users/collinbell/.m2/repository/org/bytedeco/javacpp-presets/leptonica/1.73-1.2/leptonica-1.73-1.2-linux-x86_64.jar
/Users/collinbell/.m2/repository/org/ow2/asm/asm-all/4.2/asm-all-4.2.jar
/Users/collinbell/.m2/repository/com/twelvemonkeys/common/common-image/3.1.1/common-image-3.1.1.jar
/Users/collinbell/.m2/repository/garden/garden/1.3.2/garden-1.3.2.jar
/Users/collinbell/.m2/repository/com/twelvemonkeys/imageio/imageio-psd/3.1.1/imageio-psd-3.1.1.jar
/Users/collinbell/.m2/repository/org/nd4j/nd4j-buffer/0.7.1/nd4j-buffer-0.7.1.jar
/Users/collinbell/.m2/repository/io/netty/netty/3.10.4.Final/netty-3.10.4.Final.jar
/Users/collinbell/.m2/repository/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar
/Users/collinbell/.m2/repository/org/apache/httpcomponents/httpcore/4.4.4/httpcore-4.4.4.jar
/Users/collinbell/.m2/repository/org/clojure/data.json/0.2.6/data.json-0.2.6.jar
/Users/collinbell/.m2/repository/org/deeplearning4j/deeplearning4j-core/0.7.1/deeplearning4j-core-0.7.1.jar
/Users/collinbell/.m2/repository/org/clojure/data.priority-map/0.0.7/data.priority-map-0.0.7.jar
/Users/collinbell/.m2/repository/com/twelvemonkeys/imageio/imageio-bmp/3.1.1/imageio-bmp-3.1.1.jar
/Users/collinbell/.m2/repository/cljs-ajax/cljs-ajax/0.5.8/cljs-ajax-0.5.8.jar
/Users/collinbell/.m2/repository/org/clojure/tools.reader/1.0.0-beta3/tools.reader-1.0.0-beta3.jar
/Users/collinbell/.m2/repository/org/tcrawley/dynapath/0.2.5/dynapath-0.2.5.jar
/Users/collinbell/.m2/repository/xerces/xercesImpl/2.11.0/xercesImpl-2.11.0.jar
/Users/collinbell/.m2/repository/org/nd4j/nd4j-api/0.7.1/nd4j-api-0.7.1.jar
/Users/collinbell/.m2/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar
/Users/collinbell/.m2/repository/org/projectlombok/lombok/1.16.10/lombok-1.16.10.jar
/Users/collinbell/.m2/repository/com/yahoo/platform/yui/yuicompressor/2.4.8/yuicompressor-2.4.8.jar
/Users/collinbell/.m2/repository/org/yaml/snakeyaml/1.12/snakeyaml-1.12.jar
/Users/collinbell/.m2/repository/crypto-random/crypto-random/1.2.0/crypto-random-1.2.0.jar
/Users/collinbell/.m2/repository/org/mapdb/elsa/3.0.0-M5/elsa-3.0.0-M5.jar
/Users/collinbell/.m2/repository/org/deeplearning4j/deeplearning4j-ui-model/0.7.1/deeplearning4j-ui-model-0.7.1.jar
/Users/collinbell/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar
/Users/collinbell/.m2/repository/cheshire/cheshire/5.5.0/cheshire-5.5.0.jar
/Users/collinbell/.m2/repository/org/clojure/tools.nrepl/0.2.12/tools.nrepl-0.2.12.jar
/Users/collinbell/.m2/repository/com/google/code/findbugs/annotations/2.0.1/annotations-2.0.1.jar
/Users/collinbell/.m2/repository/org/deeplearning4j/deeplearning4j-nlp/0.7.1/deeplearning4j-nlp-0.7.1.jar
/Users/collinbell/.m2/repository/com/cognitect/transit-java/0.8.311/transit-java-0.8.311.jar
/Users/collinbell/.m2/repository/org/mapdb/mapdb/3.0.2/mapdb-3.0.2.jar
/Users/collinbell/.m2/repository/org/apache/logging/log4j/log4j-core/2.7/log4j-core-2.7.jar
/Users/collinbell/.m2/repository/org/mozilla/rhino/1.7R5/rhino-1.7R5.jar
/Users/collinbell/.m2/repository/strictly-specking-standalone/strictly-specking-standalone/0.1.1/strictly-specking-standalone-0.1.1.jar
/Users/collinbell/.m2/repository/com/typesafe/play/play-iteratees_2.10/2.4.6/play-iteratees_2.10-2.4.6.jar
/Users/collinbell/.m2/repository/com/twelvemonkeys/common/common-io/3.1.1/common-io-3.1.1.jar
/Users/collinbell/.m2/repository/org/nd4j/nd4j-native/0.7.1/nd4j-native-0.7.1.jar
/Users/collinbell/.m2/repository/ch/qos/logback/logback-core/1.1.3/logback-core-1.1.3.jar
/Users/collinbell/.m2/repository/http-kit/http-kit/2.2.0/http-kit-2.2.0.jar
/Users/collinbell/.m2/repository/org/jboss/logging/jboss-logging/3.2.1.Final/jboss-logging-3.2.1.Final.jar
/Users/collinbell/.m2/repository/org/bytedeco/javacpp-presets/leptonica/1.73-1.2/leptonica-1.73-1.2-windows-x86_64.jar
/Users/collinbell/.m2/repository/org/msgpack/msgpack/0.6.10/msgpack-0.6.10.jar
/Users/collinbell/.m2/repository/clojure-opennlp/clojure-opennlp/0.3.3/clojure-opennlp-0.3.3.jar
/Users/collinbell/.m2/repository/net/cgrand/parsley/0.9.3/parsley-0.9.3.jar
/Users/collinbell/.m2/repository/org/hibernate/hibernate-validator/5.0.3.Final/hibernate-validator-5.0.3.Final.jar
/Users/collinbell/.m2/repository/commons-fileupload/commons-fileupload/1.3.1/commons-fileupload-1.3.1.jar
/Users/collinbell/.m2/repository/net/incongru/watchservice/barbary-watchservice/1.0/barbary-watchservice-1.0.jar
/Users/collinbell/.m2/repository/com/google/guava/guava/19.0/guava-19.0.jar
/Users/collinbell/.m2/repository/com/mchange/c3p0/0.9.5.2/c3p0-0.9.5.2.jar
/Users/collinbell/.m2/repository/org/clojure/core.cache/0.6.5/core.cache-0.6.5.jar
/Users/collinbell/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/3.0.2-1.2/ffmpeg-3.0.2-1.2-linux-x86_64.jar
/Users/collinbell/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/3.0.2-1.2/ffmpeg-3.0.2-1.2-macosx-x86_64.jar
/Users/collinbell/.m2/repository/net/sf/jwordnet/jwnl/1.3.3/jwnl-1.3.3.jar
/Users/collinbell/.m2/repository/org/scala-lang/modules/scala-java8-compat_2.10/0.3.0/scala-java8-compat_2.10-0.3.0.jar
/Users/collinbell/.m2/repository/org/apache/httpcomponents/httpasyncclient/4.1.1/httpasyncclient-4.1.1.jar
/Users/collinbell/.m2/repository/com/twelvemonkeys/imageio/imageio-jpeg/3.1.1/imageio-jpeg-3.1.1.jar
/Users/collinbell/.m2/repository/clout/clout/2.1.2/clout-2.1.2.jar
/Users/collinbell/.m2/repository/clj-stacktrace/clj-stacktrace/0.2.8/clj-stacktrace-0.2.8.jar
/Users/collinbell/.m2/repository/com/typesafe/play/twirl-api_2.10/1.1.1/twirl-api_2.10-1.1.1.jar
/Users/collinbell/.m2/repository/com/google/protobuf/protobuf-java/2.5.0/protobuf-java-2.5.0.jar
/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/src.zip
/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/lib/tools.jar
/Users/collinbell/.m2/repository/org/apache/logging/log4j/log4j-api/2.7/log4j-api-2.7.jar
This isnt an answer but I cant comment with my low reputation :(. The spelling for the 'apache' namespace seems to be wrong in the config
org.appache.http=ERROR
org.appache.http.wire=ERROR
org.appache.http.headers=ERROR
I had the same issue,
creating a logback.xml and putting it on classpath with below config fixed it:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<logger name="org.apache" level="ERROR" />
<logger name="httpclient" level="ERROR" />
</configuration>
Hope it helps the others.

Apache HttpClient 4.4 Proxy Basic Auth: Multiple auth attemps

I'm trying to send requests with HTTP Client 4.4 through a proxy with Basic Auth.
If I enter the right credentials, then the connection is successful.
But if I enter the wrong credentials, all the following other connection attempts will fails even with the right credentials.
It seems like once we have supplied the (wrong) credentials for the first time, the new (correct or wrong) credentials are never sent.
You will see there are two calls:
1st call, wrong proxy credentials
2nd call, correct proxy credentials
The code:
package test;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
public class Main {
private HttpClient client;
private HttpClientContext context = HttpClientContext.create();
public static void main(String[] args) throws Exception {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "DEBUG");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "ERROR");
Main main = new Main();
main.createHttpClient();
main.send(true, "test", "wrong"); // 1st call, wrong credentials, if this call is removed, it works !
main.send(true, "test", "correct"); // 2nd call, correct credentials
}
public void send(String username, String password) throws Exception {
proxyAuthenticate(username, password);
HttpUriRequest request = new HttpGet("https://the-backend.xyz");
HttpResponse httpResponse = client.execute(request, context);
int statusCode = httpResponse.getStatusLine().getStatusCode();
System.out.println("######################### " + statusCode);
}
public void createHttpClient() throws Exception {
HttpClientBuilder httpClientBuilder = HttpClients.custom();
httpClientBuilder.setProxy(new HttpHost("proxy.the-proxy.xyz", 1234));
client = httpClientBuilder.build();
}
private void proxyAuthenticate(String username, String password) {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
AuthScope scope = new AuthScope("proxy.the-proxy.xyz", 1234);
CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(scope, credentials);
context.setCredentialsProvider(provider);
}
}
The logs for 1st attempt (connect with wrong proxy cred: two http requests one without the creds, one with the creds, both returns 407, looks logical):
2015/10/07 13:39:02:502 CEST [WARN] BasicAuthCache - Unexpected I/O
error while serializing auth scheme java.io.NotSerializableException: test.Main at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at
org.apache.http.impl.client.BasicAuthCache.put(BasicAuthCache.java:107)
at test.Main.proxyAuthenticate(Main.java:109) at
test.Main.send(Main.java:56) at test.Main2.main(Main2.java:30)
2015/10/07 13:39:02:502 CEST [DEBUG] RequestAddCookies - CookieSpec
selected: default 2015/10/07 13:39:02:502 CEST [DEBUG]
PoolingHttpClientConnectionManager - Connection request: [route:
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443][total
kept alive: 0; route allocated: 0 of 3; total allocated: 0 of 3]
2015/10/07 13:39:02:502 CEST [DEBUG]
PoolingHttpClientConnectionManager - Connection leased: [id: 1][route:
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443][total
kept alive: 0; route allocated: 1 of 3; total allocated: 1 of 3]
2015/10/07 13:39:02:502 CEST [DEBUG] MainClientExec - Opening
connection
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443
2015/10/07 13:39:02:502 CEST [DEBUG]
DefaultHttpClientConnectionOperator - Connecting to
proxy.the-proxy.xyz/123.45.67.890:1234 2015/10/07 13:39:07:530 CEST
[DEBUG] DefaultHttpClientConnectionOperator - Connection established
321.54.76.098:58216<->123.45.67.890:1234 2015/10/07 13:39:07:530 CEST [DEBUG] headers - http-outgoing-1 >> CONNECT
the-backend.xyz:443 HTTP/1.1 2015/10/07 13:39:07:530
CEST [DEBUG] headers - http-outgoing-1 >> Host:
the-backend.xyz 2015/10/07 13:39:07:530 CEST [DEBUG]
headers - http-outgoing-1 >> User-Agent: Apache-HttpClient/4.4.1
(Java/1.7.0_51) 2015/10/07 13:39:07:530 CEST [DEBUG] headers -
http-outgoing-1 << HTTP/1.1 407 Proxy Authentication Required
2015/10/07 13:39:07:530 CEST [DEBUG] headers - http-outgoing-1 <<
Proxy-Authenticate: BASIC realm="InternetAccess" 2015/10/07
13:39:07:530 CEST [DEBUG] headers - http-outgoing-1 << Cache-Control:
no-cache 2015/10/07 13:39:07:530 CEST [DEBUG] headers -
http-outgoing-1 << Pragma: no-cache 2015/10/07 13:39:07:530 CEST
[DEBUG] headers - http-outgoing-1 << Content-Type: text/html;
charset=utf-8 2015/10/07 13:39:07:530 CEST [DEBUG] headers -
http-outgoing-1 << Proxy-Connection: close 2015/10/07 13:39:07:530
CEST [DEBUG] headers - http-outgoing-1 << Connection: close 2015/10/07
13:39:07:530 CEST [DEBUG] headers - http-outgoing-1 << Content-Length:
2916 2015/10/07 13:39:07:530 CEST [DEBUG] HttpAuthenticator -
Authentication required 2015/10/07 13:39:07:530 CEST [DEBUG]
HttpAuthenticator - proxy.the-proxy.xyz:1234 requested authentication
2015/10/07 13:39:07:530 CEST [DEBUG] ProxyAuthenticationStrategy -
Authentication schemes in the order of preference: [Negotiate,
Kerberos, NTLM, Digest, Basic] 2015/10/07 13:39:07:530 CEST [DEBUG]
ProxyAuthenticationStrategy - Challenge for Negotiate authentication
scheme not available 2015/10/07 13:39:07:530 CEST [DEBUG]
ProxyAuthenticationStrategy - Challenge for Kerberos authentication
scheme not available 2015/10/07 13:39:07:530 CEST [DEBUG]
ProxyAuthenticationStrategy - Challenge for NTLM authentication scheme
not available 2015/10/07 13:39:07:530 CEST [DEBUG]
ProxyAuthenticationStrategy - Challenge for Digest authentication
scheme not available 2015/10/07 13:39:07:530 CEST [DEBUG]
HttpAuthenticator - Selected authentication options: [BASIC
[complete=true]] 2015/10/07 13:39:07:530 CEST [DEBUG]
DefaultManagedHttpClientConnection - http-outgoing-1: Close connection
2015/10/07 13:39:07:530 CEST [DEBUG]
DefaultHttpClientConnectionOperator - Connecting to
proxy.the-proxy.xyz/123.45.67.890:1234 2015/10/07 13:39:12:560 CEST
[DEBUG] DefaultHttpClientConnectionOperator - Connection established
321.54.76.098:58217<->123.45.67.890:1234 2015/10/07 13:39:12:560 CEST [DEBUG] HttpAuthenticator - Generating response to an authentication
challenge using basic scheme 2015/10/07 13:39:12:560 CEST [DEBUG]
headers - http-outgoing-1 >> CONNECT
the-backend.xyz:443 HTTP/1.1 2015/10/07 13:39:12:560
CEST [DEBUG] headers - http-outgoing-1 >> Host:
the-backend.xyz 2015/10/07 13:39:12:560 CEST [DEBUG]
headers - http-outgoing-1 >> User-Agent: Apache-HttpClient/4.4.1
(Java/1.7.0_51) 2015/10/07 13:39:12:560 CEST [DEBUG] headers -
http-outgoing-1 >> Proxy-Authorization: Basic xXXxxXxXXXXX 2015/10/07
13:39:12:561 CEST [DEBUG] headers - http-outgoing-1 << HTTP/1.1 407
Proxy Authentication Required 2015/10/07 13:39:12:561 CEST [DEBUG]
headers - http-outgoing-1 << Proxy-Authenticate: BASIC
realm="InternetAccess" 2015/10/07 13:39:12:561 CEST [DEBUG] headers -
http-outgoing-1 << Cache-Control: no-cache 2015/10/07 13:39:12:561
CEST [DEBUG] headers - http-outgoing-1 << Pragma: no-cache 2015/10/07
13:39:12:561 CEST [DEBUG] headers - http-outgoing-1 << Content-Type:
text/html; charset=utf-8 2015/10/07 13:39:12:561 CEST [DEBUG] headers
- http-outgoing-1 << Proxy-Connection: close 2015/10/07 13:39:12:561 CEST [DEBUG] headers - http-outgoing-1 << Connection: close 2015/10/07
13:39:12:561 CEST [DEBUG] headers - http-outgoing-1 << Content-Length:
2966 2015/10/07 13:39:12:561 CEST [DEBUG] HttpAuthenticator -
Authentication required 2015/10/07 13:39:12:561 CEST [DEBUG]
HttpAuthenticator - proxy.the-proxy.xyz:1234 requested authentication
2015/10/07 13:39:12:561 CEST [DEBUG] HttpAuthenticator - Authorization
challenge processed 2015/10/07 13:39:12:561 CEST [DEBUG]
HttpAuthenticator - Authentication failed 2015/10/07 13:39:12:561 CEST
[DEBUG] ProxyAuthenticationStrategy - Clearing cached auth scheme for
http://proxy.the-proxy.xyz:1234 2015/10/07 13:39:12:561 CEST [DEBUG]
DefaultManagedHttpClientConnection - http-outgoing-1: Close connection
2015/10/07 13:39:12:561 CEST [DEBUG] MainClientExec - CONNECT refused
by proxy: HTTP/1.1 407 Proxy Authentication Required 2015/10/07
13:39:12:561 CEST [DEBUG] DefaultManagedHttpClientConnection -
http-outgoing-1: Close connection 2015/10/07 13:39:12:561 CEST [DEBUG]
MainClientExec - Connection discarded 2015/10/07 13:39:12:561 CEST
[DEBUG] DefaultManagedHttpClientConnection - http-outgoing-1: Close
connection 2015/10/07 13:39:12:561 CEST [DEBUG]
PoolingHttpClientConnectionManager - Connection released: [id:
1][route:
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443][total
kept alive: 0; route allocated: 0 of 3; total allocated: 0 of 3]
################### 407
The logs for 2nd attempt (connect with correct proxy cred: only one http request, why isn't there a second request with the correct creds ???):
2015/10/07 13:39:17:585 CEST [WARN] BasicAuthCache - Unexpected I/O
error while serializing auth scheme java.io.NotSerializableException: test.Main at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at
org.apache.http.impl.client.BasicAuthCache.put(BasicAuthCache.java:107)
at test.Main.proxyAuthenticate(Main.java:109) at
test.Main.send(Main.java:56) at test.Main2.main(Main2.java:32)
2015/10/07 13:39:17:585 CEST [DEBUG] RequestAddCookies - CookieSpec
selected: default 2015/10/07 13:39:17:585 CEST [DEBUG]
PoolingHttpClientConnectionManager - Connection request: [route:
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443][total
kept alive: 0; route allocated: 0 of 3; total allocated: 0 of 3]
2015/10/07 13:39:17:585 CEST [DEBUG]
PoolingHttpClientConnectionManager - Connection leased: [id: 2][route:
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443][total
kept alive: 0; route allocated: 1 of 3; total allocated: 1 of 3]
2015/10/07 13:39:17:585 CEST [DEBUG] MainClientExec - Opening
connection
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443
2015/10/07 13:39:17:585 CEST [DEBUG]
DefaultHttpClientConnectionOperator - Connecting to
proxy.the-proxy.xyz/123.45.67.890:1234
2015/10/07 13:39:17:585 CEST [DEBUG] DefaultHttpClientConnectionOperator - Connection established
321.54.76.098:58218<->123.45.67.890:1234 2015/10/07 13:39:17:586 CEST [DEBUG] headers - http-outgoing-2 >> CONNECT
the-backend.xyz:443 HTTP/1.1 2015/10/07 13:39:17:586
CEST [DEBUG] headers - http-outgoing-2 >> Host:
the-backend.xyz 2015/10/07 13:39:17:586 CEST [DEBUG]
headers - http-outgoing-2 >> User-Agent: Apache-HttpClient/4.4.1
(Java/1.7.0_51) 2015/10/07 13:39:17:586 CEST [DEBUG] headers -
http-outgoing-2 << HTTP/1.1 407 Proxy Authentication Required
2015/10/07 13:39:17:586 CEST [DEBUG] headers - http-outgoing-2 <<
Proxy-Authenticate: BASIC realm="InternetAccess" 2015/10/07
13:39:17:586 CEST [DEBUG] headers - http-outgoing-2 << Cache-Control:
no-cache 2015/10/07 13:39:17:586 CEST [DEBUG] headers -
http-outgoing-2 << Pragma: no-cache 2015/10/07 13:39:17:586 CEST
[DEBUG] headers - http-outgoing-2 << Content-Type: text/html;
charset=utf-8 2015/10/07 13:39:17:586 CEST [DEBUG] headers -
http-outgoing-2 << Proxy-Connection: close 2015/10/07 13:39:17:586
CEST [DEBUG] headers - http-outgoing-2 << Connection: close 2015/10/07
13:39:17:586 CEST [DEBUG] headers - http-outgoing-2 << Content-Length:
2916 2015/10/07 13:39:17:586 CEST [DEBUG] HttpAuthenticator -
Authentication required 2015/10/07 13:39:17:586 CEST [DEBUG]
HttpAuthenticator - proxy.the-proxy.xyz:1234 requested authentication
2015/10/07 13:39:17:586 CEST [DEBUG]
DefaultManagedHttpClientConnection - http-outgoing-2: Close connection
2015/10/07 13:39:17:586 CEST [DEBUG] MainClientExec - CONNECT refused
by proxy: HTTP/1.1 407 Proxy Authentication Required 2015/10/07
13:39:17:586 CEST [DEBUG] DefaultManagedHttpClientConnection -
http-outgoing-2: Close connection 2015/10/07 13:39:17:586 CEST [DEBUG]
MainClientExec - Connection discarded 2015/10/07 13:39:17:586 CEST
[DEBUG] DefaultManagedHttpClientConnection - http-outgoing-2: Close
connection 2015/10/07 13:39:17:586 CEST [DEBUG]
PoolingHttpClientConnectionManager - Connection released: [id:
2][route:
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443][total
kept alive: 0; route allocated: 0 of 3; total allocated: 0 of 3]
################### 407
Any idea why on the 2nd attempt, it tries without the auth (normal), the server replies that Basic auth is required, then instead of trying with the correct credentials, it closes the connection.
Thanks !
UPDATE:
If I change the HttpClient (from 4.4) to DefaultHttpClient (from 4.3) and adapt these two methods, it works.
Note that the getCredentialsProvider is called from the client in 4.3 and from context in 4.4 !!!
First time I receive a 407 status code but second time I receive 200 which is what I expect.
public void createHttpClient() throws Exception {
client = new DefaultHttpClient();
HttpHost proxy = new HttpHost("proxy.eurocontrol.be", 9513);
ConnRouteParams.setDefaultProxy(client.getParams(), proxy);
}
private void proxyAuthenticate(String username, String password) {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
AuthScope scope = new AuthScope("proxy.eurocontrol.be", 9513);
client.getCredentialsProvider().setCredentials(scope, credentials);
// Called from client !!!!!!!!!!!!!!!!!
}
The first lines of the codes clearly tells that both the requests were made.
First at - 2015/10/07 13:39:02:502
Second at - 2015/10/07 13:39:17:585
What you are printing is the status code of the server response, see this and Http Status 407
Even your logs clearly say
Unexpected I/O error while serializing auth scheme java.io.NotSerializableException
There can be an exception due to serialization also.

Huge amount of debug data with AWS for Java

I am using the was-sdk-java.
Recently I get huge amount of debug data, a snapshot below, and it completely bugs down my system (as each line item is longer). Even the binary data appears.
2015-03-01 17:10:44,644 DEBUG ~ CookieSpec selected: best-match
2015-03-01 17:10:44,644 DEBUG ~ Auth cache not set in the context
2015-03-01 17:10:44,644 DEBUG ~ Proxy auth state: UNCHALLENGED
2015-03-01 17:10:44,644 DEBUG ~ Sending request: GET /app1/xxx HTTP/1.1
2015-03-01 17:10:44,644 DEBUG ~ >> "GET /app1/xxx HTTP/1.1[\r][\n]"
2015-03-01 17:10:44,645 DEBUG ~ >> "Host: testcerts.xxx.eu[\r][\n]"
2015-03-01 17:10:44,645 DEBUG ~ >> "Authorization: AWS xxx:xxx[\r][\n]"
2015-03-01 17:10:44,645 DEBUG ~ >> "Date: Sun, 01 Mar 2015 17:10:44 GMT[\r][\n]"
2015-03-01 17:10:44,645 DEBUG ~ >> "User-Agent: aws-sdk-java/1.7.13 Linux/3.13.0-46-generic OpenJDK_64-Bit_Server_VM/24.75-b04/1.7.0_75[\r][\n]"
2015-03-01 17:10:44,645 DEBUG ~ >> "Content-Type: application/x-www-form-urlencoded; charset=utf-8[\r][\n]"
2015-03-01 17:10:44,645 DEBUG ~ >> "Connection: Keep-Alive[\r][\n]"
2015-03-01 17:10:44,645 DEBUG ~ >> "[\r][\n]"
2015-03-01 17:10:44,646 DEBUG ~ >> GET /app1/xxx HTTP/1.1
2015-03-01 17:10:44,646 DEBUG ~ >> Host: testcerts.xxx
2015-03-01 17:10:44,646 DEBUG ~ >> Authorization: AWS xxx:xxx
2015-03-01 17:10:44,646 DEBUG ~ >> Date: Sun, 01 Mar 2015 17:10:44 GMT
2015-03-01 17:10:44,646 DEBUG ~ >> User-Agent: aws-sdk-java/1.7.13 Linux/3.13.0-46-generic OpenJDK_64-Bit_Server_VM/24.75-b04/1.7.0_75
2015-03-01 17:10:44,646 DEBUG ~ >> Content-Type: application/x-www-form-urlencoded; charset=utf-8
2015-03-01 17:10:44,646 DEBUG ~ >> Connection: Keep-Alive
2015-03-01 17:10:44,655 DEBUG ~ << "HTTP/1.1 200 OK[\r][\n]"
2015-03-01 17:10:44,656 DEBUG ~ << "Server: nginx[\r][\n]"
2015-03-01 17:10:44,656 DEBUG ~ << "Date: Sun, 01 Mar 2015 17:10:44 GMT[\r][\n]"
2015-03-01 17:10:44,656 DEBUG ~ << "Content-Type: application/x-pkcs12[\r][\n]"
2015-03-01 17:10:44,656 DEBUG ~ << "Content-Length: 3249[\r][\n]"
2015-03-01 17:10:44,656 DEBUG ~ << "Connection: keep-alive[\r][\n]"
2015-03-01 17:10:44,656 DEBUG ~ << "Bucket: "testcerts"[\r][\n]"
2015-03-01 17:10:44,657 DEBUG ~ << "Accept-Ranges: bytes[\r][\n]"
2015-03-01 17:10:44,657 DEBUG ~ << "Last-Modified: Fri, 23 Jan 2015 10:04:12 GMT[\r][\n]"
2015-03-01 17:10:44,657 DEBUG ~ << "ETag: "xxx"[\r][\n]"
2015-03-01 17:10:44,657 DEBUG ~ << "Age: 0[\r][\n]"
2015-03-01 17:10:44,658 DEBUG ~ << "X-Cache-Hit: No[\r][\n]"
2015-03-01 17:10:44,658 DEBUG ~ << "Accept-Ranges: bytes[\r][\n]"
2015-03-01 17:10:44,658 DEBUG ~ << "[\r][\n]"
2015-03-01 17:10:44,658 DEBUG ~ Receiving response: HTTP/1.1 200 OK
2015-03-01 17:10:44,658 DEBUG ~ << HTTP/1.1 200 OK
2015-03-01 17:10:44,659 DEBUG ~ << Server: nginx
2015-03-01 17:10:44,659 DEBUG ~ << Date: Sun, 01 Mar 2015 17:10:44 GMT
2015-03-01 17:10:44,659 DEBUG ~ << Content-Type: application/x-pkcs12
2015-03-01 17:10:44,659 DEBUG ~ << Content-Length: 3249
2015-03-01 17:10:44,659 DEBUG ~ << Connection: keep-alive
2015-03-01 17:10:44,659 DEBUG ~ << Bucket: "testcerts"
2015-03-01 17:10:44,660 DEBUG ~ << Accept-Ranges: bytes
2015-03-01 17:10:44,660 DEBUG ~ << Last-Modified: Fri, 23 Jan 2015 10:04:12 GMT
2015-03-01 17:10:44,660 DEBUG ~ << ETag: "xxx"
2015-03-01 17:10:44,660 DEBUG ~ << Age: 0
2015-03-01 17:10:44,660 DEBUG ~ << X-Cache-Hit: No
2015-03-01 17:10:44,660 DEBUG ~ << Accept-Ranges: bytes
I tried to turn this off in log4j, as debugging of the whole application is now impossible:
log4j.logger.httpclient.wire=INFO
log4j.logger.com.amazonaws=WARN
log4j.logger.com.amazonaws.request=WARN
But this doesn't seem to make any difference. Any suggestion why I suddenly get all these log warning, and what I can do about it?

Categories

Resources