Results 1 to 9 of 9
  1. #1
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default NullPointerException with a simple EWS program. Help.

    Hi all,

    I have a very simple program, using EWS. I am just trying to connect to my gmail account (Can I connect to my gmail account in the first place with EWS?). But I am getting the following error.


    Java Code:
    package com.my.ews.cq;
    
    import microsoft.exchange.webservices.data.*;
    import java.net.URI;
    
    
    
    public class ConnectToExchange {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		
    		try {
    			ExchangeService service = new ExchangeService();
    			System.out.println("Got ExchangeService");
    			ExchangeCredentials credentials = new WebCredentials("myaccount@gmail.com", "xxxxxxx");
    			System.out.println("Set credentials");
    			service.setUrl(new java.net.URI("gmail.com"));
    			service.setCredentials(credentials);
    			
    			EmailMessage msg= new EmailMessage(service);
    			System.out.println("got a message instance");
    			msg.setSubject("Hello world!"); 
    			System.out.println("set suject to " + msg.getSubject().toString());
    			msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Managed API."));
    			System.out.println("set body to " + msg.getBody().toString());
    			msg.getToRecipients().add("mygmail@gmail.com");
    			//System.out.println("add recipient: " + msg.getDisplayTo().toString());
    			msg.send();
    			System.out.println("message sent");
    
    			
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    
    
    	}
    
    }

    But, when I run this program I get the following error:


    Java Code:
    microsoft.exchange.webservices.data.ServiceRequestException: The request failed. null
    	at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(Unknown Source)
    	at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(Unknown Source)
    	at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)
    	at microsoft.exchange.webservices.data.ExchangeService.internalCreateItems(Unknown Source)
    	at microsoft.exchange.webservices.data.ExchangeService.createItem(Unknown Source)
    	at microsoft.exchange.webservices.data.Item.internalCreate(Unknown Source)
    	at microsoft.exchange.webservices.data.EmailMessage.internalSend(Unknown Source)
    	at microsoft.exchange.webservices.data.EmailMessage.send(Unknown Source)
    	at com.my.ews.cq.ConnectToExchange.main(ConnectToExchange.java:39)
    Caused by: java.lang.NullPointerException
    	at microsoft.exchange.webservices.data.ExchangeServiceBase.prepareHttpWebRequestForUrl(Unknown Source)
    	at microsoft.exchange.webservices.data.ExchangeService.prepareHttpWebRequest(Unknown Source)
    	at microsoft.exchange.webservices.data.ServiceRequestBase.emit(Unknown Source)
    	... 9 more
    Got ExchangeService
    Set credentials
    set autodiscover
    got a message instance
    set suject to Hello world!
    set body to Sent using the EWS Managed API.

    Please advise.

  2. #2
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    Mabye a strange question. Gmail uses its own mail server. Why do you use and Exchange class?

  3. #3
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default

    Good question.

    I tried my company's email account which uses exchange server. And in the above code I changed the following line, adding the exchange webmail url. i.e.

    service.setUrl(new java.net.URI("https://owa.mycompany.com/owa/"));


    and I got this error now:


    Java Code:
    Got ExchangeService
    Set credentials
    set Credentails
    set autodiscover
    got a message instance
    set suject to Hello world!
    set body to Sent using the EWS Managed API.
    microsoft.exchange.webservices.data.ServiceRequestException: The request failed. The remote server returned an error: (440)Login Timeout
    	at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(Unknown Source)
    	at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(Unknown Source)
    	at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)
    	at microsoft.exchange.webservices.data.ExchangeService.internalCreateItems(Unknown Source)
    	at microsoft.exchange.webservices.data.ExchangeService.createItem(Unknown Source)
    	at microsoft.exchange.webservices.data.Item.internalCreate(Unknown Source)
    	at microsoft.exchange.webservices.data.EmailMessage.internalSend(Unknown Source)
    	at microsoft.exchange.webservices.data.EmailMessage.send(Unknown Source)
    	at com.my.ews.cq.ConnectToExchange.main(ConnectToExchange.java:37)
    Caused by: java.lang.Exception: The remote server returned an error: (440)Login Timeout
    	at microsoft.exchange.webservices.data.ServiceRequestBase.emit(Unknown Source)
    	... 9 more

    Please advise.

  4. #4
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    Well you got 2 things:

    1.Gmail isn't an exchange server, you cannot use it there.
    Use the SMTP class and lookup the SMTP settings of GMail.

    NullPointer means you get nothing back.

    2. A logon time-out on Exchange.
    Could mean they're using SSL and you have to use SSL making connection.
    Maybe they host an SMTP option to at your company, you can build one solution then.

    Exchange has a connector for SMTP

  5. #5
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default

    Thanks for the input.

    I need to use EWS Java API to modify an existing application which's integrated with the exchange server. Here I am just trying to get it work for just connecting to oue exchange server. Maybe gmail was a bad idea to bring it into topic.

    Let me ask another question: does protocol matter when using ews? for this particular account pop3 is enabled.

    Is there any Javadoc API specs available for EWS? Can someone please point me to a link or some sample codes? Real appreciate your help folks.

    Thanks.

  6. #6
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default

    Any help please?

  7. #7
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    I don't know EWS, but i do know that Exchange needs protocol, like SMTP to send a messega.
    Logical would be that EWS uses this protocol to, because we need a protocol to sent things on the Internet.

    You need to have a look on the Microsoft Forums on MSDN. Microsoft Forums: Get live and on-demand access to a wide range of technical and business guidance from industry experts.

    There is more about the API.
    Exchange -> Development.

    Its hard to find because Microsoft uses the .Net Framework and laguages as C# or Java.

    I cannot say it here ;-), but C# is fun to :-).

  8. #8
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default

    Thanks for the info and the reference link.

    However, I have to use EWS Java API, and not .NET or C#. Otherwise, I wouldn't be here :-)

    I can see the WSDL for my exchange server at https://myexchange.domain.com/ews/Services.wsdl

    So, if I use this WSDL to access the services/operations, do I still need to worry about the protocol? Because I assume, it'll be like any other web services, and all we need to do is simply call the appropriate methods, is all. Am I correct in my assumption?

    Please advise...


    thanks.

  9. #9
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    Well when i communicate in a webservice to a tcp port i need to set the ip of the server i communicate with.

    So i'm not 100 % sure

    When i use the SMTP protocol i use an IP (hostname) to, smtp.company.local.nl or something like that.
    But maybe in EWS Exchange does that for you.

    It's a Java API, but to Exchange. On the Msdn forum i think you'll have more succes in getting the full answer.

Similar Threads

  1. Please help with simple program.. Very simple.
    By jonytek in forum New To Java
    Replies: 7
    Last Post: 02-14-2011, 12:44 AM
  2. Program crashes: NullPointerException
    By d4nce2thisbeat in forum New To Java
    Replies: 5
    Last Post: 11-20-2010, 09:33 PM
  3. simple program
    By blastoff in forum New To Java
    Replies: 5
    Last Post: 04-14-2010, 11:25 PM
  4. [SOLVED] NullPointerException - FileInfo Program
    By keffie91 in forum New To Java
    Replies: 3
    Last Post: 01-01-2009, 05:09 PM
  5. Simple Program
    By TheRocket in forum Advanced Java
    Replies: 15
    Last Post: 12-30-2008, 02:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •