use of com.helger.xsds.bdxr.smp1.ServiceGroupType in project phoss-smp by phax.
the class MainCreate1MillionServiceGroups method main.
public static void main(final String[] args) throws Throwable {
final SMPServerRESTTestRule aRule = new SMPServerRESTTestRule(ClassPathResource.getAsFile("test-smp-server-mongodb.properties").getAbsolutePath());
aRule.before();
try {
// Set the special PhotonSecurityManager factory
PhotonSecurityManager.setFactory(new PhotonSecurityManagerFactoryMongoDB());
final ObjectFactory aObjFactory = new ObjectFactory();
final StopWatch aSWOverall = StopWatch.createdStarted();
for (int i = 0; i < 1_000_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 ServiceGroupType aSG = new ServiceGroupType();
aSG.setParticipantIdentifier(aPI);
aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
try (final WebScoped aWS = new WebScoped(new MockHttpServletRequest())) {
// Delete old - don't care about the result
if (false)
ClientBuilder.newClient().target(aRule.getFullURL()).path(sPI).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).delete();
// Create a new
final Response aResponseMsg = ClientBuilder.newClient().target(aRule.getFullURL()).path(sPI).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(aObjFactory.createServiceGroup(aSG)));
_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 com.helger.xsds.bdxr.smp1.ServiceGroupType in project peppol-commons by phax.
the class MainSMPServiceGroupList method main.
public static void main(final String[] args) throws Exception {
final URI SMP_URI = MockSMPClientConfig.getSMPURI();
final IParticipantIdentifier PARTICIPANT_ID = MockSMPClientConfig.getParticipantID();
// The main SMP client
final SMPClient aClient = new SMPClient(SMP_URI);
// Get the service group information
final ServiceGroupType aServiceGroup = aClient.getServiceGroupOrNull(PARTICIPANT_ID);
if (aServiceGroup == null)
LOGGER.error("Failed to get service group infos for " + PARTICIPANT_ID);
else
LOGGER.info(SMPDebugHelper.getAsString(aServiceGroup));
LOGGER.info("Done");
}
use of com.helger.xsds.bdxr.smp1.ServiceGroupType in project peppol-commons by phax.
the class BDXRClientReadOnly method getAllDocumentTypes.
/**
* Extract all parsable document types from the passed Service group.
*
* @param aSG
* The service group to parse. May be <code>null</code>.
* @param aIdentifierFactory
* The identifier factory to be used. May not be <code>null</code>.
* @param aUnhandledHrefHandler
* An optional consumer for Hrefs that could not be parsed into a
* document type identifier. May be <code>null</code>.
* @return Never <code>null</code> but a maybe empty list.
* @since 8.0.4
*/
@Nonnull
public static ICommonsList<IDocumentTypeIdentifier> getAllDocumentTypes(@Nullable final ServiceGroupType aSG, @Nonnull final IIdentifierFactory aIdentifierFactory, @Nullable final Consumer<String> aUnhandledHrefHandler) {
ValueEnforcer.notNull(aIdentifierFactory, "IdentifierFactory");
final ICommonsList<IDocumentTypeIdentifier> ret = new CommonsArrayList<>();
if (aSG != null && aSG.getParticipantIdentifier() != null && aSG.getServiceMetadataReferenceCollection() != null) {
final String sPathStart = "/" + CIdentifier.getURIEncoded(aSG.getParticipantIdentifier()) + '/' + URL_PART_SERVICES + '/';
for (final ServiceMetadataReferenceType aSMR : aSG.getServiceMetadataReferenceCollection().getServiceMetadataReference()) {
final String sOriginalHref = aSMR.getHref();
// Decoded href is important for unification
final String sHref = CIdentifier.createPercentDecoded(sOriginalHref);
boolean bSuccess = false;
// Case insensitive "indexOf" here
final int nPathStart = StringHelper.getIndexOfIgnoreCase(sHref, sPathStart, Locale.US);
if (nPathStart >= 0) {
final String sDocType = sHref.substring(nPathStart + sPathStart.length());
final IDocumentTypeIdentifier aDocType = aIdentifierFactory.parseDocumentTypeIdentifier(sDocType);
if (aDocType != null) {
// Found a document type
ret.add(aDocType);
bSuccess = true;
}
}
if (!bSuccess) {
// Failed to parse as doc type
if (aUnhandledHrefHandler != null)
aUnhandledHrefHandler.accept(sOriginalHref);
}
}
}
return ret;
}
use of com.helger.xsds.bdxr.smp1.ServiceGroupType in project peppol-commons by phax.
the class BDXR2ClientReadOnly method getServiceGroup.
/**
* Returns a service group. A service group references to the service
* metadata. This is a specification compliant method.
*
* @param aServiceGroupID
* The service group id corresponding to the service group which one
* wants to get.
* @return The service group. Never <code>null</code>.
* @throws SMPClientException
* in case something goes wrong
* @throws SMPClientUnauthorizedException
* A HTTP Forbidden was received, should not happen.
* @throws SMPClientNotFoundException
* The service group id did not exist.
* @throws SMPClientBadRequestException
* The request was not well formed.
* @see #getServiceGroupOrNull(IParticipantIdentifier)
*/
@Nonnull
public ServiceGroupType getServiceGroup(@Nonnull final IParticipantIdentifier aServiceGroupID) throws SMPClientException {
ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
final String sURI = getSMPHostURI() + PATH_OASIS_BDXR_SMP_2 + aServiceGroupID.getURIPercentEncoded();
if (LOGGER.isDebugEnabled())
LOGGER.debug("BDXR2Client getServiceGroup@" + sURI);
final HttpGet aRequest = new HttpGet(sURI);
final BDXR2ServiceGroupMarshaller aMarshaller = new BDXR2ServiceGroupMarshaller(isXMLSchemaValidation());
customizeMarshaller(aMarshaller);
final ServiceGroupType ret = executeGenericRequest(aRequest, new SMPHttpResponseHandlerUnsigned<>(aMarshaller));
if (LOGGER.isDebugEnabled())
LOGGER.debug("Received response: " + ret);
return ret;
}
Aggregations