use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class ServiceGroupInterfaceTest method testCreateAndDeleteServiceGroupJerseyClient.
@Test
public void testCreateAndDeleteServiceGroupJerseyClient() {
// Lower case version
final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9930:de203827312");
final String sPI_LC = aPI_LC.getURIEncoded();
// Upper case version
final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9930:DE203827312");
final String sPI_UC = aPI_UC.getURIEncoded();
final ServiceGroupType aSG_LC = new ServiceGroupType();
aSG_LC.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
aSG_LC.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
final ServiceGroupType aSG_UC = new ServiceGroupType();
aSG_UC.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_UC));
aSG_UC.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final WebTarget aTarget = ClientBuilder.newClient().target(m_aRule.getFullURL());
Response aResponseMsg;
// GET
_testResponseJerseyClient(aTarget.path(sPI_LC).request().get(), 404);
_testResponseJerseyClient(aTarget.path(sPI_UC).request().get(), 404);
try {
// PUT 1 - create
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG_LC)));
_testResponseJerseyClient(aResponseMsg, 200);
// PUT 2 - upper case - already present
aResponseMsg = _addCredentials(aTarget.path(sPI_UC).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG_UC)));
_testResponseJerseyClient(aResponseMsg, 200);
// Both regular and upper case must work
assertNotNull(aTarget.path(sPI_LC).request().get(ServiceGroupType.class));
assertNotNull(aTarget.path(sPI_UC).request().get(ServiceGroupType.class));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
// PUT 2 - overwrite
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG_LC)));
_testResponseJerseyClient(aResponseMsg, 200);
aResponseMsg = _addCredentials(aTarget.path(sPI_UC).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG_UC)));
_testResponseJerseyClient(aResponseMsg, 200);
// Both regular and upper case must work
assertNotNull(aTarget.path(sPI_LC).request().get(ServiceGroupType.class));
assertNotNull(aTarget.path(sPI_UC).request().get(ServiceGroupType.class));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
// DELETE 1
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200);
// Both must be deleted
_testResponseJerseyClient(aTarget.path(sPI_LC).request().get(), 404);
_testResponseJerseyClient(aTarget.path(sPI_UC).request().get(), 404);
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
} finally {
// DELETE 2
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200, 404);
// Both must be deleted
_testResponseJerseyClient(aTarget.path(sPI_LC).request().get(), 404);
_testResponseJerseyClient(aTarget.path(sPI_UC).request().get(), 404);
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class ServiceMetadataInterfaceTest method testCreateAndDeleteRedirectSMPClient.
@Test
public void testCreateAndDeleteRedirectSMPClient() throws SMPClientException {
// Lower case
final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
// Upper case
final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:XXX");
final IDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
final ServiceGroupType aSG = new ServiceGroupType();
aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
final RedirectType aRedir = _createRedirect();
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPRedirectManager aSRMgr = SMPMetaManager.getRedirectMgr();
final SMPClient aSMPClient = new MockSMPClient();
assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
try {
// PUT ServiceGroup
aSMPClient.saveServiceGroup(aSG, CREDENTIALS);
assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
final ISMPServiceGroup aServiceGroup = aSGMgr.getSMPServiceGroupOfID(aPI_LC);
assertNotNull(aServiceGroup);
final ISMPServiceGroup aServiceGroup_UC = aSGMgr.getSMPServiceGroupOfID(aPI_UC);
assertEquals(aServiceGroup, aServiceGroup_UC);
try {
// PUT 1 ServiceInformation
aSMPClient.saveServiceRedirect(aPI_LC, aDT, aRedir, CREDENTIALS);
assertNotNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// PUT 2 ServiceInformation
aSMPClient.saveServiceRedirect(aPI_LC, aDT, aRedir, CREDENTIALS);
assertNotNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// DELETE 1 Redirect
aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
assertNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
} finally {
// DELETE 2 Redirect
try {
aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
} catch (final SMPClientNotFoundException ex) {
// Expected
}
assertNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
}
assertNotNull(aSGMgr.getSMPServiceGroupOfID(aPI_LC));
} finally {
// DELETE ServiceGroup
try {
aSMPClient.deleteServiceGroup(aPI_LC, CREDENTIALS);
} catch (final SMPClientNotFoundException ex) {
// Expected
}
assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class ServiceMetadataInterfaceTest method testCreateAndDeleteServiceInformationSMPClient.
@Test
public void testCreateAndDeleteServiceInformationSMPClient() throws SMPClientException {
// Lower case
final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
// Upper case
final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:XXX");
final PeppolDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
final PeppolProcessIdentifier aProcID = EPredefinedProcessIdentifier.BIS3_BILLING.getAsProcessIdentifier();
final ServiceGroupType aSG = new ServiceGroupType();
aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
final ServiceInformationType aSI = new ServiceInformationType();
aSI.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
aSI.setDocumentIdentifier(aDT);
{
final ProcessListType aPL = new ProcessListType();
final ProcessType aProcess = new ProcessType();
aProcess.setProcessIdentifier(aProcID);
final ServiceEndpointList aSEL = new ServiceEndpointList();
final EndpointType aEndpoint = new EndpointType();
aEndpoint.setEndpointReference(W3CEndpointReferenceHelper.createEndpointReference("http://test.smpserver/as2"));
aEndpoint.setRequireBusinessLevelSignature(false);
aEndpoint.setCertificate("blacert");
aEndpoint.setServiceDescription("Unit test service");
aEndpoint.setTechnicalContactUrl("https://github.com/phax/phoss-smp");
aEndpoint.setTransportProfile(ESMPTransportProfile.TRANSPORT_PROFILE_AS2.getID());
aSEL.addEndpoint(aEndpoint);
aProcess.setServiceEndpointList(aSEL);
aPL.addProcess(aProcess);
aSI.setProcessList(aPL);
}
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aSIMgr = SMPMetaManager.getServiceInformationMgr();
final SMPClient aSMPClient = new MockSMPClient();
assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
try {
// PUT ServiceGroup
aSMPClient.saveServiceGroup(aSG, CREDENTIALS);
// Read both
assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
final ISMPServiceGroup aServiceGroup = aSGMgr.getSMPServiceGroupOfID(aPI_LC);
assertNotNull(aServiceGroup);
final ISMPServiceGroup aServiceGroup_UC = aSGMgr.getSMPServiceGroupOfID(aPI_UC);
assertEquals(aServiceGroup, aServiceGroup_UC);
try {
// PUT 1 ServiceInformation
aSMPClient.saveServiceInformation(aSI, CREDENTIALS);
assertNotNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// PUT 2 ServiceInformation
aSMPClient.saveServiceInformation(aSI, CREDENTIALS);
assertNotNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// DELETE 1 ServiceInformation
aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
assertNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
} finally {
// DELETE 2 ServiceInformation
try {
aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
} catch (final SMPClientNotFoundException ex) {
// Expected
}
assertNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
}
assertNotNull(aSMPClient.getServiceGroup(aPI_LC));
} finally {
// DELETE ServiceGroup
try {
aSMPClient.deleteServiceGroup(aPI_LC, CREDENTIALS);
} catch (final SMPClientNotFoundException ex) {
// Expected
}
assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class ServiceMetadataInterfaceTest method testCreateAndDeleteRedirectJerseyClient.
@Test
public void testCreateAndDeleteRedirectJerseyClient() {
// Lower case
final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
final String sPI_LC = aPI_LC.getURIEncoded();
// Upper case
final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:XXX");
final String sPI_UC = aPI_UC.getURIEncoded();
final IDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
final String sDT = aDT.getURIEncoded();
final ServiceGroupType aSG = new ServiceGroupType();
aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
final ServiceMetadataType aSM = new ServiceMetadataType();
aSM.setRedirect(_createRedirect());
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPRedirectManager aSRMgr = SMPMetaManager.getRedirectMgr();
final WebTarget aTarget = ClientBuilder.newClient().target(m_aRule.getFullURL());
Response aResponseMsg;
_testResponseJerseyClient(aTarget.path(sPI_LC).request().get(), 404);
_testResponseJerseyClient(aTarget.path(sPI_UC).request().get(), 404);
try {
// PUT ServiceGroup
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG)));
_testResponseJerseyClient(aResponseMsg, 200);
assertNotNull(aTarget.path(sPI_LC).request().get(ServiceGroupType.class));
assertNotNull(aTarget.path(sPI_UC).request().get(ServiceGroupType.class));
final ISMPServiceGroup aServiceGroup = aSGMgr.getSMPServiceGroupOfID(aPI_LC);
assertNotNull(aServiceGroup);
final ISMPServiceGroup aServiceGroup_UC = aSGMgr.getSMPServiceGroupOfID(aPI_UC);
assertEquals(aServiceGroup, aServiceGroup_UC);
try {
// PUT 1 ServiceInformation
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").path(sDT).request()).put(Entity.xml(m_aObjFactory.createServiceMetadata(aSM)));
_testResponseJerseyClient(aResponseMsg, 200);
assertNotNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// PUT 2 ServiceInformation
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").path(sDT).request()).put(Entity.xml(m_aObjFactory.createServiceMetadata(aSM)));
_testResponseJerseyClient(aResponseMsg, 200);
assertNotNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// DELETE 1 Redirect
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").path(sDT).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200);
assertNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
} finally {
// DELETE 2 Redirect
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").path(sDT).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200, 404);
assertNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
}
assertNotNull(aTarget.path(sPI_LC).request().get(ServiceGroupType.class));
} finally {
// DELETE ServiceGroup
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200, 404);
_testResponseJerseyClient(aTarget.path(sPI_LC).request().get(), 404);
_testResponseJerseyClient(aTarget.path(sPI_UC).request().get(), 404);
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class APIExecutorExportSpecificXMLVer1 method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final String sLogPrefix = "[REST API Export-Specific-XML-V1] ";
LOGGER.info(sLogPrefix + "Starting Export of '" + sPathServiceGroupID + "'");
// Only authenticated user may do so
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
// Start action after authentication
final ISMPSettingsManager aSettingsMgr = SMPMetaManager.getSettingsMgr();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, null);
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, aDataProvider.getCurrentURI());
}
// Retrieve the service group
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
if (aServiceGroup == null) {
// No such service group
throw new SMPNotFoundException("Unknown Service Group '" + sPathServiceGroupID + "'", aDataProvider.getCurrentURI());
}
final boolean bIncludeBusinessCards = aRequestScope.params().getAsBoolean(PARAM_INCLUDE_BUSINESS_CARDS, aSettingsMgr.getSettings().isDirectoryIntegrationEnabled());
final IMicroDocument aDoc = ServiceGroupExport.createExportDataXMLVer10(new CommonsArrayList<>(aServiceGroup), bIncludeBusinessCards);
LOGGER.info(sLogPrefix + "Finished creating Export data");
// Build the XML response
final IXMLWriterSettings aXWS = new XMLWriterSettings();
aUnifiedResponse.setContentAndCharset(MicroWriter.getNodeAsString(aDoc, aXWS), aXWS.getCharset()).setMimeType(new MimeType(CMimeType.APPLICATION_XML).addParameter(CMimeType.PARAMETER_NAME_CHARSET, aXWS.getCharset().name())).disableCaching();
}
Aggregations