Package ca.uhn.hl7v2.hoh.encoder

Examples of ca.uhn.hl7v2.hoh.encoder.Hl7OverHttpRequestDecoder


public class HL7Sender {

    public void send(String host, int port) throws HL7Exception {
        System.out.println("[ Executing HL7Sender : HOST:" + host + "  ;port :" + port + " ]");
        // The connection hub connects to listening servers
        ConnectionHub connectionHub = ConnectionHub.getInstance();
        // 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);
        } catch (IOException e) {
            System.out.println("Error : " + e);
        }

        // Close the connection and server
        connectionHub.discard(connection);
    }
View Full Code Here


        Map<String,String> params = getURLParameters(targetEPR);

        try {
            Message message = parser.parse(xmlFormat);
            ConnectionHub connectionHub = ConnectionHub.getInstance();
            Connection connection = getConnection(targetEPR, connectionHub);
            Initiator initiator = connection.getInitiator();
            String timeout = params.get(HL7Constants.TIMEOUT_PARAM);
            if (timeout != null) {
                initiator.setTimeoutMillis(Integer.parseInt(timeout));
            } else {
                initiator.setTimeoutMillis(HL7Constants.DEFAULT_TIMEOUT);
            }

            returnMsg = initiator.sendAndReceive(message);
            connectionHub.detach(connection);

            if (log.isDebugEnabled()) {
                log.debug("HL7 message successfully dispatched to URL " + targetEPR);
                log.debug("Response message received from target EP : " + returnMsg.toString());
            }
View Full Code Here

        // 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

        try {
            Message message = parser.parse(xmlFormat);
            ConnectionHub connectionHub = ConnectionHub.getInstance();
            Connection connection = getConnection(targetEPR, connectionHub);
            Initiator initiator = connection.getInitiator();
            String timeout = params.get(HL7Constants.TIMEOUT_PARAM);
            if (timeout != null) {
                initiator.setTimeoutMillis(Integer.parseInt(timeout));
            } else {
                initiator.setTimeoutMillis(HL7Constants.DEFAULT_TIMEOUT);
            }

            returnMsg = initiator.sendAndReceive(message);
            connectionHub.detach(connection);

            if (log.isDebugEnabled()) {
                log.debug("HL7 message successfully dispatched to URL " + targetEPR);
                log.debug("Response message received from target EP : " + returnMsg.toString());
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

   * {@inheritDoc}
   */
  @Override
  protected void doPost(HttpServletRequest theReq, HttpServletResponse theResp) throws ServletException, IOException {

    Hl7OverHttpRequestDecoder decoder = new Hl7OverHttpRequestDecoder();
    decoder.setHeaders(new LinkedHashMap<String, String>());

    Enumeration<?> headerNames = theReq.getHeaderNames();
    while (headerNames.hasMoreElements()) {
      String nextName = (String) headerNames.nextElement();
      decoder.getHeaders().put(nextName, theReq.getHeader(nextName));
    }

    decoder.setPath(theReq.getRequestURI());
    decoder.setAuthorizationCallback(myAuthorizationCallback);
    decoder.setSigner(mySigner);

    try {
      decoder.readContentsFromInputStreamAndDecode(theReq.getInputStream());
    } catch (AuthorizationFailureException e) {
      ourLog.error("Authorization failed on request for {}", theReq.getRequestURI());
      theResp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
      HTTPUtils.write401Unauthorized(theResp.getOutputStream(), false);
      return;
    } catch (DecodeException e) {
      ourLog.error("Request failure for " + theReq.getRequestURI(), e);
      theResp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      HTTPUtils.write400BadRequest(theResp.getOutputStream(), e.getMessage(), false);
      return;
    } catch (SignatureVerificationException e) {
      ourLog.error("Signature verification failed on request for {}", theReq.getRequestURI());
      theResp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      HTTPUtils.write400SignatureVerificationFailed(theResp.getOutputStream(), false);
      return;
    }

    Charset charset = decoder.getCharset();
    ourLog.debug("Message charset is {}", charset.displayName());

    RawReceivable rawMessage = new RawReceivable(decoder.getMessage());
    rawMessage.addMetadata(MessageMetadataKeys.REMOTE_HOST_ADDRESS.name(), theReq.getRemoteAddr());

    IResponseSendable<String> response;
    try {
      response = myMessageHandler.messageReceived(rawMessage);
View Full Code Here

    AbstractHl7OverHttpDecoder decoder;

    if (myProtocol.getRole() == ServerRoleEnum.CLIENT) {
      decoder = new Hl7OverHttpResponseDecoder();
    } else {
      Hl7OverHttpRequestDecoder requestDecoder = new Hl7OverHttpRequestDecoder();
      requestDecoder.setAuthorizationCallback(myProtocol.getAuthorizationServerCallback());
      decoder = requestDecoder;
      decoder.setSigner(myProtocol.getSigner());
    }

   
View Full Code Here

    AbstractHl7OverHttpDecoder decoder;

    if (myProtocol.getRole() == ServerRoleEnum.CLIENT) {
      decoder = new Hl7OverHttpResponseDecoder();
    } else {
      Hl7OverHttpRequestDecoder requestDecoder = new Hl7OverHttpRequestDecoder();
      requestDecoder.setAuthorizationCallback(myProtocol.getAuthorizationServerCallback());
      decoder = requestDecoder;
      decoder.setSigner(myProtocol.getSigner());
    }

   
View Full Code Here

TOP

Related Classes of ca.uhn.hl7v2.hoh.encoder.Hl7OverHttpRequestDecoder

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.