From d93cb99ce2c37963b4cad56fb5ec9a12529eaa67 Mon Sep 17 00:00:00 2001 From: Erlend Klakegg Bergheim Date: Wed, 24 Feb 2016 14:50:31 +0100 Subject: [PATCH] Fixing bug when reading very short ServiceGroup responses. --- .../no/difi/vefa/peppol/lookup/reader/MultiReader.java | 5 +++-- .../no/difi/vefa/peppol/lookup/LookupClientTest.java | 10 ++++++++++ .../vefa/peppol/lookup/reader/MultiReaderTest.java | 7 +++++++ .../resources/busdox-servicegroup-9915-setcce-test.xml | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 peppol-lookup/src/test/resources/busdox-servicegroup-9915-setcce-test.xml diff --git a/peppol-lookup/src/main/java/no/difi/vefa/peppol/lookup/reader/MultiReader.java b/peppol-lookup/src/main/java/no/difi/vefa/peppol/lookup/reader/MultiReader.java index 67c653ef..da69d441 100644 --- a/peppol-lookup/src/main/java/no/difi/vefa/peppol/lookup/reader/MultiReader.java +++ b/peppol-lookup/src/main/java/no/difi/vefa/peppol/lookup/reader/MultiReader.java @@ -11,6 +11,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.SequenceInputStream; +import java.util.Arrays; import java.util.List; public class MultiReader implements MetadataReader { @@ -44,11 +45,11 @@ else if (BdxrReader.NAMESPACE.equalsIgnoreCase(fetcherResponse.getNamespace())) throw new LookupException(String.format("Unknown namespace: %s", fetcherResponse.getNamespace())); } - @SuppressWarnings("all") public FetcherResponse detect(FetcherResponse fetcherResponse) throws LookupException { try { byte[] fileContent = new byte[1024]; - fetcherResponse.getInputStream().read(fileContent); + int size = fetcherResponse.getInputStream().read(fileContent); + fileContent = Arrays.copyOfRange(fileContent, 0, size); String namespace = XmlUtils.extractRootNamespace(new String(fileContent)); if (namespace != null) { diff --git a/peppol-lookup/src/test/java/no/difi/vefa/peppol/lookup/LookupClientTest.java b/peppol-lookup/src/test/java/no/difi/vefa/peppol/lookup/LookupClientTest.java index 9a2d05c5..64375050 100644 --- a/peppol-lookup/src/test/java/no/difi/vefa/peppol/lookup/LookupClientTest.java +++ b/peppol-lookup/src/test/java/no/difi/vefa/peppol/lookup/LookupClientTest.java @@ -7,6 +7,7 @@ import no.difi.vefa.peppol.lookup.fetcher.UrlFetcher; import no.difi.vefa.peppol.lookup.locator.BusdoxLocator; import no.difi.vefa.peppol.lookup.locator.DynamicLocator; +import no.difi.vefa.peppol.lookup.reader.BusdoxReader; import org.testng.annotations.Test; import java.util.List; @@ -42,6 +43,15 @@ public void simpleEndpoint() throws PeppolException { assertNotNull(endpoint); } + @Test(groups = "full") + public void simple9915() throws PeppolException { + LookupClient client = LookupClientBuilder.forTest().fetcher(new UrlFetcher()).build(); + List documentTypeIdentifiers = client.getDocumentIdentifiers(new ParticipantIdentifier("9915:setcce-test")); + + assertNotNull(documentTypeIdentifiers); + assertNotEquals(documentTypeIdentifiers.size(), 0); + } + @Test(groups = "full") public void simple9933() throws PeppolException { LookupClient client = LookupClientBuilder.forProduction().fetcher(new UrlFetcher()).build(); diff --git a/peppol-lookup/src/test/java/no/difi/vefa/peppol/lookup/reader/MultiReaderTest.java b/peppol-lookup/src/test/java/no/difi/vefa/peppol/lookup/reader/MultiReaderTest.java index 057df83c..fec84f26 100644 --- a/peppol-lookup/src/test/java/no/difi/vefa/peppol/lookup/reader/MultiReaderTest.java +++ b/peppol-lookup/src/test/java/no/difi/vefa/peppol/lookup/reader/MultiReaderTest.java @@ -6,6 +6,7 @@ import no.difi.vefa.peppol.common.model.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.testng.Assert; import org.testng.annotations.Test; import java.util.List; @@ -103,4 +104,10 @@ public void bdxrServiceMetadata() throws Exception { assertEquals(result.getEndpoint(processIdentifier, TransportProfile.AS2_1_0).getCertificate().getSubjectDN().toString(), "CN=APP_1000000005, O=DIFI, C=NO"); } + + @Test + public void busdoxServiceGroup() throws Exception { + List identifiers = reader.parseDocumentIdentifiers(new FetcherResponse(getClass().getResourceAsStream("/busdox-servicegroup-9915-setcce-test.xml"), null)); + assertEquals(identifiers.size(), 1); + } } diff --git a/peppol-lookup/src/test/resources/busdox-servicegroup-9915-setcce-test.xml b/peppol-lookup/src/test/resources/busdox-servicegroup-9915-setcce-test.xml new file mode 100644 index 00000000..4bc1f1d6 --- /dev/null +++ b/peppol-lookup/src/test/resources/busdox-servicegroup-9915-setcce-test.xml @@ -0,0 +1 @@ +9915:setcce-test \ No newline at end of file