Package ca.uhn.hl7v2.hoh.api

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


        // A connection object represents a socket attached to an HL7 server
        Connection connection = connectionHub
                .attach(host, port, new PipeParser(), MinLowerLayerProtocol.class);

        // The initiator is used to transmit unsolicited messages
        Initiator initiator = connection.getInitiator();
        HL7Message sampleMessage = new HL7Message();

        //send
        Message response = null;
        try {
            response = initiator.sendAndReceive(sampleMessage.getHL7Message());
            PipeParser parser = new PipeParser();
            String responseString = parser.encode(response);
            System.out.println("Received response:\n" + responseString);
        } catch (LLPException e) {
            System.out.println("Error : " + e);
View Full Code Here


    private SimpleServer server;

    public HL7Server(int port) {
        LowerLayerProtocol llp = LowerLayerProtocol.makeLLP(); // The transport protocol
        PipeParser parser = new PipeParser();
        server = new SimpleServer(port, llp, parser);
    }
View Full Code Here

    @Override
    protected void startEndpoint(HL7Endpoint endpoint) throws AxisFault {
        LowerLayerProtocol llp = LowerLayerProtocol.makeLLP();
        PipeParser parser = new PipeParser();
        SimpleServer server = new SimpleServer(endpoint.getPort(), llp, parser);
        Application callback = new HL7MessageProcessor(endpoint);
        server.registerApplication("*", "*", callback);
        server.start();
        serverTable.put(endpoint, server);

        log.info("Started HL7 endpoint on port: " + endpoint.getPort());
    }
View Full Code Here

        log.info("Started HL7 endpoint on port: " + endpoint.getPort());
    }

    @Override
    protected void stopEndpoint(HL7Endpoint endpoint) {
        SimpleServer server = serverTable.remove(endpoint);
        if (server != null) {
            server.stop();
        }

        log.info("Stopped HL7 endpoint on port: " + endpoint.getPort());
    }
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.