use of com.helger.smpclient.peppol.marshal.SMPMarshallerServiceMetadataType in project peppol-commons by phax.
the class SMPClient method _saveServiceInformation.
private void _saveServiceInformation(@Nonnull final IParticipantIdentifier aServiceGroupID, @Nonnull final IDocumentTypeIdentifier aDocumentTypeID, @Nonnull final ServiceMetadataType aServiceMetadata, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
final String sBody = new SMPMarshallerServiceMetadataType(isXMLSchemaValidation()).getAsString(aServiceMetadata);
if (sBody == null)
throw new IllegalArgumentException("Failed to serialize ServiceMetadata: " + aServiceMetadata);
final String sURI = getSMPHostURI() + aServiceGroupID.getURIPercentEncoded() + "/" + URL_PART_SERVICES + "/" + aDocumentTypeID.getURIPercentEncoded();
if (LOGGER.isDebugEnabled())
LOGGER.debug("SMPClient saveServiceRegistration@" + 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());
}
use of com.helger.smpclient.peppol.marshal.SMPMarshallerServiceMetadataType in project phoss-smp by phax.
the class APIExecutorServiceMetadataPut 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. saveServiceRegistration will not be executed", aDataProvider.getCurrentURI());
}
// Parse main payload
final byte[] aPayload = StreamHelper.getAllBytes(aRequestScope.getRequest().getInputStream());
final Document aServiceMetadataDoc = DOMReader.readXMLDOM(aPayload);
if (aServiceMetadataDoc == null) {
throw new SMPBadRequestException("Failed to parse provided payload as XML", aDataProvider.getCurrentURI());
}
final String sDocumentTypeID = aPathVariables.get(SMPRestFilter.PARAM_DOCUMENT_TYPE_ID);
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
ESuccess eSuccess = ESuccess.FAILURE;
switch(SMPServerConfiguration.getRESTType()) {
case PEPPOL:
{
final com.helger.xsds.peppol.smp1.ServiceMetadataType aServiceMetadata = new SMPMarshallerServiceMetadataType(XML_SCHEMA_VALIDATION).read(aServiceMetadataDoc);
if (aServiceMetadata != null) {
eSuccess = new SMPServerAPI(aDataProvider).saveServiceRegistration(sPathServiceGroupID, sDocumentTypeID, aServiceMetadata, aBasicAuth);
}
break;
}
case OASIS_BDXR_V1:
{
final com.helger.xsds.bdxr.smp1.ServiceMetadataType aServiceMetadata = new BDXR1MarshallerServiceMetadataType(XML_SCHEMA_VALIDATION).read(aServiceMetadataDoc);
if (aServiceMetadata != null) {
eSuccess = new BDXR1ServerAPI(aDataProvider).saveServiceRegistration(sPathServiceGroupID, sDocumentTypeID, aServiceMetadata, aBasicAuth);
}
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();
}
Aggregations