org.primeoservices.cfgateway.twitter.railo.RailoTwitterUserStreamGateway.java Source code

Java tutorial

Introduction

Here is the source code for org.primeoservices.cfgateway.twitter.railo.RailoTwitterUserStreamGateway.java

Source

/*
 * Copyright 2014 Jean-Bernard van Zuylen
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.primeoservices.cfgateway.twitter.railo;

import java.io.IOException;
import java.util.Map;

import org.primeoservices.cfgateway.twitter.ArgumentType;
import org.primeoservices.cfgateway.twitter.TwitterUserStream;

import railo.runtime.gateway.GatewayEngine;
import twitter4j.conf.ConfigurationBuilder;

/**
 * @author Jean-Bernard van Zuylen
 */
public class RailoTwitterUserStreamGateway extends AbstractRailoTwitterGateway<TwitterUserStream> {
    private ArgumentType argType = ArgumentType.getDefault();

    /**
     * Initializes this gateway
     */
    @Override
    @SuppressWarnings("rawtypes")
    public void init(final GatewayEngine engine, final String id, final String cfcPath, final Map config)
            throws IOException {
        try {
            this.argType = ArgumentType.fromConfigValue((String) config.get(ARGUMENT_TYPE));
            final ConfigurationBuilder cb = new ConfigurationBuilder();
            cb.setOAuthConsumerKey((String) config.get(OAUTH_CONSUMER_KEY));
            cb.setOAuthConsumerSecret((String) config.get(OAUTH_CONSUMER_SECRET));
            cb.setOAuthAccessToken((String) config.get(OAUTH_ACCESS_TOKEN));
            cb.setOAuthAccessTokenSecret((String) config.get(OAUTH_ACCESS_SECRET));
            cb.setUserStreamRepliesAllEnabled(Boolean.valueOf((String) config.get(ALL_REPLIES)));
            cb.setJSONStoreEnabled(ArgumentType.JSON.equals(this.argType));
            super.init(engine, id, new TwitterUserStream(this, cb.build()));
        } catch (Throwable t) {
            final IOException ex = new IOException("Unable to initialize gateway", t);
            this.onException(ex);
            throw ex;
        }
    }
}