16
16
*/
17
17
package com .helger .phase4 .dbnalliance ;
18
18
19
+ import java .nio .charset .StandardCharsets ;
19
20
import java .security .cert .X509Certificate ;
20
21
import java .time .OffsetDateTime ;
22
+ import java .util .UUID ;
21
23
import java .util .function .Consumer ;
22
24
23
25
import javax .annotation .Nonnull ;
27
29
28
30
import org .slf4j .Logger ;
29
31
import org .slf4j .LoggerFactory ;
32
+ import org .w3c .dom .Element ;
30
33
31
34
import com .helger .commons .ValueEnforcer ;
32
35
import com .helger .commons .annotation .Nonempty ;
33
- import com .helger .commons .datetime .XMLOffsetDateTime ;
34
36
import com .helger .commons .state .ESuccess ;
35
37
import com .helger .peppol .smp .ESMPTransportProfile ;
36
38
import com .helger .peppol .utils .PeppolCertificateHelper ;
56
58
import com .helger .xhe .v10 .CXHE10 ;
57
59
import com .helger .xhe .v10 .XHE10Marshaller ;
58
60
import com .helger .xhe .v10 .XHE10XHEType ;
59
- import java .nio .charset .StandardCharsets ;
60
- import java .util .UUID ;
61
- import org .w3c .dom .Element ;
62
61
63
62
/**
64
63
* This class contains all the specifics to send AS4 messages with the
65
64
* DBNAlliance profile. See <code>sendAS4Message</code> as the main method to
66
65
* trigger the sending, with all potential customization.
67
66
*
67
+ * @author Robinson Artemio Garcia Meléndez
68
68
* @author Philip Helger
69
69
*/
70
70
@ Immutable
@@ -75,39 +75,38 @@ public final class Phase4DBNAllianceSender
75
75
76
76
private Phase4DBNAllianceSender ()
77
77
{}
78
-
78
+
79
79
@ Nullable
80
80
private static XHE10XHEType _createXHE (@ Nonnull final IParticipantIdentifier aSenderID ,
81
81
@ Nonnull final IParticipantIdentifier aReceiverID ,
82
82
@ Nonnull final IDocumentTypeIdentifier aDocTypeID ,
83
83
@ Nonnull final IProcessIdentifier aProcID ,
84
84
@ Nonnull final Element aPayloadElement ,
85
- final boolean bClonePayloadElement
86
- )
85
+ final boolean bClonePayloadElement )
87
86
{
88
87
final DBNAllianceXHEData aData = new DBNAllianceXHEData (IF );
89
88
aData .setFromParty (aSenderID .getScheme (), aSenderID .getValue ());
90
89
aData .setToParty (aReceiverID .getScheme (), aReceiverID .getValue ());
91
90
aData .setID (UUID .randomUUID ().toString ());
92
91
aData .setCreationDateAndTime (MetaAS4Manager .getTimestampMgr ().getCurrentXMLDateTime ());
93
-
92
+
94
93
final DBNAlliancePayload aPayload = new DBNAlliancePayload (IF );
95
94
aPayload .setCustomizationID (null , aDocTypeID .getValue ());
96
95
aPayload .setProfileID (aProcID .getScheme (), aProcID .getValue ());
97
-
96
+
98
97
// Not cloning the payload element is for saving memory only (if it can be
99
98
// ensured, the source payload element is not altered externally of course)
100
99
if (bClonePayloadElement )
101
100
aPayload .setPayloadContent (aPayloadElement );
102
101
else
103
102
aPayload .setPayloadContentNoClone (aPayloadElement );
104
-
105
- aData .addPayload (aPayload );
106
-
103
+
104
+ aData .addPayload (aPayload );
105
+
107
106
// check with logging
108
107
if (!aData .areAllFieldsSet (true ))
109
108
throw new IllegalArgumentException ("The DBNAlliance XHE data is incomplete. See logs for details." );
110
-
109
+
111
110
return DBNAllianceXHEDocumentWriter .createExchangeHeaderEnvelope (aData );
112
111
}
113
112
@@ -124,6 +123,7 @@ public static DBNAllianceUserMessageBuilder builder ()
124
123
/**
125
124
* Abstract DBNAlliance UserMessage builder class with sanity methods.
126
125
*
126
+ * @author Robinson Artemio Garcia Meléndez
127
127
* @author Philip Helger
128
128
* @param <IMPLTYPE>
129
129
* The implementation type
@@ -132,8 +132,9 @@ public abstract static class AbstractDBNAllianceUserMessageBuilder <IMPLTYPE ext
132
132
extends
133
133
AbstractAS4UserMessageBuilderMIMEPayload <IMPLTYPE >
134
134
{
135
- // C4
135
+ // C1
136
136
protected IParticipantIdentifier m_aSenderID ;
137
+ // C4
137
138
protected IParticipantIdentifier m_aReceiverID ;
138
139
protected IDocumentTypeIdentifier m_aDocTypeID ;
139
140
protected IProcessIdentifier m_aProcessID ;
@@ -165,10 +166,10 @@ protected AbstractDBNAllianceUserMessageBuilder ()
165
166
throw new IllegalStateException ("Failed to init AS4 Client builder" , ex );
166
167
}
167
168
}
168
-
169
+
169
170
/**
170
- * Set the sender participant ID of the message. The participant ID must
171
- * be provided prior to sending.
171
+ * Set the sender participant ID of the message. The participant ID must be
172
+ * provided prior to sending.
172
173
*
173
174
* @param aSenderID
174
175
* The sender participant ID. May not be <code>null</code>.
@@ -486,17 +487,18 @@ protected void customizeBeforeSending () throws Phase4Exception
486
487
* The builder class for sending AS4 messages using DBNAlliance profile
487
488
* specifics. Use {@link #sendMessage()} to trigger the main transmission.
488
489
*
490
+ * @author Robinson Artemio Garcia Meléndez
489
491
* @author Philip Helger
490
492
*/
491
493
public static class DBNAllianceUserMessageBuilder extends
492
494
AbstractDBNAllianceUserMessageBuilder <DBNAllianceUserMessageBuilder >
493
495
{
494
-
496
+
495
497
private Element m_aPayloadElement ;
496
-
498
+
497
499
public DBNAllianceUserMessageBuilder ()
498
500
{}
499
-
501
+
500
502
/**
501
503
* Set the payload element to be used, if it is available as a parsed DOM
502
504
* element. Internally the DOM element will be cloned before sending it out.
@@ -511,12 +513,13 @@ public DBNAllianceUserMessageBuilder ()
511
513
public DBNAllianceUserMessageBuilder payload (@ Nonnull final Element aPayloadElement )
512
514
{
513
515
ValueEnforcer .notNull (aPayloadElement , "Payload" );
514
- ValueEnforcer .notNull (aPayloadElement .getNamespaceURI (), "Payload.NamespaceURI" );
516
+ ValueEnforcer .notEmpty (aPayloadElement .getNamespaceURI (), "Payload.NamespaceURI" );
515
517
m_aPayloadElement = aPayloadElement ;
516
518
return this ;
517
519
}
518
-
520
+
519
521
@ Override
522
+ @ OverridingMethodsMustInvokeSuper
520
523
protected ESuccess finishFields () throws Phase4Exception
521
524
{
522
525
// Ensure a DOM element is present
@@ -529,14 +532,15 @@ protected ESuccess finishFields () throws Phase4Exception
529
532
bClonePayloadElement = true ;
530
533
}
531
534
else
532
- throw new IllegalStateException ("Unexpected - element are not present" );
535
+ throw new IllegalStateException ("Unexpected - element is not present" );
533
536
534
537
// Consistency check
535
- if (CXHE10 .NAMESPACE_URI_XHE .equals (aPayloadElement .getNamespaceURI ()))
538
+ if (CXHE10 .NAMESPACE_URI_XHE .equals (aPayloadElement .getNamespaceURI ()))
536
539
throw new Phase4DBNAllianceException ("You cannot set a Exchange Header Envelope as the payload for the regular builder. The XHE is created automatically inside of this builder." );
537
540
538
541
// Optional payload validation
539
- // _validatePayload (aPayloadElement, m_aVESRegistry, m_aVESID, m_aValidationResultHandler);
542
+ // _validatePayload (aPayloadElement, m_aVESRegistry, m_aVESID,
543
+ // m_aValidationResultHandler);
540
544
541
545
// Perform SMP lookup
542
546
if (super .finishFields ().isFailure ())
0 commit comments