use of network.oxalis.as4.lang.AS4Error in project Oxalis-AS4 by OxalisCommunity.
the class As4MessageFactory method createErrorMessage.
public SOAPMessage createErrorMessage(String messageId, AS4Error as4Error) {
try {
XMLGregorianCalendar currentDate = XMLUtil.dateToXMLGeorgianCalendar(new Date());
MessageInfo messageInfo = MessageInfo.builder().withRefToMessageId(messageId).withTimestamp(currentDate).withMessageId(messageIdGenerator.generate()).build();
Error error = Error.builder().withRefToMessageInError(messageId).withErrorCode(as4Error.getErrorCode().toString()).withErrorDetail(getErrorDetail(as4Error)).withShortDescription(as4Error.getErrorCode().getShortDescription()).withOrigin(as4Error.getErrorCode().getOrigin().toString()).withCategory(as4Error.getErrorCode().getCatgory().toString()).withSeverity(as4Error.getSeverity().toString()).build();
SignalMessage signalMessage = SignalMessage.builder().withMessageInfo(messageInfo).withError(error).build();
return marshalSignalMessage(signalMessage);
} catch (OxalisAs4Exception e) {
throw new Fault(e.getCause());
}
}
use of network.oxalis.as4.lang.AS4Error in project Oxalis-AS4 by OxalisCommunity.
the class As4FaultInHandler method handleFault.
@Override
public boolean handleFault(SOAPMessageContext context) {
String messageId = Optional.ofNullable((MessageId) context.get(MessageId.MESSAGE_ID)).map(MessageId::getValue).orElse(null);
Exception exception = (Exception) context.get(Exception.class.getName());
if (exception == null) {
return true;
}
log.info("handleFault for Exception", exception);
AS4Error as4Error = toAS4Error(exception);
handleAS4Error(context, messageId, as4Error);
return true;
}
use of network.oxalis.as4.lang.AS4Error in project Oxalis-AS4 by OxalisCommunity.
the class As4FaultInHandler method toAS4Error.
public static AS4Error toAS4Error(Throwable t) {
// Is there a better way of getting the inMessage using JAX-WS?
Optional<Message> faultMessage = Optional.ofNullable(PhaseInterceptorChain.getCurrentMessage());
Optional<Message> inMessage = faultMessage.map(Message::getExchange).map(Exchange::getInMessage);
if (t instanceof Fault) {
Fault fault = (Fault) t;
t = fault.getCause();
}
if (t instanceof WebServiceException) {
WebServiceException webServiceException = (WebServiceException) t;
t = webServiceException.getCause();
}
if (t instanceof WSSecurityException && inMessage.isPresent()) {
boolean isCompressionError = (boolean) inMessage.get().getOrDefault("oxalis.as4.compressionErrorDetected", false);
if (isCompressionError) {
return new OxalisAs4Exception("Content cannot be compressed after signature/encryption", AS4ErrorCode.EBMS_0303);
}
return new OxalisAs4Exception(t.getMessage(), t, AS4ErrorCode.EBMS_0009, AS4ErrorCode.Severity.ERROR);
}
if (t instanceof AS4Error) {
return (AS4Error) t;
}
return new OxalisAs4Exception(t.getMessage(), t, AS4ErrorCode.EBMS_0004, AS4ErrorCode.Severity.ERROR);
}
use of network.oxalis.as4.lang.AS4Error in project Oxalis-AS4 by OxalisCommunity.
the class As4FaultInHandler method handleAS4Error.
protected void handleAS4Error(SOAPMessageContext context, String messageId, AS4Error as4Error) {
SOAPMessage errorMessage = as4MessageFactory.createErrorMessage(messageId, as4Error);
context.setMessage(errorMessage);
Path firstPayloadPath = (Path) context.get(AS4MessageContextKey.FIRST_PAYLOAD_PATH);
As4PayloadHeader firstPayloadHeader = (As4PayloadHeader) context.get(AS4MessageContextKey.FIRST_PAYLOAD_HEADER);
if (messageId != null && firstPayloadPath != null) {
try {
persisterHandler.persist(TransmissionIdentifier.of(messageId), firstPayloadHeader, firstPayloadPath, as4Error.getException());
} catch (Exception e) {
log.error("Unable to persist exception", e);
}
}
}
Aggregations