Search in sources :

Example 21 with BasicAuthClientCredentials

use of com.helger.http.basicauth.BasicAuthClientCredentials 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 22 with BasicAuthClientCredentials

use of com.helger.http.basicauth.BasicAuthClientCredentials 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();
}
Also used : SMPPreconditionFailedException(com.helger.phoss.smp.exception.SMPPreconditionFailedException) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPServerAPI(com.helger.phoss.smp.restapi.SMPServerAPI) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) BDXR1ServerAPI(com.helger.phoss.smp.restapi.BDXR1ServerAPI)

Example 23 with BasicAuthClientCredentials

use of com.helger.http.basicauth.BasicAuthClientCredentials 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);
}
Also used : SMPServerAPI(com.helger.phoss.smp.restapi.SMPServerAPI) SMPMarshallerServiceGroupReferenceListType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupReferenceListType) BDXR1MarshallerServiceGroupReferenceListType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupReferenceListType) SMPMarshallerServiceGroupReferenceListType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupReferenceListType) BDXR1ServerAPI(com.helger.phoss.smp.restapi.BDXR1ServerAPI) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPInternalErrorException(com.helger.phoss.smp.exception.SMPInternalErrorException) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) BDXR1MarshallerServiceGroupReferenceListType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupReferenceListType)

Example 24 with BasicAuthClientCredentials

use of com.helger.http.basicauth.BasicAuthClientCredentials in project peppol-commons by phax.

the class MainSMPServiceGroupCreate method main.

public static void main(final String[] args) throws Exception {
    final URI SMP_URI = MockSMPClientConfig.getSMPURI();
    final BasicAuthClientCredentials SMP_CREDENTIALS = MockSMPClientConfig.getSMPCredentials();
    final IParticipantIdentifier PARTICIPANT_ID = MockSMPClientConfig.getParticipantID();
    // The main SMP client
    final SMPClient aClient = new SMPClient(SMP_URI);
    // Create the service group
    aClient.saveServiceGroup(PARTICIPANT_ID, SMP_CREDENTIALS);
    LOGGER.info("Done");
}
Also used : BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPClient(com.helger.smpclient.peppol.SMPClient) URI(java.net.URI) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 25 with BasicAuthClientCredentials

use of com.helger.http.basicauth.BasicAuthClientCredentials in project peppol-commons by phax.

the class MainSMPServiceRegistrationCreate method main.

public static void main(final String[] args) throws Exception {
    final URI SMP_URI = MockSMPClientConfig.getSMPURI();
    final BasicAuthClientCredentials SMP_CREDENTIALS = MockSMPClientConfig.getSMPCredentials();
    final IParticipantIdentifier PARTICIPANT_ID = MockSMPClientConfig.getParticipantID();
    final IDocumentTypeIdentifier DOCUMENT_ID = MockSMPClientConfig.getDocumentTypeID();
    final IProcessIdentifier PROCESS_ID = MockSMPClientConfig.getProcessTypeID();
    final W3CEndpointReference START_AP_ENDPOINTREF = MockSMPClientConfig.getAPEndpointRef();
    final String AP_CERT_STRING = MockSMPClientConfig.getAPCert();
    final String AP_SERVICE_DESCRIPTION = MockSMPClientConfig.getAPServiceDescription();
    final String AP_CONTACT_URL = MockSMPClientConfig.getAPContact();
    final String AP_INFO_URL = MockSMPClientConfig.getAPInfo();
    // The main SMP client
    final SMPClient aClient = new SMPClient(SMP_URI);
    // Create the service registration
    final ServiceInformationType aServiceInformation = new ServiceInformationType();
    {
        final ProcessListType aProcessList = new ProcessListType();
        {
            final ProcessType aProcess = new ProcessType();
            {
                final ServiceEndpointList aServiceEndpointList = new ServiceEndpointList();
                {
                    final EndpointType aEndpoint = new EndpointType();
                    aEndpoint.setEndpointReference(START_AP_ENDPOINTREF);
                    aEndpoint.setTransportProfile(ESMPTransportProfile.TRANSPORT_PROFILE_AS2.getID());
                    aEndpoint.setCertificate(AP_CERT_STRING);
                    aEndpoint.setServiceActivationDate(PDTFactory.createXMLOffsetDateTime(2011, Month.JANUARY, 1));
                    aEndpoint.setServiceExpirationDate(PDTFactory.createXMLOffsetDateTime(2020, Month.DECEMBER, 31));
                    aEndpoint.setServiceDescription(AP_SERVICE_DESCRIPTION);
                    aEndpoint.setTechnicalContactUrl(AP_CONTACT_URL);
                    aEndpoint.setTechnicalInformationUrl(AP_INFO_URL);
                    aEndpoint.setMinimumAuthenticationLevel("1");
                    aEndpoint.setRequireBusinessLevelSignature(false);
                    aServiceEndpointList.getEndpoint().add(aEndpoint);
                }
                aProcess.setProcessIdentifier(new SimpleProcessIdentifier(PROCESS_ID));
                aProcess.setServiceEndpointList(aServiceEndpointList);
            }
            aProcessList.getProcess().add(aProcess);
        }
        aServiceInformation.setDocumentIdentifier(new SimpleDocumentTypeIdentifier(DOCUMENT_ID));
        aServiceInformation.setParticipantIdentifier(new SimpleParticipantIdentifier(PARTICIPANT_ID));
        aServiceInformation.setProcessList(aProcessList);
    }
    aClient.saveServiceInformation(aServiceInformation, SMP_CREDENTIALS);
    LOGGER.info("Done");
}
Also used : SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) URI(java.net.URI) ServiceInformationType(com.helger.xsds.peppol.smp1.ServiceInformationType) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) ProcessType(com.helger.xsds.peppol.smp1.ProcessType) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPClient(com.helger.smpclient.peppol.SMPClient) SimpleProcessIdentifier(com.helger.peppolid.simple.process.SimpleProcessIdentifier) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) ProcessListType(com.helger.xsds.peppol.smp1.ProcessListType) ServiceEndpointList(com.helger.xsds.peppol.smp1.ServiceEndpointList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Aggregations

BasicAuthClientCredentials (com.helger.http.basicauth.BasicAuthClientCredentials)26 ISMPServerAPIDataProvider (com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)15 SMPPreconditionFailedException (com.helger.phoss.smp.exception.SMPPreconditionFailedException)12 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)10 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)8 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)8 CMimeType (com.helger.commons.mime.CMimeType)7 MimeType (com.helger.commons.mime.MimeType)7 IMicroDocument (com.helger.xml.microdom.IMicroDocument)7 XMLWriterSettings (com.helger.xml.serialize.write.XMLWriterSettings)7 BDXR1ServerAPI (com.helger.phoss.smp.restapi.BDXR1ServerAPI)6 SMPServerAPI (com.helger.phoss.smp.restapi.SMPServerAPI)6 SMPClient (com.helger.smpclient.peppol.SMPClient)6 URI (java.net.URI)6 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)5 ISMPParticipantMigration (com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration)5 ISMPParticipantMigrationManager (com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager)5 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)5 ISMPSettingsManager (com.helger.phoss.smp.settings.ISMPSettingsManager)4 IXMLWriterSettings (com.helger.xml.serialize.write.IXMLWriterSettings)4