use of com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType 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.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType in project phoss-smp by phax.
the class SMPServiceGroupTest method testBDXRExtension.
@Test
public void testBDXRExtension() {
final IParticipantIdentifier aPI = SMPMetaManager.getIdentifierFactory().createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
final ExtensionType aExt = new ExtensionType();
// The extension "any" MUST be in a different namespace that is not empty
aExt.setAny(DOMReader.readXMLDOM("<foobar1 xmlns='abc'/>").getDocumentElement());
final ExtensionType aExt2 = new ExtensionType();
aExt2.setExtensionID("xyz");
aExt2.setAny(DOMReader.readXMLDOM("<foobar2 xmlns='def'/>").getDocumentElement());
// Must be an array!
final SMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, BDXR1ExtensionConverter.convertToString(new CommonsArrayList<>(aExt, aExt2)));
assertTrue(StringHelper.hasText(aSG.getID()));
assertEquals(CSecurity.USER_ADMINISTRATOR_ID, aSG.getOwnerID());
assertEquals(aPI, aSG.getParticipantIdentifier());
assertNotNull(aSG.getExtensionsAsString());
final com.helger.xsds.bdxr.smp1.ServiceGroupType aSGBDXR = aSG.getAsJAXBObjectBDXR1();
aSGBDXR.setServiceMetadataReferenceCollection(new com.helger.xsds.bdxr.smp1.ServiceMetadataReferenceCollectionType());
assertEquals(2, aSGBDXR.getExtension().size());
final Document aDoc = new BDXR1MarshallerServiceGroupType(true).getAsDocument(aSGBDXR);
assertNotNull(aDoc);
}
use of com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType in project phoss-smp by phax.
the class APIExecutorServiceGroupGet method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sPathServiceGroupID);
final byte[] aBytes;
switch(SMPServerConfiguration.getRESTType()) {
case PEPPOL:
{
final com.helger.xsds.peppol.smp1.ServiceGroupType ret = new SMPServerAPI(aDataProvider).getServiceGroup(sPathServiceGroupID);
aBytes = new SMPMarshallerServiceGroupType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
break;
}
case OASIS_BDXR_V1:
{
final com.helger.xsds.bdxr.smp1.ServiceGroupType ret = new BDXR1ServerAPI(aDataProvider).getServiceGroup(sPathServiceGroupID);
aBytes = new BDXR1MarshallerServiceGroupType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
break;
}
default:
throw new UnsupportedOperationException("Unsupported REST type specified!");
}
if (aBytes == null) {
// Internal error serializing the payload
throw new SMPInternalErrorException("Failed to convert the returned ServiceGroup to XML");
}
aUnifiedResponse.setContent(aBytes).setMimeType(CMimeType.TEXT_XML).setCharset(XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
}
use of com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType in project phoss-smp by phax.
the class APIExecutorServiceGroupPut method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sPathServiceGroupID);
// Is the writable API disabled?
if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
throw new SMPPreconditionFailedException("The writable REST API is disabled. saveServiceGroup will not be executed", aDataProvider.getCurrentURI());
}
// Parse main payload
final byte[] aPayload = StreamHelper.getAllBytes(aRequestScope.getRequest().getInputStream());
final Document aServiceGroupDoc = DOMReader.readXMLDOM(aPayload);
if (aServiceGroupDoc == null) {
throw new SMPBadRequestException("Failed to parse provided payload as XML", aDataProvider.getCurrentURI());
}
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
final boolean bCreateInSML = !"false".equalsIgnoreCase(aRequestScope.params().getAsString("create-in-sml"));
ESuccess eSuccess = ESuccess.FAILURE;
switch(SMPServerConfiguration.getRESTType()) {
case PEPPOL:
{
final com.helger.xsds.peppol.smp1.ServiceGroupType aServiceGroup = new SMPMarshallerServiceGroupType(XML_SCHEMA_VALIDATION).read(aServiceGroupDoc);
if (aServiceGroup != null) {
new SMPServerAPI(aDataProvider).saveServiceGroup(sPathServiceGroupID, aServiceGroup, bCreateInSML, aBasicAuth);
eSuccess = ESuccess.SUCCESS;
}
break;
}
case OASIS_BDXR_V1:
{
final com.helger.xsds.bdxr.smp1.ServiceGroupType aServiceGroup = new BDXR1MarshallerServiceGroupType(XML_SCHEMA_VALIDATION).read(aServiceGroupDoc);
if (aServiceGroup != null) {
new BDXR1ServerAPI(aDataProvider).saveServiceGroup(sPathServiceGroupID, aServiceGroup, bCreateInSML, aBasicAuth);
eSuccess = ESuccess.SUCCESS;
}
break;
}
default:
throw new UnsupportedOperationException("Unsupported REST type specified!");
}
if (eSuccess.isFailure())
aUnifiedResponse.setStatus(CHttp.HTTP_INTERNAL_SERVER_ERROR);
else
aUnifiedResponse.setStatus(CHttp.HTTP_OK).disableCaching();
}
use of com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType in project peppol-commons by phax.
the class BDXRClient method saveServiceGroup.
/**
* Saves a service group. The meta data references should not be set and are
* not used.
*
* @param aServiceGroup
* The service group to save. May not be <code>null</code>.
* @param aCredentials
* The user name and password to use as credentials. May not be
* <code>null</code>.
* @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.
*/
public void saveServiceGroup(@Nonnull final ServiceGroupType aServiceGroup, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
ValueEnforcer.notNull(aServiceGroup, "ServiceGroup");
ValueEnforcer.notNull(aCredentials, "Credentials");
final String sBody = new BDXR1MarshallerServiceGroupType(isXMLSchemaValidation()).getAsString(aServiceGroup);
if (sBody == null)
throw new IllegalArgumentException("Failed to serialize ServiceGroup: " + aServiceGroup);
final String sURI = getSMPHostURI() + CIdentifier.getURIPercentEncoded(aServiceGroup.getParticipantIdentifier());
if (LOGGER.isDebugEnabled())
LOGGER.debug("BDXRClient saveServiceGroup@" + sURI);
final HttpPut aRequest = new HttpPut(sURI);
aRequest.addHeader(CHttpHeader.AUTHORIZATION, aCredentials.getRequestValue());
aRequest.setEntity(new StringEntity(sBody, CONTENT_TYPE_TEXT_XML));
executeGenericRequest(aRequest, new SMPHttpResponseHandlerWriteOperations());
}
Aggregations