use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class ISMPRedirectManagerFuncTest method testRedirect.
@Test
public void testRedirect() throws SMPServerException {
final String sUserID = CSecurity.USER_ADMINISTRATOR_ID;
if (SMPMetaManager.getInstance().getBackendConnectionState().isFalse()) {
// Failed to get DB connection. E.g. MySQL down or misconfigured.
return;
}
final IParticipantIdentifier aPI1 = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:junittest1");
final IParticipantIdentifier aPI2 = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:junittest2");
final IDocumentTypeIdentifier aDocTypeID = PeppolIdentifierFactory.INSTANCE.createDocumentTypeIdentifierWithDefaultScheme("junit::testdoc#ext:1.0");
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceGroup aSG = aSGMgr.createSMPServiceGroup(sUserID, aPI1, null, true);
assertNotNull(aSG);
try {
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
// Create new one
ISMPRedirect aRedirect = aRedirectMgr.createOrUpdateSMPRedirect(aSG, aDocTypeID, "target", "suid", null, "<extredirect />");
assertNotNull(aRedirect);
assertSame(aSG, aRedirect.getServiceGroup());
assertTrue(aDocTypeID.hasSameContent(aRedirect.getDocumentTypeIdentifier()));
assertEquals("target", aRedirect.getTargetHref());
assertEquals("suid", aRedirect.getSubjectUniqueIdentifier());
assertEquals("<extredirect />", aRedirect.getFirstExtensionXML().trim());
final long nCount = aRedirectMgr.getSMPRedirectCount();
// Update existing
aRedirect = aRedirectMgr.createOrUpdateSMPRedirect(aSG, aDocTypeID, "target2", "suid2", null, "<extredirect2 />");
assertNotNull(aRedirect);
assertSame(aSG, aRedirect.getServiceGroup());
assertTrue(aDocTypeID.hasSameContent(aRedirect.getDocumentTypeIdentifier()));
assertEquals("target2", aRedirect.getTargetHref());
assertEquals("suid2", aRedirect.getSubjectUniqueIdentifier());
assertEquals("<extredirect2 />", aRedirect.getFirstExtensionXML().trim());
assertEquals(nCount, aRedirectMgr.getSMPRedirectCount());
// Add second one
final ISMPServiceGroup aSG2 = aSGMgr.createSMPServiceGroup(sUserID, aPI2, null, true);
assertNotNull(aSG2);
try {
aRedirect = aRedirectMgr.createOrUpdateSMPRedirect(aSG2, aDocTypeID, "target2", "suid2", null, "<extredirect2 />");
assertNotNull(aRedirect);
assertSame(aSG2, aRedirect.getServiceGroup());
assertTrue(aDocTypeID.hasSameContent(aRedirect.getDocumentTypeIdentifier()));
assertEquals("target2", aRedirect.getTargetHref());
assertEquals("suid2", aRedirect.getSubjectUniqueIdentifier());
assertEquals("<extredirect2 />", aRedirect.getFirstExtensionXML().trim());
assertEquals(nCount + 1, aRedirectMgr.getSMPRedirectCount());
// Cleanup
assertTrue(aRedirectMgr.deleteAllSMPRedirectsOfServiceGroup(aSG2).isChanged());
assertEquals(nCount, aRedirectMgr.getSMPRedirectCount());
assertTrue(aRedirectMgr.deleteAllSMPRedirectsOfServiceGroup(aSG).isChanged());
assertEquals(nCount - 1, aRedirectMgr.getSMPRedirectCount());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true).isChanged());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true).isChanged());
} finally {
aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true);
}
} finally {
aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true);
}
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class ISMPServiceInformationManagerFuncTest method testAll.
@Test
public void testAll() throws SMPServerException {
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final IParticipantIdentifier aPI1 = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:junittest1");
final IDocumentTypeIdentifier aDocTypeID = PeppolIdentifierFactory.INSTANCE.createDocumentTypeIdentifierWithDefaultScheme("junit::testdoc#ext:1.0");
final IProcessIdentifier aProcessID = PeppolIdentifierFactory.INSTANCE.createProcessIdentifierWithDefaultScheme("junit-proc");
final String sUserID = CSecurity.USER_ADMINISTRATOR_ID;
if (SMPMetaManager.getInstance().getBackendConnectionState().isFalse()) {
// Failed to get DB connection. E.g. MySQL down or misconfigured.
return;
}
aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI1, true);
final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup(sUserID, aPI1, null, true);
assertNotNull(aSG);
try {
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 />");
final SMPProcess aProcess = new SMPProcess(aProcessID, new CommonsArrayList<>(aEP), "<extproc/>");
final SMPServiceInformation aServiceInformation = new SMPServiceInformation(aSG, aDocTypeID, new CommonsArrayList<>(aProcess), "<extsi/>");
assertTrue(aServiceInfoMgr.mergeSMPServiceInformation(aServiceInformation).isSuccess());
} finally {
// Don't care about the result
aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI1, true);
}
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class BDXR1ServerAPI 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.getAsJAXBObjectBDXR1());
} 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.getAsJAXBObjectBDXR1();
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.IDocumentTypeIdentifier in project phoss-smp by phax.
the class MainReadFromFilePeppol method main.
public static void main(final String[] args) throws Throwable {
final SMPServerRESTTestRule aRule = new SMPServerRESTTestRule(ClassPathResource.getAsFile("test-smp-server-xml-peppol.properties").getAbsolutePath());
aRule.before();
try {
final String sServerBasePath = aRule.getFullURL();
final StopWatch aSWOverall = StopWatch.createdStarted();
// These values must match the values in the test file
final IParticipantIdentifier aParticipantID = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
final IDocumentTypeIdentifier aDocTypeID = PeppolIdentifierFactory.INSTANCE.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1");
// Delete existing ServiceGroup (if exists)
{
final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(aParticipantID.getURIEncoded()).queryParam("delete-in-sml", Boolean.FALSE).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).delete();
_testResponseJerseyClient(aResponseMsg, 200, 404);
}
{
// Create a new ServiceGroup
final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(aParticipantID.getURIEncoded()).queryParam("create-in-sml", Boolean.FALSE).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(new File("src/test/resources/rest-files/peppol-service-group.xml")));
_testResponseJerseyClient(aResponseMsg, 200);
}
{
// Add endpoint
final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(aParticipantID.getURIEncoded()).path("services").path(aDocTypeID.getURIEncoded()).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(new File("src/test/resources/rest-files/peppol-service-metadata.xml")));
_testResponseJerseyClient(aResponseMsg, 200);
}
{
// Add Business Card
final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path("businesscard").path(aParticipantID.getURIEncoded()).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(new File("src/test/resources/rest-files/peppol-business-card-v3.xml")));
_testResponseJerseyClient(aResponseMsg, 200);
}
aSWOverall.stop();
LOGGER.info("Overall process took " + aSWOverall.getMillis() + " ms or " + aSWOverall.getDuration());
} finally {
aRule.after();
}
}
use of com.helger.peppolid.IDocumentTypeIdentifier 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;
}
}
Aggregations