简体   繁体   中英

Exchange webservice error: the request failed. null

I am using EWS-java-api to access an outlook email and read emails. I am running into the following error:

microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. null

Here is my code:

    import microsoft.exchange.webservices.data.core.ExchangeService;
    import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
    import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName;
    import microsoft.exchange.webservices.data.core.service.item.Item;
    import microsoft.exchange.webservices.data.credential.WebCredentials;
    import microsoft.exchange.webservices.data.search.FindItemsResults;
    import microsoft.exchange.webservices.data.search.ItemView;

    import microsoft.exchange.webservices.data.search.filter.SearchFilter;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.Properties;

    Properties properties = new Properties();
    properties.put("javax.net.ssl.trustStore", "C:/Users/<path to java security>/cacerts" );
    properties.put("javax.net.ssl.trustStorePassword","changeit");
    System.setProperties(properties);

    service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);

    def usr = "abc@mycompany.ca";
    def pwd = "password";
    def url = "https://mycompanydomain/ews/exchange.asmx";
    service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
    credentials = new WebCredentials(usr, pwd);

    service.setCredentials(credentials);

    try {
        service.setUrl(new URI(url));

        service.setTraceEnabled(true);
        Calendar cal = Calendar.getInstance();
        cal.roll(Calendar.MONTH, false);
        view = new ItemView(50);

        findResults = service.findItems(WellKnownFolderName.Inbox, view);
        for(item in findResults.getItems()) {
            println("\n + email is: "+item+ "\n") ;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

And here is the full stacktrace:

15:32:13 [INFO] ScriptProcessor starts processing...
microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. null
15:32:14 [INFO] ScriptProcessor processor executed in 889ms.
    at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74)
    at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:158)
    at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:985)
    at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:1028)
    at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:1104)
    at microsoft.exchange.webservices.data.core.ExchangeService$findItems$0.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
    at Script1.run(Script1.groovy:54)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
    at org.webharvest.runtime.scripting.GroovyScriptEngine.eval(GroovyScriptEngine.java:136)
    at org.webharvest.runtime.processors.ScriptProcessor.execute(ScriptProcessor.java:74)
    at org.webharvest.runtime.processors.BaseProcessor.run(BaseProcessor.java:127)
    at org.webharvest.runtime.Scraper.execute(Scraper.java:169)
    at org.webharvest.runtime.Scraper.execute(Scraper.java:182)
    at com.freedomoss.crowdcontrol.webharvest.executor.LocalWebharvestTaskExecutor.executeWebHarvestTask(LocalWebharvestTaskExecutor.java:182)
    at com.workfusion.studio.launch.SingleThreadWebHarvestProcess.processTaskInputs(SingleThreadWebHarvestProcess.java:77)
    at com.workfusion.studio.launch.SingleThreadWebHarvestProcess.start(SingleThreadWebHarvestProcess.java:46)
    at com.workfusion.studio.launch.WebHarvestMainLauncher.launch(WebHarvestMainLauncher.java:79)
    at com.workfusion.studio.launch.WebHarvestMainLauncher.main(WebHarvestMainLauncher.java:121)
Caused by: java.lang.NullPointerException
    at com.ctc.wstx.sw.BaseStreamWriter.writeCharacters(BaseStreamWriter.java:447)
    at microsoft.exchange.webservices.data.core.EwsUtilities.formatLogMessage(EwsUtilities.java:558)
    at microsoft.exchange.webservices.data.core.ExchangeServiceBase.traceHttpRequestHeaders(ExchangeServiceBase.java:515)
    at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.buildEwsHttpWebRequest(ServiceRequestBase.java:686)
    at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.buildEwsHttpWebRequest(ServiceRequestBase.java:665)
    at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:635)
    at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:62)
    ... 22 more

Any help is greatly appreciated.

i have face same issue in setting service url so i have done first by setting credentials and setup auto discovery

When this happens, instead of failing, the user can be prompted to accept the redirection or not. That functionality needs to be implemented inside the autodiscoverRedirectionUrlValidationCallback method. In the example below, it only checks to see that the redirection url starts with "https://". To accomplish this

static class RedirectionUrlCallback implements IAutodiscoverRedirectionUrl {
        public boolean autodiscoverRedirectionUrlValidationCallback(
                String redirectionUrl) {
            return redirectionUrl.toLowerCase().startsWith("https://");
        }
    }

Now

service.autodiscoverUrl("<your_email_address>", new RedirectionUrlCallback());

can be called to deal with the redirection in a safe manner.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM