Android Open Source - mobile-connector-sdk-android X M L A P I Client






From Project

Back to project page mobile-connector-sdk-android.

License

The source code is released under:

Apache License

If you think the Android project mobile-connector-sdk-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.silverpop.engage.network;
//from   w  ww.  ja v  a 2  s. c o m
import android.content.Context;
import android.util.Log;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.silverpop.engage.config.EngageConfigManager;
import com.silverpop.engage.domain.XMLAPI;

import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by jeremydyer on 5/19/14.
 */
public class XMLAPIClient
    extends EngageClient {

    private static final String TAG = XMLAPIClient.class.getName();

    private static XMLAPIClient xmlapiClient = null;
    private final ArrayList<RequestCacheWrapper> apiCache = new ArrayList<RequestCacheWrapper>();

    private XMLAPIClient(Context context, String clientId, String secret, String refreshToken, String hostUrl) {
        super(context, clientId, secret, refreshToken, hostUrl);
    }

    public static XMLAPIClient init(Context context, String clientId, String secret, String refreshToken, String host) {
        if (xmlapiClient == null) {
            xmlapiClient = new XMLAPIClient(context, clientId, secret, refreshToken, host);
            xmlapiClient.authenticateClient(new Response.Listener<String>() {
                @Override
                public void onResponse(String s) {
                    ArrayList<RequestCacheWrapper> postedAPI = new ArrayList<RequestCacheWrapper>();
                    for (RequestCacheWrapper wrapper : xmlapiClient.apiCache) {
                        xmlapiClient.postResource(wrapper.getXmlapi(),
                                wrapper.getSuccessListener(), wrapper.getErrorListener());
                        postedAPI.add(wrapper);
                    }
                    xmlapiClient.apiCache.removeAll(postedAPI);
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    Log.w(TAG, "XMLAPIClient authentication failed");
                }
            });
        }
        return xmlapiClient;
    }


    public static XMLAPIClient get(Context context) {
        if (xmlapiClient == null) {
            Log.e(TAG, XMLAPIClient.class.getName() + " must be initialized before it can be retrieved");
            throw new RuntimeException(XMLAPIClient.class.getName() + " must be initialized before it can be retrieved");
        }
        return xmlapiClient;
    }

    private String getXMLAPIURL() {
        try {
            if (EngageConfigManager.get(mAppContext).secureConnection()) {
                return new URI("https", getHost(), "/XMLAPI", null).toString();
            } else {
                return new URI("http", getHost(), "/XMLAPI", null).toString();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    public void postResource(final XMLAPI api, Response.Listener<String> successListener, Response.ErrorListener errorListener) {
        if (isAuthenticated()) {
            //Create the Volley Request object.
            StringRequest req = new StringRequest(Request.Method.POST,
                    getXMLAPIURL(), successListener, errorListener)
            {
                protected Map<String, String> getParams() throws AuthFailureError {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("xml", api.envelope());
                    return params;
                }

                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    Map<String,String> params = new HashMap<String, String>();
                    params.put("Authorization", "Bearer " + getOauthToken());
                    return params;
                }
            };

            request(req);
        } else {
            apiCache.add(new RequestCacheWrapper(api, successListener, errorListener));
        }
    }
}




Java Source Code List

com.silverpop.engage.EngageApplication.java
com.silverpop.engage.UBFManager.java
com.silverpop.engage.XMLAPIManager.java
com.silverpop.engage.augmentation.UBFAugmentationServiceImpl.java
com.silverpop.engage.augmentation.UBFAugmentationService.java
com.silverpop.engage.augmentation.plugin.UBFAddressAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFCoordinatesAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFLocationNameAugmentationPlugin.java
com.silverpop.engage.config.EngageConfigManagerTests.java
com.silverpop.engage.config.EngageConfigManager.java
com.silverpop.engage.config.EngageConfigTest.java
com.silverpop.engage.config.EngageConfig.java
com.silverpop.engage.deeplinking.EngageDeepLinkManager.java
com.silverpop.engage.demo.engagetest.Application.java
com.silverpop.engage.demo.engagetest.EngageNotificationReceiver.java
com.silverpop.engage.demo.engagetest.MainActivity.java
com.silverpop.engage.demo.engagetest.PushReceiver.java
com.silverpop.engage.demo.engagetest.fragment.EngageConfigFragment.java
com.silverpop.engage.demo.engagetest.fragment.UBFAPIFragment.java
com.silverpop.engage.demo.engagetest.fragment.XMLAPIFragment.java
com.silverpop.engage.domain.EngageEvent.java
com.silverpop.engage.domain.JSONable.java
com.silverpop.engage.domain.UBFTests.java
com.silverpop.engage.domain.UBF.java
com.silverpop.engage.domain.XMLAPIEnum.java
com.silverpop.engage.domain.XMLAPITest.java
com.silverpop.engage.domain.XMLAPI.java
com.silverpop.engage.exception.XMLResponseParseException.java
com.silverpop.engage.location.manager.EngageLocationManager.java
com.silverpop.engage.location.manager.plugin.EngageLocationManagerDefault.java
com.silverpop.engage.location.receiver.EngageLocationReceiver.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverBase.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverGeocode.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverHardcodeTest.java
com.silverpop.engage.network.Credential.java
com.silverpop.engage.network.EngageClient.java
com.silverpop.engage.network.RequestCacheWrapper.java
com.silverpop.engage.network.UBFClient.java
com.silverpop.engage.network.XMLAPIClient.java
com.silverpop.engage.response.EngageResponseXMLTests.java
com.silverpop.engage.response.EngageResponseXML.java
com.silverpop.engage.response.XMLAPIResponseNode.java
com.silverpop.engage.store.EngageLocalEventStoreTest.java
com.silverpop.engage.store.EngageLocalEventStore.java
com.silverpop.engage.store.EngageSQLiteHelper.java
com.silverpop.engage.util.EngageExpirationParserTests.java
com.silverpop.engage.util.EngageExpirationParser.java
com.silverpop.engage.util.TimedAsyncTask.java