Skip to content

Commit

Permalink
Allow config via app.conf file. Update CXF version
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcurry committed May 11, 2023
1 parent 3af707a commit e5b491f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ $ mvn clean install \
-Ddk.skat.emcs.b2b.sample.P12_PASSPHRASE='<CHANGE_THIS>' \
-Ddk.skat.emcs.b2b.sample.OIOLedsageDocumentOpret.ENDPOINT='<CHANGE_THIS>' \
-Ddk.skat.emcs.b2b.sample.TXID_PREFIX=ACME_01_ \
-Ddk.skat.emcs.b2b.sample.ClientCertAlias='<CHANGE_THIS>
-Ddk.skat.emcs.b2b.sample.ClientCertAlias='<CHANGE_THIS>' \
-DskipTests=false
```

The following is partial output of build and exhibits the request and response written
Expand Down Expand Up @@ -161,7 +162,8 @@ $ mvn clean install \
-Ddk.skat.emcs.b2b.sample.OIOLedsageDokumentSamlingHent.ENDPOINT='<CHANGE_THIS>'
-Ddk.skat.emcs.b2b.sample.ARC=17DKK1KHPMQH2W23ABI62 \
-Ddk.skat.emcs.b2b.sample.TXID_PREFIX=ACME_01_
-Ddk.skat.emcs.b2b.sample.ClientCertAlias='<CHANGE_THIS>'
-Ddk.skat.emcs.b2b.sample.ClientCertAlias='<CHANGE_THIS>' \
-DskipTests=false
```

This service returns a **response** similar to this output (in thie case PHASE 3 based document):
Expand Down Expand Up @@ -210,7 +212,8 @@ $ mvn clean install \
-Ddk.skat.emcs.b2b.sample.P12_PASSPHRASE='<CHANGE_THIS>' \
-Ddk.skat.emcs.b2b.sample.OIOBeskedAfvisningSamlingHent.ENDPOINT='<CHANGE_THIS>' \
-Ddk.skat.emcs.b2b.sample.TXID_PREFIX=ACME_01_ \
-Ddk.skat.emcs.b2b.sample.ClientCertAlias='<CHANGE_THIS>'
-Ddk.skat.emcs.b2b.sample.ClientCertAlias='<CHANGE_THIS>' \
-DskipTests=false
```

The client is configured to search for documents within the last month. If there are no 704 messages found,
Expand Down
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
<name>emcs-b2b-ws-sample-client-java</name>
<url>http://www.skat.dk/emcs</url>
<properties>
<cxf.version>3.1.9</cxf.version>
<cxf.version>3.3.5</cxf.version>
<cxf.spring.version>5.2.22.RELEASE</cxf.spring.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<slf4j.version>1.7.2</slf4j.version>
<skipTests>true</skipTests>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -82,6 +83,11 @@
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.4.2</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down Expand Up @@ -190,6 +196,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
12 changes: 10 additions & 2 deletions src/main/java/dk/skat/emcs/b2b/sample/UTPasswordCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package dk.skat.emcs.b2b.sample;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -26,6 +27,8 @@
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.apache.wss4j.common.ext.WSPasswordCallback;

/**
Expand All @@ -40,8 +43,8 @@ public class UTPasswordCallback implements CallbackHandler {
new HashMap<String, String>();

public UTPasswordCallback() {
String P12_ALIAS = System.getProperty("dk.skat.emcs.b2b.sample.ClientCertAlias");
String P12_PASSPHRASE = System.getProperty("dk.skat.emcs.b2b.sample.P12_PASSPHRASE");
String P12_ALIAS = getConfig().getString("dk.skat.emcs.b2b.sample.ClientCertAlias");
String P12_PASSPHRASE = getConfig().getString("dk.skat.emcs.b2b.sample.P12_PASSPHRASE");
passwords.put(P12_ALIAS, P12_PASSPHRASE);
}

Expand All @@ -67,4 +70,9 @@ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallback
public void setAliasPassword(String alias, String password) {
passwords.put(alias, password);
}

private static Config getConfig() {
return ConfigFactory.parseFile(new File("app.conf")).withFallback(ConfigFactory.load());
}

}
28 changes: 18 additions & 10 deletions src/test/java/dk/skat/emcs/b2b/sample/BaseClientTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package dk.skat.emcs.b2b.sample;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;

import java.io.File;

/**
* BaseClient - Helper methods for test clients, e.g. we're using the same VAT number for all tests.
*
Expand All @@ -24,14 +29,6 @@ public class BaseClientTest {
protected static final String OIO_FORSENDELSE_AFBRYDELSE_BESKED_SAMLING_HENT = "OIOForsendelseAfbrydelseBeskedSamlingHent";
protected static final String OIO_FORSINKELSE_FORKLARING_OPRET = "OIOForsinkelseForklaringOpret";



static {
// Comment out for running tests in IDE and change "CHANGEME" values.
// System.setProperty("dk.skat.emcs.b2b.sample.P12_PASSPHRASE", "CHANGEME");
// System.setProperty("dk.skat.emcs.b2b.sample.OIOLedsageDocumentOpret.ENDPOINT", "CHANGEME");
}

/**
* Get VAT number
*
Expand Down Expand Up @@ -60,8 +57,14 @@ protected String getAfgiftOperatoerPunktAfgiftIdentifikator() {
* @return Endpoint
*/
protected String getEndpoint(String service) {
String endpointURL =
System.getProperty("dk.skat.emcs.b2b.sample." + service + ".ENDPOINT");
String key = "dk.skat.emcs.b2b.sample." + service + ".ENDPOINT";
Config conf = getConfig();
if (!conf.hasPath(key)) {
return null;
}

// if 'app.conf' does not exist TypeSafa config will try out the -D param
String endpointURL = getConfig().getString(key);
if (endpointURL == null) {
System.out.println(service + ": Endpoint not provided, skipping test");
}
Expand All @@ -72,4 +75,9 @@ protected void sleep(int minutes) throws InterruptedException {
Thread.sleep(1000 * 60 * minutes);
}

protected static Config getConfig() {
return ConfigFactory.parseFile(new File("app.conf")).withFallback(ConfigFactory.load());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void invoke() throws Exception {
if (endpointURL != null) {

// The ARC number
String ARCnumber = System.getProperty("dk.skat.emcs.b2b.sample.ARC");
String ARCnumber = getConfig().getString("dk.skat.emcs.b2b.sample.ARC");
// VAT Number of the entity sending. Rule of thumb: this number matches
// this CVR number present in the certificate.
String virksomhedSENummerIdentifikator = getVirksomhedSENummerIdentifikator();
Expand Down

0 comments on commit e5b491f

Please sign in to comment.