Java 类javax.naming.ServiceUnavailableException 实例源码

项目:OSCAR-ConCert    文件:SetPatientImmediate3Response.java   
/**
 * Parse a the External Prescriber SetPatientImmediate3Response document, re-throwing errors
 * from the remote web service if necessary.
 * 
 * @param node
 *            The document [fragment] to parse.
 * @throws DOMException
 *             Throws a DOMException if this function is passed a document
 *             it doesn't recognize.
 * @throws IllegalArgumentException
 *             Re-throws an IllegalArgumentException if the remote web
 *             service reports that it didn't receive data in a format it
 *             could recognize.
 * @throws SecurityException
 *             Re-throws a SecurityException if the remote web service
 *             reports a security-related error.
 * @throws Exception
 *             Re-throws an Exception if the remote web service reports an
 *             error that wasn't documented enough in the the External Prescriber
 *             documentation for the programmer to understand what it meant.
 */
public static void parseSetPatientImmediate3Response(Node node)
    throws DOMException, IllegalArgumentException, SecurityException,
    ServiceUnavailableException {
    NodeList childNodes;
    Node child;

    // Die if we're being asked to parse something we don't understand
    if (!node.getNodeName().equals("SetPatientImmediate3Response")) {
        throw new DOMException(
            DOMException.NOT_SUPPORTED_ERR,
            "Unable to parse a node of type " + node.getNodeName());
    }

    // Parse this node's child elements
    childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        child = childNodes.item(i);
        if (child.getNodeName().equals("SetPatientImmediate3Result")) {
            SetPatientImmediate3Result
                .parseSetPatientImmediate3Result(child);
        }
    }
}
项目:oscar-old    文件:SetPatientImmediate3Response.java   
/**
 * Parse a the External Prescriber SetPatientImmediate3Response document, re-throwing errors
 * from the remote web service if necessary.
 * 
 * @param node
 *            The document [fragment] to parse.
 * @throws DOMException
 *             Throws a DOMException if this function is passed a document
 *             it doesn't recognize.
 * @throws IllegalArgumentException
 *             Re-throws an IllegalArgumentException if the remote web
 *             service reports that it didn't receive data in a format it
 *             could recognize.
 * @throws SecurityException
 *             Re-throws a SecurityException if the remote web service
 *             reports a security-related error.
 * @throws Exception
 *             Re-throws an Exception if the remote web service reports an
 *             error that wasn't documented enough in the the External Prescriber
 *             documentation for the programmer to understand what it meant.
 */
public static void parseSetPatientImmediate3Response(Node node)
    throws DOMException, IllegalArgumentException, SecurityException,
    ServiceUnavailableException {
    NodeList childNodes;
    Node child;

    // Die if we're being asked to parse something we don't understand
    if (!node.getNodeName().equals("SetPatientImmediate3Response")) {
        throw new DOMException(
            DOMException.NOT_SUPPORTED_ERR,
            "Unable to parse a node of type " + node.getNodeName());
    }

    // Parse this node's child elements
    childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        child = childNodes.item(i);
        if (child.getNodeName().equals("SetPatientImmediate3Result")) {
            SetPatientImmediate3Result
                .parseSetPatientImmediate3Result(child);
        }
    }
}
项目:reactive.loanbroker.system    文件:BankController.java   
@RequestMapping("/{bank}/quotation") // bank name format is bank-[1-9]
public Mono<Quotation> quotation( final @PathVariable("bank") String bank, final @RequestParam(value="loanAmount", required=true) Double loanAmount){
    char bankIndex = bank.charAt(5);

    double pseudoInterestRate = bankIndex=='5' ? 0.001d : ((double)bankIndex)/100d;

    if(bankIndex=='2')
        return Mono.error(new ServiceUnavailableException("bank-"+bankIndex+" service is unavailable"));

    if(bankIndex=='3')
        return Mono.delay(Duration.ofMillis(2000)).then(Mono.just(new Quotation("Bank-"+bankIndex,loanAmount)));

    return  Mono.just(new Quotation("Bank-"+bankIndex,loanAmount * pseudoInterestRate));
}
项目:azure-spring-boot    文件:AADAuthenticationFilter.java   
private AuthenticationResult acquireTokenForGraphApi(
        String idToken,
        String tenantId) throws Throwable {
    final ClientCredential credential = new ClientCredential(
            aadAuthFilterProp.getClientId(), aadAuthFilterProp.getClientSecret());
    final UserAssertion assertion = new UserAssertion(idToken);

    AuthenticationResult result = null;
    ExecutorService service = null;
    try {
        service = Executors.newFixedThreadPool(1);
        final AuthenticationContext context = new AuthenticationContext(
                aadAuthFilterProp.getAadSignInUri() + tenantId + "/",
                true,
                service);
        final Future<AuthenticationResult> future = context
                .acquireToken(aadAuthFilterProp.getAadGraphAPIUri(), assertion, credential, null);
        result = future.get();
    } catch (ExecutionException e) {
        throw e.getCause();
    } finally {
        if (service != null) {
            service.shutdown();
        }
    }

    if (result == null) {
        throw new ServiceUnavailableException(
                "unable to acquire on-behalf-of token for client " + aadAuthFilterProp.getClientId());
    }
    return result;
}
项目:OSCAR-ConCert    文件:GetPrescriptions5Response.java   
/**
 * Parse a the External Prescriber GetPrescriptions5Response document, re-throwing errors
 * from the remote web service if necessary, and returning a list of
 * WSPrescription5 nodes.
 * 
 * @param node
 *            The document [fragment] to parse.
 * @return A list of WSPrescription5 nodes contained in the document.
 * @throws DOMException
 *             Throws a DOMExeption if this function is passed a document
 *             that it doesn't recognize.
 * @throws IllegalArgumentException
 *             Re-throws an IllegalArgumentException if the remote web
 *             service reports that it didn't receive data in a format it
 *             could recognize.
 * @throws SecurityException
 *             Re-throws a SecurityException if the remote web servcice
 *             reports a security-related error.
 * @throws Exception
 *             Re-throws an Exception if the remote web service reports an
 *             error that wasn't documented enough in the the External Prescriber
 *             documentation for the programmer to understand what it meant.
 */
public static List<Node> parseGetPrescriptions5Response(Node node)
    throws DOMException, IllegalArgumentException, SecurityException,
    ServiceUnavailableException {
    // Store a list of WSPrescription5 elements to return
    List<Node> answer = new LinkedList<Node>();
    // Store references to this node's children so we can loop through them
    NodeList childNodes;
    Node child;

    // Die if we're being asked to parse something we don't understand
    if (!node.getNodeName().equals("GetPrescriptions5Response")) {
        throw new DOMException(
            DOMException.NOT_SUPPORTED_ERR,
            "Unable to parse a node of type " + node.getNodeName());
    }

    // Parse this node's child elements
    childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        child = childNodes.item(i);
        if (child.getNodeName().equals("GetPrescriptions5Result")) {
            answer.addAll(GetPrescriptions5Result
                .parseGetPrescriptions5Result(child));
        }
    }

    return answer;
}
项目:substeps-framework    文件:SubstepsJMXClient.java   
protected JMXConnector getConnector(JMXServiceURL serviceURL, Map<String, ?> environment) throws IOException {
    // Create the JMXCconnectorServer

    JMXConnector connector = null;

    long timeout = System.currentTimeMillis() + (JMX_CLIENT_TIMEOUT_SECS * 1000);

    while (connector == null && System.currentTimeMillis() < timeout) {

        try {
            log.debug("trying to connect to: " + serviceURL);
            connector = JMXConnectorFactory.connect(serviceURL, environment);

            log.debug("connected");
        } catch (IOException e) {

            log.debug("e.getCause(): " + e.getCause().getClass());

            if (!(e.getCause() instanceof ServiceUnavailableException)) {
                log.error("not a ServiceUnavailableException", e);
                break;
            }

            log.debug("ConnectException sleeping..");
            try {
                Thread.sleep(500);
            } catch (InterruptedException e1) {
                log.debug("InterruptedException:", e1);
            }
        }
    }
    if (connector == null) {

        log.error("failed to get the JMXConnector in time");
    }

    return connector;
}
项目:ldapchai    文件:JNDIProviderImpl.java   
public boolean errorIsRetryable( final Exception e )
{
    if ( e instanceof CommunicationException || e instanceof ServiceUnavailableException )
    {
        final String msgText = e.getMessage();
        if ( msgText != null && !msgText.toLowerCase().contains( "unrecognized extended operation" ) )
        {
            return true;
        }
    }

    return super.errorIsRetryable( e );
}
项目:omr    文件:ValidadorPesquisaOnline.java   
@Override
public void run() {
    try{
        long timeIni = System.currentTimeMillis();
        result = pesquisador.pesquisar(this.service, this.xmlParametro);
        if(log.isDebugEnabled()) log.debug("Pesquisa com DLL executada em " + ((System.currentTimeMillis() - timeIni) / 1000) + " segundos.");
    }catch(RemoteAccessException e) {
        if(log.isDebugEnabled()) log.debug("Erro ao pesquisar: " + e.getMessage());
        System.out.flush();
        throw new RuntimeException(new ServiceUnavailableException("Erro ao obter client RMI: " + e.getMessage()));
    }
}
项目:netarchivesuite-svngit-migration    文件:JMXUtils.java   
/** Get a JMXConnector to a given host and port, using login and password.
 *
 * @param hostName The host to attempt to connect to.
 * @param jmxPort The port on the host to connect to
 * (a non-negative number).
 * @param login The login name to authenticate as (typically "controlRole"
 * or "monitorRole".
 * @param password The password for JMX access.
 * @return A JMX connector to the given host and port, using default RMI.
 * @throws IOFailure if connecting to JMX fails.
 */
public static JMXConnector getJMXConnector(String hostName,
                                           int jmxPort, final String login,
                                           final String password) {
    ArgumentNotValid.checkNotNullOrEmpty(hostName, "String hostName");
    ArgumentNotValid.checkNotNegative(jmxPort, "int jmxPort");
    ArgumentNotValid.checkNotNullOrEmpty(login, "String login");
    ArgumentNotValid.checkNotNullOrEmpty(password, "String password");

    JMXServiceURL rmiurl = getUrl(hostName, jmxPort, -1);
    Map<String, ?> environment = packageCredentials(login, password);
    Throwable lastException;
    int retries = 0;
    final int maxJmxRetries = getMaxTries();
    do {
        try {
            return JMXConnectorFactory.connect(rmiurl, environment);
        } catch (IOException e) {
            lastException = e;
            if (retries < maxJmxRetries && e.getCause() != null
                && (e.getCause() instanceof ServiceUnavailableException 
                      || e.getCause() instanceof SocketTimeoutException)) {
                // Sleep a bit before trying again
                TimeUtils.exponentialBackoffSleep(retries);
                /*  called exponentialBackoffSleep(retries) which used
                    Calendar.MILLISECOND as time unit, which means we only
                    wait an exponential number of milliseconds.
                */
                continue;
            }
            break;
        }
    } while (retries++ < maxJmxRetries);
    throw new IOFailure("Failed to connect to URL " + rmiurl + " after "
                        + retries + " of " + maxJmxRetries
                        + " attempts.\nException type: "
                        + lastException.getCause().getClass().getName(),
                        lastException);
}
项目:hbase    文件:TestJMXConnectorServer.java   
/**
 * This tests to validate the RegionServer's ConnectorServer after unauthorised stopRegionServer
 * call.
 */
@Test(timeout = 180000)
public void testRSConnectorServerWhenStopRegionServer() throws Exception {
  conf.set(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY,
    JMXListener.class.getName() + "," + MyAccessController.class.getName());
  conf.setInt("regionserver.rmi.registry.port", rmiRegistryPort);
  UTIL.startMiniCluster();
  admin = UTIL.getConnection().getAdmin();

  hasAccess = false;
  ServerName serverName = UTIL.getHBaseCluster().getRegionServer(0).getServerName();
  LOG.info("Stopping Region Server...");
  admin.stopRegionServer(serverName.getHostname() + ":" + serverName.getPort());

  // Check whether Region Sever JMX Connector server can be connected
  JMXConnector connector = null;
  try {
    connector = JMXConnectorFactory
        .connect(JMXListener.buildJMXServiceURL(rmiRegistryPort, rmiRegistryPort));
  } catch (IOException e) {
    if (e.getCause() instanceof ServiceUnavailableException) {
      Assert.fail("Can't connect to Region Server ConnectorServer.");
    }
  }
  Assert.assertNotNull("JMXConnector should not be null.", connector);
  connector.close();
}
项目:basis    文件:ConstrainedHttpClient.java   
/**
 * Executes the http method specified while protecting the http client with a semaphore. If the maximum number
 * of outstanding requests has been reached it will throw a ServiceUnavailableException. The other exceptions are
 * thrown by the standard http client executeMethod.
 *
 * @return
 * @throws ServiceUnavailableException If the limit of concurrent connections has been reached.
 * @throws IOException                 If an I/O (transport) error occurs. Some transport exceptions cannot be recovered from.
 */
public HttpResponse execute(HttpRequestBase request, int timeoutms) throws ServiceUnavailableException, IOException {
    if (semaphore.tryAcquire()) {
        try {
            logger.trace("Semaphore was acquired. Remaining: {} ", semaphore.availablePermits());
            return HttpUtil.execute(request, timeoutms);
        } finally {
            semaphore.release();
        }
    } else {
        throw new ServiceUnavailableException("Reached limit of " + getCurrentRequests() + " concurrent requests");
    }
}
项目:basis    文件:ConstrainedHttpClientTest.java   
public void run() {
    try {
        client.execute(new HttpGet("http://www.w3.org"), 10000);
    } catch (ServiceUnavailableException ex) {
        unavailable = true;
    } catch (IOException e) {
    }
}
项目:oscar-old    文件:GetPrescriptions5Response.java   
/**
 * Parse a the External Prescriber GetPrescriptions5Response document, re-throwing errors
 * from the remote web service if necessary, and returning a list of
 * WSPrescription5 nodes.
 * 
 * @param node
 *            The document [fragment] to parse.
 * @return A list of WSPrescription5 nodes contained in the document.
 * @throws DOMException
 *             Throws a DOMExeption if this function is passed a document
 *             that it doesn't recognize.
 * @throws IllegalArgumentException
 *             Re-throws an IllegalArgumentException if the remote web
 *             service reports that it didn't receive data in a format it
 *             could recognize.
 * @throws SecurityException
 *             Re-throws a SecurityException if the remote web servcice
 *             reports a security-related error.
 * @throws Exception
 *             Re-throws an Exception if the remote web service reports an
 *             error that wasn't documented enough in the the External Prescriber
 *             documentation for the programmer to understand what it meant.
 */
public static List<Node> parseGetPrescriptions5Response(Node node)
    throws DOMException, IllegalArgumentException, SecurityException,
    ServiceUnavailableException {
    // Store a list of WSPrescription5 elements to return
    List<Node> answer = new LinkedList<Node>();
    // Store references to this node's children so we can loop through them
    NodeList childNodes;
    Node child;

    // Die if we're being asked to parse something we don't understand
    if (!node.getNodeName().equals("GetPrescriptions5Response")) {
        throw new DOMException(
            DOMException.NOT_SUPPORTED_ERR,
            "Unable to parse a node of type " + node.getNodeName());
    }

    // Parse this node's child elements
    childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        child = childNodes.item(i);
        if (child.getNodeName().equals("GetPrescriptions5Result")) {
            answer.addAll(GetPrescriptions5Result
                .parseGetPrescriptions5Result(child));
        }
    }

    return answer;
}
项目:rsine    文件:RemoteNotificationService.java   
@Override
public void announce(Model changeSet) {
    Collection<Resource> extResources = getExternalResources(changeSet);

    try {
        for (Resource extResource : extResources) {
            notifyRemoteService(remoteServiceDetector.getRemoteService(extResource), changeSet);
        }
    }
    catch (ServiceUnavailableException e) {
        logger.warn("Remote service unavailable: " +e.getMessage());
    }
}
项目:OpenJSharp    文件:LDAPCertStoreHelper.java   
@Override
public boolean isCausedByNetworkIssue(CertStoreException e) {
    Throwable t = e.getCause();
    return (t != null && (t instanceof ServiceUnavailableException ||
                          t instanceof CommunicationException));
}
项目:OpenJSharp    文件:Connection.java   
/**
 * Reads a reply; waits until one is ready.
 */
BerDecoder readReply(LdapRequest ldr)
        throws IOException, NamingException {
    BerDecoder rber;
    boolean waited = false;

    while (((rber = ldr.getReplyBer()) == null) && !waited) {
        try {
            // If socket closed, don't even try
            synchronized (this) {
                if (sock == null) {
                    throw new ServiceUnavailableException(host + ":" + port +
                        "; socket closed");
                }
            }
            synchronized (ldr) {
                // check if condition has changed since our last check
                rber = ldr.getReplyBer();
                if (rber == null) {
                    if (readTimeout > 0) {  // Socket read timeout is specified

                        // will be woken up before readTimeout only if reply is
                        // available
                        ldr.wait(readTimeout);
                        waited = true;
                    } else {
                        // no timeout is set so we wait infinitely until
                        // a response is received
                        // https://docs.oracle.com/javase/8/docs/technotes/guides/jndi/jndi-ldap.html#PROP
                        ldr.wait();
                    }
                } else {
                    break;
                }
            }
        } catch (InterruptedException ex) {
            throw new InterruptedNamingException(
                "Interrupted during LDAP operation");
        }
    }

    if ((rber == null) && waited) {
        abandonRequest(ldr, null);
        throw new NamingException("LDAP response read timed out, timeout used:"
                        + readTimeout + "ms." );

    }
    return rber;
}
项目:jdk8u-jdk    文件:LDAPCertStoreHelper.java   
@Override
public boolean isCausedByNetworkIssue(CertStoreException e) {
    Throwable t = e.getCause();
    return (t != null && (t instanceof ServiceUnavailableException ||
                          t instanceof CommunicationException));
}
项目:OSCAR-ConCert    文件:SetPatientImmediate3Result.java   
/**
 * Parse a the External Prescriber SetPatientImmediate3Result document, re-throwing errors
 * from the remote web service if necessary.
 * 
 * @param node
 *            The document [fragment] to parse.
 * @throws DOMException
 *             Throws a DOMException if this function is passed a document
 *             it doesn't recognize.
 * @throws IllegalArgumentException
 *             Re-throws an IllegalArgumentException if the remote web
 *             service reports that it didn't receive data in a format it
 *             could recognize.
 * @throws SecurityException
 *             Re-throws a SecurityException if the remote web service
 *             reports a security-related error.
 * @throws Exception
 *             Re-throws an Exception if the remote web service reports an
 *             error that wasn't documented enough in the the External Prescriber
 *             documentation for the programmer to understand what it meant.
 */
public static void parseSetPatientImmediate3Result(Node node)
    throws DOMException, IllegalArgumentException, SecurityException,
    ServiceUnavailableException {
    // Store references to this node's children so we can loop through them
    NodeList childNodes;
    Node child;

    // Die if we're being asked to parse something we don't understand
    if (!node.getNodeName().equals("SetPatientImmediate3Result")) {
        throw new DOMException(
            DOMException.NOT_SUPPORTED_ERR,
            "Unable to parse a node of type " + node.getNodeName());
    }

    // Parse the node to see if the web service returned errors
    childNodes = node.getChildNodes();
    for (int j = 0; j < childNodes.getLength(); j++) {
        child = childNodes.item(j);
        if (child.getNodeName().equals("ResultCode")) {
            switch (WSPatientResult3.parseString(child.getTextContent())) {
                case ERROR_UNMANAGED:
                    throw new ServiceUnavailableException(
                        "The remote system experienced an unhandled error on it's side, but couldn't determine whether it was our fault or not.");
                case ERROR_AUTHENTICATION:
                    throw new SecurityException(
                        "The credentials used to send the patient data were not valid.");
                case ERROR_AUTHORIZATION:
                    throw new SecurityException(
                        "The user whose credentials were used to send the patient data is not authorized to send patient data.");
                case ERROR_UNAUTHORIZED_CLINIC:
                    throw new IllegalArgumentException(
                        "The clinic specified is not valid or has been disabled; or the user whose credentials were used is not registered to request prescription lists on behalf of that clinic.");
                case ERROR_UNKNOWN_CLINIC:
                    throw new SecurityException(
                        "The client number specified is not valid or has been disabled.");
                case ERROR_INVALIDLOCALID:
                    throw new IllegalArgumentException(
                        "The external prescription service was unable to parse the given locale ID when sending patient data.");
                case ERROR_NONSECUREACCESS:
                    throw new SecurityException(
                        "The transport method used to send the patient data was not secure, so the request was rejected.");
            }
        }
    }
}
项目:OSCAR-ConCert    文件:GetPrescriptions5Result.java   
public static List<Node> parseGetPrescriptions5Result(Node node)
    throws DOMException, IllegalArgumentException, SecurityException,
    ServiceUnavailableException {
    // Store a list of WSPrescription5 elements to return
    List<Node> answer = new LinkedList<Node>();
    // Store references to this node's children so we can loop through them
    NodeList childNodes;
    Node child;
    Result result;

    // Die if we're being asked to parse something we don't understand
    if (!node.getNodeName().equals("GetPrescriptions5Result")) {
        throw new DOMException(
            DOMException.NOT_SUPPORTED_ERR,
            "Unable to parse a node of type " + node.getNodeName());
    }

    // Parse a WSResult5 element first if there is one
    childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        child = childNodes.item(i);
        if (child.getNodeName().equals("Result")) {
            result = new Result(child);
            switch (result.getCode()) {
                case ERROR_PATIENTNOTFOUND:
                    throw new IllegalArgumentException(
                        "The patient whose data was requested was not found in the remote system's database.");
                case ERROR_UNMANAGED:
                    throw new ServiceUnavailableException(
                        "The remote system experienced an unhandled error on it's side, but couldn't determine whether it was our fault or not.");
                case ERROR_AUTHENTICATION:
                    throw new SecurityException(
                        "The credentials used to request the prescription list were not valid.");
                case ERROR_AUTHORIZATION:
                    throw new SecurityException(
                        "The user whose credentials were used to request the prescription list is not authorized to request prescription lists.");
                case ERROR_UNAUTHORIZED_CLINIC:
                    throw new IllegalArgumentException(
                        "The clinic specified is not valid or disabled; or the user whose credentials were used is not registered to request prescription lists on behalf of that clinic.");
                case ERROR_INVALIDDATEFORMAT:
                    throw new IllegalArgumentException(
                        "The external prescription service was unable to parse the given last-checked-date when requesting prescriptions.");
                case ERROR_INVALIDLOCALEID:
                    throw new IllegalArgumentException(
                        "The external prescription service was unable to parse the given locale ID when requesting prescriptions.");
                case ERROR_INVALIDDATEANDPATIENT:
                    throw new IllegalArgumentException(
                        "The external prescription service was unable to parse the given last-checked-date and patient ID.");
                case ERROR_NONSECUREACCESS:
                    throw new SecurityException(
                        "The transport method used to request the prescription list was not secure, so the request was rejected.");
            }
        }
    }

    // Now loop through the nodes again, looking for Prescriptions
    childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        child = childNodes.item(i);
        if (child.getNodeName().equals("Prescriptions")) {
            answer.addAll(Prescriptions.parsePrescriptions(child));
        }
    }

    return answer;
}
项目:jdk8u_jdk    文件:LDAPCertStoreHelper.java   
@Override
public boolean isCausedByNetworkIssue(CertStoreException e) {
    Throwable t = e.getCause();
    return (t != null && (t instanceof ServiceUnavailableException ||
                          t instanceof CommunicationException));
}
项目:lookaside_java-1.8.0-openjdk    文件:LDAPCertStoreHelper.java   
@Override
public boolean isCausedByNetworkIssue(CertStoreException e) {
    Throwable t = e.getCause();
    return (t != null && (t instanceof ServiceUnavailableException ||
                          t instanceof CommunicationException));
}
项目:infobip-open-jdk-8    文件:LDAPCertStoreHelper.java   
@Override
public boolean isCausedByNetworkIssue(CertStoreException e) {
    Throwable t = e.getCause();
    return (t != null && (t instanceof ServiceUnavailableException ||
                          t instanceof CommunicationException));
}
项目:infobip-open-jdk-8    文件:Connection.java   
/**
 * Reads a reply; waits until one is ready.
 */
BerDecoder readReply(LdapRequest ldr)
        throws IOException, NamingException {
    BerDecoder rber;
    boolean waited = false;

    while (((rber = ldr.getReplyBer()) == null) && !waited) {
        try {
            // If socket closed, don't even try
            synchronized (this) {
                if (sock == null) {
                    throw new ServiceUnavailableException(host + ":" + port +
                        "; socket closed");
                }
            }
            synchronized (ldr) {
                // check if condition has changed since our last check
                rber = ldr.getReplyBer();
                if (rber == null) {
                    if (readTimeout > 0) {  // Socket read timeout is specified

                        // will be woken up before readTimeout only if reply is
                        // available
                        ldr.wait(readTimeout);
                        waited = true;
                    } else {
                        // no timeout is set so we wait infinitely until
                        // a response is received
                        // https://docs.oracle.com/javase/8/docs/technotes/guides/jndi/jndi-ldap.html#PROP
                        ldr.wait();
                    }
                } else {
                    break;
                }
            }
        } catch (InterruptedException ex) {
            throw new InterruptedNamingException(
                "Interrupted during LDAP operation");
        }
    }

    if ((rber == null) && waited) {
        abandonRequest(ldr, null);
        throw new NamingException("LDAP response read timed out, timeout used:"
                        + readTimeout + "ms." );

    }
    return rber;
}
项目:jdk8u-dev-jdk    文件:LDAPCertStoreHelper.java   
@Override
public boolean isCausedByNetworkIssue(CertStoreException e) {
    Throwable t = e.getCause();
    return (t != null && (t instanceof ServiceUnavailableException ||
                          t instanceof CommunicationException));
}
项目:jdk8u-dev-jdk    文件:Connection.java   
/**
 * Reads a reply; waits until one is ready.
 */
BerDecoder readReply(LdapRequest ldr)
        throws IOException, NamingException {
    BerDecoder rber;
    boolean waited = false;

    while (((rber = ldr.getReplyBer()) == null) && !waited) {
        try {
            // If socket closed, don't even try
            synchronized (this) {
                if (sock == null) {
                    throw new ServiceUnavailableException(host + ":" + port +
                        "; socket closed");
                }
            }
            synchronized (ldr) {
                // check if condition has changed since our last check
                rber = ldr.getReplyBer();
                if (rber == null) {
                    if (readTimeout > 0) {  // Socket read timeout is specified

                        // will be woken up before readTimeout only if reply is
                        // available
                        ldr.wait(readTimeout);
                        waited = true;
                    } else {
                        // no timeout is set so we wait infinitely until
                        // a response is received
                        // https://docs.oracle.com/javase/8/docs/technotes/guides/jndi/jndi-ldap.html#PROP
                        ldr.wait();
                    }
                } else {
                    break;
                }
            }
        } catch (InterruptedException ex) {
            throw new InterruptedNamingException(
                "Interrupted during LDAP operation");
        }
    }

    if ((rber == null) && waited) {
        abandonRequest(ldr, null);
        throw new NamingException("LDAP response read timed out, timeout used:"
                        + readTimeout + "ms." );

    }
    return rber;
}
项目:speedtools    文件:TomTomLbsGeoCodeEngine.java   
/**
 * Perform actual LBS HTTP query.
 *
 * @param queryUrl URL to query.
 * @return Valid GeoCoderResponse object.
 * @throws AuthorizationException      Thrown in case API key is rejected by server
 * @throws ServiceUnavailableException Thrown if service is not available.
 * @throws IOException                 Thrown if GET could not be executed for some reason.
 */
@SuppressWarnings("OverlyBroadThrowsClause")
@Nonnull
private static GeoCodeEngineResponse executeLbsQuery(@Nonnull final String queryUrl)
        throws AuthorizationException, ServiceUnavailableException, IOException {
    assert queryUrl != null;
    LOG.debug("executeLbsQuery: url={}", queryUrl);
    final GetMethod get = new GetMethod(queryUrl);
    final int status = new HttpClient().executeMethod(get);

    // Log error message.
    if (status != HttpStatus.SC_OK) {
        LOG.warn("executeLbsQuery: geocoding service failure, url={}, status={} ",
                queryUrl, get.getStatusLine());
    }
    final GeoCodeEngineResponse response;
    switch (status) {

        case HttpStatus.SC_OK:
            try {
                response = unmarshalGeoCoderResponseBody(get.getResponseBodyAsStream());
            } catch (final JAXBException e) {
                LOG.warn("executeLbsQuery: cannot unmarshal response", e);
                throw new IOException("Cannot unmarshal response", e);
            } finally {
                get.releaseConnection();
            }
            assert response != null;
            break;

        case HttpStatus.SC_NO_CONTENT:
            response = new GeoCodeEngineResponse();
            break;

        case HttpStatus.SC_UNAUTHORIZED:
            // Fall through.
        case HttpStatus.SC_METHOD_NOT_ALLOWED:
            // Fall through.
        case HttpStatus.SC_NOT_ACCEPTABLE:
            // Fall through.
        case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
            throw new AuthorizationException();

        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            // Fall through.
        case HttpStatus.SC_SERVICE_UNAVAILABLE:
            // Fall through.
        case HttpStatus.SC_GATEWAY_TIMEOUT:
            // Fall through.
        case HttpStatus.SC_INSUFFICIENT_STORAGE:
            throw new ServiceUnavailableException();

        default:
            throw new IOException("Cannot call geocoder, status=" + status + " (" + get.getStatusLine() + ')');
    }
    assert response != null;
    return response;
}
项目:speedtools    文件:TomTomLbsRouteEngineRouteEngineActorImpl.java   
/**
 * Perform actual LBS HTTP query.
 *
 * @param queryUrl URL to query.
 * @return Valid route engine response object.
 * @throws AuthorizationException      Thrown in case API key is rejected by server
 * @throws ServiceUnavailableException Thrown if service is not available.
 * @throws IOException                 Thrown if GET could not be executed for some reason.
 */
@SuppressWarnings("OverlyBroadThrowsClause")
@Nonnull
private static TomTomLbsRouteEngineResponse executeLbsQuery(@Nonnull final String queryUrl)
        throws AuthorizationException, ServiceUnavailableException, IOException {
    assert queryUrl != null;
    LOG.trace("executeLbsQuery: url={}", queryUrl);
    final GetMethod get = new GetMethod(queryUrl);
    final int status = new HttpClient().executeMethod(get);

    // Log error message.
    if (status != HttpStatus.SC_OK) {
        LOG.info("executeLbsQuery: routing service failure, url={}, status={} ",
                queryUrl, get.getStatusLine());
    }
    final TomTomLbsRouteEngineResponse response;
    switch (status) {

        case HttpStatus.SC_OK:
            try {
                response = unmarshalRouterResponseBody(get.getResponseBodyAsStream());
            } catch (final JAXBException e) {
                LOG.warn("executeLbsQuery: cannot unmarshal response", e);
                throw new IOException("Cannot unmarshal response", e);
            } finally {
                get.releaseConnection();
            }
            assert response != null;
            break;

        case HttpStatus.SC_UNAUTHORIZED:
            // Fall through.
        case HttpStatus.SC_METHOD_NOT_ALLOWED:
            // Fall through.
        case HttpStatus.SC_NOT_ACCEPTABLE:
            // Fall through.
        case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
            throw new AuthorizationException();

        case HttpStatus.SC_NO_CONTENT:
            // Fall through.
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            // Fall through.
        case HttpStatus.SC_SERVICE_UNAVAILABLE:
            // Fall through.
        case HttpStatus.SC_GATEWAY_TIMEOUT:
            // Fall through.
        case HttpStatus.SC_INSUFFICIENT_STORAGE:
            throw new ServiceUnavailableException();

        default:
            throw new IOException("Cannot call route engine, status=" + status + " (" + get.getStatusLine() + ')');
    }
    assert response != null;
    return response;
}
项目:jdk7-jdk    文件:Connection.java   
/**
 * Reads a reply; waits until one is ready.
 */
BerDecoder readReply(LdapRequest ldr)
        throws IOException, NamingException {
    BerDecoder rber;
    boolean waited = false;

    while (((rber = ldr.getReplyBer()) == null) && !waited) {
        try {
            // If socket closed, don't even try
            synchronized (this) {
                if (sock == null) {
                    throw new ServiceUnavailableException(host + ":" + port +
                        "; socket closed");
                }
            }
            synchronized (ldr) {
                // check if condition has changed since our last check
                rber = ldr.getReplyBer();
                if (rber == null) {
                    if (readTimeout > 0) {  // Socket read timeout is specified

                        // will be woken up before readTimeout only if reply is
                        // available
                        ldr.wait(readTimeout);
                        waited = true;
                    } else {
                        ldr.wait(15 * 1000); // 15 second timeout
                    }
                } else {
                    break;
                }
            }
        } catch (InterruptedException ex) {
            throw new InterruptedNamingException(
                "Interrupted during LDAP operation");
        }
    }

    if ((rber == null) && waited) {
        removeRequest(ldr);
        throw new NamingException("LDAP response read timed out, timeout used:"
                        + readTimeout + "ms." );

    }
    return rber;
}
项目:openjdk-source-code-learn    文件:Connection.java   
/**
 * Reads a reply; waits until one is ready.
 */
BerDecoder readReply(LdapRequest ldr)
        throws IOException, NamingException {
    BerDecoder rber;
    boolean waited = false;

    while (((rber = ldr.getReplyBer()) == null) && !waited) {
        try {
            // If socket closed, don't even try
            synchronized (this) {
                if (sock == null) {
                    throw new ServiceUnavailableException(host + ":" + port +
                        "; socket closed");
                }
            }
            synchronized (ldr) {
                // check if condition has changed since our last check
                rber = ldr.getReplyBer();
                if (rber == null) {
                    if (readTimeout > 0) {  // Socket read timeout is specified

                        // will be woken up before readTimeout only if reply is
                        // available
                        ldr.wait(readTimeout);
                        waited = true;
                    } else {
                        ldr.wait(15 * 1000); // 15 second timeout
                    }
                } else {
                    break;
                }
            }
        } catch (InterruptedException ex) {
            throw new InterruptedNamingException(
                "Interrupted during LDAP operation");
        }
    }

    if ((rber == null) && waited) {
        removeRequest(ldr);
        throw new NamingException("LDAP response read timed out, timeout used:"
                        + readTimeout + "ms." );

    }
    return rber;
}
项目:OLD-OpenJDK8    文件:LDAPCertStoreHelper.java   
@Override
public boolean isCausedByNetworkIssue(CertStoreException e) {
    Throwable t = e.getCause();
    return (t != null && (t instanceof ServiceUnavailableException ||
                          t instanceof CommunicationException));
}
项目:OLD-OpenJDK8    文件:Connection.java   
/**
 * Reads a reply; waits until one is ready.
 */
BerDecoder readReply(LdapRequest ldr)
        throws IOException, NamingException {
    BerDecoder rber;
    boolean waited = false;

    while (((rber = ldr.getReplyBer()) == null) && !waited) {
        try {
            // If socket closed, don't even try
            synchronized (this) {
                if (sock == null) {
                    throw new ServiceUnavailableException(host + ":" + port +
                        "; socket closed");
                }
            }
            synchronized (ldr) {
                // check if condition has changed since our last check
                rber = ldr.getReplyBer();
                if (rber == null) {
                    if (readTimeout > 0) {  // Socket read timeout is specified

                        // will be woken up before readTimeout only if reply is
                        // available
                        ldr.wait(readTimeout);
                        waited = true;
                    } else {
                        ldr.wait(15 * 1000); // 15 second timeout
                    }
                } else {
                    break;
                }
            }
        } catch (InterruptedException ex) {
            throw new InterruptedNamingException(
                "Interrupted during LDAP operation");
        }
    }

    if ((rber == null) && waited) {
        removeRequest(ldr);
        throw new NamingException("LDAP response read timed out, timeout used:"
                        + readTimeout + "ms." );

    }
    return rber;
}
项目:cn1    文件:RegistryContext.java   
/**
 * Prepares a new {@link NamingException} wrapping the specified
 * {@link RemoteException} source exception. Source exception becomes a
 * {@linkplain NamingException#getCause() cause} of the generated exception.
 * 
 * The particular subclass of {@link NamingException} returned depends on
 * the particular subclass of source {@link RemoteException}.
 * 
 * If source exception is not of a specific class or is not a
 * {@link RemoteException} or is <code>null</code>, then plain
 * {@link NamingException} is returned.
 * 
 * Note: {@link Throwable#fillInStackTrace()} should be called before
 * throwing the generated exception, to provide the proper (not including
 * this method) stack trace for the exception.
 * 
 * Example of use:
 * 
 * <code>try {
 *     ...
 * } catch (RemoteException e) {
 *     throw (NamingException) newNamingException(e).fillInStackTrace();
 * }</code>
 * 
 * @param e
 *            Source {@link RemoteException}.
 * 
 * @return Generated {@link NamingException} exception.
 */
@SuppressWarnings("deprecation")
protected NamingException newNamingException(Throwable e) {
    NamingException ret = (e instanceof AccessException) ? new NoPermissionException()
            : (e instanceof ConnectException) ? new ServiceUnavailableException()
                    : (e instanceof ConnectIOException)
                            || (e instanceof ExportException)
                            || (e instanceof MarshalException)
                            || (e instanceof UnmarshalException) ? new CommunicationException()
                            : (e instanceof ActivateFailedException)
                                    || (e instanceof NoSuchObjectException)
                                    || (e instanceof java.rmi.server.SkeletonMismatchException)
                                    || (e instanceof java.rmi.server.SkeletonNotFoundException)
                                    || (e instanceof StubNotFoundException)
                                    || (e instanceof UnknownHostException) ? new ConfigurationException()
                                    : (e instanceof ServerException) ? newNamingException(e
                                            .getCause())
                                            : new NamingException();

    if (ret.getCause() == null) {
        ret.initCause(e);
    }
    return ret;
}
项目:openjdk-jdk7u-jdk    文件:Connection.java   
/**
 * Reads a reply; waits until one is ready.
 */
BerDecoder readReply(LdapRequest ldr)
        throws IOException, NamingException {
    BerDecoder rber;
    boolean waited = false;

    while (((rber = ldr.getReplyBer()) == null) && !waited) {
        try {
            // If socket closed, don't even try
            synchronized (this) {
                if (sock == null) {
                    throw new ServiceUnavailableException(host + ":" + port +
                        "; socket closed");
                }
            }
            synchronized (ldr) {
                // check if condition has changed since our last check
                rber = ldr.getReplyBer();
                if (rber == null) {
                    if (readTimeout > 0) {  // Socket read timeout is specified

                        // will be woken up before readTimeout only if reply is
                        // available
                        ldr.wait(readTimeout);
                        waited = true;
                    } else {
                        ldr.wait(15 * 1000); // 15 second timeout
                    }
                } else {
                    break;
                }
            }
        } catch (InterruptedException ex) {
            throw new InterruptedNamingException(
                "Interrupted during LDAP operation");
        }
    }

    if ((rber == null) && waited) {
        removeRequest(ldr);
        throw new NamingException("LDAP response read timed out, timeout used:"
                        + readTimeout + "ms." );

    }
    return rber;
}
项目:nextop-client    文件:RegistryContext.java   
/**
 * Prepares a new {@link NamingException} wrapping the specified
 * {@link RemoteException} source exception. Source exception becomes a
 * {@linkplain NamingException#getCause() cause} of the generated exception.
 * 
 * The particular subclass of {@link NamingException} returned depends on
 * the particular subclass of source {@link RemoteException}.
 * 
 * If source exception is not of a specific class or is not a
 * {@link RemoteException} or is <code>null</code>, then plain
 * {@link NamingException} is returned.
 * 
 * Note: {@link Throwable#fillInStackTrace()} should be called before
 * throwing the generated exception, to provide the proper (not including
 * this method) stack trace for the exception.
 * 
 * Example of use:
 * 
 * <code>try {
 *     ...
 * } catch (RemoteException e) {
 *     throw (NamingException) newNamingException(e).fillInStackTrace();
 * }</code>
 * 
 * @param e
 *            Source {@link RemoteException}.
 * 
 * @return Generated {@link NamingException} exception.
 */
@SuppressWarnings("deprecation")
protected NamingException newNamingException(Throwable e) {
    NamingException ret = (e instanceof AccessException) ? new NoPermissionException()
            : (e instanceof ConnectException) ? new ServiceUnavailableException()
                    : (e instanceof ConnectIOException)
                            || (e instanceof ExportException)
                            || (e instanceof MarshalException)
                            || (e instanceof UnmarshalException) ? new CommunicationException()
                            : (e instanceof ActivateFailedException)
                                    || (e instanceof NoSuchObjectException)
                                    || (e instanceof java.rmi.server.SkeletonMismatchException)
                                    || (e instanceof java.rmi.server.SkeletonNotFoundException)
                                    || (e instanceof StubNotFoundException)
                                    || (e instanceof UnknownHostException) ? new ConfigurationException()
                                    : (e instanceof ServerException) ? newNamingException(e
                                            .getCause())
                                            : new NamingException();

    if (ret.getCause() == null) {
        ret.initCause(e);
    }
    return ret;
}
项目:cloudstack    文件:ElastistorUtil.java   
public ElastiCenterClient(String address, String key) throws InvalidCredentialsException, InvalidParameterException, SSLHandshakeException, ServiceUnavailableException {
    elastiCenterAddress = address;
    apiKey = key;
    initialize();
}
项目:cloudstack    文件:ElastistorUtil.java   
public Object executeCommand(String command, MultivaluedMap<String, String> params, Object responeObj) throws Throwable {

            if (!initialized) {
                throw new IllegalStateException("Error : ElastiCenterClient is not initialized.");
            }

            if (command == null || command.trim().isEmpty()) {
                throw new InvalidParameterException("No command to execute.");
            }

            try {
                ClientConfig config = new DefaultClientConfig();
                Client client = Client.create(config);
                WebResource webResource = client.resource(UriBuilder.fromUri(restprotocol + elastiCenterAddress + restpath).build());

                MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
                queryParams.add(queryparamapikey, apiKey);
                queryParams.add(queryparamresponse, responseType);

                queryParams.add(queryparamcommand, command);

                if (null != params) {
                    for (String key : params.keySet()) {
                        queryParams.add(key, params.getFirst(key));
                    }
                }
                if (debug) {
                    System.out.println("Command Sent " + command + " : " + queryParams);
                }
                ClientResponse response = webResource.queryParams(queryParams).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);

                if (response.getStatus() >= 300) {
                    if (debug)
                        System.out.println("ElastiCenter returned error code : " + response.getStatus());
                    if (401 == response.getStatus()) {
                        throw new InvalidCredentialsException("Please specify a valid API Key.");
                    } else if (431 == response.getStatus()) {
                        throw new InvalidParameterException(response.getHeaders().getFirst("X-Description"));
                    } else if (432 == response.getStatus()) {
                        throw new InvalidParameterException(command + " does not exist on the ElastiCenter server.  Please specify a valid command or contact your ElastiCenter Administrator.");
                    } else {
                        throw new ServiceUnavailableException("Internal Error. Please contact your ElastiCenter Administrator.");
                    }
                } else if (null != responeObj) {
                    String jsonResponse = response.getEntity(String.class);
                    if (debug) {
                        System.out.println("Command Response : " + jsonResponse);
                    }
                    Gson gson = new Gson();
                    return gson.fromJson(jsonResponse, responeObj.getClass());
                } else {
                    return "Success";
                }
            } catch (Throwable t) {
                throw t;
            }
        }
项目:freeVM    文件:RegistryContext.java   
/**
 * Prepares a new {@link NamingException} wrapping the specified
 * {@link RemoteException} source exception. Source exception becomes a
 * {@linkplain NamingException#getCause() cause} of the generated exception.
 * 
 * The particular subclass of {@link NamingException} returned depends on
 * the particular subclass of source {@link RemoteException}.
 * 
 * If source exception is not of a specific class or is not a
 * {@link RemoteException} or is <code>null</code>, then plain
 * {@link NamingException} is returned.
 * 
 * Note: {@link Throwable#fillInStackTrace()} should be called before
 * throwing the generated exception, to provide the proper (not including
 * this method) stack trace for the exception.
 * 
 * Example of use:
 * 
 * <code>try {
 *     ...
 * } catch (RemoteException e) {
 *     throw (NamingException) newNamingException(e).fillInStackTrace();
 * }</code>
 * 
 * @param e
 *            Source {@link RemoteException}.
 * 
 * @return Generated {@link NamingException} exception.
 */
@SuppressWarnings("deprecation")
protected NamingException newNamingException(Throwable e) {
    NamingException ret = (e instanceof AccessException) ? new NoPermissionException()
            : (e instanceof ConnectException) ? new ServiceUnavailableException()
                    : (e instanceof ConnectIOException)
                            || (e instanceof ExportException)
                            || (e instanceof MarshalException)
                            || (e instanceof UnmarshalException) ? new CommunicationException()
                            : (e instanceof ActivateFailedException)
                                    || (e instanceof NoSuchObjectException)
                                    || (e instanceof java.rmi.server.SkeletonMismatchException)
                                    || (e instanceof java.rmi.server.SkeletonNotFoundException)
                                    || (e instanceof StubNotFoundException)
                                    || (e instanceof UnknownHostException) ? new ConfigurationException()
                                    : (e instanceof ServerException) ? newNamingException(e
                                            .getCause())
                                            : new NamingException();

    if (ret.getCause() == null) {
        ret.initCause(e);
    }
    return ret;
}
项目:openjdk-icedtea7    文件:Connection.java   
/**
 * Reads a reply; waits until one is ready.
 */
BerDecoder readReply(LdapRequest ldr)
        throws IOException, NamingException {
    BerDecoder rber;
    boolean waited = false;

    while (((rber = ldr.getReplyBer()) == null) && !waited) {
        try {
            // If socket closed, don't even try
            synchronized (this) {
                if (sock == null) {
                    throw new ServiceUnavailableException(host + ":" + port +
                        "; socket closed");
                }
            }
            synchronized (ldr) {
                // check if condition has changed since our last check
                rber = ldr.getReplyBer();
                if (rber == null) {
                    if (readTimeout > 0) {  // Socket read timeout is specified

                        // will be woken up before readTimeout only if reply is
                        // available
                        ldr.wait(readTimeout);
                        waited = true;
                    } else {
                        ldr.wait(15 * 1000); // 15 second timeout
                    }
                } else {
                    break;
                }
            }
        } catch (InterruptedException ex) {
            throw new InterruptedNamingException(
                "Interrupted during LDAP operation");
        }
    }

    if ((rber == null) && waited) {
        removeRequest(ldr);
        throw new NamingException("LDAP response read timed out, timeout used:"
                        + readTimeout + "ms." );

    }
    return rber;
}
项目:oscar-old    文件:SetPatientImmediate3Result.java   
/**
 * Parse a the External Prescriber SetPatientImmediate3Result document, re-throwing errors
 * from the remote web service if necessary.
 * 
 * @param node
 *            The document [fragment] to parse.
 * @throws DOMException
 *             Throws a DOMException if this function is passed a document
 *             it doesn't recognize.
 * @throws IllegalArgumentException
 *             Re-throws an IllegalArgumentException if the remote web
 *             service reports that it didn't receive data in a format it
 *             could recognize.
 * @throws SecurityException
 *             Re-throws a SecurityException if the remote web service
 *             reports a security-related error.
 * @throws Exception
 *             Re-throws an Exception if the remote web service reports an
 *             error that wasn't documented enough in the the External Prescriber
 *             documentation for the programmer to understand what it meant.
 */
public static void parseSetPatientImmediate3Result(Node node)
    throws DOMException, IllegalArgumentException, SecurityException,
    ServiceUnavailableException {
    // Store references to this node's children so we can loop through them
    NodeList childNodes;
    Node child;

    // Die if we're being asked to parse something we don't understand
    if (!node.getNodeName().equals("SetPatientImmediate3Result")) {
        throw new DOMException(
            DOMException.NOT_SUPPORTED_ERR,
            "Unable to parse a node of type " + node.getNodeName());
    }

    // Parse the node to see if the web service returned errors
    childNodes = node.getChildNodes();
    for (int j = 0; j < childNodes.getLength(); j++) {
        child = childNodes.item(j);
        if (child.getNodeName().equals("ResultCode")) {
            switch (WSPatientResult3.parseString(child.getTextContent())) {
                case ERROR_UNMANAGED:
                    throw new ServiceUnavailableException(
                        "The remote system experienced an unhandled error on it's side, but couldn't determine whether it was our fault or not.");
                case ERROR_AUTHENTICATION:
                    throw new SecurityException(
                        "The credentials used to send the patient data were not valid.");
                case ERROR_AUTHORIZATION:
                    throw new SecurityException(
                        "The user whose credentials were used to send the patient data is not authorized to send patient data.");
                case ERROR_UNAUTHORIZED_CLINIC:
                    throw new IllegalArgumentException(
                        "The clinic specified is not valid or has been disabled; or the user whose credentials were used is not registered to request prescription lists on behalf of that clinic.");
                case ERROR_UNKNOWN_CLINIC:
                    throw new SecurityException(
                        "The client number specified is not valid or has been disabled.");
                case ERROR_INVALIDLOCALID:
                    throw new IllegalArgumentException(
                        "The external prescription service was unable to parse the given locale ID when sending patient data.");
                case ERROR_NONSECUREACCESS:
                    throw new SecurityException(
                        "The transport method used to send the patient data was not secure, so the request was rejected.");
            }
        }
    }
}
项目:oscar-old    文件:GetPrescriptions5Result.java   
public static List<Node> parseGetPrescriptions5Result(Node node)
    throws DOMException, IllegalArgumentException, SecurityException,
    ServiceUnavailableException {
    // Store a list of WSPrescription5 elements to return
    List<Node> answer = new LinkedList<Node>();
    // Store references to this node's children so we can loop through them
    NodeList childNodes;
    Node child;
    Result result;

    // Die if we're being asked to parse something we don't understand
    if (!node.getNodeName().equals("GetPrescriptions5Result")) {
        throw new DOMException(
            DOMException.NOT_SUPPORTED_ERR,
            "Unable to parse a node of type " + node.getNodeName());
    }

    // Parse a WSResult5 element first if there is one
    childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        child = childNodes.item(i);
        if (child.getNodeName().equals("Result")) {
            result = new Result(child);
            switch (result.getCode()) {
                case ERROR_PATIENTNOTFOUND:
                    throw new IllegalArgumentException(
                        "The patient whose data was requested was not found in the remote system's database.");
                case ERROR_UNMANAGED:
                    throw new ServiceUnavailableException(
                        "The remote system experienced an unhandled error on it's side, but couldn't determine whether it was our fault or not.");
                case ERROR_AUTHENTICATION:
                    throw new SecurityException(
                        "The credentials used to request the prescription list were not valid.");
                case ERROR_AUTHORIZATION:
                    throw new SecurityException(
                        "The user whose credentials were used to request the prescription list is not authorized to request prescription lists.");
                case ERROR_UNAUTHORIZED_CLINIC:
                    throw new IllegalArgumentException(
                        "The clinic specified is not valid or disabled; or the user whose credentials were used is not registered to request prescription lists on behalf of that clinic.");
                case ERROR_INVALIDDATEFORMAT:
                    throw new IllegalArgumentException(
                        "The external prescription service was unable to parse the given last-checked-date when requesting prescriptions.");
                case ERROR_INVALIDLOCALEID:
                    throw new IllegalArgumentException(
                        "The external prescription service was unable to parse the given locale ID when requesting prescriptions.");
                case ERROR_INVALIDDATEANDPATIENT:
                    throw new IllegalArgumentException(
                        "The external prescription service was unable to parse the given last-checked-date and patient ID.");
                case ERROR_NONSECUREACCESS:
                    throw new SecurityException(
                        "The transport method used to request the prescription list was not secure, so the request was rejected.");
            }
        }
    }

    // Now loop through the nodes again, looking for Prescriptions
    childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        child = childNodes.item(i);
        if (child.getNodeName().equals("Prescriptions")) {
            answer.addAll(Prescriptions.parsePrescriptions(child));
        }
    }

    return answer;
}