From: Davies, B. <Bri...@Mc...> - 2016-02-22 14:27:50
|
The client is an instance of HohClientSimple. I expect then that it will set the correct Content-Type see the code snippet below. The servlet that’s registered with Jetty also extends HohServlet so I expect it should also be expect to be able to process the received HL7 content type. //Client is a HL7 over HTTP capable client public HohClientSimple httpClient() { HohClientSimple client = new HohClientSimple(env.getProperty("va.http.host"), Integer.parseInt(env.getProperty("va.http.port")), env.getProperty("va.http.uri.path"),PipeParser.getInstanceWithNoValidation()); client.setSocketFactory(new TlsSocketFactory()); return client; } //Servlet registered with embedded Jetty instance is a HTTP over HL7 Servlet type. public class HttpMessageReceiver extends HohServlet { @Override public void init(ServletConfig servletConfig) throws ServletException { setApplication(new MessageHandler()); } } //This is how I register the Servlet with Jetty. Note it is an instance of HohServlet from above. Server server = new Server(5050); ServletContextHandler handler = new ServletContextHandler(server, "/testURL"); Servlet servlet=new HttpMessageReceiver(); handler.addServlet(new ServletHolder(servlet), "/appContext"); server.start(); server.join(); System.out.println("Server started!!"); As an aside there doesn’t seem to be any available constructor for the alternative of using the DefaultContext to obtain a connection but there doesn’t seem to be any method on the connection object that takes a URI argument. Is there a way to set the URI using the DefaultContext? DefaultHapiContext ctx = new DefaultHapiContext(); // Create an HoH LLP for the context LowerLayerProtocol llp = new Hl7OverHttpLowerLayerProtocol(ServerRoleEnum.CLIENT); ctx.setLowerLayerProtocol(llp); // Use the LLP in a HapiContext to get a client connection String host = "localhost"; int port = 5050; boolean tls = false; Connection connection = ctx.newClient(host, port, tls); From: Davies, Brian [mailto:Bri...@Mc...] Sent: Friday, February 19, 2016 10:02 PM To: Mike Mills; hl7...@li... Subject: Re: [HAPI-devel] Fwd: (no subject) It does resolve to 5050. It uses a properties file with 5050. From: Mike Mills [mailto:mi...@th...] Sent: Friday, February 19, 2016 3:19 PM To: hl7...@li...<mailto:hl7...@li...> Subject: [HAPI-devel] Fwd: (no subject) I forgot to CC the list in the response... ---------- Forwarded message ---------- From: Mike Mills <mi...@th...<mailto:mi...@th...>> Date: Sat, Feb 20, 2016 at 7:18 AM Subject: Re: [HAPI-devel] (no subject) To: "Davies, Brian" <Bri...@mc...<mailto:Bri...@mc...>> Your client is sending to "Integer.parseInt(env.getProperty("http.port"))", your server is listening on hard coded port 5050. Does Integer.parseInt(env.getProperty("http.port")) resolve to port 5050? or as the property implies does it resolve to an http port? Your error trace mentions "Invalid Content-Type: text/html", this implies your HL7 cient is talking to an http server and not an mllp server. On Sat, Feb 20, 2016 at 6:29 AM, Davies, Brian <Bri...@mc...<mailto:Bri...@mc...>> wrote: I am trying to test sending a message using a HAPI http client using the following configuration. The server starts and the message is sent but import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import ca.uhn.hl7v2.hoh.hapi.client.HohClientSimple; import ca.uhn.hl7v2.hoh.sockets.TlsSocketFactory; import ca.uhn.hl7v2.parser.PipeParser; @Component @PropertySource(value = {"classpath:connection.properties" }) public class HttpClientConfig { @Autowired private Environment env; @Bean public HohClientSimple httpClient() { HohClientSimple client = new HohClientSimple(env.getProperty("http.host"), Integer.parseInt(env.getProperty("http.port")), env.getProperty("http.uri.path"),PipeParser.getInstanceWithNoValidation()); client.setSocketFactory(new TlsSocketFactory()); return client; } } import java.io.IOException; import java.util.Map; import ca.uhn.hl7v2.AcknowledgmentCode; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.model.Message; import ca.uhn.hl7v2.protocol.ReceivingApplication; import ca.uhn.hl7v2.protocol.ReceivingApplicationException; public class MessageHandler implements ReceivingApplication { @Override public Message processMessage(Message theMessage, Map<String, Object> theMetadata) throws ReceivingApplicationException, HL7Exception { Message response = null; try { response = theMessage.generateACK(); } catch (IOException e) { e.printStackTrace(); } return response; } @Override public boolean canProcess(Message theMessage) { return true; } } import java.io.IOException; import javax.servlet.Servlet; import org.eclipse.jetty.server.Server; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; import ca.uhn.hl7v2.DefaultHapiContext; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.app.Connection; import ca.uhn.hl7v2.hoh.api.DecodeException; import ca.uhn.hl7v2.hoh.api.EncodeException; import ca.uhn.hl7v2.hoh.api.ISendable; import ca.uhn.hl7v2.hoh.hapi.api.MessageSendable; import ca.uhn.hl7v2.hoh.hapi.client.HohClientSimple; import ca.uhn.hl7v2.hoh.llp.Hl7OverHttpLowerLayerProtocol; import ca.uhn.hl7v2.hoh.util.ServerRoleEnum; import ca.uhn.hl7v2.llp.LLPException; import ca.uhn.hl7v2.llp.LowerLayerProtocol; import ca.uhn.hl7v2.model.DataTypeException; import ca.uhn.hl7v2.model.Message; import ca.uhn.hl7v2.model.v25.message.ADT_A01; import ca.uhn.hl7v2.model.v25.message.ADT_A38; import ca.uhn.hl7v2.model.v25.segment.DB1; import ca.uhn.hl7v2.model.v25.segment.MSH; import ca.uhn.hl7v2.model.v25.segment.SFT; import ca.uhn.hl7v2.parser.EncodingNotSupportedException; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {HttpClientConfig.class},loader = AnnotationConfigContextLoader.class) public class SendingRequestTest { @Autowired private HohClientSimple httpClient; @Before public void initServer() throws Exception{ Server server = new Server(5050); ServletContextHandler handler = new ServletContextHandler(server, "/testURL"); Servlet servlet=new HttpMessageReceiver(); handler.addServlet(new ServletHolder(servlet), "/appContext"); server.start(); System.out.println("Server started!!"); } @Test public void testSendReceive(){ try { ADT_A38 adt=new ADT_A38(); MSH msh1=adt.getMSH(); msh1.getMsh1_FieldSeparator().setValue("|"); msh1.getMsh2_EncodingCharacters().setValue("^~\\&"); SFT sft=adt.getSFT(); adt.insertSFT(sft, 0); DB1 db1=adt.getDB1(); adt.insertDB1(db1, 0); ISendable sendable = new MessageSendable(adt); //Message message=createTestMessage(); httpClient.sendAndReceiveMessage(sendable); } catch (DataTypeException e) { e.printStackTrace(); System.out.println("datatype problem"); } catch (EncodingNotSupportedException e) { e.printStackTrace(); System.out.println("encode not supported problem"); System.exit(1); } catch (HL7Exception e) { e.printStackTrace(); } catch (DecodeException e) { e.printStackTrace(); System.out.println("decode problem"); System.exit(1); } catch (IOException e) { e.printStackTrace(); System.exit(1); } catch (EncodeException e) { e.printStackTrace(); System.out.println("encode problem, not that it's not supported"); } } } I get the following error: Feb 19, 2016 1:14:25 PM org.springframework.context.support.GenericApplicati onContext prepareRefresh INFO: Refreshing org.springframework.context.support.GenericApplicationConte xt@3b733273: startup date [Fri Feb 19 13:14:25 CST 2016]; root of context hierar chy SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder<http://cp.mcafee.com/d/k-Kr4x8qdEIfLCzB5VdxYSrhhjhupjvvhdEEFELcFKcECPpISHoHZalxOVJ_TkNlCTLyLSRWX3H0GVvnhlwwwWaAdSMGO_uMVVNZNfXCPpISr01kfto4u00VqG7QU70ocjSsH1mF4zYhCk4fyrdEIKndCXCQPrNKVJUSyrh> for further de tails. SendingRequestTest > testSendReceive STANDARD_OUT Server started!! SendingRequestTest > testSendReceive STANDARD_ERR OR ca.uhn.hl7v2.hoh.api.NonHl7ResponseException: Invalid Content-Type: text/html l at ca.uhn.hl7v2.hoh.encoder.AbstractHl7OverHttpDecoder.doReadContentsFro mInputStreamAndDecode(AbstractHl7OverHttpDecoder.java:233) at ca.uhn.hl7v2.hoh.encoder.AbstractHl7OverHttpDecoder.readHeadersAndCon tentsFromInputStreamAndDecode(AbstractHl7OverHttpDecoder.java:541) at ca.uhn.hl7v2.hoh.raw.client.AbstractRawClient.doSendAndReceiveInterna l(AbstractRawClient.java:159) …. ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140<http://cp.mcafee.com/d/1jWVIg6wUSyM--qeknAS7PpJ55d5VBdZZ4SyyCyYOCUOyrdCPqJyLQFm7bCT_tj5mru-a_rnHIeI2HBZt5m223EGgTr2HbZX3DD7T4_KrdCPpI06ISgR2D4ugGSgf-NYH5u1K4gxG6mfaAF879zAS7xObWbgg14CPIohoKrdEIKndCXCQPrNKVJUSyrh> _______________________________________________ Hl7api-devel mailing list Hl7...@li...<mailto:Hl7...@li...> https://lists.sourceforge.net/lists/listinfo/hl7api-devel<http://cp.mcafee.com/d/5fHCNAp410idEIfLCzB5VdxYSrhhjhupjvvhdEEFELcFKcECPpISHoHZalxOVJ_TkNlCTLyLSRWX3H0GVvnhlwwwWaAdSMGO_uMVVNZNfXCPpISr9PCJhbcfBiteFlKdLt00_MdM-l9QM-l9OwXn2pUXlF5Qfc-urdEIKndCXCQPrNKVJUSyrh> |