hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pan John-CXP001" <johnx...@motorola.com>
Subject RE: Help on the httpclient
Date Wed, 20 Jul 2005 20:00:06 GMT
The contents server send back is the result of the issued command. 
I just want to know is there anyway I can get the content without
trigger an exception?

--John

-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@apache.org] 
Sent: Wednesday, July 20, 2005 12:06 PM
To: HttpClient User Discussion
Subject: RE: Help on the httpclient

John,

The server sends back something that even vaguely does not resemble a
valid HTTP response:

>> "GET /execcmd?sh&vers& HTTP/1.0[\r][\n]"
>> "User-Agent: Jakarta Commons-HttpClient/3.0-rc3[\r][\n]"
>> "Authorization: Basic X1RQ9IVSFOFQUF9KOk0=[\r][\n]"
>> "Host: 10.79.134.111[\r][\n]"
>> "[\r][\n]"
<< "200[\r][\n]"
<< "Copyright (c) 2002-2004 Motorola, Inc. All Rights Reserved.[\r][\n]"
<< "[\r]Copyright (c) 1986-2000 3Com Corporation. All Rights
Reserved.[\r][\n]"
<< "SW/ST5000-PS,12.3.0.13, booted on Sun Jul 17 16:01 from local
flash[\r][\n]"
<< "FW/ST5000-BOOT1,2.2.0.01[\r][\n]"
<< "Booted image: 'a:/primary/boot.ppc'.[\r][\n]"
<< "Configuration file source: 'a:/secondar'.[\r][\n]"
<< "CPU: MPC-750[\r][\n]"
<< "X25 - 3.3[\r][\n]"
<< "Frame Relay - 2.0[\r][\n]"
<< "CLNP - 2.0[\r][\n]"
<< "Firmware Version FW/ST5000-BOOT2,4.3.0.02[\r][\n]"
<< "null[\r][\n]"

HttpClient is not a browser and is not intended for handling any
arbitrary content.

Oleg



On Wed, 2005-07-20 at 13:51 -0400, Pan John-CXP001 wrote:
> Just did a little Further check in the debugging message. It seems the

> server is sending back the contents in the header.
> But when I send the same url through IE explorer, the returned message

> from server is intepreted by IE browser correctly.
> 
> -John
> 
> -----Original Message-----
> From: Pan John-CXP001
> Sent: Wednesday, July 20, 2005 10:13 AM
> To: HttpClient User Discussion
> Subject: RE: Help on the httpclient
> 
> Roland: 
> 
> Thanks for the prompt reply. The following are the debugging printout.

> I did find that the command result was sent back by server in the
> debugging message, but why the    method.getResponseBodyAsString()
> doesn't print the result out. What causes the exception?
> 
> --John
> 
> ----------------------------------------------------------------------
> --
> -------------------------
> 2005/07/20 09:52:58:271 PDT [DEBUG] HttpClient - Java version: 
> 1.4.2_08 2005/07/20 09:52:58:302 PDT [DEBUG] HttpClient - Java vendor:

> Sun Microsystems Inc.
> 2005/07/20 09:52:58:312 PDT [DEBUG] HttpClient - Java class path:
> D:\BCMJava\classes;C:\JBuilder9\lib\moca\commons-cli-1.0.jar;C:\JBuild
> er 
> 9\lib\moca\pnm_al.jar;C:\JBuilder9\lib\moca\pnm_common.jar;C:\JBuilder
> 9\ 
> lib\moca\pnm_idl.jar;C:\JBuilder9\lib\moca\jutil.jar;C:\JBuilder9\lib\
> mo 
> ca\snmp4_13.jar;C:\JBuilder9\lib\moca\commons-httpclient-3.0-rc3.jar;C
> :\ 
> JBuilder9\lib\moca\commons-logging.jar;C:\JBuilder9\lib\moca\commons-l
> og 
> ging-api.jar;C:\JBuilder9\lib\moca\commons-codec-1.3.jar;C:\j2sdk1.4.2
> _0 
> 8\demo\jfc\Java2D\Java2Demo.jar;C:\j2sdk1.4.2_08\demo\plugin\jfc\Java2
> D\ 
> Java2Demo.jar;C:\j2sdk1.4.2_08\jre\javaws\javaws.jar;C:\j2sdk1.4.2_08\
> jr 
> e\lib\charsets.jar;C:\j2sdk1.4.2_08\jre\lib\ext\dnsns.jar;C:\j2sdk1.4.
> 2_ 
> 08\jre\lib\ext\ldapsec.jar;C:\j2sdk1.4.2_08\jre\lib\ext\localedata.jar
> ;C 
> :\j2sdk1.4.2_08\jre\lib\ext\sunjce_provider.jar;C:\j2sdk1.4.2_08\jre\l
> ib 
> \im\indicim.jar;C:\j2sdk1.4.2_08\jre\lib\im\thaiim.jar;C:\j2sdk1.4.2_0
> 8\ 
> jre\lib\jce.jar;C:\j2sdk1.4.2_08\jre\lib\jsse.jar;C:\j2sdk1.4.2_08\jre
> \l 
> ib\plugin.jar;C:\j2sdk1.4.2_08\jre\lib\rt.jar;C:\j2sdk1.4.2_08\jre\lib
> \s 
> unrsasign.jar;C:\j2sdk1.4.2_08\lib\dt.jar;C:\j2sdk1.4.2_08\lib\htmlcon
> ve rter.jar;C:\j2sdk1.4.2_08\lib\tools.jar
> 2005/07/20 09:52:58:342 PDT [DEBUG] HttpClient - Operating system
name:
> Windows XP
> 2005/07/20 09:52:58:342 PDT [DEBUG] HttpClient - Operating system
> architecture: x86
> 2005/07/20 09:52:58:352 PDT [DEBUG] HttpClient - Operating system
> version: 5.1
> 2005/07/20 09:52:59:023 PDT [DEBUG] HttpClient - SUN 1.42: SUN (DSA 
> key/parameter generation; DSA signing; SHA-1, MD5 digests; 
> SecureRandom;
> X.509 certificates; JKS keystore; PKIX CertPathValidator; PKIX 
> CertPathBuilder; LDAP, Collection CertStores) 2005/07/20 09:52:59:023 
> PDT [DEBUG] HttpClient - SunJSSE 1.42: Sun JSSE provider(implements 
> RSA Signatures, PKCS12, SunX509 key/trust factories, SSLv3, TLSv1) 
> 2005/07/20 09:52:59:023 PDT [DEBUG] HttpClient - SunRsaSign 1.42: 
> SUN's provider for RSA signatures 2005/07/20 09:52:59:023 PDT [DEBUG] 
> HttpClient - SunJCE 1.42: SunJCE Provider (implements DES, Triple DES,

> AES, Blowfish, PBE, Diffie-Hellman, HMAC-MD5, HMAC-SHA1) 2005/07/20
> 09:52:59:043 PDT [DEBUG] HttpClient - SunJGSS 1.0: Sun (Kerberos v5) 
> 2005/07/20 09:52:59:043 PDT [DEBUG] DefaultHttpParams - Set parameter 
> http.useragent = Jakarta Commons-HttpClient/3.0-rc3 2005/07/20
> 09:52:59:063 PDT [DEBUG] DefaultHttpParams - Set parameter 
> http.protocol.version = HTTP/1.1 2005/07/20 09:52:59:073 PDT [DEBUG] 
> DefaultHttpParams - Set parameter http.connection-manager.class = 
> class org.apache.commons.httpclient.SimpleHttpConnectionManager
> 2005/07/20 09:52:59:073 PDT [DEBUG] DefaultHttpParams - Set parameter 
> http.protocol.cookie-policy = rfc2109 2005/07/20 09:52:59:073 PDT 
> [DEBUG] DefaultHttpParams - Set parameter 
> http.protocol.element-charset = US-ASCII 2005/07/20 09:52:59:073 PDT 
> [DEBUG] DefaultHttpParams - Set parameter 
> http.protocol.content-charset = ISO-8859-1 2005/07/20
> 09:52:59:073 PDT [DEBUG] DefaultHttpParams - Set parameter 
> http.method.retry-handler =
> org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@1dd46f7
> 2005/07/20 09:52:59:083 PDT [DEBUG] DefaultHttpParams - Set parameter 
> http.dateparser.patterns = [EEE, dd MMM yyyy HH:mm:ss zzz, EEEE, 
> dd-MMM-yy HH:mm:ss zzz, EEE MMM d HH:mm:ss yyyy, EEE, dd-MMM-yyyy 
> HH:mm:ss z, EEE, dd-MMM-yyyy HH-mm-ss z, EEE, dd MMM yy HH:mm:ss z, 
> EEE dd-MMM-yyyy HH:mm:ss z, EEE dd MMM yyyy HH:mm:ss z, EEE 
> dd-MMM-yyyy HH-mm-ss z, EEE dd-MMM-yy HH:mm:ss z, EEE dd MMM yy 
> HH:mm:ss z, EEE,dd-MMM-yy HH:mm:ss z, EEE,dd-MMM-yyyy HH:mm:ss z, EEE,

> dd-MM-yyyy HH:mm:ss z] 2005/07/20 09:52:59:083 PDT [DEBUG] 
> DefaultHttpParams - Set parameter http.authentication.preemptive = 
> true 2005/07/20 09:52:59:083 PDT [DEBUG] DefaultHttpParams - Set 
> parameter http.protocol.version = HTTP/1.0 2005/07/20 09:52:59:203 PDT

> [DEBUG] DefaultHttpParams - Set parameter http.method.retry-handler =
> org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@1dfafd1
> 2005/07/20 09:52:59:413 PDT [DEBUG] HttpMethodDirector - Preemptively 
> sending default basic credentials 2005/07/20 09:53:00:204 PDT [DEBUG] 
> HttpMethodDirector - Authenticating with BASIC <any
> realm>@10.79.134.111:80 2005/07/20 09:53:00:214 PDT [DEBUG]
> HttpMethodParams - Credential charset not configured, using HTTP 
> element charset 2005/07/20 09:53:00:224 PDT [DEBUG] HttpConnection - 
> Open connection to 10.79.134.111:80 2005/07/20 09:53:00:775 PDT 
> [DEBUG] header - >> "GET /execcmd?sh&vers& HTTP/1.0[\r][\n]"
> 2005/07/20 09:53:00:775 PDT [DEBUG] HttpMethodBase - Adding Host 
> request header 2005/07/20 09:53:00:815 PDT [DEBUG] header - >>
"Authorization:
> Basic X1RQ9IVSFOFQUF9KOk0=[\r][\n]"
> 2005/07/20 09:53:00:815 PDT [DEBUG] header - >> "User-Agent: Jakarta 
> Commons-HttpClient/3.0-rc3[\r][\n]"
> 2005/07/20 09:53:00:815 PDT [DEBUG] header - >> "Host:
> 10.79.134.111[\r][\n]"
> 2005/07/20 09:53:00:815 PDT [DEBUG] header - >> "[\r][\n]"
> 2005/07/20 09:53:01:086 PDT [DEBUG] header - << "HTTP/1.0 401 
> Unauthorized[\r][\n]"
> 2005/07/20 09:53:01:096 PDT [DEBUG] header - << "Server:
> NetBuilderHTTPDv0.1[\r][\n]"
> 2005/07/20 09:53:01:096 PDT [DEBUG] header - << "WWW-Authenticate: 
> Basic realm="ST5000_r122"[\r][\n]"
> 2005/07/20 09:53:01:096 PDT [DEBUG] HttpMethodDirector - Authorization

> required 2005/07/20 09:53:01:096 PDT [DEBUG] AuthChallengeProcessor - 
> Supported authentication schemes in the order of preference: [ntlm, 
> digest, basic] 2005/07/20 09:53:01:096 PDT [DEBUG] 
> AuthChallengeProcessor - Challenge for ntlm authentication scheme not 
> available 2005/07/20 09:53:01:106 PDT [DEBUG] AuthChallengeProcessor -

> Challenge for digest authentication scheme not available 2005/07/20
> 09:53:01:106 PDT [INFO] AuthChallengeProcessor - basic authentication 
> scheme selected 2005/07/20 09:53:01:106 PDT [DEBUG] 
> AuthChallengeProcessor - Using authentication scheme: basic 2005/07/20
> 09:53:01:106 PDT [DEBUG] AuthChallengeProcessor - Authorization 
> challenge processed 2005/07/20 09:53:01:106 PDT [DEBUG] 
> HttpMethodDirector - Authentication
> scope: BASIC 'ST5000_r122'@10.79.134.111:80 2005/07/20 09:53:01:106 
> PDT [DEBUG] HttpMethodDirector - Retry authentication 2005/07/20
> 09:53:01:106 PDT [DEBUG] HttpMethodBase - Resorting to protocol 
> version default close connection policy 2005/07/20 09:53:01:106 PDT 
> [DEBUG] HttpMethodBase - Should close connection, using HTTP/1.0 
> 2005/07/20
> 09:53:01:106 PDT [DEBUG] HttpConnection - Connection is locked.  Call 
> to
> releaseConnection() ignored.
> 2005/07/20 09:53:01:106 PDT [DEBUG] HttpMethodDirector - 
> Authenticating with BASIC 'ST5000_r122'@10.79.134.111:80 2005/07/20 
> 09:53:01:116 PDT [DEBUG] HttpMethodParams - Credential charset not 
> configured, using HTTP element charset 2005/07/20 09:53:01:116 PDT 
> [DEBUG] HttpConnection - Open connection to 10.79.134.111:80 
> 2005/07/20 09:53:01:546 PDT [DEBUG] header - >> "GET /execcmd?sh&vers&
HTTP/1.0[\r][\n]"
> 2005/07/20 09:53:01:546 PDT [DEBUG] HttpMethodBase - Adding Host 
> request header 2005/07/20 09:53:01:546 PDT [DEBUG] header - >>
"User-Agent:
> Jakarta Commons-HttpClient/3.0-rc3[\r][\n]"
> 2005/07/20 09:53:01:546 PDT [DEBUG] header - >> "Authorization: Basic 
> X1RQ9IVSFOFQUF9KOk0=[\r][\n]"
> 2005/07/20 09:53:01:556 PDT [DEBUG] header - >> "Host:
> 10.79.134.111[\r][\n]"
> 2005/07/20 09:53:01:556 PDT [DEBUG] header - >> "[\r][\n]"
> 2005/07/20 09:53:01:877 PDT [DEBUG] header - << "200[\r][\n]"
> 2005/07/20 09:53:01:877 PDT [DEBUG] header - << "Copyright (c) 
> 2002-2004 Motorola, Inc. All Rights Reserved.[\r][\n]"
> 2005/07/20 09:53:01:877 PDT [DEBUG] header - << "[\r]Copyright (c) 
> 1986-2000 3Com Corporation. All Rights Reserved.[\r][\n]"
> 2005/07/20 09:53:01:877 PDT [DEBUG] header - << 
> "SW/ST5000-PS,12.3.0.13, booted on Sun Jul 17 16:01 from local
flash[\r][\n]"
> 2005/07/20 09:53:01:877 PDT [DEBUG] header - << 
> "FW/ST5000-BOOT1,2.2.0.01[\r][\n]"
> 2005/07/20 09:53:01:907 PDT [DEBUG] header - << "Booted image:
> 'a:/primary/boot.ppc'.[\r][\n]"
> 2005/07/20 09:53:01:917 PDT [DEBUG] header - << "Configuration file
> source: 'a:/secondar'.[\r][\n]"
> 2005/07/20 09:53:01:917 PDT [DEBUG] header - << "CPU: MPC-750[\r][\n]"
> 2005/07/20 09:53:01:917 PDT [DEBUG] header - << "X25 - 3.3[\r][\n]"
> 2005/07/20 09:53:01:917 PDT [DEBUG] header - << "Frame Relay - 
> 2.0[\r][\n]"
> 2005/07/20 09:53:01:917 PDT [DEBUG] header - << "CLNP - 2.0[\r][\n]"
> 2005/07/20 09:53:01:917 PDT [DEBUG] header - << "Firmware Version 
> FW/ST5000-BOOT2,4.3.0.02[\r][\n]"
> 2005/07/20 09:53:02:067 PDT [DEBUG] header - << "null[\r][\n]"
> 2005/07/20 09:53:02:067 PDT [DEBUG] HttpMethodDirector - Closing the 
> connection.
> 2005/07/20 09:53:02:067 PDT [DEBUG] HttpConnection - Releasing 
> connection back to connection manager.
> Fatal protocol violation: The server 10.79.134.111 failed to respond 
> with a valid HTTP response
> org.apache.commons.httpclient.ProtocolException: The server
> 10.79.134.111 failed to respond with a valid HTTP response
> 	at
> org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethod
> Ba
> se.java:1846)
> 	at
> org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBa
> se
> .java:1592)
> 	at
> org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.ja
> va
> :995)
> 	at
> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Http
> Me
> thodDirector.java:393)
> 	at
> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMet
> ho
> dDirector.java:168)
> 	at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java
> :3
> 96)
> 	at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java
> :3
> 24)
> 	at
> com.motorola.moca.bcm.bcmutils.BcmRuncmd.main(BcmRuncmd.java:62)
> 2005/07/20 09:53:02:117 PDT [DEBUG] HttpConnection - Releasing 
> connection back to connection manager.
> 
> 
> -----Original Message-----
> From: Roland Weber [mailto:ROLWEBER@de.ibm.com]
> Sent: Tuesday, July 19, 2005 10:42 PM
> To: HttpClient User Discussion
> Subject: Re: Help on the httpclient
> 
> Hi John,
> 
> please post a wire log so we know what's going on:
> http://jakarta.apache.org/commons/httpclient/logging.html
> 
> cheers,
>   Roland
> 
> 
> 
> 
> 
> "Pan John-CXP001" <johnxpan@motorola.com>
> 20.07.2005 05:42
> Please respond to
> "HttpClient User Discussion"
> 
> 
> To
> <httpclient-user@jakarta.apache.org>
> cc
> 
> Subject
> Help on the httpclient
> 
> 
> 
> 
> 
> 
> I wrote a simple http client to talk with the http server running on 
> one of our routers. The server version is 1.0.  However, when I do a 
> GET on the router, I got the following error message.
>  
> 2005-7-19 20:35:10
> org.apache.commons.httpclient.auth.AuthChallengeProcessor
> selectAuthScheme
> info: basic authentication scheme selected Fatal protocol violation: 
> The server 10.79.134.111 failed to respond with a valid HTTP response
> org.apache.commons.httpclient.ProtocolException: The server
> 10.79.134.111 failed to respond with a valid HTTP response  at 
> org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethod
> Ba
> se.java:1846)
>  at
> org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBa
> se
> .java:1592)
>  at
> org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.ja
> va
> :995)
>  at
> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Http
> Me
> thodDirector.java:393)
>  at
> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMet
> ho
> dDirector.java:168)
>  at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java
> :3
> 96)
>  at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java
> :3
> 24)
>  at com.motorola.moca.bcm.bcmutils.BcmRuncmd.main(BcmRuncmd.java:57)
> 
> When I use the IE browser to access the same webpage 
> "http://10.79.134.111/execcmd?sh&vers
> <http://10.79.134.111/execcmd?sh&vers> &" on my router, it works fine.
> I am confused since I don't know it's my client problem or it's 
> router's http server problem.
>  
> Any help will be appreciated;
>  
> 
> --John
>  
> 
> ----------------------------------------------------------------------
> --
> -------------------------------
> import org.apache.commons.httpclient.*; import 
> org.apache.commons.httpclient.methods.*;
> import org.apache.commons.httpclient.params.HttpMethodParams;
> import org.apache.commons.httpclient.auth.*;
> import org.apache.commons.httpclient.HttpVersion;
> import java.io.*;
>  
> public class BcmRuncmd {
>   public BcmRuncmd() {
>   }
> 
>   // Define the url
>   // http://10.79.134.111/execcmd?sh&vers
> <http://10.79.134.111/execcmd?sh&vers> &  -- works on IE
>   private static String url = "http://10.79.134.111/execcmd?sh&vers
> <http://10.79.134.111/execcmd?sh&vers> &";
>   //private static   String url =
> "http://mail-archives.apache.org/mod_mbox/jakarta-httpclient-user/2005
> 07
> .mbox/threads.html
> <http://mail-archives.apache.org/mod_mbox/jakarta-httpclient-user/2005
> 07
> .mbox/threads.html> ";
> 
>     public static void main(String[] args) {
>      // Create an instance of HttpClient.
>       HttpClient client = new HttpClient();
>  
>       //Set Authentication
>       client.getParams().setAuthenticationPreemptive(true);
>       client.getParams().setVersion(HttpVersion.HTTP_1_0);
>       UsernamePasswordCredentials upc = new 
> UsernamePasswordCredentials("john", "mypwd");
>       client.getState().setCredentials(AuthScope.ANY,upc);
>  
>       // Create a method instance.
>       GetMethod method = new GetMethod(url);
>       method.setDoAuthentication(true);
>  
>       // Provide custom retry handler is necessary
>       method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
> new DefaultHttpMethodRetryHandler(3, false));
>  
>       try {
>         // Execute the method.
>         int statusCode = client.executeMethod(method);
>  
>         System.out.println("Status Text >>> " + 
> HttpStatus.getStatusText(statusCode));
>         if (statusCode != HttpStatus.SC_OK) {
>           System.err.println("Method failed: " + 
> method.getStatusLine());
>         }
>  
> 
>         // Read the response body.
>          System.out.println(new
> String(method.getResponseBodyAsString()));
>  
>       } catch (HttpException e) {
>         System.err.println("Fatal protocol violation: " + 
> e.getMessage());
>         e.printStackTrace();
>       } catch (IOException e) {
>         System.err.println("Fatal transport error: " +
e.getMessage());
>         e.printStackTrace();
>       } finally {
>         // Release the connection.
>         method.releaseConnection();
>       }
>     }
> }
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> httpclient-user-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> httpclient-user-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> httpclient-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message