text:
package org.jboss.aerogear.unifiedpush;

import net.iharder.Base64;
import org.jboss.aerogear.unifiedpush.exception.PushSenderException;
import org.jboss.aerogear.unifiedpush.exception.PushSenderHttpException;
import org.jboss.aerogear.unifiedpush.utils.HttpRequestUtil;
import org.jboss.aerogear.unifiedpush.message.MessageResponseCallback;
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage;
import org.jboss.aerogear.unifiedpush.model.ProxyConfig;
import org.jboss.aerogear.unifiedpush.model.TrustStoreConfig;
import org.jboss.aerogear.unifiedpush.utils.PushConfiguration;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.jboss.aerogear.unifiedpush.utils.ValidationUtils.isEmpty;

public class DefaultPushSender implements PushSender {

    private static final Logger logger = Logger.getLogger(DefaultPushSender.class.getName());

    private static final Charset UTF_8 = Charset.forName("UTF-8");

    private final PushConfiguration pushConfiguration;
    private final ProxyConfig proxy;
    private final TrustStoreConfig customTrustStore;

    /**
     * Only called by builder.
     */
    private DefaultPushSender(Builder builder) {
        pushConfiguration = builder.pushConfiguration;
        proxy = builder.proxy;
        customTrustStore = builder.customTrustStore;
    }

    /**
     * Starts a {@link Builder} by providing a UnifiedPush Server URL
     *
     * @param rootServerURL of the UnifiedPush Server
     * @return a {@link Builder} instance
     */
    public static Builder withRootServerURL(String rootServerURL) {
        return new Builder(rootServerURL);
    }

    /**
     * Starts a {@link Builder} using an external config file
     *
     * @param location of the push configuration file
     * @return a {@link Builder} instance
     */
    public static Builder withConfig(String location) {
        try {
            return new Builder(PushConfiguration.read(location));
        }
        catch(IOException e){
            logger.log(Level.SEVERE, "Could not read config file", e);
            return null;
        }
    }

    /**
     * Builder to build Client with more configuration.
     */
    public static class Builder {

        private PushConfiguration pushConfiguration;
        private ProxyConfig proxy;
        private TrustStoreConfig customTrustStore;

        private Builder(String rootServerURL) {
            pushConfiguration = new PushConfiguration();
            if (isEmpty(rootServerURL)) {
                throw new IllegalStateException("server can not be null");
            }
            pushConfiguration.setServerUrl(!rootServerURL.endsWith("/") ? rootServerURL + '/' : rootServerURL);
        }

        private Builder(PushConfiguration pushConfiguration) {
          this.pushConfiguration = pushConfiguration;
        }

        /**
         * Specifies which Push Application the sender will be using.
         *
         * @param pushApplicationId The pushApplicationID
         * @return the current {@link Builder} instance
         */
        public Builder pushApplicationId(String pushApplicationId) {
            pushConfiguration.setPushApplicationId(pushApplicationId);
            return this;
        }

        /**
         * Set the masterSecret used to authenticate against the Push Server.
         *
         * @param masterSecret The masterSecret
         * @return the current {@link Builder} instance
         */
        public Builder masterSecret(String masterSecret){
            pushConfiguration.setMasterSecret(masterSecret);
            return this;
        }

        /**
         * Set a custom trustStore.
         *
         * @param trustStorePath The trustStore file path.
         * @param trustStoreType The trustStore type. If null the default type iss used.
         * @param trustStorePassword The trustStore password.
         * @return the current {@link Builder} instance
         */
        public Builder customTrustStore(String trustStorePath, String trustStoreType, String trustStorePassword) {
            customTrustStore = new TrustStoreConfig(trustStorePath, trustStoreType, trustStorePassword);
            return this;
        }

        /**
         * Specify proxy that should be used to connect.
         *
         * @param proxyHost Hostname of proxy.
         * @param proxyPort Port of proxy.
         * @return the current {@link Builder} instance
         */
        public Builder proxy(String proxyHost, int proxyPort) {
            if (proxy == null) {
                proxy = new ProxyConfig(Proxy.Type.HTTP);
            }
            proxy.setProxyHost(proxyHost);
            proxy.setProxyPort(proxyPort);
            return this;
        }

        /**
         * If proxy needs authentication, specify User.
         *
         * @param proxyUser Username for authentication.
         * @return the current {@link Builder} instance
         */
        public Builder proxyUser(String proxyUser) {
            if (proxy == null) {
                proxy = new ProxyConfig(Proxy.Type.HTTP);
            }
            proxy.setProxyUser(proxyUser);
            return this;
        }

        /**
         * Sets password used with specified user.
         *
         * @param proxyPassword Password for user authentication.
         * @return the current {@link Builder} instance
         */
        public Builder proxyPassword(String proxyPassword) {
            if (proxy == null) {
                proxy = new ProxyConfig(Proxy.Type.HTTP);
            }
            proxy.setProxyPassword(proxyPassword);
            return this;
        }

        /**
         * Configure type of proxy.
         *
         * @param proxyType Type of proxy as
         * @return the current {@link Builder} instance
         */
        public Builder proxyType(Proxy.Type proxyType) {
            if (proxy == null) {
                proxy = new ProxyConfig(Proxy.Type.HTTP);
            }
            proxy.setProxyType(proxyType);
            return this;
        }

        /**
         * Build the {@link DefaultPushSender}.
         *
         * @return the built up {@link DefaultPushSender}
         */
        public DefaultPushSender build() {
            return new DefaultPushSender(this);
        }
    }

    /**
     * Construct the URL fired against the Unified Push Server
     *
     * @return a StringBuilder containing the constructed URL
     */
    protected String buildUrl() {
        if (isEmpty(getServerURL())) {
            throw new IllegalStateException("server can not be null");
        }

        return getServerURL() + "rest/sender/";
    }

    @Override
    public void send(UnifiedMessage unifiedMessage, MessageResponseCallback callback) {
        String jsonString = unifiedMessage.getObject().toJsonString();
        // fire!
        submitPayload(buildUrl(), jsonString, pushConfiguration.getPushApplicationId(), pushConfiguration.getMasterSecret(), callback, new ArrayList<String>());
    }

    @Override
    public void send(UnifiedMessage unifiedMessage) {
        send(unifiedMessage, null);
    }

    /**
     * The actual method that does the real send and connection handling
     *
     * @param url the URL to use for the HTTP POST request.
     * @param jsonPayloadObject the JSON payload of the POST request
     * @param pushApplicationId the registered applications identifier.
     * @param masterSecret the master secret for the push server.
     * @param callback the {@link MessageResponseCallback} that will be called once the POST request completes.
     * @param redirectUrls a list containing the previous redirectUrls, used to detect an infinite loop
     * @throws {@link org.jboss.aerogear.unifiedpush.exception.PushSenderHttpException} when delivering push message to Unified Push Server fails.
     * @throws {@link org.jboss.aerogear.unifiedpush.exception.PushSenderException} when generic error during sending occurs, such as an infinite redirect loop.
     */
    private void submitPayload(String url, String jsonPayloadObject, String pushApplicationId, String masterSecret,
            MessageResponseCallback callback, List<String> redirectUrls) {
        if (redirectUrls.contains(url)) {
            throw new PushSenderException("The site contains an infinite redirect loop! Duplicate url: " +
                    url);
        } else {
            redirectUrls.add(url);
        }

        HttpURLConnection httpURLConnection = null;
        try {
            final String credentials = pushApplicationId + ':' + masterSecret;
            final String encoded = Base64.encodeBytes(credentials.getBytes(UTF_8));

            // POST the payload to the UnifiedPush Server
            httpURLConnection = (HttpURLConnection) HttpRequestUtil.post(url, encoded, jsonPayloadObject, UTF_8, proxy,
                    customTrustStore);

            final int statusCode = httpURLConnection.getResponseCode();
            logger.log(Level.INFO, String.format("HTTP Response code from UnifiedPush Server: %s", statusCode));

            // if we got a redirect, let's extract the 'Location' header from the response
            // and submit the payload again
            if (isRedirect(statusCode)) {
                String redirectURL = httpURLConnection.getHeaderField("Location");
                logger.log(Level.INFO, String.format("Performing redirect to '%s'", redirectURL));
                // execute the 'redirect'
                submitPayload(redirectURL, jsonPayloadObject, pushApplicationId, masterSecret, callback, redirectUrls);
            } else if (statusCode >= 400) {
                // treating any 400/500 error codes an an exception to a sending attempt:
                logger.log(Level.SEVERE, "The Unified Push Server returned status code: " + statusCode);
                throw new PushSenderHttpException(statusCode);
            } else {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        } catch (PushSenderHttpException pshe) {
            throw pshe;
        } catch (Exception e) {
            logger.log(Level.INFO, "Error happening while trying to send the push delivery request", e);

            throw new PushSenderException(e.getMessage(), e);
        }
        finally {
            // tear down
            if (httpURLConnection != null) {
                httpURLConnection.disconnect();
            }

        }
    }

    /**
     * checks if the given status code is a redirect (301, 302 or 303 response status code)
     */
    private static boolean isRedirect(int statusCode) {
        return statusCode == HttpURLConnection.HTTP_MOVED_PERM ||
                statusCode == HttpURLConnection.HTTP_MOVED_TEMP ||
                statusCode == HttpURLConnection.HTTP_SEE_OTHER;
    }

    /**
     * Get the used server URL.
     *
     * @return The Server that is used
     */
    @Override
    public String getServerURL() {
        return pushConfiguration.getServerUrl();
    }

    @Override
    public ProxyConfig getProxy() {
        return proxy;
    }

    @Override
    public TrustStoreConfig getCustomTrustStore() {
        return customTrustStore;
    }

    @Override
    public String getPushApplicationId() {
        return pushConfiguration.getPushApplicationId();
    }

    @Override
    public String getMasterSecret() {
        return pushConfiguration.getMasterSecret();
    }

}


text:
package ch.wsl.box.client.mocks

import ch.wsl.box.client.services.REST
import ch.wsl.box.client.viewmodel.BoxDef.BoxDefinitionMerge
import ch.wsl.box.client.viewmodel.BoxDefinition
import ch.wsl.box.model.shared.{BoxTranslationsFields, CSVTable, Child, ExportDef, Field, FormActionsMetadata, IDs, JSONCount, JSONField, JSONFieldMap, JSONFieldTypes, JSONID, JSONKeyValue, JSONLookup, JSONLookups, JSONLookupsRequest, JSONMetadata, JSONQuery, Layout, LayoutBlock, LoginRequest, NewsEntry, PDFTable, SharedLabels, TableAccess, WidgetsNames, XLSTable}
import ch.wsl.box.shared.utils.JSONUtils._
import io.circe.Json
import io.circe.syntax._
import org.scalajs.dom.File
import scribe.Logging

import scala.concurrent.Future

class RestMock(values:Values) extends REST with Logging {
  override def version(): Future[String] = Future.successful("version")

  override def appVersion(): Future[String] = Future.successful("appVersion")

  override def validSession(): Future[Boolean] = Future.successful{
    true
  }

  override def cacheReset(): Future[String] = {
    println("cacheReset not implemented")
    ???
  }

  override def entities(kind: String): Future[Seq[String]] = {
    kind match {
      case "form" => Future.successful(values.formEntities)
      case _ => {
        println(s"entities for $kind not implemented")
        ???
      }
    }
  }

  override def specificKind(kind: String, lang: String, entity: String): Future[String] = {
    println("specificKind not implemented")
    ???
  }

  override def list(kind: String, lang: String, entity: String, limit: Int): Future[Seq[Json]] = {
    println("list1 not implemented")
    ???
  }

  override def list(kind: String, lang: String, entity: String, query: JSONQuery): Future[Seq[Json]] = {
    println("list2 not implemented")
    ???
  }

  override def csv(kind: String, lang: String, entity: String, q: JSONQuery): Future[Seq[Seq[String]]] = {
    println("csv not implemented")
    ???
  }

  override def count(kind: String, lang: String, entity: String): Future[Int] = {
    println("count not implemented")
    ???
  }

  override def keys(kind: String, lang: String, entity: String): Future[Seq[String]] = {
    println("keys not implemented")
    ???
  }

  override def ids(kind: String, lang: String, entity: String, q: JSONQuery): Future[IDs] = {
    println("ids not implemented")
    ???
  }

  override def metadata(kind: String, lang: String, entity: String, public:Boolean): Future[JSONMetadata] = Future.successful{
    values.metadata
  }

  override def tabularMetadata(kind: String, lang: String, entity: String): Future[JSONMetadata] = {
    println("tabularMetadata not implemented")
    ???
  }

  override def children(kind: String, entity: String, lang: String, public:Boolean): Future[Seq[JSONMetadata]] = Future.successful{
    values.children(entity)
  }

  override def lookup(kind:String, lang:String,entity:String,  field:String, query: JSONQuery,public:Boolean): Future[Seq[JSONLookup]] = {
    println("lookup not implemented")
    ???
  }

  override def lookups(kind: String, lang: String, entity: String, fk: JSONLookupsRequest): Future[Seq[JSONLookups]] = ???

  override def get(kind: String, lang: String, entity: String, id: JSONID, public:Boolean): Future[Json] = Future.successful{
    values.get(id)
  }

  override def update(kind: String, lang: String, entity: String, id: JSONID, data: Json, public:Boolean): Future[Json] = {
    Future.successful(values.update(id,data))
  }

  override def updateMany(kind: String, lang: String, entity: String, ids: Seq[JSONID], data: Seq[Json]): Future[Seq[Json]] = ???

  override def insert(kind: String, lang: String, entity: String, data: Json, public:Boolean): Future[Json] = Future.successful{
    values.insert(data)
  }

  override def delete(kind: String, lang: String, entity: String, id: JSONID): Future[JSONCount] = {
    println("delete not implemented")
    ???
  }

  override def deleteMany(kind: String, lang: String, entity: String, ids: Seq[JSONID]): Future[JSONCount] = ???

  override def sendFile(file: File, id: JSONID, entity: String): Future[Int] = {
    println("sendFile not implemented")
    ???
  }

  override def login(request: LoginRequest): Future[Json] = Future.successful{
    Json.True
  }

  override def logout(): Future[String] = {
    println("logout not implemented")
    ???
  }

  override def labels(lang: String): Future[Map[String, String]] = {
    Future.successful(lang match {
      case "en" => Map(
        SharedLabels.header.lang -> values.headerLangEn
      )
      case "it" => Map(
        SharedLabels.header.lang -> values.headerLangIt
      )
    })
  }

  override def conf(): Future[Map[String, String]] = Future.successful{
    values.conf
  }

  override def ui(): Future[Map[String, String]] = Future.successful{
    values.uiConf
  }

  override def news(lang: String): Future[Seq[NewsEntry]] = {
    println("news not implemented")
    ???
  }

  override def dataMetadata(kind: String, name: String, lang: String): Future[JSONMetadata] = {
    println("dataMetadata not implemented")
    ???
  }

  override def dataDef(kind: String, name: String, lang: String): Future[ExportDef] = {
    println("dataDef not implemented")
    ???
  }

  override def dataList(kind: String, lang: String): Future[Seq[ExportDef]] = {
    println("dataList not implemented")
    ???
  }

  override def data(kind: String, name: String, params: Json, lang: String): Future[Seq[Seq[String]]] = {
    println("data not implemented")
    ???
  }

  override def tableAccess(table: String, kind: String): Future[TableAccess] = {
    println("table Access not implemented")
    ???
  }

  override def renderTable(table: PDFTable): Future[String] = ???
  override def exportCSV(table: CSVTable): Future[File] = ???
  override def exportXLS(table: XLSTable): Future[File] = ???

  override def generateStub(entity: String): Future[Boolean] = {
    println("generateStub not implemented")
    ???
  }

  override def definition(): Future[BoxDefinition] = ???

  override def definitionDiff(definition: BoxDefinition): Future[BoxDefinitionMerge] = ???

  override def definitionCommit(merge: BoxDefinitionMerge): Future[Boolean] = ???

  override def translationsFields(lang: String): Future[Seq[Field]] = ???

  override def translationsFieldsCommit(merge: BoxTranslationsFields): Future[Boolean] = ???

  override def execute(functionName: String, lang: String, data:Json) = ???
}

redpajama_set_name: RedPajamaGithub