Skip to content
Snippets Groups Projects
Commit b0eabdd0 authored by OZGCloud's avatar OZGCloud
Browse files

Merge pull request 'OZG-3665_implement_close' (#61) from OZG-3665_implement_close into master

parents 98ef9bfb bacc95d1
No related branches found
No related tags found
No related merge requests found
......@@ -79,4 +79,6 @@ class Actions {
private URI statusList;
@NotNull
private URI fetchRequest;
@NotNull
private URI closeRequest;
}
......@@ -19,13 +19,17 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.webservices.client.WebServiceTemplateBuilder;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.stereotype.Service;
import org.springframework.ws.soap.SoapFaultDetailElement;
import org.springframework.ws.soap.addressing.client.ActionCallback;
import org.springframework.ws.soap.addressing.version.Addressing10;
import org.springframework.ws.soap.client.SoapFaultClientException;
import org.w3._2005._08.addressing.AttributedURIType;
import de.itvsh.kop.eingangsadapter.common.errorhandling.TechnicalException;
import de.xoev.transport.xta._211.ContentType;
import de.xoev.transport.xta._211.ExceptionType;
import de.xoev.transport.xta._211.GenericContentContainer;
import eu.osci.ws._2008._05.transport.MsgBoxCloseRequestType;
import eu.osci.ws._2008._05.transport.MsgBoxFetchRequest;
import eu.osci.ws._2008._05.transport.MsgBoxStatusListRequestType;
import eu.osci.ws._2008._05.transport.MsgSelector;
......@@ -38,6 +42,9 @@ import lombok.extern.log4j.Log4j2;
@Service
class XtaRemoteService {
private static final String ERROR_ON_CLOSE_LOG_TEMPLATE = "Error result on close request.\nReason: %s";
private static final String DETAIL_LOG_TEMPLATE = "Code: %s, Message: %s";
@Autowired
@Valid
private XtaProperties properties;
......@@ -143,8 +150,48 @@ class XtaRemoteService {
}
public void close(@NonNull XtaMessageId messageId) {
// TODO Auto-generated method stub
LOG.warn("close not jet implemented");
var callback = new ActionCallback(properties.getActions().getCloseRequest(), new Addressing10(), getTargetUri());
var template = webServiceTemplateBuilder.setMarshaller(osciMarshaller).setUnmarshaller(xoevMarshaller).build();
try {
template.marshalSendAndReceive(buildCloseRequest(messageId.toString()), callback);
} catch (SoapFaultClientException e) {
logErrorOnClose(e);
}
}
private JAXBElement<MsgBoxCloseRequestType> buildCloseRequest(String msgId) {
MsgBoxCloseRequestType request = new MsgBoxCloseRequestType();
var lastMsgReceived = request.getLastMsgReceived();
AttributedURIType attribute = new AttributedURIType();
attribute.setValue(msgId);
lastMsgReceived.add(attribute);
return new ObjectFactory().createMsgBoxCloseRequest(request);
}
private void logErrorOnClose(SoapFaultClientException e) {
try {
var fault = e.getSoapFault();
StringBuilder logBuilder = new StringBuilder(ERROR_ON_CLOSE_LOG_TEMPLATE.formatted(e.getSoapFault().getFaultStringOrReason()));
var entries = fault.getFaultDetail().getDetailEntries();
entries.forEachRemaining(entry -> logBuilder.append("\n").append(formatFaultEntry(entry)));
LOG.error(logBuilder.toString(), e);
} catch (Exception e1) {
LOG.error("Error on loggging close error", e1);
LOG.error("origin error was", e);
}
}
private String formatFaultEntry(SoapFaultDetailElement soapfaultdetailelement1) {
@SuppressWarnings("unchecked")
ExceptionType exceptionType = ((JAXBElement<ExceptionType>) xoevMarshaller.unmarshal(soapfaultdetailelement1.getSource())).getValue();
return DETAIL_LOG_TEMPLATE.formatted(exceptionType.getErrorCode().getCode(), exceptionType.getErrorCode().getName().toString());
}
}
......@@ -2,6 +2,7 @@ package de.ozgcloud.eingang.xta;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Profile;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
......@@ -10,6 +11,7 @@ import de.itvsh.kop.eingangsadapter.semantik.SemantikAdapter;
import lombok.NonNull;
import lombok.extern.log4j.Log4j2;
@Profile("!itcase")
@Log4j2
@Component
class XtaRunner implements ApplicationListener<ContextRefreshedEvent> {
......
......@@ -14,3 +14,4 @@ ozgcloud:
actions:
status-list: "http://www.osci.eu/ws/2008/05/transport/urn/messageTypes/MsgBoxStatusListRequest"
fetch-request: "http://www.osci.eu/ws/2008/05/transport/urn/messageTypes/MsgBoxFetchRequest"
close-request: "http://www.osci.eu/ws/2008/05/transport/urn/messageTypes/MsgBoxCloseRequest"
package de.ozgcloud.eingang.xta;
import java.util.UUID;
class XtaMessageTestFactory {
static final XtaMessageId MESSAGE_ID = XtaMessageId.from(UUID.randomUUID().toString());
static final XtaMessageId MESSAGE_ID = XtaMessageId.from("urn:de:xta:messageid:dataport_xta_210:81e40808-91c6-4765-aaf4-1aa62fec8be9");
static XtaMessage create() {
return createBuilder().build();
......
......@@ -61,4 +61,11 @@ class XtaRemoteServiceITCase {
}
}
@Nested
class TestClose {
@Test
void shouldThrowNoException() {
assertThatNoException().isThrownBy(() -> remoteService.close(XtaMessageTestFactory.MESSAGE_ID));
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment