Here is my full code
package client;
import java.util.Properties;
import com.google.gdata.client.calendar.*;
import com.google.gdata.data.calendar.*;
import com.google.gdata.util.*;
import java.io.IOException;
import java.net.*;
import java.io.*;
import java.util.Properties;
public class Clientproxy {
/**
* @param args
* @throws Throwable
*/
public static void main(String[] args) throws Throwable {
Properties systemSettings = System.getProperties();
System.getProperties().put( "proxySet", "true" );
systemSettings.put("http.proxyHost", "univPrxyhost");
systemSettings.put("http.proxyPort", "port");
System.setProperties(systemSettings);
URL feedUrl = new
URL("http://www.google.com/calendar/feeds/default/
allcalendars/full");
HttpURLConnection con = (HttpURLConnection)
feedUrl.openConnection();
//
// it's not the greatest idea to use a sun.misc.* class
// Sun strongly advises not to use them since they can
// change or go away in a future release so beware.
//
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
String encodedUserPwd =
encoder.encode("ncl.ac.uk\
[EMAIL PROTECTED]:password".getBytes());
con.setRequestProperty
("Proxy-Authorization", "Basic " + encodedUserPwd);
// PROXY ----------
con.connect();
// Create a CalenderService and authenticate
CalendarService myService = new CalendarService("exampleCo-
exampleApp-1");
try {
myService.setUserCredentials("[EMAIL PROTECTED]",
"password");
} catch (AuthenticationException e) {
e.printStackTrace();
}
// Send the request and print the response
CalendarFeed resultFeed = null;
try {
feedUrl = new
URL("http://www.google.com/calendar/feeds/default/
allcalendars/full");
resultFeed = myService.getFeed(feedUrl,
CalendarFeed.class);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
System.out.println("Your calendars:");
System.out.println();
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
CalendarEntry entry = resultFeed.getEntries().get(i);
System.out.println("\t" + entry.getTitle().getPlainText());
}
}
}
On Apr 21, 11:40 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> i am tring to run google calender sample code along with my username
> and password.
> it works fine at home internet but throwing exceptions at univ
> network.
>
> On Apr 21, 11:38 am, "[EMAIL PROTECTED]"
>
>
>
> <[EMAIL PROTECTED]> wrote:
> > Thank you for reply i have gone through link. add proxy host and port
> > within the code along with
> > sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
> > String encodedUserPwd =
> > encoder.encode("myunivdomain\
> > [EMAIL PROTECTED]:password".getBytes());
> > con.setRequestProperty
> > ("Proxy-Authorization", "Basic " + encodedUserPwd);
> > // PROXY ----------
>
> > con.connect();
>
> > But still i am geting this errors.
>
> > com.google.gdata.util.AuthenticationException: Error connecting with
> > login URI
> > at
> > com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(Unknown
> > Source)
> > at
> > com.google.gdata.client.GoogleAuthTokenFactory.setUserCredentials(Unknown
> > Source)
> > at com.google.gdata.client.GoogleService.setUserCredentials(Unknown
> > Source)
> > at com.google.gdata.client.GoogleService.setUserCredentials(Unknown
> > Source)
> > at client.Clientproxy.main(Clientproxy.java:48)
> > Caused by: java.net.ConnectException: Connection refused: connect
> > at java.net.PlainSocketImpl.socketConnect(Native Method)
> > at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> > at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:
> > 195)
> > at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> > at java.net.Socket.connect(Socket.java:519)
> > at java.net.Socket.connect(Socket.java:469)
> > at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
> > at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
> > at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
> > at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:
> > 271)
> > at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:328)
> > at
> > sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClien...
> > 172)
> > at
> > sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:
> > 729)
> > at
> > sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Abstrac...
> > 158)
> > at
> > sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection...
> > 832)
> > at
> > sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLCon...
> > 230)
> > at
> > com.google.gdata.client.GoogleAuthTokenFactory.makePostRequest(Unknown
> > Source)
> > ... 5 more
> > com.google.gdata.util.AuthenticationException: Unauthorized
> > <HTML>
> > <HEAD>
> > <TITLE>Authorization required</TITLE>
> > </HEAD>
> > <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
> > <H1>Authorization required</H1>
> > <H2>Error 401</H2>
> > </BODY>
> > </HTML>
>
> > at
> > com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(Unknown
> > Source)
> > at
> > com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(Unknown
> > Source)
> > at
> > com.google.gdata.client.http.HttpGDataRequest.checkResponse(Unknown
> > Source)
> > at com.google.gdata.client.http.HttpGDataRequest.execute(Unknown
> > Source)
> > at com.google.gdata.client.http.GoogleGDataRequest.execute(Unknown
> > Source)
> > at com.google.gdata.client.Service.getFeed(Unknown Source)
> > at com.google.gdata.client.Service.getFeed(Unknown Source)
> > at com.google.gdata.client.GoogleService.getFeed(Unknown Source)
> > at com.google.gdata.client.Service.getFeed(Unknown Source)
> > at client.Clientproxy.main(Clientproxy.java:58)
> > Exception in thread "main" java.lang.NullPointerException
> > at client.Clientproxy.main(Clientproxy.java:71)
> > Your calendars:
>
> > On Apr 18, 8:01 pm, "Austin (Google)" <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
>
> > > This seems like a proxy setting issue within your JVM environment.
> > > The Java client library uses the standard network library from J2SE,
> > > you need to supply the correct proxy setting of your network
> > > configuration. I found this page on the web that has a lot of
> > > information on setting proxy setting in Java -
>
> > >http://www.rgagnon.com/javadetails/java-0085.html
>
> > > Hope it helps,
> > > Austin
>
> > > On Fri, Apr 18, 2008 at 4:50 AM, Akbar Shaik
>
> > > <[EMAIL PROTECTED]> wrote:
> > > > Hi
>
> > > > I am Akbar Shaik doing MSc in Newcastle University. When i was runing
> > > > my
> > > > client java application for Google calendar API from home network, it
> > > > was
> > > > working fine. when i am rying to run same code from university network
> > > > i am
> > > > geting this error massages.
>
> > > > Your calendars:
> > > > com.google.gdata.util.AuthenticationException: Error connecting with
> > > > login
> > > > URI
> > > > at com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(Unknown
> > > > Source)
> > > > at
> > > > com.google.gdata.client.GoogleAuthTokenFactory.setUserCredentials(Unknown
> > > > Source)
> > > > at com.google.gdata.client.GoogleService.setUserCredentials(Unknown
> > > > Source)
> > > > at com.google.gdata.client.GoogleService.setUserCredentials(Unknown
> > > > Source)
> > > > at test.CalendarTest.main(CalendarTest.java:26)
> > > > Caused by: java.net.ConnectException: Connection timed out: connect
> > > > at java.net.PlainSocketImpl.socketConnect(Native Method)
> > > > at java.net.PlainSocketImpl.doConnect(Unknown Source)
> > > > at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
> > > > at java.net.PlainSocketImpl.connect(Unknown Source)
> > > > at java.net.Socket.connect(Unknown Source)
> > > > at java.net.Socket.connect(Unknown Source)
> > > > at sun.net.NetworkClient.doConnect(Unknown Source)
> > > > at sun.net.www.http.HttpClient.openServer(UnknownSource)
> > > > at sun.net.www.http.HttpClient.openServer(UnknownSource)
> > > > at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
> > > > at sun.net.www.protocol.https.HttpsClient.New(UnknownSource)
> > > > at
> > > > sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClien...
> > > > Source)
> > > > at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown
> > > > Source)
> > > > at
> > > > sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown
> > > > Source)
> > > > at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown
> > > > Source)
> > > > at
> > > > sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown
> > > > Source)
> > > > at
> > > > com.google.gdata.client.GoogleAuthTokenFactory.makePostRequest(Unknown
> > > > Source)
> > > > ... 5 more
> > > > Exception in thread "main" java.lang.NullPointerException
> > > > at test.CalendarTest.main(CalendarTest.java:47)
>
> > > > code snipped
> > > > System.setProperty("http.proxyHost", "xyz.com");
> > > > System.setProperty("http.proxyPort", "8080");
> > > > CalendarService myService = new
> > > > CalendarService("exampleCo-exampleApp-1");
> > > > try {
> > > > myService.setUserCredentials(username, password);
> > > > }
>
> > > > i am not sure what i shd in place of xyz.com. as i am runing this
> > > > application on my laptop.
>
> > > > Please reply soon
>
> > > > AKBAR B SHAIK- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---