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();
}
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());
}
Aggregations