Closed Diwahars closed 9 years ago
more infornation?
I'm having the same problem trying to run this: String apiVersion = zabbixApi.apiVersion(); System.out.println("api version:" + apiVersion);
Here's the output: 16:13:15.388 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> POST /zabbix/api_jsonrpc.php HTTP/1.1 16:13:15.389 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Type: application/json-rpc 16:13:15.389 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Length: 63 16:13:15.389 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: 192.168.7.26:10051 16:13:15.389 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive 16:13:15.389 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.3.6 (java 1.5) 16:13:15.389 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate 16:13:15.390 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "POST /zabbix/api_jsonrpc.php HTTP/1.1[\r][\n]" 16:13:15.390 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: application/json-rpc[\r][\n]" 16:13:15.390 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Length: 63[\r][\n]" 16:13:15.390 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: 192.168.7.26:10051[\r][\n]" 16:13:15.390 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]" 16:13:15.390 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.3.6 (java 1.5)[\r][\n]" 16:13:15.390 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" 16:13:15.390 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]" 16:13:15.391 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "{"id":1,"jsonrpc":"2.0","method":"apiinfo.version","params":{}}" 16:13:15.396 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "OK" 16:13:15.397 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "end of stream" 16:13:15.398 [main] DEBUG o.a.h.i.c.DefaultHttpResponseParser - Garbage in response: OK 16:13:15.399 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "end of stream" 16:13:15.399 [main] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: Close connection 16:13:15.399 [main] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: Shutdown connection 16:13:15.400 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Connection discarded 16:13:15.400 [main] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: Close connection 16:13:15.400 [main] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://192.168.7.26:10051][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20] Exception in thread "main" java.lang.RuntimeException: DefaultZabbixApi call exception! at io.github.hengyunabc.zabbix.api.DefaultZabbixApi.call(DefaultZabbixApi.java:147) at io.github.hengyunabc.zabbix.api.DefaultZabbixApi.apiVersion(DefaultZabbixApi.java:87) at io.github.hengyunabc.zabbix.api.test.HttpClientConfigExample.main(HttpClientConfigExample.java:31) Caused by: org.apache.http.client.ClientProtocolException at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) at io.github.hengyunabc.zabbix.api.DefaultZabbixApi.call(DefaultZabbixApi.java:142) ... 2 more Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:151) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260) at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161) at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:153) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ... 5 more
@aitchon It seems that server do not response correctly. You can use curl or telnet to test the server's state.
I used curl and it was successful.
-------- Original message -------- From: hengyunabc notifications@github.com Date: 10/03/2015 7:24 AM (GMT-05:00) To: hengyunabc/zabbix-api zabbix-api@noreply.github.com Cc: Al Itchon AItchon@boardreader.com Subject: Re: [zabbix-api] Runtime Exception!! (#4)
@aitchonhttps://github.com/aitchon It seems that server do not response correctly. You can use curl or telnet to test the server's state.
— Reply to this email directly or view it on GitHubhttps://github.com/hengyunabc/zabbix-api/issues/4#issuecomment-145238060.
Is there any network firewall? The different between java httpclient request and curl request is User-Agent
:
16:13:15.390 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.3.6 (java 1.5)[\r][\n]"
You can try to set User-Agent in java code.
I set the user agent along with a few other headers to match the curl headers: HttpUriRequest httpRequest = org.apache.http.client.methods.RequestBuilder .post().setUri(uri) .addHeader("Content-Type", "application/json-rpc") .addHeader("Accept", "/") .addHeader("User-Agent", "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2") .setEntity(new StringEntity(JSON.toJSONString(request))) .build(); curl output: -bash-4.1$ curl -i -X POST -H 'Content-Type: application/json-rpc' -d '{"id":1,"jsonrpc":"2.0","method":"apiinfo.version","params":[]}' http://192.168.7.26/zabbix/api_jsonrpc.php HTTP/1.1 200 OK Date: Mon, 05 Oct 2015 01:32:49 GMT Server: Apache/2.2.15 (CentOS) Access-Control-Allow-Origin: * Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Methods: POST Access-Control-Max-Age: 1000 Content-Length: 41 Connection: close Content-Type: application/json
{"jsonrpc":"2.0","result":"2.4.3","id":1}
Java output: 18:31:25.945 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: best-match 18:31:26.020 [main] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context 18:31:26.023 [main] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://192.168.7.26:10051][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20] 18:31:26.056 [main] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://192.168.7.26:10051][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20] 18:31:26.059 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Opening connection {}->http://192.168.7.26:10051 18:31:26.091 [main] DEBUG o.a.h.i.c.HttpClientConnectionOperator - Connecting to /192.168.7.26:10051 18:31:26.202 [main] DEBUG o.a.h.i.c.HttpClientConnectionOperator - Connection established 192.168.17.162:53245<->192.168.7.26:10051 18:31:26.202 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Executing request POST /zabbix/api_jsonrpc.php HTTP/1.1 18:31:26.202 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED 18:31:26.203 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED 18:31:26.206 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> POST /zabbix/apijsonrpc.php HTTP/1.1 18:31:26.206 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Type: application/json-rpc 18:31:26.206 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept: /_ 18:31:26.206 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2 18:31:26.206 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Length: 63 18:31:26.206 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: 192.168.7.26:10051 18:31:26.206 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive 18:31:26.206 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate 18:31:26.206 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "POST /zabbix/apijsonrpc.php HTTP/1.1[\r][\n]" 18:31:26.206 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: application/json-rpc[\r][\n]" 18:31:26.207 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: /_[\r][\n]" 18:31:26.207 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2[\r][\n]" 18:31:26.207 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Length: 63[\r][\n]" 18:31:26.207 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: 192.168.7.26:10051[\r][\n]" 18:31:26.207 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]" 18:31:26.207 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" 18:31:26.207 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]" 18:31:26.207 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "{"id":1,"jsonrpc":"2.0","method":"apiinfo.version","params":{}}" 18:31:26.207 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "OK" 18:31:26.207 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "end of stream" 18:31:26.208 [main] DEBUG o.a.h.i.c.DefaultHttpResponseParser - Garbage in response: OK 18:31:26.209 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "end of stream" 18:31:26.209 [main] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: Close connection 18:31:26.209 [main] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: Shutdown connection 18:31:26.209 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Connection discarded 18:31:26.209 [main] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: Close connection 18:31:26.209 [main] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://192.168.7.26:10051][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20] null Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58) Caused by: java.lang.RuntimeException: DefaultZabbixApi call exception! at io.github.hengyunabc.zabbix.api.DefaultZabbixApi.call(DefaultZabbixApi.java:150) at io.github.hengyunabc.zabbix.api.DefaultZabbixApi.apiVersion(DefaultZabbixApi.java:87) at io.github.hengyunabc.zabbix.api.test.HttpClientConfigExample.main(HttpClientConfigExample.java:31) ... 5 more Caused by: org.apache.http.client.ClientProtocolException at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) at io.github.hengyunabc.zabbix.api.DefaultZabbixApi.call(DefaultZabbixApi.java:144) ... 7 more Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:151) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260) at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161) at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:153) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ... 10 more
From: hengyunabc [mailto:notifications@github.com] Sent: Saturday, October 03, 2015 11:33 AM To: hengyunabc/zabbix-api zabbix-api@noreply.github.com Cc: Al Itchon AItchon@boardreader.com Subject: Re: [zabbix-api] Runtime Exception!! (#4)
Is there any network firewall? The different between java httpclient request and curl request is User-Agent:
16:13:15.390 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.3.6 (java 1.5)[\r][\n]"
You can try to set User-Agent in java code.
— Reply to this email directly or view it on GitHubhttps://github.com/hengyunabc/zabbix-api/issues/4#issuecomment-145256940.
@aitchon It seems that curl request send to port 80, but the java http request send to port 10051?
Thanks! I knew it had to be something simple like that.
From: hengyunabc [mailto:notifications@github.com] Sent: Sunday, October 04, 2015 9:59 PM To: hengyunabc/zabbix-api zabbix-api@noreply.github.com Cc: Al Itchon AItchon@boardreader.com Subject: Re: [zabbix-api] Runtime Exception!! (#4)
@aitchonhttps://github.com/aitchon It seems that curl request send to port 80, but the java http request send to port 10051?
— Reply to this email directly or view it on GitHubhttps://github.com/hengyunabc/zabbix-api/issues/4#issuecomment-145410434.
HI @hengyunabc ,
I'm getting below exception? how to resolve this? Exception in thread "main" java.lang.RuntimeException: DefaultZabbixApi call exception! at com.java.emc.zabbixpoc.DefaultZabbixApi.call(DefaultZabbixApi.java:147) at com.java.emc.zabbixpoc.ZabbixTriggerModelVer2.main(ZabbixTriggerModelVer2.java:143)