Search in sources :

Example 1 with BDXR1MarshallerServiceMetadataType

use of com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceMetadataType 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();
}
Also used : ESuccess(com.helger.commons.state.ESuccess) SMPMarshallerServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceMetadataType) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) SMPServerAPI(com.helger.phoss.smp.restapi.SMPServerAPI) BDXR1ServerAPI(com.helger.phoss.smp.restapi.BDXR1ServerAPI) Document(org.w3c.dom.Document) BDXR1MarshallerServiceMetadataType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceMetadataType) SMPPreconditionFailedException(com.helger.phoss.smp.exception.SMPPreconditionFailedException) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) BDXR1MarshallerServiceMetadataType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceMetadataType) SMPMarshallerServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceMetadataType)

Example 2 with BDXR1MarshallerServiceMetadataType

use of com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceMetadataType in project peppol-commons by phax.

the class BDXRClient method _saveServiceInformation.

private void _saveServiceInformation(@Nonnull final ParticipantIdentifierType aServiceGroupID, @Nonnull final DocumentIdentifierType aDocumentTypeID, @Nonnull final ServiceMetadataType aServiceMetadata, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
    final String sBody = new BDXR1MarshallerServiceMetadataType(isXMLSchemaValidation()).getAsString(aServiceMetadata);
    if (sBody == null)
        throw new IllegalArgumentException("Failed to serialize ServiceMetadata: " + aServiceMetadata);
    final String sURI = getSMPHostURI() + CIdentifier.getURIPercentEncoded(aServiceGroupID) + "/" + URL_PART_SERVICES + "/" + CIdentifier.getURIPercentEncoded(aDocumentTypeID);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("BDXRClient 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());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) BDXR1MarshallerServiceMetadataType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceMetadataType) SMPHttpResponseHandlerWriteOperations(com.helger.smpclient.httpclient.SMPHttpResponseHandlerWriteOperations) HttpPut(org.apache.http.client.methods.HttpPut)

Aggregations

BDXR1MarshallerServiceMetadataType (com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceMetadataType)2 ESuccess (com.helger.commons.state.ESuccess)1 BasicAuthClientCredentials (com.helger.http.basicauth.BasicAuthClientCredentials)1 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)1 SMPPreconditionFailedException (com.helger.phoss.smp.exception.SMPPreconditionFailedException)1 BDXR1ServerAPI (com.helger.phoss.smp.restapi.BDXR1ServerAPI)1 ISMPServerAPIDataProvider (com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)1 SMPServerAPI (com.helger.phoss.smp.restapi.SMPServerAPI)1 SMPHttpResponseHandlerWriteOperations (com.helger.smpclient.httpclient.SMPHttpResponseHandlerWriteOperations)1 SMPMarshallerServiceMetadataType (com.helger.smpclient.peppol.marshal.SMPMarshallerServiceMetadataType)1 HttpPut (org.apache.http.client.methods.HttpPut)1 StringEntity (org.apache.http.entity.StringEntity)1 Document (org.w3c.dom.Document)1