Skip to content

Commit

Permalink
Merge pull request #108 from hapifhir/ja_20230610_servlet_migration
Browse files Browse the repository at this point in the history
Jakarta Servlet migration
  • Loading branch information
jamesagnew authored Oct 30, 2023
2 parents 2a2c295 + d8b7677 commit 8369098
Show file tree
Hide file tree
Showing 39 changed files with 902 additions and 781 deletions.
2 changes: 1 addition & 1 deletion hapi-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<parent>
<artifactId>hapi</artifactId>
<groupId>ca.uhn.hapi</groupId>
<version>2.4</version>
<version>2.5</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion hapi-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>hapi</artifactId>
<groupId>ca.uhn.hapi</groupId>
<version>2.4</version>
<version>2.5</version>
</parent>

<dependencyManagement>
Expand Down
2 changes: 1 addition & 1 deletion hapi-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>hapi</artifactId>
<groupId>ca.uhn.hapi</groupId>
<version>2.4</version>
<version>2.5</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
33 changes: 25 additions & 8 deletions hapi-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hapi</artifactId>
<groupId>ca.uhn.hapi</groupId>
<version>2.4</version>
<version>2.5</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -69,14 +69,31 @@
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-embedded</artifactId>
<version>6.1.26</version>
<optional>true</optional>
</dependency>

<!-- Jetty -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlets</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlet</artifactId>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlet</artifactId>
</dependency>

</dependencies>

<reporting>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package ca.uhn.hl7v2.examples.hoh;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.security.SslSelectChannelConnector;

import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.app.HL7Service;
Expand All @@ -11,6 +8,14 @@
import ca.uhn.hl7v2.hoh.util.HapiSocketTlsFactoryWrapper;
import ca.uhn.hl7v2.hoh.util.ServerRoleEnum;
import ca.uhn.hl7v2.llp.LowerLayerProtocol;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.SecureRequestCustomizer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.util.ssl.SslContextFactory;

public class CustomCertificateServer {

Expand Down Expand Up @@ -50,13 +55,22 @@ public static void main(String[] args) throws Exception {
// Create a Jetty Server
Server s = new Server();

SslSelectChannelConnector ssl = new SslSelectChannelConnector();
ssl.setKeystore("src/test/resources/keystore.jks");
ssl.setPassword("changeit");
ssl.setKeyPassword("changeit");
ssl.setPort(443);
HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());

SslContextFactory.Server ssl = new SslContextFactory.Server();
ssl.setKeyStorePath("src/test/resources/keystore.jks");
ssl.setKeyStorePassword("changeit");
ssl.setKeyManagerPassword("changeit");

ServerConnector sslConnector = new ServerConnector(s,
new SslConnectionFactory(ssl, "http/1.1"),
new HttpConnectionFactory(https));
sslConnector.setPort(443);
sslConnector.setIdleTimeout(50000);

s.setConnectors(new Connector[]{ sslConnector });

s.addConnector(ssl);
s.start();
// END SNIPPET: server
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletConfig;

import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.hoh.hapi.server.HohServlet;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.protocol.ReceivingApplication;
import ca.uhn.hl7v2.protocol.ReceivingApplicationException;
import jakarta.servlet.ServletConfig;

/**
* Example servlet implementation which receives HL7 messages
Expand Down Expand Up @@ -44,6 +43,7 @@ private static class MyApplication implements ReceivingApplication<Message>
* @param theMetadata A map containing additional information about
* the message, where it came from, etc.
*/
@Override
public Message processMessage(Message theMessage, Map<String, Object> theMetadata) throws ReceivingApplicationException, HL7Exception {
System.out.println("Received message:\n" + theMessage.encode());

Expand Down Expand Up @@ -73,6 +73,7 @@ public Message processMessage(Message theMessage, Map<String, Object> theMetadat
/**
* {@inheritDoc}
*/
@Override
public boolean canProcess(Message theMessage) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package ca.uhn.hl7v2.examples.hoh;

import javax.servlet.Servlet;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
import jakarta.servlet.Servlet;
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.server.Server;

public class JettyBasedRawServer {

Expand All @@ -20,7 +19,7 @@ public static void main(String[] args) throws Exception {

// Create a Jetty server instance
Server server = new Server(port);
Context context = new Context(server, "/Hl7Listener", Context.SESSIONS);
ServletContextHandler context = new ServletContextHandler("/Hl7Listener");
Servlet servlet = new ExampleRawHl7OverHttpServlet();

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ public static void main(String[] args) throws KeyStoreException, NoSuchAlgorithm
}

// START SNIPPET: llp
// Create the ConnectionHub
String host = "localhost";
int port = 8080;
boolean tls = false;

Hl7OverHttpLowerLayerProtocol llp;
llp = new Hl7OverHttpLowerLayerProtocol(ServerRoleEnum.CLIENT);
llp.setHost(host);

//Create a message signer
BouncyCastleCmsMessageSigner signer = new BouncyCastleCmsMessageSigner();
Expand All @@ -65,10 +71,6 @@ public static void main(String[] args) throws KeyStoreException, NoSuchAlgorithm
signer.setAliasPassword("key_password");
llp.setSigner(signer);

// Create the ConnectionHub
String host = "localhost";
int port = 8080;
boolean tls = false;

DefaultHapiContext ctx = new DefaultHapiContext();
ctx.setLowerLayerProtocol(llp);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package ca.uhn.hl7v2.examples.hoh;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import ca.uhn.hl7v2.hoh.hapi.server.HohServlet;
import ca.uhn.hl7v2.hoh.sign.BouncyCastleCmsMessageSigner;
import ca.uhn.hl7v2.hoh.util.KeystoreUtils;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;

//START SNIPPET: servlet
public class SignatureServlet extends HohServlet {
Expand Down
1 change: 1 addition & 0 deletions hapi-hl7overhttp/doc_hapi.html
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ <h2><a name="Drop-In_LLP_Replacement"></a>Drop-In LLP Replacement</h2>

// Create an HoH LLP for the context
LowerLayerProtocol llp = new Hl7OverHttpLowerLayerProtocol(ServerRoleEnum.CLIENT);
llp.setHost(&quot;localhost&quot;);
ctx.setLowerLayerProtocol(llp);

// Use the LLP in a HapiContext to get a client connection
Expand Down
29 changes: 20 additions & 9 deletions hapi-hl7overhttp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<parent>
<artifactId>hapi</artifactId>
<groupId>ca.uhn.hapi</groupId>
<version>2.4</version>
<version>2.5</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -75,18 +75,29 @@
<artifactId>commons-lang</artifactId>
<version>${commons-lang.version}</version>
</dependency>

<!-- Jetty -->
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>${jetty.version}</version>
<optional>true</optional>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-sslengine</artifactId>
<version>${jetty.version}</version>
<optional>true</optional>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlets</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class Hl7OverHttpRequestEncoder extends AbstractHl7OverHttpEncoder {
private String myHost;
private int myPort;

public Hl7OverHttpRequestEncoder() {
super();
}

public void setHost(String theHost) {
myHost = theHost;
}
Expand Down Expand Up @@ -46,10 +50,10 @@ protected void addSpecificHeaders() {
} else {
ourLog.warn("Host has been set, but port has not");
}
getHeaders().put("Host", hostBuilder.toString());
} else {
ourLog.warn("Host has not been set");
}
getHeaders().put("Host", hostBuilder.toString());
}

@Override
Expand Down
Loading

0 comments on commit 8369098

Please sign in to comment.