Skip to content

Commit

Permalink
Issue #74 Sockets not closing properly
Browse files Browse the repository at this point in the history
  • Loading branch information
FrodeBjerkholt committed Feb 4, 2020
1 parent 5cb39f4 commit 34a0866
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/main/java/no/difi/oxalis/as4/outbound/As4MessageSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,20 @@ public class As4MessageSender {
private PolicyService policyService;

public TransmissionResponse send(TransmissionRequest request) throws OxalisAs4TransmissionException {
Dispatch<SOAPMessage> dispatch = createDispatch(request);
Collection<Attachment> attachments = prepareAttachments(request);
dispatch.getRequestContext().put(Message.ATTACHMENTS, attachments);

Messaging messaging = messagingProvider.createMessagingHeader(request, attachments);
SoapHeader header = getSoapHeader(messaging);
dispatch.getRequestContext().put(Header.HEADER_LIST, new ArrayList<>(Collections.singletonList(header)));
try (DispatchImpl<SOAPMessage> dispatch = createDispatch(request)) {
Collection<Attachment> attachments = prepareAttachments(request);
dispatch.getRequestContext().put(Message.ATTACHMENTS, attachments);

Messaging messaging = messagingProvider.createMessagingHeader(request, attachments);
SoapHeader header = getSoapHeader(messaging);
dispatch.getRequestContext().put(Header.HEADER_LIST, new ArrayList<>(Collections.singletonList(header)));
return invoke(request, dispatch);
} catch (IOException e) {
throw new OxalisAs4TransmissionException("Failed to send message", e);
}
}

private TransmissionResponse invoke(TransmissionRequest request, DispatchImpl<SOAPMessage> dispatch) throws OxalisAs4TransmissionException {
try {
SOAPMessage response = dispatch.invoke(null);
return transmissionResponseConverter.convert(request, response);
Expand Down Expand Up @@ -137,14 +143,14 @@ private String getContentID(TransmissionRequest request) {
return messageIdGenerator.generate();
}

private Dispatch<SOAPMessage> createDispatch(TransmissionRequest request) throws OxalisAs4TransmissionException {
Dispatch<SOAPMessage> dispatch = getService(request)
private DispatchImpl<SOAPMessage> createDispatch(TransmissionRequest request) throws OxalisAs4TransmissionException {
DispatchImpl<SOAPMessage> dispatch = (DispatchImpl<SOAPMessage>) getService(request)
.createDispatch(PORT_NAME, SOAPMessage.class, Service.Mode.MESSAGE);
dispatch.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, request.getEndpoint().getAddress().toString());

configureSecurity(request, dispatch);

final Client client = ((DispatchImpl<SOAPMessage>) dispatch).getClient();
final Client client = dispatch.getClient();

if (CEF_CONFORMANCE.equalsIgnoreCase(as4settings.getString(As4Conf.TYPE))) {
client.getInInterceptors().add(getLoggingBeforeSecurityInInterceptor());
Expand Down

0 comments on commit 34a0866

Please sign in to comment.