PublisherService extends HttpServlet { public void metadataProvider(OutputStream outputStream, String syntax, ParticipantIdentifier participantIdentifier, DocumentTypeIdentifier documentTypeIdentifier) throws JAXBException, PublisherException { PublisherServiceMetadata serviceMetadata = serviceMetadataProvider.get(participantIdentifier, documentTypeIdentifier); PublisherSyntax publisherSyntax = publisherSyntaxProvider.getSyntax(syntax); Marshaller marshaller = publisherSyntax.getMarshaller(); if (signer == null) { marshaller.marshal(publisherSyntax.of(serviceMetadata, false), outputStream); } else { Document document = DomUtils.newDocumentBuilder().newDocument(); marshaller.marshal(publisherSyntax.of(serviceMetadata, true), document); signer.sign(document, outputStream); } } PublisherService(ServiceGroupProvider serviceGroupProvider,
                            ServiceMetadataProvider serviceMetadataProvider,
                            PublisherSyntaxProvider publisherSyntaxProvider,
                            Signer signer); void serviceGroup(OutputStream outputStream, String syntax, URI rootUri,
                             ParticipantIdentifier participantIdentifier); void metadataProvider(OutputStream outputStream, String syntax, ParticipantIdentifier participantIdentifier,
                                 DocumentTypeIdentifier documentTypeIdentifier);  }
@Test public void simpleServiceMetadata() throws Exception { PublisherServiceMetadata serviceMetadata = ServiceMetadataBuilder.newInstance() .participant(ParticipantIdentifier.of("9908:999888777")) .documentTypeIdentifier(DTI_INVOICE) .add(PI_INVOICE, EndpointBuilder.newInstance() .transportProfile(TransportProfile.AS2_1_0) .address(URI.create("http: .activationDate(new Date()) .expirationDate(new Date()) .certificate("Test".getBytes()) .build()) .build(); Mockito.when(serviceMetadataProvider.get( Mockito.any(ParticipantIdentifier.class), Mockito.any(DocumentTypeIdentifier.class))) .thenReturn(serviceMetadata); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); publisherService.metadataProvider(byteArrayOutputStream, null, ParticipantIdentifier.of("9908:999888777"), DTI_INVOICE); System.out.println(byteArrayOutputStream.toString()); }