Search in sources :

Example 6 with ServiceGroupType

use of com.helger.xsds.bdxr.smp2.ServiceGroupType in project peppol-commons by phax.

the class SMPClientReadOnly 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() + aServiceGroupID.getURIPercentEncoded();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("SMPClient getServiceGroup@" + sURI);
    final HttpGet aRequest = new HttpGet(sURI);
    final SMPMarshallerServiceGroupType aMarshaller = new SMPMarshallerServiceGroupType(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) SMPMarshallerServiceGroupType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupType) SMPMarshallerCompleteServiceGroupType(com.helger.smpclient.peppol.marshal.SMPMarshallerCompleteServiceGroupType) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) SMPMarshallerServiceGroupType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupType) CompleteServiceGroupType(com.helger.xsds.peppol.smp1.CompleteServiceGroupType) Nonnull(javax.annotation.Nonnull)

Example 7 with ServiceGroupType

use of com.helger.xsds.bdxr.smp2.ServiceGroupType in project peppol-commons by phax.

the class BDXR2Client method saveServiceGroup.

/**
 * Saves a service group. The meta data references should not be set and are
 * not used.
 *
 * @param aParticipantID
 *        The participant identifier for which the service group is to save.
 * @param aCredentials
 *        The user name and password to use as credentials.
 * @return The created {@link ServiceGroupType} object.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         The user name or password was not correct.
 * @throws SMPClientNotFoundException
 *         A HTTP Not Found was received. This can happen if the service was
 *         not found.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 */
@Nonnull
public ServiceGroupType saveServiceGroup(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
    ValueEnforcer.notNull(aParticipantID, "ParticipantID");
    ValueEnforcer.notNull(aCredentials, "Credentials");
    final ServiceGroupType aServiceGroup = new ServiceGroupType();
    aServiceGroup.setParticipantID(new BDXR2ParticipantIdentifier(aParticipantID.getScheme(), aParticipantID.getValue()));
    saveServiceGroup(aServiceGroup, aCredentials);
    return aServiceGroup;
}
Also used : BDXR2ParticipantIdentifier(com.helger.peppolid.bdxr.smp2.participant.BDXR2ParticipantIdentifier) ServiceGroupType(com.helger.xsds.bdxr.smp2.ServiceGroupType) Nonnull(javax.annotation.Nonnull)

Example 8 with ServiceGroupType

use of com.helger.xsds.bdxr.smp2.ServiceGroupType in project peppol-commons by phax.

the class BDXRClientReadOnly 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() + aServiceGroupID.getURIPercentEncoded();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("BDXRClient getServiceGroup@" + sURI);
    final HttpGet aRequest = new HttpGet(sURI);
    final BDXR1MarshallerServiceGroupType aMarshaller = new BDXR1MarshallerServiceGroupType(isXMLSchemaValidation());
    customizeMarshaller(aMarshaller);
    final ServiceGroupType ret = executeGenericRequest(aRequest, new SMPHttpResponseHandlerUnsigned<>(aMarshaller));
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Received response: " + ret);
    return ret;
}
Also used : BDXR1MarshallerServiceGroupType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType) HttpGet(org.apache.http.client.methods.HttpGet) ServiceGroupType(com.helger.xsds.bdxr.smp1.ServiceGroupType) BDXR1MarshallerServiceGroupType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType) Nonnull(javax.annotation.Nonnull)

Example 9 with ServiceGroupType

use of com.helger.xsds.bdxr.smp2.ServiceGroupType in project phoss-smp by phax.

the class ServiceGroupInterfaceTest method testCreateAndDeleteServiceGroupSMPClient.

@Test
public void testCreateAndDeleteServiceGroupSMPClient() throws SMPClientException {
    // Lower case version
    final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9930:de203827312");
    // Upper case version
    final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9930:DE203827312");
    final ServiceGroupType aSG = new ServiceGroupType();
    aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
    aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
    final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
    final SMPClient aSMPClient = new MockSMPClient();
    // GET
    assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
    assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
    try {
        // PUT 1 - create
        aSMPClient.saveServiceGroup(aSG, CREDENTIALS);
        // Both regular and upper case must work
        assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
        assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
        // PUT 2 - overwrite
        aSMPClient.saveServiceGroup(aSG, CREDENTIALS);
        // Both regular and upper case must work
        assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
        assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
        // DELETE 1
        aSMPClient.deleteServiceGroup(aPI_LC, CREDENTIALS);
        // Both must be deleted
        assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
        assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
    } finally {
        // DELETE 2
        try {
            aSMPClient.deleteServiceGroup(aPI_LC, CREDENTIALS);
        } catch (final SMPClientNotFoundException ex) {
        // Expected
        }
        // Both must be deleted
        assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
        assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
    }
}
Also used : MockSMPClient(com.helger.phoss.smp.mock.MockSMPClient) SMPClientNotFoundException(com.helger.smpclient.exception.SMPClientNotFoundException) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) MockSMPClient(com.helger.phoss.smp.mock.MockSMPClient) SMPClient(com.helger.smpclient.peppol.SMPClient) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 10 with ServiceGroupType

use of com.helger.xsds.bdxr.smp2.ServiceGroupType 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));
    }
}
Also used : Response(javax.ws.rs.core.Response) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) WebTarget(javax.ws.rs.client.WebTarget) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Aggregations

ServiceGroupType (com.helger.xsds.peppol.smp1.ServiceGroupType)21 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)18 ServiceMetadataReferenceCollectionType (com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType)16 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)14 Test (org.junit.Test)13 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)12 Nonnull (javax.annotation.Nonnull)10 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)9 Response (javax.ws.rs.core.Response)9 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)8 WebTarget (javax.ws.rs.client.WebTarget)7 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)6 SMPClient (com.helger.smpclient.peppol.SMPClient)6 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