Search in sources :

Example 1 with SMPMarshallerServiceGroupReferenceListType

use of com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupReferenceListType in project peppol-commons by phax.

the class SMPClientReadOnly method getServiceGroupReferenceList.

/**
 * Gets a list of references to the CompleteServiceGroup's owned by the
 * specified userId. This is a non-specification compliant method.
 *
 * @param sUserID
 *        The username for which to retrieve service groups.
 * @param aCredentials
 *        The user name and password to use as credentials.
 * @return A list of references to complete service groups and never
 *         <code>null</code>.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         The username or password was not correct.
 * @throws SMPClientNotFoundException
 *         The userId did not exist.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 * @see #getServiceGroupReferenceListOrNull(String,
 *      BasicAuthClientCredentials)
 */
@Nonnull
public ServiceGroupReferenceListType getServiceGroupReferenceList(@Nonnull final String sUserID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
    ValueEnforcer.notNull(sUserID, "UserID");
    ValueEnforcer.notNull(aCredentials, "Credentials");
    final String sURI = getSMPHostURI() + URL_PART_LIST + "/" + CIdentifier.createPercentEncoded(sUserID);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("SMPClient getServiceGroupReferenceList@" + sURI);
    final HttpGet aRequest = new HttpGet(sURI);
    aRequest.addHeader(CHttpHeader.AUTHORIZATION, aCredentials.getRequestValue());
    final SMPMarshallerServiceGroupReferenceListType aMarshaller = new SMPMarshallerServiceGroupReferenceListType(isXMLSchemaValidation());
    customizeMarshaller(aMarshaller);
    return executeGenericRequest(aRequest, new SMPHttpResponseHandlerUnsigned<>(aMarshaller));
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) SMPMarshallerServiceGroupReferenceListType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupReferenceListType) Nonnull(javax.annotation.Nonnull)

Example 2 with SMPMarshallerServiceGroupReferenceListType

use of com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupReferenceListType 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)

Aggregations

SMPMarshallerServiceGroupReferenceListType (com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupReferenceListType)2 BasicAuthClientCredentials (com.helger.http.basicauth.BasicAuthClientCredentials)1 SMPInternalErrorException (com.helger.phoss.smp.exception.SMPInternalErrorException)1 BDXR1ServerAPI (com.helger.phoss.smp.restapi.BDXR1ServerAPI)1 ISMPServerAPIDataProvider (com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)1 SMPServerAPI (com.helger.phoss.smp.restapi.SMPServerAPI)1 BDXR1MarshallerServiceGroupReferenceListType (com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupReferenceListType)1 Nonnull (javax.annotation.Nonnull)1 HttpGet (org.apache.http.client.methods.HttpGet)1