Skip to content

Commit

Permalink
Fixing bug when reading very short ServiceGroup responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
klakegg committed Feb 24, 2016
1 parent ce109c5 commit d93cb99
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<DocumentTypeIdentifier> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<DocumentTypeIdentifier> identifiers = reader.parseDocumentIdentifiers(new FetcherResponse(getClass().getResourceAsStream("/busdox-servicegroup-9915-setcce-test.xml"), null));
assertEquals(identifiers.size(), 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:ServiceGroup xmlns="http://busdox.org/transport/identifiers/1.0/" xmlns:ns2="http://busdox.org/serviceMetadata/publishing/1.0/" xmlns:ns3="http://www.w3.org/2005/08/addressing" xmlns:ns4="http://www.w3.org/2000/09/xmldsig#"><ParticipantIdentifier scheme="iso6523-actorid-upis">9915:setcce-test</ParticipantIdentifier><ns2:ServiceMetadataReferenceCollection><ns2:ServiceMetadataReference href="http://test-smp.peppol.gr/iso6523-actorid-upis%3A%3A9915%3Asetcce-test/services/busdox-docid-qns%3A%3Aurn%3Aoasis%3Anames%3Aspecification%3Aubl%3Aschema%3Axsd%3AInvoice-AS4%3A%3AInvoice%23%23urn%3Awww.cenbii.eu%3Atransaction%3Abiicoretrdm010%3Aver1.0%3A%23urn%3Awww.edelivery.eu%3Abis%3Aedelivery4a%3Aver1.0%3A%3A2.0"/></ns2:ServiceMetadataReferenceCollection></ns2:ServiceGroup>

0 comments on commit d93cb99

Please sign in to comment.