Skip to content

Commit a219605

Browse files
Replaced WebClient with autogenerated Webclient
1 parent d232317 commit a219605

File tree

9 files changed

+258
-312
lines changed

9 files changed

+258
-312
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ interface)](https://www.bzst.de/EN/Businesses/CESOP/electronic_data_transmission
1515
The BZSt (Bundeszentralamt für Steuern / Federal Central Tax Office) provides the Digital Inbox (DIP) as a service
1616
for payment service providers to transmit financial data.
1717

18+
This library uses a [generated](./bzst-dip-java-client/pom.xml) client from an [``openapi.yml``](./openapi/openapi.yml)
19+
using [OpenAPI Generator](https://openapi-generator.tech/).
20+
1821
Clients need to register / login
1922
at [BZSt online.portal](https://www.bzst.de/DE/Service/Portalinformation/Massendaten/DIP/dip.html?nn=68828)
2023
through [Elster](https://www.elster.de/elsterweb/start), [BundID](https://id.bund.de/de)

bzst-dip-java-client-demo/src/main/java/software/xdev/Application.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.slf4j.LoggerFactory;
1010

1111
import software.xdev.bzst.dip.client.BzstDipClient;
12-
import software.xdev.bzst.dip.client.exception.HttpStatusCodeNotExceptedException;
1312
import software.xdev.bzst.dip.client.model.configuration.BzstDipConfiguration;
1413
import software.xdev.bzst.dip.client.model.configuration.BzstDipConfigurationBuilder;
1514
import software.xdev.bzst.dip.client.model.configuration.BzstDipDpiMessageType;
@@ -35,7 +34,7 @@ public final class Application
3534
private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);
3635

3736
public static void main(final String[] args)
38-
throws InterruptedException, HttpStatusCodeNotExceptedException, IOException
37+
throws InterruptedException, IOException
3938
{
4039
final BzstDipConfiguration configuration = createConfiguration();
4140
final BzstDipClient bzstDipClient = new BzstDipClient(configuration);

bzst-dip-java-client-demo/src/main/java/software/xdev/ApplicationWithConfigurationFromProperties.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.slf4j.LoggerFactory;
77

88
import software.xdev.bzst.dip.client.BzstDipClient;
9-
import software.xdev.bzst.dip.client.exception.HttpStatusCodeNotExceptedException;
109
import software.xdev.bzst.dip.client.model.configuration.BzstDipConfiguration;
1110
import software.xdev.bzst.dip.client.model.configuration.BzstDipConfigurationBuilder;
1211
import software.xdev.bzst.dip.client.model.configuration.PropertiesSupplier;
@@ -19,7 +18,7 @@ public final class ApplicationWithConfigurationFromProperties
1918
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationWithConfigurationFromProperties.class);
2019

2120
public static void main(final String[] args)
22-
throws InterruptedException, HttpStatusCodeNotExceptedException, IOException
21+
throws InterruptedException, IOException
2322
{
2423
final BzstDipConfiguration configuration = createConfigurationFromProperties();
2524
final BzstDipClient bzstDipClient = new BzstDipClient(configuration);

bzst-dip-java-client-demo/src/main/java/software/xdev/ApplicationWithCsvInput.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.slf4j.LoggerFactory;
1111

1212
import software.xdev.bzst.dip.client.BzstDipClient;
13-
import software.xdev.bzst.dip.client.exception.HttpStatusCodeNotExceptedException;
1413
import software.xdev.bzst.dip.client.model.configuration.BzstDipConfiguration;
1514
import software.xdev.bzst.dip.client.model.message.BzstDipCompleteResult;
1615

@@ -21,7 +20,7 @@ public final class ApplicationWithCsvInput
2120
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationWithCsvInput.class);
2221

2322
public static void main(final String[] args)
24-
throws InterruptedException, HttpStatusCodeNotExceptedException, IOException
23+
throws InterruptedException, IOException
2524
{
2625
final BzstDipConfiguration configuration = Application.createConfiguration();
2726

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/BzstDipClient.java

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
2323

24-
import software.xdev.bzst.dip.client.exception.HttpStatusCodeNotExceptedException;
24+
import software.xdev.bzst.dip.client.generated.api.MdEinreichenProviderApi;
25+
import software.xdev.bzst.dip.client.generated.client.ApiClient;
2526
import software.xdev.bzst.dip.client.model.configuration.BzstDipConfiguration;
2627
import software.xdev.bzst.dip.client.model.message.BzstDipCompleteResult;
2728
import software.xdev.bzst.dip.client.model.message.BzstDipMessage;
@@ -45,10 +46,29 @@ public class BzstDipClient
4546
{
4647
private static final Logger LOGGER = LoggerFactory.getLogger(BzstDipClient.class);
4748
private final BzstDipConfiguration configuration;
49+
private final WebClient webClient;
4850

4951
public BzstDipClient(final BzstDipConfiguration configuration)
52+
{
53+
this(configuration, new WebClient(configuration));
54+
}
55+
56+
public BzstDipClient(final BzstDipConfiguration configuration, final ApiClient apiClient)
57+
{
58+
this(configuration, new WebClient(configuration, apiClient));
59+
}
60+
61+
public BzstDipClient(
62+
final BzstDipConfiguration configuration,
63+
final MdEinreichenProviderApi mdEinreichenProviderApi)
64+
{
65+
this(configuration, new WebClient(configuration, mdEinreichenProviderApi));
66+
}
67+
68+
public BzstDipClient(final BzstDipConfiguration configuration, final WebClient webClient)
5069
{
5170
this.configuration = configuration;
71+
this.webClient = webClient;
5272
}
5373

5474
/**
@@ -60,7 +80,6 @@ public BzstDipClient(final BzstDipConfiguration configuration)
6080
* @return the result which only contains the dataTransferNumber
6181
*/
6282
public BzstDipSendingResult sendDipOnly(final BzstDipMessage message)
63-
throws HttpStatusCodeNotExceptedException
6483
{
6584
return this.sendDipOnly(message.toXmlType(this.configuration));
6685
}
@@ -73,7 +92,6 @@ public BzstDipSendingResult sendDipOnly(final BzstDipMessage message)
7392
* @return the result which only contains the dataTransferNumber
7493
*/
7594
public BzstDipSendingResult sendDipOnly(final String csvData)
76-
throws HttpStatusCodeNotExceptedException
7795
{
7896
return this.sendDipOnly(ReportableSellerCsvFileParser.parseCsvData(csvData, this.configuration));
7997
}
@@ -87,7 +105,6 @@ public BzstDipSendingResult sendDipOnly(final String csvData)
87105
*/
88106
public BzstDipSendingResult sendDipOnly(
89107
final List<CorrectableReportableSellerType> correctableReportableSellerTypes)
90-
throws HttpStatusCodeNotExceptedException
91108
{
92109
return this.sendDipOnly(
93110
correctableReportableSellerTypes,
@@ -107,19 +124,15 @@ public BzstDipSendingResult sendDipOnly(
107124
public BzstDipSendingResult sendDipOnly(
108125
final List<CorrectableReportableSellerType> correctableReportableSellerTypes,
109126
final CorrectablePlatformOperatorType correctablePlatformOperatorType)
110-
throws HttpStatusCodeNotExceptedException
111127
{
112-
try(final WebClient client = new WebClient(this.configuration))
113-
{
114-
return this.sendDipOnlyInternal(correctableReportableSellerTypes, correctablePlatformOperatorType, client);
115-
}
128+
return this.sendDipOnlyInternal(correctableReportableSellerTypes, correctablePlatformOperatorType);
116129
}
117130

118131
/**
119132
* Sends the message and queries a result.
120133
* <p>
121134
* Querying the result might take a few seconds and is configured in
122-
* {@link BzstDipConfiguration#queryResultConfiguration}.
135+
* {@link BzstDipConfiguration#getQueryResultConfiguration()}.
123136
* </p>
124137
* <p>
125138
* In special cases {@link #sendDipOnly(BzstDipMessage)} can be used, if the result is not needed,
@@ -129,7 +142,7 @@ public BzstDipSendingResult sendDipOnly(
129142
* @return the result which contains the dataTransferNumber and all found responses in the API.
130143
*/
131144
public BzstDipCompleteResult sendDipAndQueryResult(final BzstDipMessage message)
132-
throws HttpStatusCodeNotExceptedException, InterruptedException, IOException
145+
throws InterruptedException, IOException
133146
{
134147
return this.sendDipAndQueryResult(message.toXmlType(this.configuration));
135148
}
@@ -138,7 +151,7 @@ public BzstDipCompleteResult sendDipAndQueryResult(final BzstDipMessage message)
138151
* Sends the message and queries a result.
139152
* <p>
140153
* Querying the result might take a few seconds and is configured in
141-
* {@link BzstDipConfiguration#queryResultConfiguration}.
154+
* {@link BzstDipConfiguration#getQueryResultConfiguration()}.
142155
* </p>
143156
* <p>
144157
* In special cases {@link #sendDipOnly(String)} can be used, if the result is not needed,
@@ -148,7 +161,7 @@ public BzstDipCompleteResult sendDipAndQueryResult(final BzstDipMessage message)
148161
* @return the result which contains the dataTransferNumber and all found responses in the API.
149162
*/
150163
public BzstDipCompleteResult sendDipAndQueryResult(final String csvData)
151-
throws HttpStatusCodeNotExceptedException, InterruptedException, IOException
164+
throws InterruptedException, IOException
152165
{
153166
return this.sendDipAndQueryResult(ReportableSellerCsvFileParser.parseCsvData(csvData, this.configuration));
154167
}
@@ -157,7 +170,7 @@ public BzstDipCompleteResult sendDipAndQueryResult(final String csvData)
157170
* Sends the message and queries a result.
158171
* <p>
159172
* Querying the result might take a few seconds and is configured in
160-
* {@link BzstDipConfiguration#queryResultConfiguration}.
173+
* {@link BzstDipConfiguration#getQueryResultConfiguration()}.
161174
* </p>
162175
* <p>
163176
* In special cases {@link #sendDipOnly(List)} can be used, if the result is not needed,
@@ -169,7 +182,7 @@ public BzstDipCompleteResult sendDipAndQueryResult(final String csvData)
169182
public BzstDipCompleteResult sendDipAndQueryResult(
170183
final List<CorrectableReportableSellerType> correctableReportableSellerTypes
171184
)
172-
throws HttpStatusCodeNotExceptedException, InterruptedException, IOException
185+
throws InterruptedException, IOException
173186
{
174187
return this.sendDipAndQueryResult(
175188
correctableReportableSellerTypes,
@@ -181,7 +194,7 @@ public BzstDipCompleteResult sendDipAndQueryResult(
181194
* Sends the message and queries a result.
182195
* <p>
183196
* Querying the result might take a few seconds and is configured in
184-
* {@link BzstDipConfiguration#queryResultConfiguration}.
197+
* {@link BzstDipConfiguration#getQueryResultConfiguration()}.
185198
* </p>
186199
* <p>
187200
* In special cases {@link #sendDipOnly(List, CorrectablePlatformOperatorType)} can be used, if the result is
@@ -196,19 +209,16 @@ public BzstDipCompleteResult sendDipAndQueryResult(
196209
final List<CorrectableReportableSellerType> correctableReportableSellerTypes,
197210
final CorrectablePlatformOperatorType correctablePlatformOperatorType
198211
)
199-
throws HttpStatusCodeNotExceptedException, InterruptedException, IOException
212+
throws InterruptedException, IOException
200213
{
201-
try(final WebClient client = new WebClient(this.configuration))
202-
{
203214
final BzstDipSendingResult sendingResult =
204-
this.sendDipOnlyInternal(correctableReportableSellerTypes, correctablePlatformOperatorType, client);
215+
this.sendDipOnlyInternal(correctableReportableSellerTypes, correctablePlatformOperatorType);
205216

206217
Thread.sleep(this.configuration.getQueryResultConfiguration().delayBeforeCheckingResults().toMillis());
207-
208-
final BzstDipRequestStatusResult requestStatusResult = this.queryDipResultWithRetry(client, sendingResult);
218+
219+
final BzstDipRequestStatusResult requestStatusResult = this.queryDipResultWithRetry(sendingResult);
209220

210221
return BzstDipCompleteResult.fromResult(sendingResult, requestStatusResult);
211-
}
212222
}
213223

214224
/**
@@ -217,19 +227,15 @@ public BzstDipCompleteResult sendDipAndQueryResult(
217227
* suggest only using this method, if specifically needed.
218228
* @return all found {@link BzstDipSingleTransferResult}s
219229
*/
220-
public BzstDipRequestStatusResult queryDipResult() throws HttpStatusCodeNotExceptedException, IOException
230+
public BzstDipRequestStatusResult queryDipResult() throws IOException
221231
{
222-
try(final WebClient client = new WebClient(this.configuration))
223-
{
224-
return client.readAndConfirmDataTransferNumbers();
225-
}
232+
return this.webClient.readAndConfirmDataTransferNumbers();
226233
}
227234

228235
private BzstDipSendingResult sendDipOnlyInternal(
229236
final List<CorrectableReportableSellerType> correctableReportableSellerTypes,
230-
final CorrectablePlatformOperatorType correctablePlatformOperatorType,
231-
final WebClient client
232-
) throws HttpStatusCodeNotExceptedException
237+
final CorrectablePlatformOperatorType correctablePlatformOperatorType
238+
)
233239
{
234240
final XMLDocumentCreator xmlDocumentCreator = new XMLDocumentCreator(this.configuration);
235241
final String signedXML =
@@ -242,20 +248,19 @@ private BzstDipSendingResult sendDipOnlyInternal(
242248
LOGGER.debug("Created following XML-Document:\n{}", signedXML);
243249

244250
LOGGER.debug("XML data will now be uploaded...");
245-
final String dataTransferNumber = client.getDataTransferNumber();
251+
final String dataTransferNumber = this.webClient.getDataTransferNumber();
246252
LOGGER.debug("Data transfer number: {}", dataTransferNumber);
247253

248-
client.uploadMassData(dataTransferNumber, signedXML);
254+
this.webClient.uploadMassData(dataTransferNumber, signedXML);
249255

250-
client.closeSubmission(dataTransferNumber);
256+
this.webClient.closeSubmission(dataTransferNumber);
251257

252258
return new BzstDipSendingResult(dataTransferNumber);
253259
}
254260

255261
private BzstDipRequestStatusResult queryDipResultWithRetry(
256-
final WebClient webClient,
257262
final BzstDipSendingResult sendingResult)
258-
throws HttpStatusCodeNotExceptedException, InterruptedException, IOException
263+
throws InterruptedException, IOException
259264
{
260265
BzstDipRequestStatusResult requestStatusResult;
261266
int retryCounter = 0;
@@ -265,7 +270,7 @@ private BzstDipRequestStatusResult queryDipResultWithRetry(
265270
{
266271
Thread.sleep(this.configuration.getQueryResultConfiguration().delayInBetweenResultChecks().toMillis());
267272
}
268-
requestStatusResult = webClient.readAndConfirmDataTransferNumbers();
273+
requestStatusResult = this.webClient.readAndConfirmDataTransferNumbers();
269274
retryCounter++;
270275
}
271276
while(

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/exception/HttpStatusCodeNotExceptedException.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

bzst-dip-java-client/src/main/java/software/xdev/bzst/dip/client/util/WebClientUtil.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,9 @@
1616
package software.xdev.bzst.dip.client.util;
1717

1818
import java.io.IOException;
19-
import java.io.InputStream;
2019
import java.io.StringReader;
21-
import java.security.KeyStore;
22-
import java.security.PrivateKey;
23-
import java.time.Duration;
2420
import java.util.ArrayList;
25-
import java.util.Date;
2621
import java.util.List;
27-
import java.util.UUID;
2822

2923
import javax.xml.parsers.DocumentBuilder;
3024
import javax.xml.parsers.DocumentBuilderFactory;
@@ -39,10 +33,7 @@
3933
import org.xml.sax.InputSource;
4034
import org.xml.sax.SAXException;
4135

42-
import io.jsonwebtoken.Jwts;
43-
import software.xdev.bzst.dip.client.exception.EncryptionException;
4436
import software.xdev.bzst.dip.client.factory.DocumentBuilderFactoryNoExternalEntities;
45-
import software.xdev.bzst.dip.client.model.configuration.BzstDipConfiguration;
4637

4738

4839
/**
@@ -51,46 +42,12 @@
5142
public final class WebClientUtil
5243
{
5344
private static final Logger LOGGER = LoggerFactory.getLogger(WebClientUtil.class);
54-
public static final String MDS_POSTFIX = "/auth/realms/mds";
5545
public static final String TAG_NAME_DATENTRANSFERNUMMER = "Datentransfernummer";
5646

5747
private WebClientUtil()
5848
{
5949
}
6050

61-
public static String createRequestToken(final BzstDipConfiguration configuration)
62-
{
63-
LOGGER.debug("Creating jwt token...");
64-
try(final InputStream keystoreInputStream = configuration.getCertificateKeystoreInputStream().get())
65-
{
66-
final KeyStore.PrivateKeyEntry privateKeyEntry = SigningUtil.getPrivateKeyEntry(
67-
keystoreInputStream,
68-
configuration.getCertificateKeystorePassword(),
69-
SigningUtil.KEYSTORE_TYPE
70-
);
71-
72-
final PrivateKey privateKey = privateKeyEntry.getPrivateKey();
73-
final String clientId = configuration.getClientId();
74-
LOGGER.debug("Using client id: {}", clientId);
75-
76-
return Jwts.builder()
77-
.issuer(clientId)
78-
.subject(clientId)
79-
.audience().add(
80-
configuration.getRealmEnvironmentBaseUrl() + MDS_POSTFIX)
81-
.and()
82-
.issuedAt(new Date())
83-
.expiration(new Date(System.currentTimeMillis() + Duration.ofMinutes(5).toMillis()))
84-
.id(UUID.randomUUID().toString())
85-
.notBefore(new Date(System.currentTimeMillis() - Duration.ofMinutes(1).toMillis()))
86-
.signWith(privateKey, Jwts.SIG.RS256)
87-
.compact();
88-
}
89-
catch(final IOException ioException)
90-
{
91-
throw new EncryptionException("An error occurred while creating the request token.", ioException);
92-
}
93-
}
9451

9552
public static List<String> extractTransferNumberFromXml(final String xmlString) throws IOException
9653
{

0 commit comments

Comments
 (0)