use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class SMPServerAPI method getServiceRegistration.
@Nonnull
public SignedServiceMetadataType getServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocTypeID) throws SMPServerException {
final String sLog = LOG_PREFIX + "GET /" + sPathServiceGroupID + "/services/" + sPathDocTypeID;
final String sAction = "getServiceRegistration";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
}
final ISMPServiceGroup aPathServiceGroup = SMPMetaManager.getServiceGroupMgr().getSMPServiceGroupOfID(aPathServiceGroupID);
if (aPathServiceGroup == null) {
throw new SMPNotFoundException("No such Service Group '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
}
final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocTypeID);
if (aPathDocTypeID == null) {
throw SMPBadRequestException.failedToParseDocType(sPathDocTypeID, m_aAPIDataProvider.getCurrentURI());
}
// First check for redirection, then for actual service
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
final ISMPRedirect aRedirect = aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aPathServiceGroup, aPathDocTypeID);
final SignedServiceMetadataType aSignedServiceMetadata = new SignedServiceMetadataType();
if (aRedirect != null) {
aSignedServiceMetadata.setServiceMetadata(aRedirect.getAsJAXBObjectPeppol());
} else {
// Get as regular service information
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aPathServiceGroup, aPathDocTypeID);
final ServiceMetadataType aSM = aServiceInfo == null ? null : aServiceInfo.getAsJAXBObjectPeppol();
if (aSM != null) {
aSignedServiceMetadata.setServiceMetadata(aSM);
} else {
// Neither nor is present, or no endpoint is available
throw new SMPNotFoundException("service(" + sPathServiceGroupID + "," + sPathDocTypeID + ")", m_aAPIDataProvider.getCurrentURI());
}
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return aSignedServiceMetadata;
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class SMPRedirectTest method testCaseSensitivity.
@Test
public void testCaseSensitivity() {
final IParticipantIdentifier aPI = new SimpleParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:UpperCase");
final IDocumentTypeIdentifier aDocTypeID = new SimpleDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "testDocType");
final SMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, null);
// Create new one
final ISMPRedirect aRedirect = new SMPRedirect(aSG, aDocTypeID, "target", "suid", null, "<extredirect/>");
assertSame(aSG, aRedirect.getServiceGroup());
assertEquals(aDocTypeID, aRedirect.getDocumentTypeIdentifier());
assertEquals("target", aRedirect.getTargetHref());
assertEquals("suid", aRedirect.getSubjectUniqueIdentifier());
assertNull(aRedirect.getCertificate());
assertFalse(aRedirect.hasCertificate());
assertEquals("[{\"Any\":\"<extredirect />\"}]", aRedirect.getExtensionsAsString());
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class SMPServiceGroupTest method testBDXRExtension.
@Test
public void testBDXRExtension() {
final IParticipantIdentifier aPI = SMPMetaManager.getIdentifierFactory().createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
final ExtensionType aExt = new ExtensionType();
// The extension "any" MUST be in a different namespace that is not empty
aExt.setAny(DOMReader.readXMLDOM("<foobar1 xmlns='abc'/>").getDocumentElement());
final ExtensionType aExt2 = new ExtensionType();
aExt2.setExtensionID("xyz");
aExt2.setAny(DOMReader.readXMLDOM("<foobar2 xmlns='def'/>").getDocumentElement());
// Must be an array!
final SMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, BDXR1ExtensionConverter.convertToString(new CommonsArrayList<>(aExt, aExt2)));
assertTrue(StringHelper.hasText(aSG.getID()));
assertEquals(CSecurity.USER_ADMINISTRATOR_ID, aSG.getOwnerID());
assertEquals(aPI, aSG.getParticipantIdentifier());
assertNotNull(aSG.getExtensionsAsString());
final com.helger.xsds.bdxr.smp1.ServiceGroupType aSGBDXR = aSG.getAsJAXBObjectBDXR1();
aSGBDXR.setServiceMetadataReferenceCollection(new com.helger.xsds.bdxr.smp1.ServiceMetadataReferenceCollectionType());
assertEquals(2, aSGBDXR.getExtension().size());
final Document aDoc = new BDXR1MarshallerServiceGroupType(true).getAsDocument(aSGBDXR);
assertNotNull(aDoc);
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class SMPServiceGroupTest method testBasic.
@Test
public void testBasic() {
final IParticipantIdentifier aPI = SMPMetaManager.getIdentifierFactory().createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
final SMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, "<foobar />");
assertTrue(StringHelper.hasText(aSG.getID()));
assertEquals(CSecurity.USER_ADMINISTRATOR_ID, aSG.getOwnerID());
assertEquals(aPI, aSG.getParticipantIdentifier());
assertEquals("[{\"Any\":\"<foobar />\"}]", aSG.getExtensionsAsString());
final com.helger.xsds.peppol.smp1.ServiceGroupType aSGPeppol = aSG.getAsJAXBObjectPeppol();
assertNotNull(aSGPeppol.getExtension());
aSGPeppol.setServiceMetadataReferenceCollection(new com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType());
final Document aDoc = new SMPMarshallerServiceGroupType(true).getAsDocument(aSGPeppol);
assertNotNull(aDoc);
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class SMPServiceInformationTest method testBasic.
@Test
public void testBasic() {
final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("0088:dummy");
final ISMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, null);
final XMLOffsetDateTime aStartDT = PDTFactory.getCurrentXMLOffsetDateTime();
final XMLOffsetDateTime aEndDT = aStartDT.plusYears(1);
final SMPEndpoint aEP = new SMPEndpoint("tp", "http://localhost/as2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep/>");
assertEquals("tp", aEP.getTransportProfile());
assertEquals("http://localhost/as2", aEP.getEndpointReference());
assertFalse(aEP.isRequireBusinessLevelSignature());
assertEquals("minauth", aEP.getMinimumAuthenticationLevel());
assertEquals(aStartDT, aEP.getServiceActivationDateTime());
assertEquals(aEndDT, aEP.getServiceExpirationDateTime());
assertEquals("cert", aEP.getCertificate());
assertEquals("sd", aEP.getServiceDescription());
assertEquals("tc", aEP.getTechnicalContactUrl());
assertEquals("ti", aEP.getTechnicalInformationUrl());
assertEquals("[{\"Any\":\"<extep />\"}]", aEP.getExtensionsAsString());
final IProcessIdentifier aProcessID = new SimpleProcessIdentifier(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME, "testproc");
final SMPProcess aProcess = new SMPProcess(aProcessID, CollectionHelper.newList(aEP), "<extproc/>");
assertEquals(aProcessID, aProcess.getProcessIdentifier());
assertEquals(1, aProcess.getAllEndpoints().size());
assertEquals("[{\"Any\":\"<extproc />\"}]", aProcess.getExtensionsAsString());
final IDocumentTypeIdentifier aDocTypeID = new SimpleDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "testdoctype");
final SMPServiceInformation aSI = new SMPServiceInformation(aSG, aDocTypeID, CollectionHelper.newList(aProcess), "<extsi/>");
assertSame(aSG, aSI.getServiceGroup());
assertEquals(aDocTypeID, aSI.getDocumentTypeIdentifier());
assertEquals(1, aSI.getAllProcesses().size());
assertEquals("[{\"Any\":\"<extsi />\"}]", aSI.getExtensionsAsString());
}
Aggregations