You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by fr...@b-rail.be on 2003/04/11 10:27:00 UTC
Already tried to authenticate to "extranettest.r
kw-onafts.fgov.be#null" but still receiving 407
Hi,
I use now the nightly build which fix previous problem i have before.
Now i seem to have a problem to authenticate my client to the proxy. This code work fine when i use the alpha 2 release
But now i have this error:
java.lang.IllegalStateException: Not Used.
at org.apache.commons.httpclient.HttpMethodBase.checkUsed(HttpMethodBase.java:1580)
at org.apache.commons.httpclient.methods.GetMethod.getResponseBodyAsStream(GetMethod.java:309)
at be.brail.util.https.BrailHttpsBroker.postByte(BrailHttpsBroker.java:399)
at be.brail.rkw.BrailComTools.login(BrailComTools.java:107)2003-04-11 08:26:41,109
INFO <org.apache.commons.httpclient.HttpMethodBase> Already tried to authenticate to "extranettest.rkw-onafts.fgov.be#null" but still receiving 407.
2003-04-11 08:26:41,109 DEBUG <org.apache.commons.httpclient.ConnectMethod> CONNECT status code 407
2003-04-11 08:26:41,109 DEBUG <org.apache.commons.httpclient.methods.GetMethod> enter GetMethod.getResponseBodyAsStream()
at TestWithHttpInterface.main(TestWithHttpInterface.java:44)
Exception in thread "main"
Here is the part of code for the authentification:
public static synchronized HttpClient initialiseConnection(String host, int port,
String proxyhost,int proxyport,
String proxyUser, String proxyPswd,
String domain,
SecureProtocolSocketFactory sslSFact)
{
log4j.debug("Enter in brailSSLProtocol.initialiseConnection with proxy");
///Nt authentification class needed to contact the proxy
NTCredentials usrPassCr = new NTCredentials(proxyUser,proxyPswd,proxyhost,"CAMPBMZF");
HttpClient client = new HttpClient();
Protocol myHTTPS = new Protocol( "https", sslSFact, 443 );
client.getHostConfiguration().setHost(host,port,myHTTPS);
client.getHostConfiguration().setProxy(proxyhost,proxyport);
log4j.debug("Before the method setProxyCredentials");
client.getState().setProxyCredentials(null,usrPassCr);
log4j.debug("After the method setProxyCredentials");
return client;
}
And the method where the error occurs:
public HttpServerResponse postByte(byte[] request, HttpPostParameter hpp , Collection parameters)
throws HttpsBrokerException
{
log4j.debug("Enter in Brail.HttpsBroker.postByte");
///To manage the response from the server
HttpServerResponse serverResponse = null;
/// check of the session (HttpClient)
if(session == null)
{
throw new HttpsBrokerException(0,"postByte","The session is not properly initialised - HttpClient Object");
}
if(hpp == null)
{
throw new HttpsBrokerException(0,"postByte","The HttpPostParameter is not properly initialised");
}
log4j.debug("postByte - Creating the PostMethod object");
///Creation of the post method and configuration
PostMethod post = new PostMethod(hpp.getUrl());
post.addRequestHeader("Content-Type", hpp.getContentType());
post.setHttp11(true);
///// TO disable the 'expect: 100-continue' handshake
///post.setUseExpectHeader(false);
if (parameters != null)
{ /// There are some parameters
int sizeCol = 0;
sizeCol = parameters.size();
ArrayList par = (ArrayList)parameters;
NameValuePair [] n = new NameValuePair[sizeCol];
for (int i = 0 ; i < sizeCol ; i++)
{
n[i] = new NameValuePair(((HttpParamTransport)par.get(i)).getParamName(),
((HttpParamTransport)par.get(i)).getParamValue());
}
post.setQueryString(n);
log4j.debug("postByte - Adding of the parameters");
if( request != null)
{
log4j.debug("postByte - Add of the request body");
String strReq = new String(request);
post.setRequestBody(strReq); ///Setting of the byte to send
post.setRequestContentLength(strReq.length());
}
}
else
{
if( request != null)
{
log4j.debug("postByte - Add of the request body. No parameters ");
String strReq = new String(request);
post.setRequestBody(strReq); ///Setting of the byte to send
post.setRequestContentLength(strReq.length());
}
}
/// Do the post
try
{
log4j.debug("postByte - Execute the POST");
session.executeMethod(post);
}
catch (IOException ex)
{
//ex.printStackTrace();
throw new HttpsBrokerException(0,"postByte","Error on the post to the server: " + ex.getMessage());
}
BufferedReader postReader = null;
log4j.debug("postByte - Retrieve the response body stream");
try
{
postReader = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream()));
}
catch (IOException ex1)
{
throw new HttpsBrokerException(4,"sendFile","Error on the response body: " + ex1.getMessage());
}
catch (NullPointerException ex)
{
postReader = null;
}
log4j.debug("postByte - Compose the HttpServerResponse");
serverResponse = new HttpServerResponse(post.getStatusLine(),postReader);
return serverResponse;
}
I have join the complete trace log of the transaction.
Re:Already tried to authenticate to "extranettes
t.rkw-onafts.fgov.be#null" but still receiving 407
Posted by fr...@b-rail.be.
And yes, thanks in advance.
François
francois.geraerts@b-rail.be (11/04/03 9:27):
>Hi,
>
>I use now the nightly build which fix previous problem i have before.
>Now i seem to have a problem to authenticate my client to the proxy. This code
work fine when i use the alpha 2 release
>But now i have this error:
>
>java.lang.IllegalStateException: Not Used.
>
> at org.apache.commons.httpclient.HttpMethodBase.checkUsed(HttpMethodBase.
java:1580)
>
> at org.apache.commons.httpclient.methods.GetMethod.
getResponseBodyAsStream(GetMethod.java:309)
>
> at be.brail.util.https.BrailHttpsBroker.postByte(BrailHttpsBroker.java:399)
>
> at be.brail.rkw.BrailComTools.login(BrailComTools.java:107)2003-04-11
08:26:41,109
>INFO <org.apache.commons.httpclient.HttpMethodBase> Already tried to
authenticate to "extranettest.rkw-onafts.fgov.be#null" but still receiving 407.
>
>2003-04-11 08:26:41,109 DEBUG <org.apache.commons.httpclient.ConnectMethod>
CONNECT status code 407
>
>2003-04-11 08:26:41,109 DEBUG <org.apache.commons.httpclient.methods.
GetMethod> enter GetMethod.getResponseBodyAsStream()
>
>
>
> at TestWithHttpInterface.main(TestWithHttpInterface.java:44)
>
>Exception in thread "main"
>
>
>Here is the part of code for the authentification:
>
> public static synchronized HttpClient initialiseConnection(String host, int
port,
> String proxyhost,
int proxyport,
> String proxyUser,
String proxyPswd,
> String domain,
>
SecureProtocolSocketFactory sslSFact)
> {
>
>
> log4j.debug("Enter in brailSSLProtocol.initialiseConnection with proxy");
>
> ///Nt authentification class needed to contact the proxy
> NTCredentials usrPassCr = new NTCredentials(proxyUser,proxyPswd,proxyhost,
"CAMPBMZF");
>
>
> HttpClient client = new HttpClient();
> Protocol myHTTPS = new Protocol( "https", sslSFact, 443 );
>
> client.getHostConfiguration().setHost(host,port,myHTTPS);
> client.getHostConfiguration().setProxy(proxyhost,proxyport);
>
> log4j.debug("Before the method setProxyCredentials");
>
> client.getState().setProxyCredentials(null,usrPassCr);
>
> log4j.debug("After the method setProxyCredentials");
>
> return client;
> }
>
>
>And the method where the error occurs:
>
> public HttpServerResponse postByte(byte[] request, HttpPostParameter hpp ,
Collection parameters)
> throws HttpsBrokerException
> {
>
> log4j.debug("Enter in Brail.HttpsBroker.postByte");
>
> ///To manage the response from the server
> HttpServerResponse serverResponse = null;
>
>
> /// check of the session (HttpClient)
> if(session == null)
> {
> throw new HttpsBrokerException(0,"postByte","The session is not properly
initialised - HttpClient Object");
> }
>
>
> if(hpp == null)
> {
> throw new HttpsBrokerException(0,"postByte","The HttpPostParameter is
not properly initialised");
> }
>
>
> log4j.debug("postByte - Creating the PostMethod object");
> ///Creation of the post method and configuration
> PostMethod post = new PostMethod(hpp.getUrl());
>
>
>
> post.addRequestHeader("Content-Type", hpp.getContentType());
> post.setHttp11(true);
>
> ///// TO disable the 'expect: 100-continue' handshake
> ///post.setUseExpectHeader(false);
>
>
>
> if (parameters != null)
> { /// There are some parameters
>
>
> int sizeCol = 0;
> sizeCol = parameters.size();
> ArrayList par = (ArrayList)parameters;
> NameValuePair [] n = new NameValuePair[sizeCol];
>
>
> for (int i = 0 ; i < sizeCol ; i++)
> {
> n[i] = new NameValuePair(((HttpParamTransport)par.get(i)).
getParamName(),
> ((HttpParamTransport)par.get(i)).
getParamValue());
>
> }
>
> post.setQueryString(n);
> log4j.debug("postByte - Adding of the parameters");
>
> if( request != null)
> {
> log4j.debug("postByte - Add of the request body");
>
> String strReq = new String(request);
> post.setRequestBody(strReq); ///Setting of the byte to send
> post.setRequestContentLength(strReq.length());
> }
>
> }
> else
> {
> if( request != null)
> {
> log4j.debug("postByte - Add of the request body. No parameters ");
> String strReq = new String(request);
> post.setRequestBody(strReq); ///Setting of the byte to send
> post.setRequestContentLength(strReq.length());
> }
> }
>
> /// Do the post
> try
> {
> log4j.debug("postByte - Execute the POST");
> session.executeMethod(post);
> }
> catch (IOException ex)
> {
> //ex.printStackTrace();
> throw new HttpsBrokerException(0,"postByte","Error on the post to the
server: " + ex.getMessage());
> }
>
>
> BufferedReader postReader = null;
>
> log4j.debug("postByte - Retrieve the response body stream");
> try
> {
> postReader = new BufferedReader(new InputStreamReader(post.
getResponseBodyAsStream()));
> }
> catch (IOException ex1)
> {
> throw new HttpsBrokerException(4,"sendFile","Error on the response body:
" + ex1.getMessage());
> }
> catch (NullPointerException ex)
> {
> postReader = null;
> }
>
> log4j.debug("postByte - Compose the HttpServerResponse");
> serverResponse = new HttpServerResponse(post.getStatusLine(),postReader);
>
>
> return serverResponse;
> }
>
>
>
>
>
>
>
>I have join the complete trace log of the transaction.