();
CapsuleAdressee adressee = new CapsuleAdressee("401", null, null);
addressees.add(adressee);
@@ -115,6 +125,7 @@ public void init() throws DhxException, IOException {
when(persistenceService.getFolderByNameOrDefaultFolder("/")).thenReturn(folder);
capsuleService.setConfig(config);
when(config.getCapsuleValidate()).thenReturn(true);
+ when(soapConfig.getDhxSubsystemPrefix()).thenReturn("DHX");
capsuleService.setDhxServerConfig(serverConfig);
testFile = testFolder.newFile(filename);
when(serverConfig.createDocumentFile()).thenReturn(testFile);
@@ -178,7 +189,7 @@ public void getDocumentFromIncomingContainer() throws DhxException, IOException
InternalXroadMember client = getMember("400", null);
InternalXroadMember service = getMember("401", null);
SendDocument sendDocument = getSendDocument(null, null, handler);
- DhxOrganisation recipient = DhxOrganisationFactory.createDhxOrganisation(service);
+ DhxOrganisation recipient = dhxOrganisationFactory.createDhxOrganisation(service);
IncomingDhxPackage pckg = new IncomingDhxPackage(client, service, sendDocument, recipient);
// mock container
@@ -257,7 +268,7 @@ public void getDocumentFromIncomingContainerRepresentee() throws DhxException, I
DhxRepresentee serviceRepresentee = new DhxRepresentee("500", null, null, null, "system");
InternalXroadMember service = getMember("401", serviceRepresentee);
SendDocument sendDocument = getSendDocument(null, null, handler);
- DhxOrganisation recipient = DhxOrganisationFactory.createDhxOrganisation(service);
+ DhxOrganisation recipient = dhxOrganisationFactory.createDhxOrganisation(service);
IncomingDhxPackage pckg = new IncomingDhxPackage(client, service, sendDocument, recipient);
// mock container
@@ -302,7 +313,7 @@ public void getDocumentFromIncomingContainerSenderNotFound() throws DhxException
InternalXroadMember client = getMember("400", null);
InternalXroadMember service = getMember("401", null);
SendDocument sendDocument = getSendDocument(null, null, handler);
- DhxOrganisation recipient = DhxOrganisationFactory.createDhxOrganisation(service);
+ DhxOrganisation recipient = dhxOrganisationFactory.createDhxOrganisation(service);
IncomingDhxPackage pckg = new IncomingDhxPackage(client, service, sendDocument, recipient);
// mock container
@@ -350,7 +361,7 @@ public void getDocumentFromIncomingContainerSenderRepresenteeNotFound()
InternalXroadMember client = getMember("400", clientRepresentee);
InternalXroadMember service = getMember("401", null);
SendDocument sendDocument = getSendDocument(null, null, handler);
- DhxOrganisation recipient = DhxOrganisationFactory.createDhxOrganisation(service);
+ DhxOrganisation recipient = dhxOrganisationFactory.createDhxOrganisation(service);
IncomingDhxPackage pckg = new IncomingDhxPackage(client, service, sendDocument, recipient);
// mock container
@@ -404,7 +415,7 @@ public void getDocumentFromIncomingContainerManyRecipients() throws DhxException
InternalXroadMember client = getMember("400", null);
InternalXroadMember service = getMember("401", null);
SendDocument sendDocument = getSendDocument(null, null, handler);
- DhxOrganisation recipient = DhxOrganisationFactory.createDhxOrganisation(service);
+ DhxOrganisation recipient = dhxOrganisationFactory.createDhxOrganisation(service);
IncomingDhxPackage pckg = new IncomingDhxPackage(client, service, sendDocument, recipient);
// mock container
@@ -449,7 +460,7 @@ public void getDocumentFromIncomingContainerPersonalCode() throws DhxException,
InternalXroadMember client = getMember("400", null);
InternalXroadMember service = getMember("401", null);
SendDocument sendDocument = getSendDocument(null, null, handler);
- DhxOrganisation recipient = DhxOrganisationFactory.createDhxOrganisation(service);
+ DhxOrganisation recipient = dhxOrganisationFactory.createDhxOrganisation(service);
IncomingDhxPackage pckg = new IncomingDhxPackage(client, service, sendDocument, recipient);
// mock container
@@ -498,7 +509,7 @@ public void getDocumentFromIncomingContainerStructuralUnit() throws DhxException
InternalXroadMember client = getMember("400", null);
InternalXroadMember service = getMember("401", null);
SendDocument sendDocument = getSendDocument(null, null, handler);
- DhxOrganisation recipient = DhxOrganisationFactory.createDhxOrganisation(service);
+ DhxOrganisation recipient = dhxOrganisationFactory.createDhxOrganisation(service);
IncomingDhxPackage pckg = new IncomingDhxPackage(client, service, sendDocument, recipient);
// mock container
DecContainer container = getDecContainer(client, service);
diff --git a/dhx-adapter-server/src/test/java/ee/ria/dhx/server/persistence/service/PersistenceServiceTest.java b/dhx-adapter-server/src/test/java/ee/ria/dhx/server/persistence/service/PersistenceServiceTest.java
index a4330146..ee6b5e80 100644
--- a/dhx-adapter-server/src/test/java/ee/ria/dhx/server/persistence/service/PersistenceServiceTest.java
+++ b/dhx-adapter-server/src/test/java/ee/ria/dhx/server/persistence/service/PersistenceServiceTest.java
@@ -16,6 +16,7 @@
import ee.ria.dhx.server.persistence.repository.OrganisationRepository;
import ee.ria.dhx.types.DhxRepresentee;
import ee.ria.dhx.types.InternalXroadMember;
+import ee.ria.dhx.ws.DhxOrganisationFactory;
import ee.ria.dhx.ws.config.SoapConfig;
import ee.ria.dhx.ws.service.AddressService;
@@ -23,6 +24,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
@@ -42,6 +44,9 @@ public class PersistenceServiceTest {
PersistenceService persistenceService;
+ @InjectMocks
+ DhxOrganisationFactory dhxOrganisationFactory;
+
@Mock
SoapConfig config;
@@ -55,6 +60,7 @@ public void init() throws DhxException {
persistenceService.setAddressService(addressService);
persistenceService.setFolderRepository(folderRepository);
persistenceService.setOrganisationRepository(organisationRepository);
+ persistenceService.setDhxOrganisationFactory(dhxOrganisationFactory);
Folder folder = new Folder();
folder.setName("folder");
persistenceService.setSpecialOrganisations("adit,kovtp,rt,eelnoud");
diff --git a/dhx-adapter-ws/doc/ee/ria/dhx/ws/DhxHttpComponentsMessageSender.html b/dhx-adapter-ws/doc/ee/ria/dhx/ws/DhxHttpComponentsMessageSender.html
index 62377825..51726dba 100644
--- a/dhx-adapter-ws/doc/ee/ria/dhx/ws/DhxHttpComponentsMessageSender.html
+++ b/dhx-adapter-ws/doc/ee/ria/dhx/ws/DhxHttpComponentsMessageSender.html
@@ -106,7 +106,7 @@ Class DhxHttpComp
org.springframework.ws.transport.http.HttpComponentsMessageSender
-- ee.ria.dhx.ws.DhxHttpComponentsMessageSender
+- ee.ria.dhx.ws.connection.DhxHttpComponentsMessageSender
diff --git a/dhx-adapter-ws/doc/ee/ria/dhx/ws/class-use/DhxHttpComponentsMessageSender.html b/dhx-adapter-ws/doc/ee/ria/dhx/ws/class-use/DhxHttpComponentsMessageSender.html
index a76bb503..5de40f29 100644
--- a/dhx-adapter-ws/doc/ee/ria/dhx/ws/class-use/DhxHttpComponentsMessageSender.html
+++ b/dhx-adapter-ws/doc/ee/ria/dhx/ws/class-use/DhxHttpComponentsMessageSender.html
@@ -3,7 +3,7 @@
-Uses of Class ee.ria.dhx.ws.DhxHttpComponentsMessageSender
+Uses of Class ee.ria.dhx.ws.connection.DhxHttpComponentsMessageSender
@@ -70,9 +70,9 @@
-No usage of ee.ria.dhx.ws.DhxHttpComponentsMessageSender
+No usage of ee.ria.dhx.ws.connection.DhxHttpComponentsMessageSender
diff --git a/dhx-adapter-ws/pom.xml b/dhx-adapter-ws/pom.xml
index 4026055c..a4c8092c 100644
--- a/dhx-adapter-ws/pom.xml
+++ b/dhx-adapter-ws/pom.xml
@@ -6,7 +6,7 @@
ee.ria.dhx
DHX-adapter
- 1.0.4
+ ${revision}
dhx-adapter-ws
Web services
@@ -37,8 +37,58 @@
xerces
xercesImpl
- 2.8.1
+ 2.12.0
+
+ org.codehaus.woodstox
+ stax2-api
+ 4.2
+
+
+ com.fasterxml.woodstox
+ woodstox-core
+ 5.3.0
+
+
+
+ net.java.dev.msv
+ msv-core
+ 2013.6.1
+
+
+
+ org.apache.ws.commons.axiom
+ axiom-api
+ 1.2.22
+
+
+ org.apache.ws.commons.axiom
+ axiom-impl
+ 1.2.22
+
+
+ org.codehaus.woodstox
+ woodstox-core-asl
+
+
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.9
+
+
+
+
+
+ ee.ria.dhx
+ dhx-adapter-core
+ ${project.parent.version}
+ test-jar
+ test
+
+
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/bigdata/BigDataHandler.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/bigdata/BigDataHandler.java
index 4c0d9a31..f67d3ed6 100644
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/bigdata/BigDataHandler.java
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/bigdata/BigDataHandler.java
@@ -61,7 +61,7 @@ protected abstract void handleBigDataStartElement(Field dataField, Stack
Stack currentObjPath, String uri, String localName, String qname,
Attributes attributes) throws DhxException;
- protected abstract void handleBigDataCharacters(char[] chars) throws IOException;
+ protected abstract void handleBigDataCharacters(char[] chars, int start, int length) throws IOException;
protected abstract void handleBigDataEndElement(String uri, String localName, String qname)
throws IOException, SAXException;
@@ -154,13 +154,7 @@ public void startElement(String uri, String localName, String qname, Attributes
public void characters(char[] ch, int start, int length) throws SAXException {
if (isDocument) {
try {
- char[] charSub;
- if (start > 0 || ch.length > length) {
- charSub = Arrays.copyOfRange(ch, start, start + length);
- } else {
- charSub = ch;
- }
- handleBigDataCharacters(charSub);
+ handleBigDataCharacters(ch, start, length);
} catch (IOException ex) {
throw new SAXException("Error occured while reading document." + ex.getMessage(), ex);
}
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/bigdata/BigDataMarshallHandler.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/bigdata/BigDataMarshallHandler.java
index c59ba091..3b8f9b54 100644
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/bigdata/BigDataMarshallHandler.java
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/bigdata/BigDataMarshallHandler.java
@@ -124,7 +124,7 @@ public void startDocument() throws SAXException {
@Override
public void endDocument() throws SAXException {
- log.info("document started !!!!");
+ log.info("document ended !!!!");
if (!nonamespaces)
super.endDocument();
}
@@ -209,7 +209,7 @@ protected void handleBigDataStartElement(Field dataField, Stack currentP
@Override
@Loggable
- protected void handleBigDataCharacters(char[] chars) throws IOException {
+ protected void handleBigDataCharacters(char[] chars, int start, int length) throws IOException {
log.error("CHARECTER CANNOT BE HERE!!!!");
}
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/bigdata/BigDataUnmarshallHandler.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/bigdata/BigDataUnmarshallHandler.java
index 45138e63..fb537421 100644
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/bigdata/BigDataUnmarshallHandler.java
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/bigdata/BigDataUnmarshallHandler.java
@@ -79,8 +79,8 @@ protected void handleBigDataStartElement(Field dataField, Stack currentP
@Override
@Loggable(Loggable.TRACE)
- protected void handleBigDataCharacters(char[] chars) throws IOException {
- writer.write(chars);
+ protected void handleBigDataCharacters(char[] chars, int start, int length) throws IOException {
+ writer.write(chars, start, length);
}
@Override
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/DhxHttpComponentsMessageSender.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/DhxHttpComponentsMessageSender.java
deleted file mode 100644
index 6050e76e..00000000
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/DhxHttpComponentsMessageSender.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package ee.ria.dhx.ws;
-
-import org.apache.http.client.methods.HttpPost;
-import org.springframework.ws.transport.WebServiceConnection;
-import org.springframework.ws.transport.http.HttpComponentsConnection;
-import org.springframework.ws.transport.http.HttpComponentsMessageSender;
-import org.springframework.ws.transport.http.HttpTransportConstants;
-
-import java.io.IOException;
-import java.net.URI;
-
-public class DhxHttpComponentsMessageSender extends HttpComponentsMessageSender {
-
- @Override
- public WebServiceConnection createConnection(URI uri) throws IOException {
- HttpComponentsConnection connection = (HttpComponentsConnection) super.createConnection(uri);
- HttpPost postMethod = connection.getHttpPost();
- postMethod.addHeader(
- HttpTransportConstants.HEADER_CONTENT_TRANSFER_ENCODING,
- "base64");
- return super.createConnection(uri);
- }
-
-}
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/DhxOrganisationFactory.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/DhxOrganisationFactory.java
index fcb98151..5dff71af 100644
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/DhxOrganisationFactory.java
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/DhxOrganisationFactory.java
@@ -5,9 +5,8 @@
import ee.ria.dhx.types.eu.x_road.dhx.producer.SendDocument;
import ee.ria.dhx.util.StringUtil;
import ee.ria.dhx.ws.config.SoapConfig;
-import ee.ria.dhx.ws.context.AppContext;
-import lombok.Setter;
+import org.springframework.beans.factory.annotation.Autowired;
/**
* Class for creating DhxOrganisation. Simplifies object creation by setting dhxSubsystemPrefix
@@ -18,8 +17,8 @@
*/
public class DhxOrganisationFactory {
- @Setter
- private static String dhxSubsystemPrefix;
+ @Autowired
+ SoapConfig soapConfig;
/**
* Method for creating DhxOrganisation. Simplifies object creation by setting dhxSubsystemPrefix
@@ -29,11 +28,8 @@ public class DhxOrganisationFactory {
* @param system - system of the organisation(either Xroad subsystem or representee system)
* @return DhxOrganisation object
*/
- public static DhxOrganisation createDhxOrganisation(String memberCode, String system) {
- if (dhxSubsystemPrefix == null) {
- SoapConfig config = AppContext.getApplicationContext().getBean(SoapConfig.class);
- dhxSubsystemPrefix = config.getDhxSubsystemPrefix();
- }
+ public DhxOrganisation createDhxOrganisation(String memberCode, String system) {
+ String dhxSubsystemPrefix = soapConfig.getDhxSubsystemPrefix();
return new DhxOrganisation(memberCode, system, dhxSubsystemPrefix);
}
@@ -44,11 +40,8 @@ public static DhxOrganisation createDhxOrganisation(String memberCode, String sy
* @param member - Xroad member of the organisation
* @return DhxOrganisation object
*/
- public static DhxOrganisation createDhxOrganisation(InternalXroadMember member) {
- if (dhxSubsystemPrefix == null) {
- SoapConfig config = AppContext.getApplicationContext().getBean(SoapConfig.class);
- dhxSubsystemPrefix = config.getDhxSubsystemPrefix();
- }
+ public DhxOrganisation createDhxOrganisation(InternalXroadMember member) {
+ String dhxSubsystemPrefix = soapConfig.getDhxSubsystemPrefix();
return new DhxOrganisation(member, dhxSubsystemPrefix);
}
@@ -60,7 +53,7 @@ public static DhxOrganisation createDhxOrganisation(InternalXroadMember member)
* @param service - recipient of the request
* @return DhxOrganisation object
*/
- public static DhxOrganisation createIncomingRecipientOrgnisation(SendDocument document,
+ public DhxOrganisation createIncomingRecipientOrgnisation(SendDocument document,
InternalXroadMember service) {
String code;
String system;
@@ -71,7 +64,7 @@ public static DhxOrganisation createIncomingRecipientOrgnisation(SendDocument do
code = service.getMemberCode();
system = service.getSubsystemCode();
}
- DhxOrganisation recipient = DhxOrganisationFactory.createDhxOrganisation(code, system);
+ DhxOrganisation recipient = createDhxOrganisation(code, system);
return recipient;
}
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/DhxConfig.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/DhxConfig.java
index b7378183..789c7484 100644
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/DhxConfig.java
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/DhxConfig.java
@@ -1,7 +1,7 @@
package ee.ria.dhx.ws.config;
+import ee.ria.dhx.ws.DhxOrganisationFactory;
import org.springframework.beans.factory.annotation.Value;
-// import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -124,10 +124,12 @@ public String getAcceptedDhxProtocolVersions() {
*/
@Bean
public JAXBContext getJaxbContext() throws JAXBException {
- if (this.jaxbContext == null) {
- this.jaxbContext = JAXBContext.newInstance(marshallContext);
- }
- return jaxbContext;
+ return JAXBContext.newInstance(marshallContext);
+ }
+
+ @Bean
+ public DhxOrganisationFactory dhxOrganisationFactory() {
+ return new DhxOrganisationFactory();
}
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/DhxWebServiceConfig.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/DhxWebServiceConfig.java
new file mode 100644
index 00000000..4d3078c1
--- /dev/null
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/DhxWebServiceConfig.java
@@ -0,0 +1,50 @@
+package ee.ria.dhx.ws.config;
+
+import lombok.Getter;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.ws.soap.SoapMessageFactory;
+import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory;
+
+import java.io.File;
+
+/**
+ *
+ * @author Kaarel Raspel
+ *
+ */
+@Configuration
+public class DhxWebServiceConfig {
+
+ @Value("${soap.dhx.attachment.cache.threshold:#{null}}")
+ @Getter
+ Integer attachmentCacheThreshold;
+
+ @Value("${soap.dhx.attachment.cache.dir:#{null}}")
+ @Getter
+ String attachmentCacheDir;
+
+ /**
+ * Creates messageFactory for sending and returns.
+ * @return messagefactory
+ */
+ @Bean
+ @Primary
+ public SoapMessageFactory axiomSoapMessageFactorySend() {
+ return new AxiomSoapMessageFactory() {{
+ Integer attachmentCacheThreshold = DhxWebServiceConfig.this.getAttachmentCacheThreshold();
+ if (attachmentCacheThreshold != null) {
+ setAttachmentCaching(true);
+ setAttachmentCacheThreshold(attachmentCacheThreshold /* MB */ * 1024 /* KB */ * 1024 /* Byte */);
+
+ String attachmentCacheDir = DhxWebServiceConfig.this.getAttachmentCacheDir();
+ if (attachmentCacheDir != null) {
+ setAttachmentCacheDir(new File(attachmentCacheDir));
+ }
+ }
+ }};
+ }
+
+}
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/SoapConfig.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/SoapConfig.java
index f1959ead..5f69bb71 100644
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/SoapConfig.java
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/SoapConfig.java
@@ -2,6 +2,16 @@
import ee.ria.dhx.types.InternalXroadMember;
+import org.apache.http.HeaderElement;
+import org.apache.http.HeaderElementIterator;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.conn.ConnectionKeepAliveStrategy;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.message.BasicHeaderElementIterator;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.protocol.HttpContext;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Bean;
@@ -172,6 +182,50 @@ public String addPrefixIfNeeded(String system) {
return system.toUpperCase();
}
+ @Bean
+ public ConnectionKeepAliveStrategy soapHttpClientKeepAliveStrategy() {
+ return new ConnectionKeepAliveStrategy() {
+
+ public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
+
+ HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
+
+ while (it.hasNext()) {
+ HeaderElement he = it.nextElement();
+ String param = he.getName();
+ String value = he.getValue();
+ if (value != null && param.equalsIgnoreCase("timeout")) {
+
+ try {
+ return Long.parseLong(value) * 1000;
+ } catch(NumberFormatException ignore) {
+ }
+
+ }
+ }
+ // otherwise keep alive for seconds
+ return getHttpTimeout() * 1000;
+ }
+ };
+ }
+
+ @Bean
+ public RequestConfig defaultRequestConfig() {
+ return RequestConfig.custom()
+ .setConnectTimeout(getConnectionTimeout())
+ .setConnectionRequestTimeout(getReadTimeout())
+ .build();
+ }
+
+ @Bean
+ public HttpClient soapHttpClient(ConnectionKeepAliveStrategy soapHttpClientKeepAliveStrategy,
+ RequestConfig defaultRequestConfig) {
+ return HttpClientBuilder.create()
+ .setKeepAliveStrategy(soapHttpClientKeepAliveStrategy)
+ .setDefaultRequestConfig(defaultRequestConfig)
+ .build();
+ }
+
/**
* Method returns default xroad client. That client will be used as sender when sending documents.
*
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/endpoint/DhxEndpointConfig.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/endpoint/DhxEndpointConfig.java
index 16e3838c..0a8cd852 100644
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/endpoint/DhxEndpointConfig.java
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/endpoint/DhxEndpointConfig.java
@@ -44,22 +44,16 @@ public class DhxEndpointConfig extends WsConfigurationSupport {
* @return DefaultMethodEndpointAdapter
*/
@Bean(name = "dhxMethodEndpointAdapter")
- public DefaultMethodEndpointAdapter dhxMethodEndpointAdapter() {
- List argumentResolvers = null;
- List returnValueHandlers = null;
- if (argumentResolvers == null) {
- argumentResolvers = new ArrayList();
- }
- if (returnValueHandlers == null) {
- returnValueHandlers = new ArrayList();
- }
- returnValueHandlers.addAll(methodProcessors());
- argumentResolvers.addAll(methodProcessors());
+ public DefaultMethodEndpointAdapter dhxMethodEndpointAdapter(List dhxMethodProcessors) {
+ final List argumentResolvers = new ArrayList(dhxMethodProcessors);
+ final List returnValueHandlers = new ArrayList(dhxMethodProcessors);
+
argumentResolvers.add(new MessageContextMethodArgumentResolver());
- DefaultMethodEndpointAdapter adapter = new DefaultMethodEndpointAdapter();
- adapter.setMethodArgumentResolvers(argumentResolvers);
- adapter.setMethodReturnValueHandlers(returnValueHandlers);
- return adapter;
+
+ return new DefaultMethodEndpointAdapter() {{
+ setMethodArgumentResolvers(argumentResolvers);
+ setMethodReturnValueHandlers(returnValueHandlers);
+ }};
}
/**
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/marshaller/MarshallerConfig.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/marshaller/MarshallerConfig.java
index 9da23d6d..70a1ee61 100644
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/marshaller/MarshallerConfig.java
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/config/marshaller/MarshallerConfig.java
@@ -49,12 +49,6 @@
import org.xml.sax.helpers.XMLReaderFactory;
-//import org.apache.axiom.om.OMException;
-//import org.apache.axiom.om.OMXMLStreamReader;
-//import javax.xml.stream.XMLStreamReader;
-
-
-
/**
* Contains beans needed for marshalling.
*
@@ -78,10 +72,10 @@ public class MarshallerConfig {
public Jaxb2Marshaller getDhxJaxb2Marshaller() {
DhxJaxb2Marshaller dhxJaxb2Marshaller = null;
dhxJaxb2Marshaller = new DhxJaxb2Marshaller();
- //dhxJaxb2Marshaller.setMtomEnabled(true);
log.debug("Creating marshaller for folowing paths: "
+ dhxConfig.getMarshallContext());
dhxJaxb2Marshaller.setContextPaths(dhxConfig.getMarshallContextAsList());
+ dhxJaxb2Marshaller.setMtomEnabled(true);
return dhxJaxb2Marshaller;
}
@@ -295,7 +289,7 @@ public String addSwaRefAttachment(DataHandler dataHandler) {
String contentId = UUID.randomUUID() + "@" + dataHandler.getName();
this.mimeContainer.addAttachment(contentId, dataHandler);
log.debug("DhxJaxb2AttachmentMarshaller.addSwaRefAttachment contentId={}", contentId);
- return contentId;
+ return CID + contentId;
}
@Override
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/connection/ChunkedHttpComponentsConnection.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/connection/ChunkedHttpComponentsConnection.java
new file mode 100644
index 00000000..97fc4645
--- /dev/null
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/connection/ChunkedHttpComponentsConnection.java
@@ -0,0 +1,66 @@
+package ee.ria.dhx.ws.connection;
+
+import lombok.SneakyThrows;
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.FileEntity;
+import org.apache.http.protocol.HttpContext;
+import org.springframework.ws.WebServiceMessage;
+import org.springframework.ws.transport.http.HttpComponentsConnection;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Field;
+
+public class ChunkedHttpComponentsConnection extends HttpComponentsConnection {
+
+ private final HttpClient httpClient;
+ private final HttpContext httpContext;
+
+ private FileOutputStream requestOutputBuffer;
+ private File tempFile;
+
+ protected ChunkedHttpComponentsConnection(HttpClient httpClient, HttpPost httpPost, HttpContext httpContext) {
+ super(httpClient, httpPost, httpContext);
+ this.httpClient = httpClient;
+ this.httpContext = httpContext;
+ }
+
+ @Override
+ protected void onSendBeforeWrite(WebServiceMessage message) throws IOException {
+ this.tempFile = File.createTempFile("dhx_chunked_", ".tmp");
+ this.requestOutputBuffer = new FileOutputStream(tempFile);
+ }
+
+ @Override
+ protected OutputStream getRequestOutputStream() throws IOException {
+ return this.requestOutputBuffer;
+ }
+
+ @Override
+ protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
+ FileEntity chunkedEntity = new DeleteOnCloseChunkedFileEntity(this.tempFile);
+ this.getHttpPost().setEntity(chunkedEntity);
+ this.requestOutputBuffer = null;
+ this.tempFile = null;
+ if (this.httpContext != null) {
+ setHttpResponse(this.httpClient.execute(this.getHttpPost(), this.httpContext));
+ } else {
+ setHttpResponse(this.httpClient.execute(this.getHttpPost()));
+ }
+ }
+
+ @SneakyThrows
+ private void setHttpResponse(HttpResponse httpResponse) {
+ setParentField("httpResponse", httpResponse);
+ }
+
+ private void setParentField(String fieldName, Object newValue) throws NoSuchFieldException, IllegalAccessException {
+ Field field = getClass().getSuperclass().getDeclaredField(fieldName);
+ FieldUtils.writeField(field, this, newValue, true);
+ }
+}
\ No newline at end of file
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/connection/DeleteOnCloseChunkedFileEntity.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/connection/DeleteOnCloseChunkedFileEntity.java
new file mode 100644
index 00000000..dc48a598
--- /dev/null
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/connection/DeleteOnCloseChunkedFileEntity.java
@@ -0,0 +1,20 @@
+package ee.ria.dhx.ws.connection;
+
+import org.apache.http.entity.FileEntity;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.StandardOpenOption;
+
+public class DeleteOnCloseChunkedFileEntity extends FileEntity {
+ public DeleteOnCloseChunkedFileEntity(File file) {
+ super(file);
+ setChunked(true);
+ }
+
+ public InputStream getContent() throws IOException {
+ return Files.newInputStream(file.toPath(), StandardOpenOption.DELETE_ON_CLOSE);
+ }
+}
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/connection/DhxHttpComponentsMessageSender.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/connection/DhxHttpComponentsMessageSender.java
new file mode 100644
index 00000000..0918ea4e
--- /dev/null
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/connection/DhxHttpComponentsMessageSender.java
@@ -0,0 +1,31 @@
+package ee.ria.dhx.ws.connection;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.protocol.HttpContext;
+import org.springframework.ws.transport.WebServiceConnection;
+import org.springframework.ws.transport.http.HttpComponentsMessageSender;
+import org.springframework.ws.transport.http.HttpTransportConstants;
+
+import java.io.IOException;
+import java.net.URI;
+
+public class DhxHttpComponentsMessageSender extends HttpComponentsMessageSender {
+
+ public DhxHttpComponentsMessageSender(HttpClient httpClient) {
+ super(httpClient);
+ }
+
+ @Override
+ public WebServiceConnection createConnection(URI uri) throws IOException {
+ HttpPost httpPost = new HttpPost(uri);
+ if (this.isAcceptGzipEncoding()) {
+ httpPost.addHeader("Accept-Encoding", "gzip");
+ httpPost.addHeader(HttpTransportConstants.HEADER_CONTENT_TRANSFER_ENCODING, "base64");
+ }
+
+ HttpContext httpContext = this.createContext(uri);
+ return new ChunkedHttpComponentsConnection(this.getHttpClient(), httpPost, httpContext);
+ }
+
+}
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/AddressServiceImpl.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/AddressServiceImpl.java
index 8d91523d..c09f6c11 100644
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/AddressServiceImpl.java
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/AddressServiceImpl.java
@@ -72,6 +72,10 @@ public class AddressServiceImpl implements AddressService {
@Setter
DhxImplementationSpecificService dhxImplementationSpecificService;
+ @Autowired
+ @Setter
+ DhxOrganisationFactory dhxOrganisationFactory;
+
@Autowired
DhxConfig dhxConfig;
@@ -346,12 +350,12 @@ public InternalXroadMember getClientForMemberCode(String memberCode,
List members = getAdresseeList();
Date curDate = new Date();
DhxOrganisation soughtOrganisation =
- DhxOrganisationFactory.createDhxOrganisation(memberCode, system);
+ dhxOrganisationFactory.createDhxOrganisation(memberCode, system);
if (members != null && members.size() > 0) {
log.debug("local adressee list size: {}", members.size());
for (InternalXroadMember member : members) {
DhxOrganisation addresslistOrganisation =
- DhxOrganisationFactory.createDhxOrganisation(member);
+ dhxOrganisationFactory.createDhxOrganisation(member);
if (addresslistOrganisation.equals(soughtOrganisation)) {
if (member.getRepresentee() == null
|| (member.getRepresentee().getStartDate().getTime() <= curDate.getTime()
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/DhxGateway.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/DhxGateway.java
index bc664dbf..29dd7aa9 100644
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/DhxGateway.java
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/DhxGateway.java
@@ -16,7 +16,7 @@
import ee.ria.dhx.types.eu.x_road.xsd.identifiers.XRoadServiceIdentifierType;
import ee.ria.dhx.types.eu.x_road.xsd.representation.XRoadRepresentedPartyType;
import ee.ria.dhx.util.StringUtil;
-import ee.ria.dhx.ws.DhxHttpComponentsMessageSender;
+import ee.ria.dhx.ws.connection.DhxHttpComponentsMessageSender;
import ee.ria.dhx.ws.config.DhxConfig;
import ee.ria.dhx.ws.config.SoapConfig;
import ee.ria.dhx.ws.service.DhxMarshallerService;
@@ -24,7 +24,9 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
+import org.apache.http.client.HttpClient;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.stereotype.Component;
import org.springframework.ws.WebServiceMessage;
@@ -36,8 +38,7 @@
import org.springframework.ws.soap.SoapHeader;
import org.springframework.ws.soap.SoapHeaderElement;
import org.springframework.ws.soap.SoapMessage;
-import org.springframework.ws.soap.saaj.SaajSoapMessage;
-import org.springframework.ws.transport.http.HttpTransportConstants;
+import org.springframework.ws.soap.SoapMessageFactory;
import org.springframework.xml.transform.StringSource;
import java.io.IOException;
@@ -47,20 +48,10 @@
import javax.annotation.PostConstruct;
import javax.xml.bind.JAXBElement;
-import javax.xml.soap.AttachmentPart;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
-import org.apache.http.impl.client.AbstractHttpClient;
-import org.apache.http.conn.ConnectionKeepAliveStrategy;
-import org.apache.http.HeaderElement;
-import org.apache.http.HeaderElementIterator;
-import org.apache.http.HttpResponse;
-import org.apache.http.protocol.HTTP;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.message.BasicHeaderElementIterator;
-
@Slf4j
@@ -88,44 +79,22 @@ public class DhxGateway extends WebServiceGatewaySupport {
@Autowired
Jaxb2Marshaller dhxJaxb2Marshaller;
+ @Autowired
+ HttpClient soapHttpClient;
+
+ @Autowired
+ @Qualifier("axiomSoapMessageFactorySend")
+ SoapMessageFactory messageFactory;
+
/**
* Postconstruct method which sets marshaller and unmarshaller.
*/
@PostConstruct
public void init() {
+ setMessageFactory(messageFactory);
setMarshaller(dhxJaxb2Marshaller);
setUnmarshaller(dhxJaxb2Marshaller);
- DhxHttpComponentsMessageSender messageSender = new DhxHttpComponentsMessageSender();
- messageSender.setConnectionTimeout(soapConfig.getConnectionTimeout());
- messageSender.setReadTimeout(soapConfig.getReadTimeout());
-
-
- AbstractHttpClient httpClient = (AbstractHttpClient)messageSender.getHttpClient();
-
- httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
-
- public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
-
- HeaderElementIterator it = new BasicHeaderElementIterator(
- response.headerIterator(HTTP.CONN_KEEP_ALIVE));
-
- while (it.hasNext()) {
- HeaderElement he = it.nextElement();
- String param = he.getName();
- String value = he.getValue();
- if (value != null && param.equalsIgnoreCase("timeout")) {
-
- try {
- return Long.parseLong(value) * 1000;
- } catch(NumberFormatException ignore) {
- }
-
- }
- }
- // otherwise keep alive for seconds
- return soapConfig.getHttpTimeout() * 1000;
- }
- });
+ DhxHttpComponentsMessageSender messageSender = new DhxHttpComponentsMessageSender(soapHttpClient);
getWebServiceTemplate().setMessageSender(messageSender);
/*
@@ -166,16 +135,6 @@ public void doWithMessage(WebServiceMessage message)
throws IOException, TransformerException {
try {
SoapHeader header = ((SoapMessage) message).getSoapHeader();
- for (Iterator it = ((SaajSoapMessage) message).getSaajMessage()
- .getAttachments(); it.hasNext();) {
- AttachmentPart attachment = (AttachmentPart) it.next();
- log.debug("attachment part: {}",
- attachment.getContentType());
- attachment
- .setMimeHeader(
- HttpTransportConstants.HEADER_CONTENT_TRANSFER_ENCODING,
- "base64");
- }
// Transformer transformer =
// SAXTransformerFactory.newInstance().newTransformer();
TransformerFactory fact = TransformerFactory
@@ -326,6 +285,10 @@ protected SendDocumentResponse sendDocument(OutgoingDhxPackage document,
+ " faultString:"
+ response.getFault().getFaultString()));
} catch (WebServiceFaultException ex) {
+ log.warn("Document send failed: {} ReceiptId: {} Fault: {}",
+ document.getService().toString(),
+ document.getService().getRepresentee(),
+ ex.getMessage());
Fault fault = new Fault();
fault.setFaultCode(ex.getWebServiceMessage().getFaultCode()
.getLocalPart());
@@ -427,10 +390,10 @@ public InternalXroadMember getXroadClientAndSetRersponseHeader(
MessageContext messageContext) throws DhxException {
try {
InternalXroadMember client = null;
- SaajSoapMessage soapRequest = (SaajSoapMessage) messageContext
+ SoapMessage soapRequest = (SoapMessage) messageContext
.getRequest();
SoapHeader reqheader = soapRequest.getSoapHeader();
- SaajSoapMessage soapResponse = (SaajSoapMessage) messageContext
+ SoapMessage soapResponse = (SoapMessage) messageContext
.getResponse();
SoapHeader respheader = soapResponse.getSoapHeader();
TransformerFactory transformerFactory = TransformerFactory
@@ -488,7 +451,7 @@ public InternalXroadMember getXroadClientAndSetRersponseHeader(
public InternalXroadMember getXroadService(MessageContext messageContext)
throws DhxException {
InternalXroadMember service = null;
- SaajSoapMessage soapRequest = (SaajSoapMessage) messageContext
+ SoapMessage soapRequest = (SoapMessage) messageContext
.getRequest();
SoapHeader reqheader = soapRequest.getSoapHeader();
Iterator itr = reqheader.examineAllHeaderElements();
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/DhxMarshallerServiceImpl.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/DhxMarshallerServiceImpl.java
index 2d901672..65186a35 100644
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/DhxMarshallerServiceImpl.java
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/DhxMarshallerServiceImpl.java
@@ -17,6 +17,10 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.xml.serialize.XMLSerializer;
+import org.codehaus.stax2.XMLStreamReader2;
+import org.codehaus.stax2.validation.XMLValidationException;
+import org.codehaus.stax2.validation.XMLValidationSchema;
+import org.codehaus.stax2.validation.XMLValidationSchemaFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Node;
@@ -43,13 +47,13 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import javax.xml.stream.XMLInputFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
/**
* Version DhxMarshallerService for capsules with big data files. No limitation on data file size is
@@ -586,20 +590,27 @@ public void validate(final InputStream fileStream, InputStream schemaStream)
throws DhxException {
try {
log.info("Starting validating document capsule.");
- Source schemaSource = new StreamSource(schemaStream);
// to prevent original inpustream closing crete a new one
- Source xmlFile = new StreamSource(fileStream);
- SchemaFactory schemaFactory = SchemaFactory
- .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema schema = schemaFactory.newSchema(schemaSource);
- Validator validator = schema.newValidator();
- validator.validate(xmlFile);
+ XMLValidationSchemaFactory schemaFactory = XMLValidationSchemaFactory.newInstance(XMLValidationSchema.SCHEMA_ID_W3C_SCHEMA);
+ XMLValidationSchema validationSchema = schemaFactory.createSchema(schemaStream);
+ XMLStreamReader2 xmlStreamReader = (XMLStreamReader2) XMLInputFactory.newInstance().createXMLStreamReader(fileStream);
+ xmlStreamReader.validateAgainst(validationSchema);
+
+ try {
+ while (xmlStreamReader.hasNext()) {
+ xmlStreamReader.next();
+ }
+ } finally {
+ xmlStreamReader.close();
+ }
+
log.info("Document capsule is validated.");
- } catch (Exception ex) {
+ } catch (XMLValidationException ex) {
throw new DhxException(DhxExceptionEnum.CAPSULE_VALIDATION_ERROR,
- "Error occured while validating capsule. "
- + ex.getMessage(),
- ex);
+ "Error occurred while validating capsule. " + ex.getMessage(), ex);
+ } catch (Exception ex) {
+ throw new DhxException(DhxExceptionEnum.TECHNICAL_ERROR,
+ "Error occurred while preparing for capsule validation. " + ex.getMessage(), ex);
}
}
diff --git a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/DhxPackageServiceImpl.java b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/DhxPackageServiceImpl.java
index 180cb05f..7f146a89 100644
--- a/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/DhxPackageServiceImpl.java
+++ b/dhx-adapter-ws/src/main/java/ee/ria/dhx/ws/service/impl/DhxPackageServiceImpl.java
@@ -71,6 +71,9 @@ public class DhxPackageServiceImpl implements DhxPackageService {
@Autowired
DhxImplementationSpecificService dhxImplementationSpecificService;
+ @Autowired
+ DhxOrganisationFactory dhxOrganisationFactory;
+
private void checkProtocolVersion(String protocolVersion)
throws DhxException {
log.debug("checking protocol version " + protocolVersion);
@@ -237,7 +240,7 @@ protected IncomingDhxPackage extractAndValidateDocument(
}
log.info("Document received.");
DhxOrganisation recipient =
- DhxOrganisationFactory.createIncomingRecipientOrgnisation(document, service);
+ dhxOrganisationFactory.createIncomingRecipientOrgnisation(document, service);
IncomingDhxPackage dhxDocument = new IncomingDhxPackage(client,
service, document, container,
CapsuleVersionEnum.forClass(container.getClass()), recipient);
@@ -299,7 +302,7 @@ protected IncomingDhxPackage extractAndValidateDocumentNoParsing(
log.debug("Validating capsule is disabled");
}
DhxOrganisation recipient =
- DhxOrganisationFactory.createIncomingRecipientOrgnisation(document, service);
+ dhxOrganisationFactory.createIncomingRecipientOrgnisation(document, service);
IncomingDhxPackage dhxDocument = new IncomingDhxPackage(client,
service, document, recipient);
if (config.getCheckRecipient()) {
@@ -348,13 +351,13 @@ protected void checkRecipient(DhxOrganisation recipient,
if (representee.getStartDate().getTime() <= curDate.getTime()
&& (representee.getEndDate() == null || representee
.getEndDate().getTime() >= curDate.getTime())) {
- recipientList.add(DhxOrganisationFactory.createDhxOrganisation(representee
+ recipientList.add(dhxOrganisationFactory.createDhxOrganisation(representee
.getRepresenteeCode(), representee.getRepresenteeSystem()));
}
}
}
for (String subSystem : soapConfig.getAcceptedSubsystemsAsList()) {
- recipientList.add(DhxOrganisationFactory.createDhxOrganisation(soapConfig.getMemberCode(),
+ recipientList.add(dhxOrganisationFactory.createDhxOrganisation(soapConfig.getMemberCode(),
subSystem));
}
Boolean found = false;
@@ -403,7 +406,7 @@ protected void checkRecipient(DhxOrganisation recipient,
protected void checkSender(InternalXroadMember client,
CapsuleAdressee capsuleSender) throws DhxException {
log.info("Checking sender.");
- DhxOrganisation sender = DhxOrganisationFactory.createDhxOrganisation(client);
+ DhxOrganisation sender = dhxOrganisationFactory.createDhxOrganisation(client);
if (client.getRepresentee() != null) {
InternalXroadMember member = addressService.getClientForMemberCode(
client.getMemberCode(), client.getSubsystemCode());
diff --git a/dhx-adapter-ws/src/main/resources/application.properties.example b/dhx-adapter-ws/src/main/resources/application.properties.example
index 01eba7bf..813945d2 100644
--- a/dhx-adapter-ws/src/main/resources/application.properties.example
+++ b/dhx-adapter-ws/src/main/resources/application.properties.example
@@ -54,6 +54,14 @@ soap.accepted-subsystems=DHX,DHX.subsystem
#soap.read-timeout=120000
#soap.http-timeout=300
+# # # # #
+# Increasing memory efficiency while sending large documents
+# # # # #
+# Tells DHX to use filesystem caching instead of memory if attachment size is bigger than following value in MB.
+#soap.dhx.attachment.cache.threshold=10
+# Specify directory to be used for caching. By default Java temp directory.
+#soap.dhx.attachment.cache.dir=
+
#template representing how many times and with how bug timeouts document will be resent.
#for example 5,10,15 means that after first failed try application will wait 5 seconds and try again.
#If second attempt fails, then there will be 10 seconds timeout before third attempt and so on
diff --git a/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/TestApp.java b/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/TestApp.java
index 5f278330..81fc789b 100644
--- a/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/TestApp.java
+++ b/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/TestApp.java
@@ -13,10 +13,16 @@
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.test.context.TestPropertySource;
+import org.springframework.ws.soap.SoapMessageFactory;
// @SpringBootApplication
@TestPropertySource("classpath:test-application.properties")
-@ComponentScan(basePackages = "ee.ria.dhx.ws.config,ee.ria.dhx.ws.config.endpoint,ee.ria.dhx.ws,ee.ria.dhx.ws.service.impl")
+@ComponentScan(basePackages = {
+ "ee.ria.dhx.ws.config",
+ "ee.ria.dhx.ws.config.endpoint",
+ "ee.ria.dhx.ws",
+ "ee.ria.dhx.ws.service.impl"
+})
@Slf4j
// @EnableAutoConfiguration
public class TestApp {
@@ -49,4 +55,10 @@ public DhxImplementationSpecificService getDhxImplementationSpecificService()
return specificService;
}
+ @Bean
+ @Primary
+ public SoapMessageFactory messageFactory(SoapMessageFactory axiomSoapMessageFactorySend) {
+ return Mockito.spy(axiomSoapMessageFactorySend);
+ }
+
}
diff --git a/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/integration/DhxServerIT.java b/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/integration/DhxServerIT.java
index 6633720f..350f382e 100644
--- a/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/integration/DhxServerIT.java
+++ b/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/integration/DhxServerIT.java
@@ -5,6 +5,7 @@
import static org.springframework.ws.test.server.RequestCreators.withSoapEnvelope;
import ee.ria.dhx.exception.DhxException;
+import ee.ria.dhx.mock.MockWebServiceClient;
import ee.ria.dhx.types.DhxRepresentee;
import ee.ria.dhx.types.IncomingDhxPackage;
import ee.ria.dhx.types.InternalXroadMember;
@@ -17,11 +18,6 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-/*
- * import org.springframework.ws.test.server.MockWebServiceClient; import
- * org.springframework.ws.test.server.RequestCreator; import
- * org.springframework.ws.test.server.RequestCreators;
- */
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@@ -32,7 +28,6 @@
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.ws.context.MessageContext;
-import org.springframework.ws.test.server.MockWebServiceClient;
import org.springframework.ws.test.server.ResponseMatchers;
import java.util.ArrayList;
@@ -46,8 +41,6 @@
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
-// import org.springframework.test.context.junit4.SpringRunner;
-
/**
* Tests on DhxEndpoint. Real XML-s are sent to endpoint and received response is being validated.
*
diff --git a/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/service/impl/AddressServiceImplTest.java b/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/service/impl/AddressServiceImplTest.java
index dadee1b1..84cab902 100644
--- a/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/service/impl/AddressServiceImplTest.java
+++ b/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/service/impl/AddressServiceImplTest.java
@@ -25,6 +25,8 @@
import ee.ria.dhx.ws.service.DhxImplementationSpecificService;
import ee.ria.dhx.ws.service.DhxMarshallerService;
+import org.mockito.InjectMocks;
+import org.mockito.Spy;
import org.springframework.core.io.ClassPathResource;
import org.junit.Before;
@@ -39,7 +41,6 @@
import java.io.IOException;
import java.io.InputStream;
-import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -64,6 +65,9 @@ public class AddressServiceImplTest {
@Mock
DhxGateway dhxGateway;
+ @InjectMocks
+ DhxOrganisationFactory dhxOrganisationFactory;
+
AddressServiceImpl addressService;
@Mock
@@ -80,11 +84,11 @@ public void init() {
addressService.setDhxGateway(dhxGateway);
addressService.setDhxMarshallerService(dhxMarshallerService);
addressService.setDhxImplementationSpecificService(specificService);
+ addressService.setDhxOrganisationFactory(dhxOrganisationFactory);
when(config.getXroadInstance()).thenReturn("ee");
when(config.getDhxRepresentationGroupName()).thenReturn("DHX vahendajad");
when(config.getDhxSubsystemPrefix()).thenReturn("DHX");
//when(config.getGlobalConfLocation()).thenReturn("http://x-road.eu/packages/EE_public-anchor.xml");
- DhxOrganisationFactory.setDhxSubsystemPrefix("DHX");
}
@Test
diff --git a/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/service/impl/DhxPackageServceImplTest.java b/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/service/impl/DhxPackageServceImplTest.java
index 37c93ff5..94dcab60 100644
--- a/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/service/impl/DhxPackageServceImplTest.java
+++ b/dhx-adapter-ws/src/test/java/ee/ria/dhx/ws/service/impl/DhxPackageServceImplTest.java
@@ -4,6 +4,7 @@
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -21,6 +22,7 @@
import ee.ria.dhx.types.eu.x_road.dhx.producer.SendDocument;
import ee.ria.dhx.types.eu.x_road.dhx.producer.SendDocumentResponse;
import ee.ria.dhx.util.CapsuleVersionEnum;
+import ee.ria.dhx.util.FileDataHandler;
import ee.ria.dhx.util.FileUtil;
import ee.ria.dhx.ws.DhxOrganisationFactory;
import ee.ria.dhx.ws.config.CapsuleConfig;
@@ -29,59 +31,76 @@
import ee.ria.dhx.ws.service.DhxImplementationSpecificService;
import ee.ria.dhx.ws.service.DhxMarshallerService;
+import org.assertj.core.util.Lists;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.springframework.core.io.ClassPathResource;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.springframework.util.ResourceUtils;
import org.springframework.ws.context.MessageContext;
-import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+
+@RunWith(MockitoJUnitRunner.class)
public class DhxPackageServceImplTest {
- @Mock
- DhxGateway dhxGateway;
+ private static final String FILE_NAME_KAPSEL_21_XML = "kapsel_21.xml";
+ private FileDataHandler FILE_HANDLER_KAPSEL_21_XML = FileUtil.getDatahandlerFromFile(
+ ResourceUtils.getFile("classpath:" + FILE_NAME_KAPSEL_21_XML)
+ );
+
+ private final SendDocument REQUEST = new SendDocument() {{
+ consignmentId = "consignmentId";
+ documentAttachment = FILE_HANDLER_KAPSEL_21_XML;
+ dhxVersion = "1.0";
+ }};
+ private final InternalXroadMember CLIENT = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
+ private final InternalXroadMember SERVICE = new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ private final InternalXroadMember SERVICE_SUBSYSTEM = new InternalXroadMember("ee", "GOV", "401", "DHX.subsystem", "Name", null);
@Mock
- DhxImplementationSpecificService dhxImplementationSpecificService;
+ private DhxGateway dhxGateway;
@Mock
- DhxConfig dhxConfig;
+ private DhxImplementationSpecificService dhxImplementationSpecificService;
- DhxPackageServiceImpl dhxPackageService;
+ @Mock
+ private DhxConfig dhxConfig;
@Mock
- DhxMarshallerService dhxMarshallerService;
+ private DhxMarshallerService dhxMarshallerService;
@Mock
- CapsuleConfig capsuleConfig;
+ private CapsuleConfig capsuleConfig;
@Mock
- SoapConfig soapConfig;
+ private SoapConfig soapConfig;
+
+ @InjectMocks
+ private DhxOrganisationFactory dhxOrganisationFactory = spy(DhxOrganisationFactory.class);
+
+ @InjectMocks
+ private DhxPackageServiceImpl dhxPackageService;
@Rule
public ExpectedException expectedEx = ExpectedException.none();
+ public DhxPackageServceImplTest() throws FileNotFoundException {}
+
@Before
public void init() throws DhxException {
- MockitoAnnotations.initMocks(this);
- dhxPackageService = new DhxPackageServiceImpl();
- dhxPackageService.setDocumentGateway(dhxGateway);
- dhxPackageService.setDhxImplementationSpecificService(dhxImplementationSpecificService);
- dhxPackageService.setConfig(dhxConfig);
- dhxPackageService.setDhxMarshallerService(dhxMarshallerService);
- dhxPackageService.setCapsuleConfig(capsuleConfig);
- dhxPackageService.setSoapConfig(soapConfig);
when(dhxConfig.getCapsuleValidate()).thenReturn(true);
when(dhxConfig.getCheckDhxVersion()).thenReturn(true);
when(dhxConfig.getCheckDuplicate()).thenReturn(true);
@@ -90,25 +109,23 @@ public void init() throws DhxException {
when(dhxConfig.getParseCapsule()).thenReturn(true);
when(dhxConfig.getParseCapsule()).thenReturn(true);
when(dhxConfig.getAcceptedDhxProtocolVersions()).thenReturn(",1.0,");
+
when(capsuleConfig.getCurrentCapsuleVersion()).thenReturn(CapsuleVersionEnum.V21);
- when(capsuleConfig.getXsdForVersion(CapsuleVersionEnum.V21)).thenReturn(
- "jar://Dvk_kapsel_vers_2_1_eng_est.xsd");
- DhxOrganisationFactory.setDhxSubsystemPrefix("DHX");
- List subsystems = new ArrayList();
- subsystems.add("DHX");
+ when(capsuleConfig.getXsdForVersion(CapsuleVersionEnum.V21)).thenReturn("jar://Dvk_kapsel_vers_2_1_eng_est.xsd");
+
+ List subsystems = Lists.newArrayList("DHX");
when(soapConfig.getAcceptedSubsystemsAsList()).thenReturn(subsystems);
when(soapConfig.getMemberCode()).thenReturn("401");
+ when(soapConfig.getDhxSubsystemPrefix()).thenReturn("DHX");
- List adressees = new ArrayList();
- CapsuleAdressee adressee = new CapsuleAdressee("401");
- adressees.add(adressee);
- when(capsuleConfig.getAdresseesFromContainer(any())).thenReturn(adressees);
+ CapsuleAdressee addressee = new CapsuleAdressee("401");
+ List addressees = Lists.newArrayList(addressee);
+ when(capsuleConfig.getAdresseesFromContainer(any())).thenReturn(addressees);
CapsuleAdressee sender = new CapsuleAdressee("400");
when(capsuleConfig.getSenderFromContainer(any())).thenReturn(sender);
- when(
- dhxImplementationSpecificService.isDuplicatePackage(any(InternalXroadMember.class),
- anyString())).thenReturn(false);
+ when(dhxImplementationSpecificService.isDuplicatePackage(any(InternalXroadMember.class), anyString()))
+ .thenReturn(false);
}
@@ -116,10 +133,13 @@ public void init() throws DhxException {
@Test
public void sendPackage() throws DhxException {
+ // Prepare
OutgoingDhxPackage pckg = new OutgoingDhxPackage(null, null, null, null, null);
SendDocumentResponse resp = new SendDocumentResponse();
when(dhxGateway.sendDocument(pckg)).thenReturn(resp);
+ // Test
DhxSendDocumentResult result = dhxPackageService.sendPackage(pckg);
+ // Verify
assertEquals(pckg, result.getSentPackage());
assertEquals(resp, result.getResponse());
verify(dhxGateway, times(1)).sendDocument(pckg);
@@ -127,13 +147,16 @@ public void sendPackage() throws DhxException {
@Test
public void sendMultiplePackages() throws DhxException {
+ // Prepare
List pckgs = new ArrayList();
OutgoingDhxPackage pckg = new OutgoingDhxPackage(null, null, null, null, null);
pckgs.add(pckg);
pckgs.add(pckg);
SendDocumentResponse resp = new SendDocumentResponse();
when(dhxGateway.sendDocument(pckg)).thenReturn(resp);
+ // Test
List results = dhxPackageService.sendMultiplePackages(pckgs);
+ // Verify
assertEquals(2, results.size());
assertEquals(pckg, results.get(0).getSentPackage());
assertEquals(resp, results.get(0).getResponse());
@@ -159,45 +182,29 @@ private DecContainer getContainer() {
@Test
public void receiveDocumentFromEndpoint() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
- SendDocumentResponse response =
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Test
+ SendDocumentResponse response = dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
+ // Verify
assertEquals("id1", response.getReceiptId());
assertNull(response.getFault());
- verify(dhxMarshallerService, times(1)).unmarshallAndValidate(any(InputStream.class),
- any(InputStream.class));
- verify(dhxImplementationSpecificService, times(1)).receiveDocument(
- any(IncomingDhxPackage.class), any(MessageContext.class));
- verify(dhxImplementationSpecificService, times(1)).isDuplicatePackage(
- any(InternalXroadMember.class), anyString());
+ verify(dhxMarshallerService, times(1))
+ .unmarshallAndValidate(any(InputStream.class), any(InputStream.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .isDuplicatePackage(any(InternalXroadMember.class), anyString());
}
@Test
public void receiveDocumentFromEndpointToRepresentee() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- request.setRecipient("410");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
+ REQUEST.setRecipient("410");
List representees = new ArrayList();
DhxRepresentee representee = new DhxRepresentee("410", new Date(), null, null, null);
representees.add(representee);
@@ -207,38 +214,29 @@ public void receiveDocumentFromEndpointToRepresentee() throws DhxException, IOEx
when(capsuleConfig.getAdresseesFromContainer(any())).thenReturn(adressees);
when(dhxImplementationSpecificService.getRepresentationList()).thenReturn(representees);
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
- SendDocumentResponse response =
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Test
+ SendDocumentResponse response = dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
+ // Verify
assertEquals("id1", response.getReceiptId());
assertNull(response.getFault());
- verify(dhxMarshallerService, times(1)).unmarshallAndValidate(any(InputStream.class),
- any(InputStream.class));
- verify(dhxImplementationSpecificService, times(1)).receiveDocument(
- any(IncomingDhxPackage.class), any(MessageContext.class));
- verify(dhxImplementationSpecificService, times(1)).isDuplicatePackage(
- any(InternalXroadMember.class), anyString());
+ verify(dhxMarshallerService, times(1))
+ .unmarshallAndValidate(any(InputStream.class), any(InputStream.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .isDuplicatePackage(any(InternalXroadMember.class), anyString());
}
@Test
public void receiveDocumentFromEndpointToRepresenteeSubsystem() throws DhxException,
IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- request.setRecipient("410");
- request.setRecipientSystem("subsystem");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
+ REQUEST.setRecipient("410");
+ REQUEST.setRecipientSystem("subsystem");
List representees = new ArrayList();
DhxRepresentee representee = new DhxRepresentee("410", new Date(), null, null, "subsystem");
representees.add(representee);
@@ -248,519 +246,367 @@ public void receiveDocumentFromEndpointToRepresenteeSubsystem() throws DhxExcept
when(capsuleConfig.getAdresseesFromContainer(any())).thenReturn(adressees);
when(dhxImplementationSpecificService.getRepresentationList()).thenReturn(representees);
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
- SendDocumentResponse response =
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ SendDocumentResponse response = dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
+ // Verify
assertEquals("id1", response.getReceiptId());
assertNull(response.getFault());
- verify(dhxMarshallerService, times(1)).unmarshallAndValidate(any(InputStream.class),
- any(InputStream.class));
- verify(dhxImplementationSpecificService, times(1)).receiveDocument(
- any(IncomingDhxPackage.class), any(MessageContext.class));
- verify(dhxImplementationSpecificService, times(1)).isDuplicatePackage(
- any(InternalXroadMember.class), anyString());
+ verify(dhxMarshallerService, times(1))
+ .unmarshallAndValidate(any(InputStream.class), any(InputStream.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .isDuplicatePackage(any(InternalXroadMember.class), anyString());
}
@Test
public void receiveDocumentFromEndpointToRepresenteeOutdated() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- request.setRecipient("410");
- request.setRecipientSystem("subsystem");
+ // Prepare
+ REQUEST.setRecipient("410");
+ REQUEST.setRecipientSystem("subsystem");
Date date = new Date();
Date date2 = new Date(date.getTime()-10000);
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
List representees = new ArrayList();
DhxRepresentee representee = new DhxRepresentee("410", date, date2, null, "subsystem");
representees.add(representee);
when(dhxImplementationSpecificService.getRepresentationList()).thenReturn(representees);
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Verify
expectedEx.expect(DhxException.class);
expectedEx
.expectMessage("DHX.InvalidAddressee Recipient not found in representativesList and own member code");
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
}
@Test
public void receiveDocumentFromEndpointToRepresenteeWrongCapsuleAdressee() throws DhxException,
IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- request.setRecipient("410");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
+ REQUEST.setRecipient("410");
List representees = new ArrayList();
DhxRepresentee representee = new DhxRepresentee("410", new Date(), null, null, null);
representees.add(representee);
when(dhxImplementationSpecificService.getRepresentationList()).thenReturn(representees);
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Verify
expectedEx.expect(DhxException.class);
- expectedEx
- .expectMessage("DHX.InvalidAddressee Recipient not found in capsule recipient list");
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ expectedEx.expectMessage("DHX.InvalidAddressee Recipient not found in capsule recipient list");
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
}
@Test
public void receiveDocumentFromEndpointToWrongRepresentee() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- request.setRecipient("420");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
+ REQUEST.setRecipient("420");
List representees = new ArrayList();
DhxRepresentee representee = new DhxRepresentee("410", new Date(), null, null, "subsystem");
representees.add(representee);
when(dhxImplementationSpecificService.getRepresentationList()).thenReturn(representees);
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Verify
expectedEx.expect(DhxException.class);
expectedEx
.expectMessage("DHX.InvalidAddressee Recipient not found in representativesList and own member code");
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
}
@Test
public void receiveDocumentFromEndpointToWrongRepresenteeSubsystem() throws DhxException,
IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- request.setRecipient("410");
- request.setRecipientSystem("subsystem2");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
+ REQUEST.setRecipient("410");
+ REQUEST.setRecipientSystem("subsystem2");
List representees = new ArrayList();
DhxRepresentee representee = new DhxRepresentee("410", new Date(), null, null, "subsystem");
representees.add(representee);
when(dhxImplementationSpecificService.getRepresentationList()).thenReturn(representees);
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Verify
expectedEx.expect(DhxException.class);
expectedEx
.expectMessage("DHX.InvalidAddressee Recipient not found in representativesList and own member code");
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
}
@Test
public void receiveDocumentFromEndpointNonDefaultSubsystem() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX.subsystem", "Name", null);
- DhxOrganisationFactory.setDhxSubsystemPrefix("DHX");
- List subsystems = new ArrayList();
- subsystems.add("DHX.subsystem");
+ // Prepare
+ List subsystems = Lists.newArrayList("DHX.subsystem");
when(soapConfig.getAcceptedSubsystemsAsList()).thenReturn(subsystems);
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Test
SendDocumentResponse response =
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE_SUBSYSTEM, null);
+ // Verify
assertEquals("id1", response.getReceiptId());
assertNull(response.getFault());
- verify(dhxMarshallerService, times(1)).unmarshallAndValidate(any(InputStream.class),
- any(InputStream.class));
- verify(dhxImplementationSpecificService, times(1)).receiveDocument(
- any(IncomingDhxPackage.class), any(MessageContext.class));
- verify(dhxImplementationSpecificService, times(1)).isDuplicatePackage(
- any(InternalXroadMember.class), anyString());
+ verify(dhxMarshallerService, times(1))
+ .unmarshallAndValidate(any(InputStream.class), any(InputStream.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .isDuplicatePackage(any(InternalXroadMember.class), anyString());
}
@Test
public void receiveDocumentFromEndpointWrongSubsystem() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX.subsystem", "Name", null);
+ // Prepare
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Verify
expectedEx.expect(DhxException.class);
expectedEx
.expectMessage("DHX.InvalidAddressee Recipient not found in representativesList and own member code");
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE_SUBSYSTEM, null);
}
@Test
public void receiveDocumentFromEndpointNoParsing() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
when(dhxConfig.getParseCapsule()).thenReturn(false);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
- verify(dhxMarshallerService, times(1)).validate(any(InputStream.class),
- any(InputStream.class));
- verify(dhxMarshallerService, times(0)).unmarshallAndValidate(any(InputStream.class),
- any(InputStream.class));
- verify(dhxImplementationSpecificService, times(1)).receiveDocument(
- any(IncomingDhxPackage.class), any(MessageContext.class));
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
+ // Verify
+ verify(dhxMarshallerService, times(1))
+ .validate(any(InputStream.class), any(InputStream.class));
+ verify(dhxMarshallerService, times(0))
+ .unmarshallAndValidate(any(InputStream.class), any(InputStream.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class));
}
@Test
public void receiveDocumentFromEndpointNovalidation() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
when(dhxConfig.getCapsuleValidate()).thenReturn(false);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
- verify(dhxMarshallerService, times(1)).unmarshallAndValidate(any(InputStream.class),
- Mockito.isNull(InputStream.class));
- verify(dhxImplementationSpecificService, times(1)).receiveDocument(
- any(IncomingDhxPackage.class), any(MessageContext.class));
- verify(dhxImplementationSpecificService, times(1)).isDuplicatePackage(
- any(InternalXroadMember.class), anyString());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
+ // Verify
+ verify(dhxMarshallerService, times(1))
+ .unmarshallAndValidate(any(InputStream.class), Mockito.isNull(InputStream.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .isDuplicatePackage(any(InternalXroadMember.class), anyString());
}
@Test
public void receiveDocumentFromEndpointNoValidationNoParsing() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
when(dhxConfig.getCapsuleValidate()).thenReturn(false);
when(dhxConfig.getParseCapsule()).thenReturn(false);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
- verify(dhxMarshallerService, times(0)).unmarshallAndValidate(any(InputStream.class),
- any(InputStream.class));
- verify(dhxMarshallerService, times(0)).validate(any(InputStream.class),
- Mockito.isNull(InputStream.class));
- verify(dhxImplementationSpecificService, times(1)).receiveDocument(
- any(IncomingDhxPackage.class), any(MessageContext.class));
- verify(dhxImplementationSpecificService, times(1)).isDuplicatePackage(
- any(InternalXroadMember.class), anyString());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
+ // Verify
+ verify(dhxMarshallerService, times(0))
+ .unmarshallAndValidate(any(InputStream.class), any(InputStream.class));
+ verify(dhxMarshallerService, times(0))
+ .validate(any(InputStream.class), Mockito.isNull(InputStream.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class));
+ verify(dhxImplementationSpecificService, times(1))
+ .isDuplicatePackage(any(InternalXroadMember.class), anyString());
}
@Test
public void receiveDocumentFromEndpointDuplicate() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
- when(
- dhxImplementationSpecificService.isDuplicatePackage(any(InternalXroadMember.class),
- anyString())).thenReturn(true);
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ when(dhxImplementationSpecificService.isDuplicatePackage(any(InternalXroadMember.class), anyString()))
+ .thenReturn(true);
+ // Verify
expectedEx.expect(DhxException.class);
expectedEx.expectMessage("DHX.Duplicate Already got package with this consignmentID");
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
- verify(dhxImplementationSpecificService, times(1)).isDuplicatePackage(
- any(InternalXroadMember.class), anyString());
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
+ // Verify
+ verify(dhxImplementationSpecificService, times(1))
+ .isDuplicatePackage(any(InternalXroadMember.class), anyString());
}
@Test
public void receiveDocumentFromEndpointRepresenteeSender() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
+ // Prepare
List adressees = new ArrayList();
CapsuleAdressee adressee = new CapsuleAdressee("500");
adressees.add(adressee);
when(capsuleConfig.getAdresseesFromContainer(any())).thenReturn(adressees);
DhxRepresentee representee = new DhxRepresentee("400", null, null, null, null);
representee.setRepresenteeCode("400");
- InternalXroadMember client =
- new InternalXroadMember("ee", "GOV", "420", "DHX", "Name", representee);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Verify
expectedEx.expect(DhxException.class);
- expectedEx
- .expectMessage("DHX.InvalidAddressee Recipient not found in capsule recipient list");
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ expectedEx.expectMessage("DHX.InvalidAddressee Recipient not found in capsule recipient list");
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
}
@Test
public void receiveDocumentFromEndpointWrongCapsuleAdressee() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
+ // Prepare
List adressees = new ArrayList();
CapsuleAdressee adressee = new CapsuleAdressee("500");
adressees.add(adressee);
when(capsuleConfig.getAdresseesFromContainer(any())).thenReturn(adressees);
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Verify
expectedEx.expect(DhxException.class);
- expectedEx
- .expectMessage("DHX.InvalidAddressee Recipient not found in capsule recipient list");
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ expectedEx.expectMessage("DHX.InvalidAddressee Recipient not found in capsule recipient list");
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
}
@Test
public void receiveDocumentFromEndpointWrongAdressee() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "501", "DHX", "Name", null);
+ InternalXroadMember service = new InternalXroadMember("ee", "GOV", "501", "DHX", "Name", null);
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Verify
expectedEx.expect(DhxException.class);
- expectedEx
- .expectMessage("DHX.InvalidAddressee Recipient not found in representativesList and own member code");
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ expectedEx.expectMessage("DHX.InvalidAddressee Recipient not found in representativesList and own member code");
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, service, null);
}
@Test
public void receiveDocumentFromEndpointNoRecipientCheck() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
+ // Prepare
List adressees = new ArrayList();
CapsuleAdressee adressee = new CapsuleAdressee("500");
adressees.add(adressee);
when(capsuleConfig.getAdresseesFromContainer(any())).thenReturn(adressees);
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
when(dhxConfig.getCheckRecipient()).thenReturn(false);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
- SendDocumentResponse response =
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Test
+ SendDocumentResponse response = dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
+ // Verify
assertEquals("id1", response.getReceiptId());
assertNull(response.getFault());
}
@Test
public void receiveDocumentFromEndpointWrongSender() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
InternalXroadMember client = new InternalXroadMember("ee", "GOV", "500", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Verify
expectedEx.expect(DhxException.class);
expectedEx.expectMessage("DHX.SenderDoesNotMatch Xroad sender not found in capsule");
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, client, SERVICE, null);
}
@Test
public void receiveDocumentFromEndpointNoSenderCheck() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- request.setDHXVersion("1.0");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "500", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
when(dhxConfig.getCheckSender()).thenReturn(false);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
- SendDocumentResponse response =
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ SendDocumentResponse response = dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
+ // Verify
assertEquals("id1", response.getReceiptId());
+ // Test
assertNull(response.getFault());
}
@Test
public void receiveDocumentFromEndpointWrongVersion() throws DhxException, IOException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- request.setDHXVersion("2.0");
- File file = new ClassPathResource("kapsel_21.xml").getFile();
- request.setDocumentAttachment(FileUtil.getDatahandlerFromFile(file));
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
+ REQUEST.setDHXVersion("2.0");
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Verify
expectedEx.expect(DhxException.class);
expectedEx.expectMessage("DHX.UnsupportedVersion Version not supported");
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
}
@Test
public void receiveDocumentFromEndpointNoDocument() throws DhxException {
- SendDocument request = new SendDocument();
- request.setConsignmentId("consignmentId");
- request.setDHXVersion("1.0");
- InternalXroadMember client = new InternalXroadMember("ee", "GOV", "400", "DHX", "Name", null);
- InternalXroadMember service =
- new InternalXroadMember("ee", "GOV", "401", "DHX", "Name", null);
+ // Prepare
+ REQUEST.setDocumentAttachment(null);
when(dhxConfig.getParseCapsule()).thenReturn(true);
- when(
- dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class),
- any(MessageContext.class))).thenReturn("id1");
- when(
- dhxMarshallerService
- .unmarshallAndValidate(any(InputStream.class), any(InputStream.class))).thenReturn(
- new DecContainer());
+ when(dhxImplementationSpecificService.receiveDocument(any(IncomingDhxPackage.class), any(MessageContext.class)))
+ .thenReturn("id1");
+ when(dhxMarshallerService.unmarshallAndValidate(any(InputStream.class), any(InputStream.class)))
+ .thenReturn(new DecContainer());
+ // Verify
expectedEx.expect(DhxException.class);
expectedEx.expectMessage("Attached capsule is not found in request");
- dhxPackageService.receiveDocumentFromEndpoint(request, client, service, null);
+ // Test
+ dhxPackageService.receiveDocumentFromEndpoint(REQUEST, CLIENT, SERVICE, null);
}
}
diff --git a/dhx-adapter-ws/src/test/resources/Dvk_kapsel_vers_2_1_eng_est.xsd b/dhx-adapter-ws/src/test/resources/Dvk_kapsel_vers_2_1_eng_est.xsd
index 75c73a6c..041e9b5a 100644
--- a/dhx-adapter-ws/src/test/resources/Dvk_kapsel_vers_2_1_eng_est.xsd
+++ b/dhx-adapter-ws/src/test/resources/Dvk_kapsel_vers_2_1_eng_est.xsd
@@ -643,7 +643,7 @@
-
+
diff --git a/dhx-adapter-ws/src/test/resources/test-application.properties b/dhx-adapter-ws/src/test/resources/test-application.properties
index ea642976..40c1b642 100644
--- a/dhx-adapter-ws/src/test/resources/test-application.properties
+++ b/dhx-adapter-ws/src/test/resources/test-application.properties
@@ -29,7 +29,7 @@ dhx.parse-capsule=true
#soap.security-server-appender=/cgi-bin/consumer_proxy
-soap.security-server=https://try
+soap.security-server=http://try
soap.xroad-instance=ee-dev
soap.member-class=GOV
soap.protocol-version=4.0
diff --git a/pom.xml b/pom.xml
index ce9eccb8..75384416 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,9 +5,11 @@
ee.ria.dhx
DHX-adapter
- 1.0.4
+ ${revision}
pom
+ 1.0.4-SNAPSHOT
+
UTF-8
1.7
@@ -77,7 +79,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M1
+ 3.0.0-M3
org.apache.maven.plugins
@@ -185,7 +187,7 @@
org.apache.maven.plugins
maven-failsafe-plugin
- 3.0.0-M1
+ 3.0.0-M3