Search in sources :

Example 26 with ESuccess

use of com.helger.commons.state.ESuccess 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)

Example 27 with ESuccess

use of com.helger.commons.state.ESuccess in project peppol-commons by phax.

the class SignedServiceMetadataTypeFuncTest method testReadInvalid.

@Test
public void testReadInvalid() throws Exception {
    final SMPMarshallerSignedServiceMetadataType aMarshaller = new SMPMarshallerSignedServiceMetadataType(true);
    aMarshaller.setValidationEventHandlerFactory(x -> new LoggingValidationEventHandler());
    final byte[] aBytes = StreamHelper.getAllBytes(new ClassPathResource("smp/signed-service-metadata1.xml"));
    assertNotNull(aBytes);
    final SignedServiceMetadataType aSSM = aMarshaller.read(aBytes);
    assertNotNull(aSSM);
    final Document aDocument = DOMReader.readXMLDOM(aBytes);
    assertNotNull(aDocument);
    final TrustStoreBasedX509KeySelector aKeySelector = new TrustStoreBasedX509KeySelector(SMPClientConfiguration.loadTrustStore());
    // Certificate expired 2021-03-01
    aKeySelector.setValidationDateTime(PDTFactory.createLocalDateTime(2021, Month.JANUARY, 1));
    final ESuccess eSuccess = SMPHttpResponseHandlerSigned.checkSignature(aDocument, aKeySelector);
    assertTrue(eSuccess.isFailure());
}
Also used : ESuccess(com.helger.commons.state.ESuccess) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) TrustStoreBasedX509KeySelector(com.helger.smpclient.security.TrustStoreBasedX509KeySelector) LoggingValidationEventHandler(com.helger.jaxb.validation.LoggingValidationEventHandler) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) Test(org.junit.Test)

Aggregations

ESuccess (com.helger.commons.state.ESuccess)27 Nonnull (javax.annotation.Nonnull)15 ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)13 DBExecutor (com.helger.db.jdbc.executor.DBExecutor)13 Nullable (javax.annotation.Nullable)9 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)8 MutableBoolean (com.helger.commons.mutable.MutableBoolean)7 Wrapper (com.helger.commons.wrapper.Wrapper)7 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)6 EChange (com.helger.commons.state.EChange)6 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)6 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)6 ValueEnforcer (com.helger.commons.ValueEnforcer)5 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)5 ICommonsList (com.helger.commons.collection.impl.ICommonsList)5 StringHelper (com.helger.commons.string.StringHelper)5 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)5 Document (org.w3c.dom.Document)5 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)4 CallbackList (com.helger.commons.callback.CallbackList)4