11package dev .dsf .bpe .message ;
22
3- import java .util .Objects ;
43import java .util .stream .Stream ;
54
65import org .camunda .bpm .engine .delegate .DelegateExecution ;
1110import org .hl7 .fhir .r4 .model .Task .ParameterComponent ;
1211
1312import dev .dsf .bpe .ConstantsPing ;
14- import dev .dsf .bpe .mail .ErrorMailService ;
15- import dev .dsf .bpe .util .PingStatusGenerator ;
1613import dev .dsf .bpe .v1 .ProcessPluginApi ;
1714import dev .dsf .bpe .v1 .activity .AbstractTaskMessageSend ;
18- import dev .dsf .bpe .v1 .variables .Target ;
1915import dev .dsf .bpe .v1 .variables .Variables ;
2016import jakarta .ws .rs .WebApplicationException ;
2117import jakarta .ws .rs .core .Response ;
18+ import jakarta .ws .rs .core .Response .StatusType ;
2219
2320public class SendPing extends AbstractTaskMessageSend
2421{
25- private final PingStatusGenerator statusGenerator ;
26- private final ErrorMailService errorMailService ;
27-
28- public SendPing (ProcessPluginApi api , PingStatusGenerator statusGenerator , ErrorMailService errorMailService )
22+ public SendPing (ProcessPluginApi api )
2923 {
3024 super (api );
31-
32- this .statusGenerator = statusGenerator ;
33- this .errorMailService = errorMailService ;
34- }
35-
36- @ Override
37- public void afterPropertiesSet () throws Exception
38- {
39- super .afterPropertiesSet ();
40-
41- Objects .requireNonNull (statusGenerator , "statusGenerator" );
42- Objects .requireNonNull (errorMailService , "errorMailService" );
4325 }
4426
4527 @ Override
@@ -51,36 +33,17 @@ protected Stream<ParameterComponent> getAdditionalInputParameters(DelegateExecut
5133 }
5234
5335 @ Override
54- protected void handleSendTaskError (DelegateExecution execution , Variables variables , Exception exception ,
55- String errorMessage )
36+ protected void handleIntermediateThrowEventError (DelegateExecution execution , Variables variables ,
37+ Exception exception , String errorMessage )
5638 {
57- Target target = variables .getTarget ();
58- Task mainTask = variables .getStartTask ();
59-
60- if (mainTask != null )
61- {
62- String statusCode = ConstantsPing .CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_REACHABLE ;
63- if (exception instanceof WebApplicationException webApplicationException )
64- {
65- if (webApplicationException .getResponse () != null && webApplicationException .getResponse ()
66- .getStatus () == Response .Status .FORBIDDEN .getStatusCode ())
67- {
68- statusCode = ConstantsPing .CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_ALLOWED ;
69- }
70- }
71-
72- String specialErrorMessage = createErrorMessage (exception );
73-
74- mainTask .addOutput (statusGenerator .createPingStatusOutput (target , statusCode , specialErrorMessage ));
75- variables .updateTask (mainTask );
76-
77- if (ConstantsPing .CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_REACHABLE .equals (statusCode ))
78- errorMailService .endpointNotReachableForPing (mainTask .getIdElement (), target , specialErrorMessage );
79- else if (ConstantsPing .CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_ALLOWED .equals (statusCode ))
80- errorMailService .endpointReachablePingForbidden (mainTask .getIdElement (), target , specialErrorMessage );
81- }
82-
83- super .handleSendTaskError (execution , variables , exception , errorMessage );
39+ String statusCode = exception instanceof WebApplicationException w && w .getResponse () != null
40+ && w .getResponse ().getStatus () == Response .Status .FORBIDDEN .getStatusCode ()
41+ ? ConstantsPing .CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_ALLOWED
42+ : ConstantsPing .CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_REACHABLE ;
43+ execution .setVariableLocal ("statusCode" , statusCode );
44+
45+ String specialErrorMessage = createErrorMessage (exception );
46+ execution .setVariableLocal ("errorMessage" , specialErrorMessage );
8447 }
8548
8649 @ Override
@@ -91,10 +54,14 @@ protected void addErrorMessage(Task task, String errorMessage)
9154
9255 private String createErrorMessage (Exception exception )
9356 {
94- return exception .getClass ().getSimpleName ()
95- + ((exception .getMessage () != null && !exception .getMessage ().isBlank ())
96- ? (": " + exception .getMessage ())
97- : "" );
57+ if (exception instanceof WebApplicationException w
58+ && (exception .getMessage () == null || exception .getMessage ().isBlank ()))
59+ {
60+ StatusType statusInfo = w .getResponse ().getStatusInfo ();
61+ return statusInfo .getStatusCode () + " " + statusInfo .getReasonPhrase ();
62+ }
63+ else
64+ return exception .getMessage ();
9865 }
9966
10067 private Identifier getLocalEndpointIdentifier ()
0 commit comments