Package ca.uhn.hl7v2.hoh.api

Examples of ca.uhn.hl7v2.hoh.api.DecodeException


      ourLog.debug("Caught IOException, going to close socket", e);
      closeSocket(socket);
      throw e;
    } catch (SignatureVerificationException e) {
      ourLog.debug("Failed to verify message signature", e);
      throw new DecodeException("Failed to verify message signature", e);
    } finally {
      returnSocket(socket);
    }

  }
View Full Code Here


        response.addMetadata(MessageMetadataKeys.REMOTE_HOST_ADDRESS.name(), hostAddress);

      } catch (NoMessageReceivedException ex) {
        ourLog.debug("No message received yet");
      } catch (IOException e) {
        throw new DecodeException("Failed to read response from remote host", e);
      }
    } while (response == null && System.currentTimeMillis() < endTime);

    return response;
  }
View Full Code Here

      if (firstLine == null || isBlank(firstLine)) {
        throw new NoMessageReceivedException();
      }

      if (!firstLine.startsWith("HTTP/1.1 ")) {
        throw new DecodeException("HTTP response begins with unknown HTTP version. Line is: " + firstLine);
      }

      String statusPart = firstLine.substring(9);
      int spaceIdx = statusPart.indexOf(' ');
      if (spaceIdx == -1) {
        throw new DecodeException("Invalid response line, no space after status code. Line is: " + firstLine);
      }

      String statusCode = statusPart.substring(0, spaceIdx);
      try {
        setResponseStatus(Integer.parseInt(statusCode));
      } catch (NumberFormatException e) {
        throw new DecodeException("Invalid response line. Bad status code: " + statusCode);
      }

      setResponseName(statusPart.substring(spaceIdx).trim());
      myActionLine = firstLine;
    }
View Full Code Here

      if (firstLine == null || isBlank(firstLine)) {
        throw new NoMessageReceivedException();
      }

      if (!firstLine.startsWith("POST ")) {
        throw new DecodeException("HTTP request line message is not valid. Only POST action is supported. Request line was: " + firstLine);
      }

      firstLine = firstLine.substring(5);
      int nextSpace = firstLine.indexOf(' ');
      if (nextSpace == -1) {
        throw new DecodeException("HTTP request line message is not valid. Not HTTP version found. Request line was: " + firstLine);
      }

      setUri(firstLine.substring(0, nextSpace));
      if (isBlank(getUri())) {
        throw new DecodeException("HTTP request line message is not valid. No request URI found. Request line was: " + firstLine);
      }

      String protocolVersion = firstLine.substring(nextSpace + 1);
      if (!"HTTP/1.1".equals(protocolVersion)) {
        throw new DecodeException("HTTP request line message is not valid. HTTP version not supported. Request line was: " + firstLine);
      }

      myActionLine = firstLine;
    }
   
View Full Code Here

    if (myGzipCoding) {
      ourLog.debug("Decoding message contents using GZIP encoding style");
      try {
        bytes = GZipUtils.uncompress(bytes);
      } catch (IOException e) {
        throw new DecodeException("Failed to uncompress GZip content", e);
      }
    }

    Charset charset = getCharset();
    ourLog.debug("Message is {} bytes with charset {}", bytes.length, charset.name());
View Full Code Here

      if ("transfer-encoding".equals(nextHeader)) {
        if ("chunked".equalsIgnoreCase(nextValue)) {
          myTransferEncoding = TransferEncoding.CHUNKED;
        } else {
          throw new DecodeException("Unknown transfer encoding: " + nextValue);
        }
      } else if ("content-length".equals(nextHeader)) {
        try {
          myContentLength = Integer.parseInt(nextValue);
        } catch (NumberFormatException e) {
          addConformanceProblem("Could not parse Content-Length header value: " + nextHeader);
        }
      } else if ("content-type".equals(nextHeader)) {
        int colonIndex = nextValue.indexOf(';');
        if (colonIndex == -1) {
          myContentType = nextValue;
        } else {
          myContentType = nextValue.substring(0, colonIndex);
          myEncodingStyle = EncodingStyle.withNameCaseInsensitive(myContentType);
          String charsetDef = nextValue.substring(colonIndex + 1).trim();
          if (charsetDef.startsWith("charset=")) {
            String charsetName = charsetDef.substring(8);
            Charset charset;
            try {
              charset = Charset.forName(charsetName);
            } catch (UnsupportedCharsetException e) {
              addConformanceProblem("Unsupported or invalid charset: " + charsetName);
              continue;
            }
            setCharset(charset);
          }
        }

        myContentType = myContentType.trim();

      } else if ("authorization".equals(nextHeader)) {
        int spaceIndex = nextValue.indexOf(' ');
        if (spaceIndex == -1) {
          throw new DecodeException("Invalid authorization header. No authorization style detected");
        }
        String type = nextValue.substring(0, spaceIndex);
        if ("basic".equalsIgnoreCase(type)) {
          String encodedCredentials = nextValue.substring(spaceIndex + 1);
          byte[] decodedCredentials = Base64.decodeBase64(encodedCredentials);
          String credentialsString = new String(decodedCredentials, getDefaultCharset());
          int colonIndex = credentialsString.indexOf(':');
          if (colonIndex == -1) {
            setUsername(credentialsString);
          } else {
            setUsername(credentialsString.substring(0, colonIndex));
            setPassword(credentialsString.substring(colonIndex + 1));
          }
        } else {
          addConformanceProblem("Invalid authorization type. Only basic authorization is supported.");
        }
      } else if ("content-coding".equals(nextHeader)) {
        if (StringUtils.isNotBlank(nextValue)) {
          if ("gzip".equals(nextValue)) {
            myGzipCoding = true;
          } else {
            throw new DecodeException("Unknown content-coding: " + nextValue);
          }
        }
      } else if (HTTP_HEADER_HL7_SIGNATURE_LC.equals(nextHeader)) {
        mySignature = nextValue;
      }
View Full Code Here

    }

    decodeBody();
   
    if (getContentType() == null) {
      throw new DecodeException("Content-Type not specified");
    }
    if (getEncodingStyle() == null) {
      throw new NonHl7ResponseException("Invalid Content-Type: " + getContentType(), getContentType(), getMessage());
    }
   
View Full Code Here

    while (true) {
      String nextSize;
      try {
        nextSize = readLine(theInputStream);
      } catch (IOException e) {
        throw new DecodeException("Failed to decode CHUNKED encoding", e);
      }

      if (nextSize.length() == 0) {
        break;
      }

      int nextSizeInt;
      try {
        nextSizeInt = Integer.parseInt(nextSize, 16);
      } catch (NumberFormatException e) {
        throw new DecodeException("Failed to decode CHUNKED encoding", e);
      }

      ourLog.debug("Next CHUNKED size: {}", nextSizeInt);

      if (nextSizeInt < 0) {
        throw new DecodeException("Received invalid octet count in chunked transfer encoding: " + nextSize);
      }

      if (nextSizeInt > 0) {
        int totalRead = 0;
        myLastStartedReading = System.currentTimeMillis();
        do {
          int nextRead = Math.min(nextSizeInt, byteBuffer.length);
          int bytesRead = theInputStream.read(byteBuffer, 0, nextRead);
          if (bytesRead == -1) {
            throw new DecodeException("Reached EOF while reading in message chunk");
          }
          if (bytesRead == 0 && totalRead < nextSizeInt) {
            pauseDuringTimedOutRead();
          }
          totalRead += bytesRead;
View Full Code Here

    }
    if (getSigner() != null) {
      try {
        getSigner().verify(myBytes, mySignature);
      } catch (SignatureFailureException e) {
        throw new DecodeException("Failed to verify signature due to an error (signature may possibly be valid, but verification failed)", e);
      }
    }
  }
View Full Code Here

          break;
        }

        int colonIndex = nextLine.indexOf(':');
        if (colonIndex == -1) {
          throw new DecodeException("Invalid HTTP header line detected. Value is: " + nextLine);
        }

        String key = nextLine.substring(0, colonIndex);
        String value = nextLine.substring(colonIndex + 1).trim();
        getHeaders().put(key, value);
View Full Code Here

TOP

Related Classes of ca.uhn.hl7v2.hoh.api.DecodeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.