use of com.helger.phoss.smp.restapi.BDXR1ServerAPI in project phoss-smp by phax.
the class APIExecutorServiceGroupGet 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:
{
final com.helger.xsds.peppol.smp1.ServiceGroupType ret = new SMPServerAPI(aDataProvider).getServiceGroup(sPathServiceGroupID);
aBytes = new SMPMarshallerServiceGroupType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
break;
}
case OASIS_BDXR_V1:
{
final com.helger.xsds.bdxr.smp1.ServiceGroupType ret = new BDXR1ServerAPI(aDataProvider).getServiceGroup(sPathServiceGroupID);
aBytes = new BDXR1MarshallerServiceGroupType(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 ServiceGroup to XML");
}
aUnifiedResponse.setContent(aBytes).setMimeType(CMimeType.TEXT_XML).setCharset(XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
}
use of com.helger.phoss.smp.restapi.BDXR1ServerAPI 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.phoss.smp.restapi.BDXR1ServerAPI in project phoss-smp by phax.
the class APIExecutorServiceMetadataDeleteAll 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. deleteServiceRegistrations will not be executed.", aDataProvider.getCurrentURI());
}
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
switch(SMPServerConfiguration.getRESTType()) {
case PEPPOL:
new SMPServerAPI(aDataProvider).deleteServiceRegistrations(sPathServiceGroupID, aBasicAuth);
break;
case OASIS_BDXR_V1:
new BDXR1ServerAPI(aDataProvider).deleteServiceRegistrations(sPathServiceGroupID, aBasicAuth);
break;
default:
throw new UnsupportedOperationException("Unsupported REST type specified!");
}
aUnifiedResponse.setStatus(HttpServletResponse.SC_OK).disableCaching();
}
use of com.helger.phoss.smp.restapi.BDXR1ServerAPI in project phoss-smp by phax.
the class APIExecutorUserListGet 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 sPathUserID = aPathVariables.get(SMPRestFilter.PARAM_USER_ID);
// No service group available
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, null);
final BasicAuthClientCredentials aCredentials = getMandatoryAuth(aRequestScope.headers());
final byte[] aBytes;
switch(SMPServerConfiguration.getRESTType()) {
case PEPPOL:
{
// Unspecified extension
final com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType ret = new SMPServerAPI(aDataProvider).getServiceGroupReferenceList(sPathUserID, aCredentials);
aBytes = new SMPMarshallerServiceGroupReferenceListType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
break;
}
case OASIS_BDXR_V1:
{
// Unspecified extension
final com.helger.xsds.bdxr.smp1.ServiceGroupReferenceListType ret = new BDXR1ServerAPI(aDataProvider).getServiceGroupReferenceList(sPathUserID, aCredentials);
aBytes = new BDXR1MarshallerServiceGroupReferenceListType(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);
}
Aggregations