Example usage for javax.xml.stream XMLStreamException getClass

List of usage examples for javax.xml.stream XMLStreamException getClass

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:microsoft.exchange.webservices.data.AutodiscoverService.java

/**
 * Calls the Autodiscover service to retrieve configuration settings.
 *
 * @param <TSettings>  the generic type
 * @param cls          the cls//from  w w  w  .  j a  va2s  .  c  o m
 * @param emailAddress The email address to retrieve configuration settings for.
 * @param currentHop   Current number of redirection urls/addresses attempted so far.
 * @return The requested configuration settings.
 * @throws Exception the exception
 */
private <TSettings extends ConfigurationSettingsBase> TSettings internalGetLegacyUserSettings(
        Class<TSettings> cls, String emailAddress, List<String> redirectionEmailAddresses,
        OutParam<Integer> currentHop) throws Exception {
    String domainName = EwsUtilities.domainFromEmailAddress(emailAddress);

    int scpUrlCount;
    OutParam<Integer> outParamInt = new OutParam<Integer>();
    List<URI> urls = this.getAutodiscoverServiceUrls(domainName, outParamInt);
    scpUrlCount = outParamInt.getParam();
    if (urls.size() == 0) {
        throw new ServiceValidationException(Strings.AutodiscoverServiceRequestRequiresDomainOrUrl);
    }

    // Assume caller is not inside the Intranet, regardless of whether SCP
    // Urls
    // were returned or not. SCP Urls are only relevent if one of them
    // returns
    // valid Autodiscover settings.
    this.isExternal = true;

    int currentUrlIndex = 0;

    // Used to save exception for later reporting.
    Exception delayedException = null;
    TSettings settings;

    do {
        URI autodiscoverUrl = urls.get(currentUrlIndex);
        boolean isScpUrl = currentUrlIndex < scpUrlCount;

        try {
            settings = this.getLegacyUserSettingsAtUrl(cls, emailAddress, autodiscoverUrl);

            switch (settings.getResponseType()) {
            case Success:
                // Not external if Autodiscover endpoint found via SCP
                // returned the settings.
                if (isScpUrl) {
                    this.isExternal = false;
                }
                this.url = autodiscoverUrl;
                return settings;
            case RedirectUrl:
                if (currentHop.getParam() < AutodiscoverMaxRedirections) {
                    currentHop.setParam(currentHop.getParam() + 1);

                    this.traceMessage(TraceFlags.AutodiscoverResponse,
                            String.format("Autodiscover " + "service " + "returned " + "redirection URL '%s'.",
                                    settings.getRedirectTarget()));

                    urls.add(currentUrlIndex, new URI(settings.getRedirectTarget()));

                    break;
                } else {
                    throw new AutodiscoverLocalException(Strings.MaximumRedirectionHopsExceeded);
                }
            case RedirectAddress:
                if (currentHop.getParam() < AutodiscoverMaxRedirections) {
                    currentHop.setParam(currentHop.getParam() + 1);

                    this.traceMessage(TraceFlags.AutodiscoverResponse, String.format(
                            "Autodiscover " + "service " + "returned " + "redirection email " + "address '%s'.",
                            settings.getRedirectTarget()));
                    // Bug E14:255576 If this email address was already tried, we may have a loop
                    // in SCP lookups. Disable consideration of SCP records.
                    this.disableScpLookupIfDuplicateRedirection(settings.getRedirectTarget(),
                            redirectionEmailAddresses);

                    return this.internalGetLegacyUserSettings(cls, settings.getRedirectTarget(),
                            redirectionEmailAddresses, currentHop);
                } else {
                    throw new AutodiscoverLocalException(Strings.MaximumRedirectionHopsExceeded);
                }
            case Error:
                // Don't treat errors from an SCP-based Autodiscover service
                // to be conclusive.
                // We'll try the next one and record the error for later.
                if (isScpUrl) {
                    this.traceMessage(TraceFlags.AutodiscoverConfiguration, "Error returned by "
                            + "Autodiscover service " + "found via SCP, treating " + "as inconclusive.");

                    delayedException = new AutodiscoverRemoteException(Strings.AutodiscoverError,
                            settings.getError());
                    currentUrlIndex++;
                } else {
                    throw new AutodiscoverRemoteException(Strings.AutodiscoverError, settings.getError());
                }
                break;
            default:
                EwsUtilities.EwsAssert(false, "Autodiscover.GetConfigurationSettings",
                        "An unexpected error has occured. " + "This code path should never be reached.");
                break;
            }
        } catch (XMLStreamException ex) {
            this.traceMessage(TraceFlags.AutodiscoverConfiguration,
                    String.format("%s failed: XML parsing error: %s", url, ex.getMessage()));

            // The content at the URL wasn't a valid response, let's try the
            // next.
            currentUrlIndex++;
        } catch (IOException ex) {
            this.traceMessage(TraceFlags.AutodiscoverConfiguration,
                    String.format("%s failed: I/O error: %s", url, ex.getMessage()));

            // The content at the URL wasn't a valid response, let's try the next.
            currentUrlIndex++;
        } catch (Exception ex) {
            HttpWebRequest response = null;
            URI redirectUrl;
            OutParam<URI> outParam1 = new OutParam<URI>();
            if ((response != null) && this.tryGetRedirectionResponse(response, outParam1)) {
                redirectUrl = outParam1.getParam();
                this.traceMessage(TraceFlags.AutodiscoverConfiguration,
                        String.format("Host returned a redirection to url %s", redirectUrl.toString()));

                currentHop.setParam(currentHop.getParam() + 1);
                urls.add(currentUrlIndex, redirectUrl);
            } else {
                if (response != null) {
                    this.processHttpErrorResponse(response, ex);

                }

                this.traceMessage(TraceFlags.AutodiscoverConfiguration,
                        String.format("%s failed: %s (%s)", url, ex.getClass().getName(), ex.getMessage()));

                // The url did not work, let's try the next.
                currentUrlIndex++;
            }
        }
    } while (currentUrlIndex < urls.size());

    // If we got this far it's because none of the URLs we tried have
    // worked. As a next-to-last chance, use GetRedirectUrl to
    // try to get a redirection URL using an HTTP GET on a non-SSL
    // Autodiscover endpoint. If successful, use this
    // redirection URL to get the configuration settings for this email
    // address. (This will be a common scenario for
    // DataCenter deployments).
    URI redirectionUrl = this.getRedirectUrl(domainName);
    OutParam<TSettings> outParam = new OutParam<TSettings>();
    if ((redirectionUrl != null)
            && this.tryLastChanceHostRedirection(cls, emailAddress, redirectionUrl, outParam)) {
        settings = outParam.getParam();
        return settings;
    } else {
        // Getting a redirection URL from an HTTP GET failed too. As a last
        // chance, try to get an appropriate SRV Record
        // using DnsQuery. If successful, use this redirection URL to get
        // the configuration settings for this email address.
        redirectionUrl = this.getRedirectionUrlFromDnsSrvRecord(domainName);
        if ((redirectionUrl != null)
                && this.tryLastChanceHostRedirection(cls, emailAddress, redirectionUrl, outParam)) {
            return outParam.getParam();
        }

        // If there was an earlier exception, throw it.
        if (delayedException != null) {
            throw delayedException;
        }

        throw new AutodiscoverLocalException(Strings.AutodiscoverCouldNotBeLocated);
    }
}

From source file:microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.java

/**
 * Calls the Autodiscover service to retrieve configuration settings.
 *
 * @param <TSettings>  the generic type
 * @param cls          the cls//w  w w  . ja  v  a2s  .  com
 * @param emailAddress The email address to retrieve configuration settings for.
 * @param currentHop   Current number of redirection urls/addresses attempted so far.
 * @return The requested configuration settings.
 * @throws Exception the exception
 */
private <TSettings extends ConfigurationSettingsBase> TSettings internalGetLegacyUserSettings(
        Class<TSettings> cls, String emailAddress, List<String> redirectionEmailAddresses,
        OutParam<Integer> currentHop) throws Exception {
    String domainName = EwsUtilities.domainFromEmailAddress(emailAddress);

    int scpUrlCount;
    OutParam<Integer> outParamInt = new OutParam<Integer>();
    List<URI> urls = this.getAutodiscoverServiceUrls(domainName, outParamInt);
    scpUrlCount = outParamInt.getParam();
    if (urls.size() == 0) {
        throw new ServiceValidationException(
                "This Autodiscover request requires that either the Domain or Url be specified.");
    }

    // Assume caller is not inside the Intranet, regardless of whether SCP
    // Urls
    // were returned or not. SCP Urls are only relevent if one of them
    // returns
    // valid Autodiscover settings.
    this.isExternal = true;

    int currentUrlIndex = 0;

    // Used to save exception for later reporting.
    Exception delayedException = null;
    TSettings settings;

    do {
        URI autodiscoverUrl = urls.get(currentUrlIndex);
        boolean isScpUrl = currentUrlIndex < scpUrlCount;

        try {
            settings = this.getLegacyUserSettingsAtUrl(cls, emailAddress, autodiscoverUrl);

            switch (settings.getResponseType()) {
            case Success:
                // Not external if Autodiscover endpoint found via SCP
                // returned the settings.
                if (isScpUrl) {
                    this.isExternal = false;
                }
                this.url = autodiscoverUrl;
                return settings;
            case RedirectUrl:
                if (currentHop.getParam() < AutodiscoverMaxRedirections) {
                    currentHop.setParam(currentHop.getParam() + 1);

                    this.traceMessage(TraceFlags.AutodiscoverResponse,
                            String.format("Autodiscover " + "service " + "returned " + "redirection URL '%s'.",
                                    settings.getRedirectTarget()));

                    urls.add(currentUrlIndex, new URI(settings.getRedirectTarget()));

                    break;
                } else {
                    throw new MaximumRedirectionHopsExceededException();
                }
            case RedirectAddress:
                if (currentHop.getParam() < AutodiscoverMaxRedirections) {
                    currentHop.setParam(currentHop.getParam() + 1);

                    this.traceMessage(TraceFlags.AutodiscoverResponse, String.format(
                            "Autodiscover " + "service " + "returned " + "redirection email " + "address '%s'.",
                            settings.getRedirectTarget()));
                    // Bug E14:255576 If this email address was already tried, we may have a loop
                    // in SCP lookups. Disable consideration of SCP records.
                    this.disableScpLookupIfDuplicateRedirection(settings.getRedirectTarget(),
                            redirectionEmailAddresses);

                    return this.internalGetLegacyUserSettings(cls, settings.getRedirectTarget(),
                            redirectionEmailAddresses, currentHop);
                } else {
                    throw new MaximumRedirectionHopsExceededException();
                }
            case Error:
                // Don't treat errors from an SCP-based Autodiscover service
                // to be conclusive.
                // We'll try the next one and record the error for later.
                if (isScpUrl) {
                    this.traceMessage(TraceFlags.AutodiscoverConfiguration, "Error returned by "
                            + "Autodiscover service " + "found via SCP, treating " + "as inconclusive.");

                    delayedException = new AutodiscoverRemoteException(
                            "The Autodiscover service returned an error.", settings.getError());
                    currentUrlIndex++;
                } else {
                    throw new AutodiscoverRemoteException("The Autodiscover service returned an error.",
                            settings.getError());
                }
                break;
            default:
                EwsUtilities.EwsAssert(false, "Autodiscover.GetConfigurationSettings",
                        "An unexpected error has occured. " + "This code path should never be reached.");
                break;
            }
        } catch (XMLStreamException ex) {
            this.traceMessage(TraceFlags.AutodiscoverConfiguration,
                    String.format("%s failed: XML parsing error: %s", url, ex.getMessage()));

            // The content at the URL wasn't a valid response, let's try the
            // next.
            currentUrlIndex++;
        } catch (IOException ex) {
            this.traceMessage(TraceFlags.AutodiscoverConfiguration,
                    String.format("%s failed: I/O error: %s", url, ex.getMessage()));

            // The content at the URL wasn't a valid response, let's try the next.
            currentUrlIndex++;
        } catch (Exception ex) {
            HttpWebRequest response = null;
            URI redirectUrl;
            OutParam<URI> outParam1 = new OutParam<URI>();
            if ((response != null) && this.tryGetRedirectionResponse(response, outParam1)) {
                redirectUrl = outParam1.getParam();
                this.traceMessage(TraceFlags.AutodiscoverConfiguration,
                        String.format("Host returned a redirection to url %s", redirectUrl.toString()));

                currentHop.setParam(currentHop.getParam() + 1);
                urls.add(currentUrlIndex, redirectUrl);
            } else {
                if (response != null) {
                    this.processHttpErrorResponse(response, ex);

                }

                this.traceMessage(TraceFlags.AutodiscoverConfiguration,
                        String.format("%s failed: %s (%s)", url, ex.getClass().getName(), ex.getMessage()));

                // The url did not work, let's try the next.
                currentUrlIndex++;
            }
        }
    } while (currentUrlIndex < urls.size());

    // If we got this far it's because none of the URLs we tried have
    // worked. As a next-to-last chance, use GetRedirectUrl to
    // try to get a redirection URL using an HTTP GET on a non-SSL
    // Autodiscover endpoint. If successful, use this
    // redirection URL to get the configuration settings for this email
    // address. (This will be a common scenario for
    // DataCenter deployments).
    URI redirectionUrl = this.getRedirectUrl(domainName);
    OutParam<TSettings> outParam = new OutParam<TSettings>();
    if ((redirectionUrl != null)
            && this.tryLastChanceHostRedirection(cls, emailAddress, redirectionUrl, outParam)) {
        settings = outParam.getParam();
        return settings;
    } else {
        // Getting a redirection URL from an HTTP GET failed too. As a last
        // chance, try to get an appropriate SRV Record
        // using DnsQuery. If successful, use this redirection URL to get
        // the configuration settings for this email address.
        redirectionUrl = this.getRedirectionUrlFromDnsSrvRecord(domainName);
        if ((redirectionUrl != null)
                && this.tryLastChanceHostRedirection(cls, emailAddress, redirectionUrl, outParam)) {
            return outParam.getParam();
        }

        // If there was an earlier exception, throw it.
        if (delayedException != null) {
            throw delayedException;
        }

        throw new AutodiscoverLocalException("The Autodiscover service couldn't be located.");
    }
}

From source file:org.wso2.bps.integration.common.utils.RequestSender.java

public void assertRequest(String eprUrl, String operation, String payload, int numberOfInstances,
        String expectedException, boolean twoWay) throws XMLStreamException, AxisFault {

    for (int i = 0; i < numberOfInstances; i++) {
        OMElement result = null;/*from   w  w  w. ja  v a  2s. c om*/
        try {
            EndpointReference epr = new EndpointReference(eprUrl + "/" + operation);
            if (twoWay) {
                result = this.sendRequest(payload, epr);
                //  Assert.fail("Exception expected!!! : " + result.toString());

            } else {
                this.sendRequestOneWay(payload, epr);
            }
        } catch (XMLStreamException e) {
            if (!e.getClass().getSimpleName().equals(expectedException)) {
                throw new XMLStreamException(e);
            }
        } catch (AxisFault axisFault) {
            log.error("Error occurred while sending request.", axisFault);
            if (!axisFault.getClass().getSimpleName().equals(expectedException)) {
                throw new AxisFault(axisFault.getMessage());
            }
        }

        assert result != null;
        if (!(result.toString().contains(expectedException))) {
            Assert.fail("Expected response not found");
        }
    }
}

From source file:org.wso2.brs.integration.common.utils.RequestSender.java

public void assertRequest(String eprUrl, String operation, String payload, int numberOfInstances,
        String expectedException, boolean twoWay) throws XMLStreamException, AxisFault {

    for (int i = 0; i < numberOfInstances; i++) {
        OMElement result = null;//w  w w  .j  av  a2s.  c om
        try {
            EndpointReference epr = new EndpointReference(eprUrl + "/" + operation);
            if (twoWay) {
                result = this.sendRequest(payload, epr);
                //  Assert.fail("Exception expected!!! : " + result.toString());

            } else {
                this.sendRequestOneWay(payload, epr);
            }
        } catch (XMLStreamException e) {
            if (!e.getClass().getSimpleName().equals(expectedException)) {
                throw new XMLStreamException(e);
            }
        } catch (AxisFault axisFault) {
            axisFault.printStackTrace();
            if (!axisFault.getClass().getSimpleName().equals(expectedException)) {
                throw new AxisFault(axisFault.getMessage());
            }
        }

        assert result != null;
        if (!(result.toString().contains(expectedException))) {
            Assert.fail("Expected response not found");
        }
    }
}

From source file:org.wso2.carbon.automation.test.utils.axis2client.AxisServiceClientUtils.java

public static void sendRequest(String eprUrl, String operation, String payload, int numberOfInstances,
        String expectedException, boolean twoWay) throws XMLStreamException, IOException {
    assertFalse(!AxisServiceClientUtils.isServiceAvailable(eprUrl));
    for (int i = 0; i < numberOfInstances; i++) {
        try {/*from  w  w w  .j  a  v a2s .  co m*/
            EndpointReference epr = new EndpointReference(operation);
            if (twoWay) {
                OMElement result = AxisServiceClientUtils.sendRequest(payload, epr);
                fail("Exception expected!!! : " + result.toString());
            } else {
                AxisServiceClientUtils.sendRequestOneWay(payload, epr);
            }
        } catch (XMLStreamException e) {
            if (!e.getClass().getSimpleName().equals(expectedException)) {
                throw new XMLStreamException(e);
            }
        } catch (AxisFault axisFault) {
            if (!axisFault.getClass().getSimpleName().equals(expectedException)) {
                throw new AxisFault(axisFault.getMessage());
            }
        }
        if (expectedException != null) {
            fail("Exception expected. But not found!!");
        }
    }
}

From source file:org.wso2.esb.integration.common.utils.clients.axis2client.AxisServiceClientUtils.java

public static void sendRequest(String eprUrl, String operation, String payload, int numberOfInstances,
        String expectedException, boolean twoWay) throws XMLStreamException, AxisFault {
    assertFalse(!AxisServiceClientUtils.isServiceAvailable(eprUrl));

    for (int i = 0; i < numberOfInstances; i++) {
        try {/*  w w  w.j av  a2 s  .co m*/
            EndpointReference epr = new EndpointReference(operation);
            if (twoWay) {
                OMElement result = AxisServiceClientUtils.sendRequest(payload, epr);
                fail("Exception expected!!! : " + result.toString());

            } else {
                AxisServiceClientUtils.sendRequestOneWay(payload, epr);
            }
        } catch (XMLStreamException e) {
            if (!e.getClass().getSimpleName().equals(expectedException)) {
                throw new XMLStreamException(e);
            }
        } catch (AxisFault axisFault) {
            if (!axisFault.getClass().getSimpleName().equals(expectedException)) {
                throw new AxisFault(axisFault.getMessage());
            }
        }
        if (expectedException != null) {
            fail("Exception expected. But not found!!");
        }
    }
}