hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Divakar Satyanarayan <Divak...@mascotsystems.com>
Subject RE: java.net.UnknownHostException
Date Fri, 31 Jan 2003 15:30:17 GMT
Yes I made some modification & below is my code.

I have got it working with the following code but request is getting timed
out.

	public static void main(String[] args) throws Exception
	{	
		
			String strURL = "http://201.173.335.213/xxxx/xxxxx";

			String strHost = "201.173.335.213";
		
		URL u = new URL("http://"+strURL);

		
		PostMethod post = new PostMethod(strURL);
		
		inputXML();

		post.setRequestBody("inputXml="+sbInputXML.toString());


        if ((u.getPath() == null) || (u.getPath().length() == 0)) 
		{
			post.setPath("/");
		}
        else 
		{
			post.setPath(u.getPath());
		}

		System.out.println("THe Path is " +post.getPath() );

		post.setRequestHeader("Content-type", "text/xml");
				
		System.out.println("THe Object 3 ");
/*
		HttpConnection oHttpConnection = new
HttpConnection(strURL,440); 
		 
		oHttpConnection.open();*/

		//HttpClient hc = new
HttpClient(oHttpConnection.getHttpConnectionManager());

		HttpClient hc = new HttpClient();
		
		System.out.println(" About to configure ");

		/*HostConfiguration cfg = new HostConfiguration();
		
		System.out.println(" Configured Host ");

      //  cfg.setHost(new URI(u));

		cfg.setHost(strHost,440,"http"); 
		
		System.out.println("THe Host "+cfg.getHost());

		System.out.println("THe Host URL "+cfg.getHostURL());	 

		System.out.println("THe Protocol "+cfg.getProtocol());

		System.out.println("Is Host Set "+cfg.isHostSet());	
		
		System.out.println("Client Uses Port "+hc.getPort());

		
				*/
		int iResultCode = hc.executeMethod(post);
		
		System.out.println("iResultCode = " + iResultCode);

		System.out.println("Server response:" +
post.getResponseBodyAsString() );

        post.releaseConnection();
}


> -----Original Message-----
> From:	Michael Becke [SMTP:becke@u.washington.edu]
> Sent:	Friday, January 31, 2003 8:51 PM
> To:	Commons HttpClient Project
> Subject:	Re: java.net.UnknownHostException
> 
> Are you using the most recent code from CVS?  I just tried this example 
> and it worked for me.  Did you make any changes to the example?
> 
> Mike
> 
> Divakar Satyanarayan wrote:
> > The first thing I did was to run the sample code PostXML.java. But it
> gave
> > me a run time exception 
> > 
> > Exception in thread "main" java.lang.IllegalArgumentException: host
> > parameter is null
> >         at
> >
> org.apache.commons.httpclient.HttpConnection.<init>(HttpConnection.java:21
> 7)
> >         at
> >
> org.apache.commons.httpclient.HttpConnection.<init>(HttpConnection.java:14
> 5)
> >         at
> >
> org.apache.commons.httpclient.SimpleHttpConnectionManager.getConnection(Si
> mp
> > leHttpConnectionManager.java:118)
> >         at
> >
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:541
> )
> >         at
> >
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:474
> )
> >         at PostXML.main(PostXML.java:268)
> > 
> >  Once the host configuration is done I could see the host & port to
> which it
> > is configured. But I am puzzled by the above exception when
> exceuteMethod is
> > invoked.
> >   
> >  Are there any leads to the solution for the above problem.
> > 
> > Divakar
> > 
> > 
> > 
> >>-----Original Message-----
> >>From:	Michael Becke [SMTP:becke@u.washington.edu]
> >>Sent:	Friday, January 31, 2003 7:36 PM
> >>To:	Commons HttpClient Project
> >>Subject:	Re: java.net.UnknownHostException
> >>
> >>Please take a look at the following URL as an example of how to use  
> >>HttpClient to read from a server:
> >>
> >>http://cvs.apache.org/viewcvs/jakarta-commons/httpclient/src/examples/ 
> >>BasicAuthenticatonExample.java?rev=1.3&content-type=text/vnd.viewcvs- 
> >>markup
> >>
> >>It seems that the problem is that you are attempting to read directly  
> >>from an HttpConnection.  Though this seems logical given how the  
> >>java.net.UrlConnection works, HttpClient handles things a little  
> >>differently.  All posts, gets, etc. are done via HttpMethods like  
> >>PostMethod and GetMethod.  HttpConnection is not meant to be used  
> >>directly.
> >>
> >>Mike
> >>
> >>On Friday, January 31, 2003, at 07:32 AM, Divakar Satyanarayan wrote:
> >>
> >>
> >>>Hi,
> >>>
> >>> I am using HTTPConnection to get a connection to an URL. It works  
> >>>fine when
> >>>I give just the IP address but when I specify the full path it gives me
> >>>following exception
> >>>
> >>>java.net.UnknownHostException: 201.173.335.213/xxxx/xxxxx
> >>>        at java.net.InetAddress.getAllByName0(InetAddress.java:571)
> >>>        at java.net.InetAddress.getAllByName0(InetAddress.java:540)
> >>>        at java.net.InetAddress.getByName(InetAddress.java:472)
> >>>        at java.net.Socket.<init>(Socket.java:100)
> >>>        at
> >>>org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.cre
> 
> >>>ateSo
> >>>cket(DefaultProtocolSocketFactory.java:104)
> >>>        at
> >>>org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:4
> 
> >>>88)
> >>>        at TrialConnectionClient.main(TrialConnectionClient.java:237).
> >>>
> >>> What am I missing ? I've pasted the code
> >>>
> >>>			HttpConnection oHttpConnection = new
> >>>HttpConnection(strURL,440);
> >>>
> >>>			logMessage("Connected before"+
> >>>oHttpConnection.isOpen() );
> >>>			
> >>>			logMessage("Connected before"+
> >>>oHttpConnection.getProxyHost());
> >>>
> >>>			logMessage("Connected before"+
> >>>oHttpConnection.getPort());	
> >>>			
> >>>			oHttpConnection.open();
> >>>
> >>>			logMessage("Connected after"+
> >>>oHttpConnection.isOpen() );
> >>>			
> >>>			RequestOutputStream oRequestOutputStream = new
> >>>RequestOutputStream(oHttpConnection.getRequestOutputStream(),false);
> >>>			
> >>>			logMessage("Output Stream ");
> >>>
> >>>			strXml = "inputXml="+sbInputXML.toString();
> >>>
> >>>			oRequestOutputStream.println(strXml);
> >>>			//oRequestOutputStream.close();
> >>>			
> >>>			logMessage(" Input Stream ");
> >>>			
> >>>			
> >>>			
> >>>			BufferedReader oBufferedReader = new
> >>>BufferedReader(new
> >>>InputStreamReader(oHttpConnection.getResponseInputStream()));
> >>>			
> >>>			logMessage("Opening the input Stream");
> >>>			
> >>>			String line;
> >>>			
> >>>			System.out.println(System.currentTimeMillis());
> >>>
> >>>			logMessage("Buffered Input starting to read");
> >>>
> >>>			while ((line = oBufferedReader.readLine()) != null)
> >>>			{
> >>>				System.out.println(line);
> >>>				sbXMLText.append(line + "\n");
> >>>			}
> >>>		
> >>>
> >>>
> >>>
> >>>>Regards,
> >>>>Divakar
> >>>>___________________________
> >>>>DIVAKAR SATYANARAYAN
> >>>>+91-80-5521701-6 Ext : 1018
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>>DISCLAIMER: Information contained and transmitted by this E-MAIL is
> >>>proprietary to Mascot Systems Limited and is intended for use only by  
> >>>the
> >>>individual or entity to which it is addressed, and may contain  
> >>>information
> >>>that is privileged, confidential or exempt from disclosure under  
> >>>applicable
> >>>law. If this is a forwarded message, the content of this E-MAIL may  
> >>>not have
> >>>been sent with the authority of the Company. If you are not the  
> >>>intended
> >>>recipient, an agent of the intended recipient or a person responsible  
> >>>for
> >>>delivering the information to the named recipient, you are notified  
> >>>that any
> >>>use, distribution, transmission, printing, copying or dissemination of
> 
> >>>this
> >>>information in any way or in any manner is strictly prohibited. If you
> 
> >>>have
> >>>received this communication in error, please delete this mail & notify
> 
> >>>us
> >>>immediately at Mailadmin@mascotsystems.com Before opening attachments,
> >>>please scan for viruses.
> >>>
> >>>
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail:  
> >>>commons-httpclient-dev-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail:  
> >>>commons-httpclient-dev-help@jakarta.apache.org
> >>>
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail:
> >>commons-httpclient-dev-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail:
> >>commons-httpclient-dev-help@jakarta.apache.org
> >>
> >>
> > 
> > DISCLAIMER: Information contained and transmitted by this E-MAIL is
> > proprietary to Mascot Systems Limited and is intended for use only by
> the
> > individual or entity to which it is addressed, and may contain
> information
> > that is privileged, confidential or exempt from disclosure under
> applicable
> > law. If this is a forwarded message, the content of this E-MAIL may not
> have
> > been sent with the authority of the Company. If you are not the intended
> > recipient, an agent of the intended recipient or a person responsible
> for
> > delivering the information to the named recipient, you are notified that
> any
> > use, distribution, transmission, printing, copying or dissemination of
> this
> > information in any way or in any manner is strictly prohibited. If you
> have
> > received this communication in error, please delete this mail & notify
> us
> > immediately at Mailadmin@mascotsystems.com Before opening attachments,
> > please scan for viruses. 
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> commons-httpclient-dev-help@jakarta.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-httpclient-dev-help@jakarta.apache.org
> 
> 
DISCLAIMER: Information contained and transmitted by this E-MAIL is
proprietary to Mascot Systems Limited and is intended for use only by the
individual or entity to which it is addressed, and may contain information
that is privileged, confidential or exempt from disclosure under applicable
law. If this is a forwarded message, the content of this E-MAIL may not have
been sent with the authority of the Company. If you are not the intended
recipient, an agent of the intended recipient or a person responsible for
delivering the information to the named recipient, you are notified that any
use, distribution, transmission, printing, copying or dissemination of this
information in any way or in any manner is strictly prohibited. If you have
received this communication in error, please delete this mail & notify us
immediately at Mailadmin@mascotsystems.com Before opening attachments,
please scan for viruses. 



Mime
View raw message