use of com.helger.phoss.smp.restapi.SMPServerAPI in project phoss-smp by phax.
the class APIExecutorServiceGroupCompleteGet 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);
final byte[] aBytes;
switch(SMPServerConfiguration.getRESTType()) {
case PEPPOL:
{
// Unspecified extension
final com.helger.xsds.peppol.smp1.CompleteServiceGroupType ret = new SMPServerAPI(aDataProvider).getCompleteServiceGroup(sPathServiceGroupID);
aBytes = new SMPMarshallerCompleteServiceGroupType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
break;
}
case OASIS_BDXR_V1:
{
// Unspecified extension
final com.helger.xsds.bdxr.smp1.CompleteServiceGroupType ret = new BDXR1ServerAPI(aDataProvider).getCompleteServiceGroup(sPathServiceGroupID);
aBytes = new BDXR1MarshallerCompleteServiceGroupType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
break;
}
default:
throw new UnsupportedOperationException("Unsupported REST type specified!");
}
if (aBytes == null) {
// Internal error serializing the payload
throw new SMPInternalErrorException("Failed to convert the returned CompleteServiceGroup to XML");
}
aUnifiedResponse.setContent(aBytes).setMimeType(CMimeType.TEXT_XML).setCharset(XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
}
use of com.helger.phoss.smp.restapi.SMPServerAPI in project phoss-smp by phax.
the class APIExecutorServiceGroupDelete 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. deleteServiceGroup will not be executed", aDataProvider.getCurrentURI());
}
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
final boolean bDeleteInSML = !"false".equalsIgnoreCase(aRequestScope.params().getAsString("delete-in-sml"));
switch(SMPServerConfiguration.getRESTType()) {
case PEPPOL:
new SMPServerAPI(aDataProvider).deleteServiceGroup(sPathServiceGroupID, bDeleteInSML, aBasicAuth);
break;
case OASIS_BDXR_V1:
new BDXR1ServerAPI(aDataProvider).deleteServiceGroup(sPathServiceGroupID, bDeleteInSML, aBasicAuth);
break;
default:
throw new UnsupportedOperationException("Unsupported REST type specified!");
}
aUnifiedResponse.setStatus(CHttp.HTTP_OK).disableCaching();
}
use of com.helger.phoss.smp.restapi.SMPServerAPI in project phoss-smp by phax.
the class APIExecutorServiceMetadataDelete 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. deleteServiceRegistration will not be executed", aDataProvider.getCurrentURI());
}
final String sDocumentTypeID = aPathVariables.get(SMPRestFilter.PARAM_DOCUMENT_TYPE_ID);
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
switch(SMPServerConfiguration.getRESTType()) {
case PEPPOL:
new SMPServerAPI(aDataProvider).deleteServiceRegistration(sPathServiceGroupID, sDocumentTypeID, aBasicAuth);
break;
case OASIS_BDXR_V1:
new BDXR1ServerAPI(aDataProvider).deleteServiceRegistration(sPathServiceGroupID, sDocumentTypeID, aBasicAuth);
break;
default:
throw new UnsupportedOperationException("Unsupported REST type specified!");
}
aUnifiedResponse.setStatus(CHttp.HTTP_OK).disableCaching();
}
use of com.helger.phoss.smp.restapi.SMPServerAPI in project phoss-smp by phax.
the class APIExecutorServiceMetadataGet 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 String sPathDocumentTypeID = aPathVariables.get(SMPRestFilter.PARAM_DOCUMENT_TYPE_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sPathServiceGroupID);
// Create the unsigned response document
final Document aDoc;
switch(SMPServerConfiguration.getRESTType()) {
case PEPPOL:
{
final com.helger.xsds.peppol.smp1.SignedServiceMetadataType ret = new SMPServerAPI(aDataProvider).getServiceRegistration(sPathServiceGroupID, sPathDocumentTypeID);
// Convert to DOM document
// Disable XSD check, because Signature is added later
final SMPMarshallerSignedServiceMetadataType aMarshaller = new SMPMarshallerSignedServiceMetadataType(false);
aDoc = aMarshaller.getAsDocument(ret);
break;
}
case OASIS_BDXR_V1:
{
final com.helger.xsds.bdxr.smp1.SignedServiceMetadataType ret = new BDXR1ServerAPI(aDataProvider).getServiceRegistration(sPathServiceGroupID, sPathDocumentTypeID);
// Convert to DOM document
// Disable XSD check, because Signature is added later
final BDXR1MarshallerSignedServiceMetadataType aMarshaller = new BDXR1MarshallerSignedServiceMetadataType(false);
aDoc = aMarshaller.getAsDocument(ret);
break;
}
default:
throw new UnsupportedOperationException("Unsupported REST type specified!");
}
if (aDoc == null)
throw new IllegalStateException("Failed to serialize unsigned node!");
// Sign the document
try {
SMPKeyManager.getInstance().signXML(aDoc.getDocumentElement(), SMPServerConfiguration.getRESTType().isBDXR());
LOGGER.info("Successfully signed response XML");
} catch (final Exception ex) {
throw new SMPInternalErrorException("Error in signing the response XML", ex);
}
// Serialize the signed document
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream()) {
if (false) {
// IMPORTANT: no indent and no align!
final IXMLWriterSettings aSettings = XMLWriterSettings.createForCanonicalization();
// Write the result to a byte array
if (XMLWriter.writeToStream(aDoc, aBAOS, aSettings).isFailure())
throw new IllegalStateException("Failed to serialize signed node!");
} else {
// for validating the signature!
try {
final Transformer aTransformer = XMLTransformerFactory.newTransformer();
aTransformer.transform(new DOMSource(aDoc), new StreamResult(aBAOS));
} catch (final TransformerException ex) {
throw new IllegalStateException("Failed to serialized signed node", ex);
}
}
aUnifiedResponse.setContent(aBAOS.toByteArray()).setMimeType(CMimeType.TEXT_XML).setCharset(XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
}
}
use of com.helger.phoss.smp.restapi.SMPServerAPI 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