use of org.osate.aadl2.ProcessType in project phoss-smp by phax.
the class MainCreateManyEndpoints method main.
public static void main(final String[] args) throws Throwable {
final String sServerBasePath = "http://localhost:90";
final WebScopeTestRule aRule = new WebScopeTestRule();
aRule.before();
try {
final StopWatch aSWOverall = StopWatch.createdStarted();
final ObjectFactory aObjFactory = new ObjectFactory();
for (final EPredefinedDocumentTypeIdentifier aEDT : new EPredefinedDocumentTypeIdentifier[] { EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30, EPredefinedDocumentTypeIdentifier.CREDITNOTE_EN16931_PEPPOL_V30, EPredefinedDocumentTypeIdentifier.CROSSINDUSTRYINVOICE_CEN_EU_EN16931_2017, EPredefinedDocumentTypeIdentifier.INVOICE_CEN_EU_EN16931_2017_COMPLIANT_XOEV_DE_KOSIT_STANDARD_XRECHNUNG_1_2, EPredefinedDocumentTypeIdentifier.CREDITNOTE_CEN_EU_EN16931_2017_COMPLIANT_XOEV_DE_KOSIT_STANDARD_XRECHNUNG_1_2, EPredefinedDocumentTypeIdentifier.CROSSINDUSTRYINVOICE_CEN_EU_EN16931_2017_COMPLIANT_XOEV_DE_KOSIT_STANDARD_XRECHNUNG_1_2, EPredefinedDocumentTypeIdentifier.INVOICE_CEN_EU_EN16931_2017_COMPLIANT_XOEV_DE_KOSIT_STANDARD_XRECHNUNG_2_0, EPredefinedDocumentTypeIdentifier.CREDITNOTE_CEN_EU_EN16931_2017_COMPLIANT_XOEV_DE_KOSIT_STANDARD_XRECHNUNG_2_0, EPredefinedDocumentTypeIdentifier.CROSSINDUSTRYINVOICE_CEN_EU_EN16931_2017_COMPLIANT_XOEV_DE_KOSIT_STANDARD_XRECHNUNG_2_02, EPredefinedDocumentTypeIdentifier.INVOICE_CEN_EU_EN16931_2017_COMPLIANT_XOEV_DE_KOSIT_STANDARD_XRECHNUNG_2_0_CONFORMANT_XOEV_DE_KOSIT_EXTENSION_XRECHNUNG_2_0, EPredefinedDocumentTypeIdentifier.CREDITNOTE_CEN_EU_EN16931_2017_COMPLIANT_XOEV_DE_KOSIT_STANDARD_XRECHNUNG_2_0_CONFORMANT_XOEV_DE_KOSIT_EXTENSION_XRECHNUNG_2_0, EPredefinedDocumentTypeIdentifier.CROSSINDUSTRYINVOICE_CEN_EU_EN16931_2017_COMPLIANT_XOEV_DE_KOSIT_STANDARD_XRECHNUNG_2_0_CONFORMANT_XOEV_DE_KOSIT_EXTENSION_XRECHNUNG_2_02 }) {
final PeppolDocumentTypeIdentifier aDT = aEDT.getAsDocumentTypeIdentifier();
final String sDT = aDT.getURIEncoded();
final PeppolProcessIdentifier aProcID = EPredefinedProcessIdentifier.BIS3_BILLING.getAsProcessIdentifier();
for (int i = 0; i < 10_000; ++i) {
final StopWatch aSW = StopWatch.createdStarted();
final PeppolParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:test-philip-" + StringHelper.getLeadingZero(i, 7));
final String sPI = aPI.getURIEncoded();
final ServiceMetadataType aSM = new ServiceMetadataType();
final ServiceInformationType aSI = new ServiceInformationType();
aSI.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI));
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_PEPPOL_AS4_V2.getID());
aSEL.addEndpoint(aEndpoint);
aProcess.setServiceEndpointList(aSEL);
aPL.addProcess(aProcess);
aSI.setProcessList(aPL);
}
aSM.setServiceInformation(aSI);
try (final WebScoped aWS = new WebScoped(new MockHttpServletRequest())) {
// Delete old - don't care about the result
if (false)
ClientBuilder.newClient().target(sServerBasePath).path(sPI).path("services").path(sDT).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).delete();
// Create a new
final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(sPI).path("services").path(sDT).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(aObjFactory.createServiceMetadata(aSM)));
_testResponseJerseyClient(aResponseMsg, 200);
}
aSW.stop();
LOGGER.info(sPI + " took " + aSW.getMillis() + " ms");
}
}
aSWOverall.stop();
LOGGER.info("Overall process took " + aSWOverall.getMillis() + " ms or " + aSWOverall.getDuration());
} finally {
aRule.after();
}
}
use of org.osate.aadl2.ProcessType in project phoss-smp by phax.
the class ServiceMetadataInterfaceTest method testCreateAndDeleteServiceInformationJerseyClient.
@Test
public void testCreateAndDeleteServiceInformationJerseyClient() {
// 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 PeppolDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
final String sDT = aDT.getURIEncoded();
final PeppolProcessIdentifier aProcID = EPredefinedProcessIdentifier.BIS3_BILLING.getAsProcessIdentifier();
final ServiceGroupType aSG = new ServiceGroupType();
aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
final ServiceMetadataType aSM = new ServiceMetadataType();
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);
}
aSM.setServiceInformation(aSI);
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aSIMgr = SMPMetaManager.getServiceInformationMgr();
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);
// Read both
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(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(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(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// DELETE 1 ServiceInformation
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").path(sDT).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200);
assertNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
} finally {
// DELETE 2 ServiceInformation
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").path(sDT).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200, 404);
assertNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
}
assertNotNull(aTarget.path(sPI_LC).request().get(ServiceGroupType.class));
} finally {
// DELETE ServiceGroup
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).delete();
// May be 500 if no MySQL is running
_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 org.osate.aadl2.ProcessType in project AGREE by loonwerks.
the class EphemeralImplementationUtil method createComponentImplementationInternal.
/**
* Internal method to actually create the ephemeral component implementation and containing resource.
* <p>
* This method is intended to by invoked only from the command stack so that editing permissions are managed
* through the transactional editing domain.
*
* @param ct The {@link ComponentType} for which to create an ephemeral implementation.
* @param aadlResource The {@link Resource} in which to place the ephemeral implementation and it containing
* {@link AadlPackage}.
* @return A {@link ComponentImplementation} matching the given component type.
* @throws InterruptedException
*/
private ComponentImplementation createComponentImplementationInternal(ComponentType ct, Resource aadlResource) throws InterruptedException {
// Create a package and public section to contain the created
// component implementation
AadlPackage aadlPackage = Aadl2Factory.eINSTANCE.createAadlPackage();
aadlPackage.setName(aadlResource.getURI().trimFragment().trimFileExtension().lastSegment().toString());
PublicPackageSection publicSection = aadlPackage.createOwnedPublicSection();
// Add import for package containing ct
AadlPackage ctPackage = (AadlPackage) AgreeUtils.getClosestContainerOfType(ct, AadlPackage.class);
publicSection.getImportedUnits().add(ctPackage);
// Add renames clause to make linking to ct easy
PackageRename ctRename = publicSection.createOwnedPackageRename();
ctRename.setName("");
ctRename.setRenamedPackage(ctPackage);
ctRename.setRenameAll(true);
// Create the component implementation in the public section
ComponentImplementation compImpl;
if (ct instanceof ThreadType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getThreadImplementation());
} else if (ct instanceof ThreadGroupType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getThreadGroupImplementation());
} else if (ct instanceof ProcessType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getProcessImplementation());
} else if (ct instanceof SubprogramType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getSubprogramImplementation());
} else if (ct instanceof ProcessorType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getProcessorImplementation());
} else if (ct instanceof BusType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getBusImplementation());
} else if (ct instanceof DeviceType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getDeviceImplementation());
} else if (ct instanceof SystemType) {
compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getSystemImplementation());
} else {
throw new AgreeException("Unhandled component type: " + ct.getClass().toString());
}
compImpl.setType(ct);
compImpl.setName(ct.getName() + ".wrapper");
// Add the package and its contents to the resource
aadlResource.getContents().add(aadlPackage);
// IResource as we build it.
try {
aadlResource.save(null);
} catch (IOException e) {
e.printStackTrace();
setErrorMessage(e.getMessage());
return null;
} catch (NullPointerException npe) {
npe.printStackTrace();
setErrorMessage(npe.getMessage());
npe.getMessage();
return null;
// } catch (InterruptedException e) {
// throw e;
} catch (Exception e) {
e.printStackTrace();
errorMessage = e.getMessage();
e.getMessage();
return null;
}
return compImpl;
}
use of org.osate.aadl2.ProcessType in project peppol-commons by phax.
the class SMPClientReadOnly method getEndpoint.
/**
* Extract the Endpoint from the ServiceMetadata that matches the passed
* process ID and the optional required transport profile.
*
* @param aServiceMetadata
* The unsigned service meta data object. May not be <code>null</code>.
* @param aProcessID
* The process identifier to be looked up. May not be <code>null</code>
* .
* @param aTransportProfile
* The required transport profile to be used. May not be
* <code>null</code>.
* @return <code>null</code> if no matching endpoint was found
* @since 8.2.6
*/
@Nullable
public static EndpointType getEndpoint(@Nonnull final ServiceMetadataType aServiceMetadata, @Nonnull final IProcessIdentifier aProcessID, @Nonnull final ISMPTransportProfile aTransportProfile) {
ValueEnforcer.notNull(aServiceMetadata, "ServiceMetadata");
final ServiceInformationType aServiceInformation = aServiceMetadata.getServiceInformation();
if (aServiceInformation == null) {
// It seems to be a redirect and not service information
return null;
}
ValueEnforcer.notNull(aServiceInformation.getProcessList(), "ServiceMetadata.ServiceInformation.ProcessList");
ValueEnforcer.notNull(aProcessID, "ProcessID");
ValueEnforcer.notNull(aTransportProfile, "TransportProfile");
// Iterate all processes
for (final ProcessType aProcessType : aServiceInformation.getProcessList().getProcess()) {
// Matches the requested one?
if (_hasSameContent(aProcessType.getProcessIdentifier(), aProcessID)) {
// Filter all endpoints by required transport profile
final ICommonsList<EndpointType> aRelevantEndpoints = new CommonsArrayList<>();
for (final EndpointType aEndpoint : aProcessType.getServiceEndpointList().getEndpoint()) if (aTransportProfile.getID().equals(aEndpoint.getTransportProfile()))
aRelevantEndpoints.add(aEndpoint);
if (aRelevantEndpoints.size() != 1) {
if (LOGGER.isWarnEnabled())
LOGGER.warn("Found " + aRelevantEndpoints.size() + " endpoints for process " + aProcessID + " and transport profile " + aTransportProfile.getID() + (aRelevantEndpoints.isEmpty() ? "" : ": " + aRelevantEndpoints.toString() + " - using the first one"));
}
// Use the first endpoint or null
final EndpointType ret = aRelevantEndpoints.getFirst();
if (LOGGER.isDebugEnabled())
LOGGER.debug("Found matching endpoint: " + ret);
return ret;
}
}
if (LOGGER.isDebugEnabled())
LOGGER.debug("Found no matching SMP endpoint");
return null;
}
use of org.osate.aadl2.ProcessType in project peppol-commons by phax.
the class SMPDebugHelper method getAsString.
@Nonnull
public static String getAsString(@Nonnull final ServiceMetadataType aServiceMetadata) {
final StringBuilder aSB = new StringBuilder();
aSB.append("Service meta data:\n");
final ServiceInformationType aServiceInformation = aServiceMetadata.getServiceInformation();
if (aServiceInformation != null) {
aSB.append(" Service information:\n");
aSB.append(" Participant: ").append(CIdentifier.getURIEncoded(aServiceInformation.getParticipantIdentifier())).append('\n');
aSB.append(" Document type: ").append(CIdentifier.getURIEncoded(aServiceInformation.getDocumentIdentifier())).append('\n');
for (final ProcessType aProcess : aServiceInformation.getProcessList().getProcess()) {
aSB.append(" Process: ").append(CIdentifier.getURIEncoded(aProcess.getProcessIdentifier())).append('\n');
for (final EndpointType aEndpoint : aProcess.getServiceEndpointList().getEndpoint()) {
aSB.append(" Endpoint: ").append(W3CEndpointReferenceHelper.getAddress(aEndpoint.getEndpointReference())).append('\n');
aSB.append(" Transport profile: ").append(aEndpoint.getTransportProfile()).append('\n');
aSB.append(" Business level signature: ").append(aEndpoint.isRequireBusinessLevelSignature()).append('\n');
aSB.append(" Min auth level: ").append(aEndpoint.getMinimumAuthenticationLevel()).append('\n');
if (aEndpoint.getServiceActivationDate() != null)
aSB.append(" Valid from: ").append(aEndpoint.getServiceActivationDate()).append('\n');
if (aEndpoint.getServiceExpirationDate() != null)
aSB.append(" Valid to: ").append(aEndpoint.getServiceExpirationDate()).append('\n');
aSB.append(" Certficiate string: ").append(aEndpoint.getCertificate()).append('\n');
aSB.append(" Service description: ").append(aEndpoint.getServiceDescription()).append('\n');
aSB.append(" Contact URL: ").append(aEndpoint.getTechnicalContactUrl()).append('\n');
aSB.append(" Info URL: ").append(aEndpoint.getTechnicalInformationUrl()).append('\n');
}
}
}
final RedirectType aRedirect = aServiceMetadata.getRedirect();
if (aRedirect != null) {
aSB.append(" Service redirect:\n");
aSB.append(" Certificate UID: ").append(aRedirect.getCertificateUID()).append('\n');
aSB.append(" Href: ").append(aRedirect.getHref()).append('\n');
}
return aSB.toString();
}
Aggregations