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;
}
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;
}
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;
}
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));
}
}
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));
}
}
Aggregations