Search in sources :

Example 16 with SMPBadRequestException

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

Aggregations

SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)16 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)11 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)11 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)10 SMPPreconditionFailedException (com.helger.phoss.smp.exception.SMPPreconditionFailedException)9 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)9 ISMPServerAPIDataProvider (com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)9 BasicAuthClientCredentials (com.helger.http.basicauth.BasicAuthClientCredentials)8 IUser (com.helger.photon.security.user.IUser)8 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)5 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)5 Nonnull (javax.annotation.Nonnull)5 ISMPBusinessCardManager (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager)4 ISMPParticipantMigration (com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration)4 ISMPParticipantMigrationManager (com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager)4 IMicroDocument (com.helger.xml.microdom.IMicroDocument)4 ICommonsList (com.helger.commons.collection.impl.ICommonsList)3 CMimeType (com.helger.commons.mime.CMimeType)3 MimeType (com.helger.commons.mime.MimeType)3 ESuccess (com.helger.commons.state.ESuccess)3