Hi, Alain

Thank you for reply. Here's my code:

My query that provides user list:

public class UserProfileQuery implements Query<UserPrincipal, 
List<GoogleUser>> {

    @Inject
    private TwoLeggedHmacAuthenticatorFactory authenticatorFactory;

    private String domainAdminEmail;

    @Override
    public List<GoogleUser> fetch(UserPrincipal params) {
        String authDomain = params.getAuthDomain();
        // newAuthenticator method just creates new instance of 
TwoLeggedHmacAuthenticator 
        // with dev or production environment properties of key and secret
        TwoLeggedHmacAuthenticator twoLeggedHmacAuthenticator = 
authenticatorFactory.newAuthenticator(authDomain);
        // This factory creates new instance of RetrieveAllProfilesCommand 
class
        ProfilesCommandFactory profilesCommandFactory = new 
ProfilesCommandFactory(twoLeggedHmacAuthenticator);
        RetrieveAllProfilesCommand command = 
profilesCommandFactory.newRetrieveAllProfilesCommand(
                new RetrieveAllProfilesCommand.CommandData(authDomain, 
domainAdminEmail));
        return command.execute();
    }

    public void setDomainAdminEmail(String domainAdminEmail) {
        this.domainAdminEmail = domainAdminEmail;
    }
}

public class TwoLeggedHmacAuthenticator implements GoogleAuthenticator{
    private final String marketPlaceConsumerKey;
    private final String marketPlaceConsumerSecret;
    private final String domain;
    
    /*package*/ TwoLeggedHmacAuthenticator(String domain, String 
marketPlaceConsumerKey, String marketPlaceConsumerSecret){
        this.domain = domain;
        this.marketPlaceConsumerKey = marketPlaceConsumerKey;
        this.marketPlaceConsumerSecret = marketPlaceConsumerSecret;
    }
    
    @Override
    public void initWithCredentials(GoogleService googleService) throws 
GdataAuthException {
        GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
        oauthParameters.setOAuthConsumerKey(marketPlaceConsumerKey);
        oauthParameters.setOAuthConsumerSecret(marketPlaceConsumerSecret);
        oauthParameters.setOAuthType(OAuthType.TWO_LEGGED_OAUTH);
        try {
            googleService.setOAuthCredentials(oauthParameters, new 
OAuthHmacSha1Signer());
        } catch (OAuthException e) {
            throw new GdataAuthException(e);
        }        
    }

    @Override
    public String getDomain() {
        return this.domain;
    }
}

public class RetrieveAllProfilesCommand extends 
AbstractGoogleCommand<RetrieveAllProfilesCommand.CommandData, 
List<GoogleUser>, ContactsService> {

    private static final String URL_FORMAT_PROFILES = "
https://www.google.com/m8/feeds/profiles/domain/%s/full?xoauth_requestor_id=%s
";

    public RetrieveAllProfilesCommand(ContactsService s, CommandData param) 
{
        super(s, param);
    }

    @Override
    protected List<GoogleUser> doExecute(CommandData cmdData) throws 
IOException, ServiceException {
        URL feedUrl = new URL(format(URL_FORMAT_PROFILES, 
cmdData.getDomain(), cmdData.getDomainAdminEmail()));
        // exception throws here after getFeed invokation
        ContactFeed contactFeed = getGoogleService().getFeed(feedUrl, 
ContactFeed.class);
        return parseEntries(contactFeed.getEntries());
    }

    private List<GoogleUser> parseEntries(List<ContactEntry> entries) {
        // ...
    }

    public static class CommandData {
       // ...
    }
}

[AbstractGoogleCommand]

public abstract class AbstractGoogleCommand<P, R, S extends GoogleService> {
    protected static final String APPS_FEEDS_URL_BASE = "
https://apps-apis.google.com/a/feeds/";;
    public static final String APPLICATION_NAME = "my-app-name";

    private Logger logger = Logger.getLogger(getClass().getName());

    private S googleService;
    private P param;

    protected AbstractGoogleCommand(S s, @Nullable P param) {
        this.googleService = s;
        this.param = param;
    }

    public final R execute() {
        try {
            return doExecute(param);
        } catch (AuthenticationException e) {
            logger.log(Level.SEVERE, e.getAuthHeader());
            logger.log(Level.SEVERE, e.getDebugInfo());
            logger.log(Level.SEVERE, e.getDomainName());
            logger.log(Level.SEVERE, e.getMessage());
            throw new GoogleAuthenticationException(e.getMessage(), e);
        } catch (IOException e) {
            logger.log(Level.SEVERE, e.getMessage(), e);
            throw new GdataCommandExecutionFailed(e);
        } catch (ServiceException e) {
            logger.log(Level.SEVERE, e.getMessage(), e);
            throw new GdataCommandExecutionFailed(e);
        }
    }

    protected abstract R doExecute(P cmdData) throws IOException, 
ServiceException;

    protected S getGoogleService() {
        return googleService;
    }
}

Thank you Alain for your help.

Best regards,
Maxim

-- 
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html

Reply via email to