Search in sources :

Example 26 with ServiceGroupType

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();
    }
}
Also used : PeppolParticipantIdentifier(com.helger.peppolid.peppol.participant.PeppolParticipantIdentifier) WebScoped(com.helger.web.scope.mgr.WebScoped) Response(javax.ws.rs.core.Response) PhotonSecurityManagerFactoryMongoDB(com.helger.phoss.smp.backend.mongodb.PhotonSecurityManagerFactoryMongoDB) ObjectFactory(com.helger.xsds.peppol.smp1.ObjectFactory) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) SMPServerRESTTestRule(com.helger.phoss.smp.mock.SMPServerRESTTestRule) StopWatch(com.helger.commons.timing.StopWatch)

Example 27 with ServiceGroupType

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");
}
Also used : SMPClient(com.helger.smpclient.peppol.SMPClient) URI(java.net.URI) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 28 with ServiceGroupType

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;
}
Also used : ServiceMetadataReferenceType(com.helger.xsds.bdxr.smp1.ServiceMetadataReferenceType) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Nonnull(javax.annotation.Nonnull)

Example 29 with ServiceGroupType

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;
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) BDXR2ServiceGroupMarshaller(com.helger.smpclient.bdxr2.marshal.BDXR2ServiceGroupMarshaller) ServiceGroupType(com.helger.xsds.bdxr.smp2.ServiceGroupType) Nonnull(javax.annotation.Nonnull)

Aggregations

ServiceGroupType (com.helger.xsds.peppol.smp1.ServiceGroupType)21 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)19 ServiceMetadataReferenceCollectionType (com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType)16 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)14 Test (org.junit.Test)14 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)12 Nonnull (javax.annotation.Nonnull)11 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)9 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)9 Response (javax.ws.rs.core.Response)9 WebTarget (javax.ws.rs.client.WebTarget)7 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)6 SMPClient (com.helger.smpclient.peppol.SMPClient)5 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)4 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)4 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)4 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)4 MockSMPClient (com.helger.phoss.smp.mock.MockSMPClient)4 ServiceGroupType (com.helger.xsds.bdxr.smp1.ServiceGroupType)4 CompleteServiceGroupType (com.helger.xsds.peppol.smp1.CompleteServiceGroupType)4