Search in sources :

Example 1 with AS4Error

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());
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) AS4Error(network.oxalis.as4.lang.AS4Error) Error(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Error) OxalisAs4Exception(network.oxalis.as4.lang.OxalisAs4Exception) Fault(org.apache.cxf.interceptor.Fault) Date(java.util.Date)

Example 2 with AS4Error

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;
}
Also used : AS4Error(network.oxalis.as4.lang.AS4Error) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) OxalisAs4Exception(network.oxalis.as4.lang.OxalisAs4Exception) WebServiceException(javax.xml.ws.WebServiceException)

Example 3 with AS4Error

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);
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) SOAPMessage(javax.xml.soap.SOAPMessage) WebServiceException(javax.xml.ws.WebServiceException) OxalisAs4Exception(network.oxalis.as4.lang.OxalisAs4Exception) AS4Error(network.oxalis.as4.lang.AS4Error) Fault(org.apache.cxf.interceptor.Fault) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException)

Example 4 with AS4Error

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);
        }
    }
}
Also used : Path(java.nio.file.Path) SOAPMessage(javax.xml.soap.SOAPMessage) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) OxalisAs4Exception(network.oxalis.as4.lang.OxalisAs4Exception) WebServiceException(javax.xml.ws.WebServiceException)

Aggregations

OxalisAs4Exception (network.oxalis.as4.lang.OxalisAs4Exception)4 WebServiceException (javax.xml.ws.WebServiceException)3 AS4Error (network.oxalis.as4.lang.AS4Error)3 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)3 SOAPMessage (javax.xml.soap.SOAPMessage)2 Fault (org.apache.cxf.interceptor.Fault)2 Path (java.nio.file.Path)1 Date (java.util.Date)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 Exchange (org.apache.cxf.message.Exchange)1 Message (org.apache.cxf.message.Message)1 Error (org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Error)1