Git Product home page Git Product logo

shariff-backend-java's Introduction

Shariff Java Backend build status

Shariff is used to determine how often a page is shared in social media, but without generating requests from the displaying page to the social sites.

Shariff Logo © 2014 Heise Zeitschriften Verlag

This document describes the Java backend. The following backends are also available:

This Shariff backend is not a part of the official backends by Heise Online! It bases on the work of shariff-backend-php.

Features

  • Easy to use Java servlet
  • Supports addthis, facebook, flattr, googleplus, linkedin, pinterest, reddit, stumbleupon, xing
  • Parallel counter fetching to minimize response time
  • Comes with a simple caching mechanism that can be replaced by other cache solutions like Ehcache
  • Built with maven, package is available at Maven Central
  • Uses slf4j, for log output just add a binding to your classpath
  • Requires Java 8 or higher

Installing the Shariff backend on your own server

Just add Shariff (org.shredzone.shariff:backend:1.1) to your maven or gradle dependencies, or copy the shariff.jar and json.jar to your project's lib folder. Then add the Shariff servlet to your web.xml:

<servlet>
    <servlet-name>shariff</servlet-name>
    <servlet-class>org.shredzone.shariff.ShariffServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>shariff</servlet-name>
    <url-pattern>/shariff/</url-pattern>
</servlet-mapping>

Use init-param to configure the servlet:

<servlet>
    <servlet-name>shariff</servlet-name>
    <servlet-class>org.shredzone.shariff.ShariffServlet</servlet-class>
    <init-param>
        <param-name>targets</param-name>
        <param-value>googleplus,facebook</param-value>
    </init-param>
</servlet>

The following configuration options are available:

Key Description
host Regular expression of acceptable hosts (e.g. "^(.*\.)?example\.com$"). If unset, only the host of the servlet is accepted.
cacheSize Maximum number of urls to be cached in memory. Default is 1000.
cacheTimeToLiveMs Maximum time urls are cached, in ms. Default is 1 minute.
targets List of services to be enabled (see Features). Case sensitive. Services must be separated by comma. Default is all available services.
threads Number of fetcher threads. Defaults to number of active targets.
facebook.id The ID of your Facebook application.
facebook.secret The client secret of your Facebook application.

Note that you must set up facebook.id and facebook.secret to retrieve a valid Facebook share counter. Facebook does not offer an anonymous way any more, at least none I am aware of.

Testing your installation

If the backend runs under http://example.com/shariff/, calling the URL http://example.com/shariff/?url=http%3A%2F%2Fwww.example.com should return a JSON structure with numbers in it, e.g.:

{"facebook":1452,"googleplus":23}

You can also invoke ShariffBackend directly. Pass in the Facebook credentials via system properties facebook.id and facebook.secret if necessary. It returns the share counters for the given URLs on the command line:

java -cp shariff.jar:json.jar -Dfacebook.id=myId -Dfacebook.secret=mySecret org.shredzone.shariff.ShariffBackend http://www.heise.de

Shariff Servlet

You can extend the ShariffServlet class and override its protected methods if you need more control about fetching or caching the count data.

To replace the caching mechanism (e.g. by Ehcache), override the getCountsCached() method.

For reading and normalizing the url parameter, override the getUrl() method.

For an individual test whether the given url contains a valid host or not, override the isValidHost() method.

Use this snippet to set the Facebook credentials programmatically:

Facebook facebook = getBackend().getTarget(Facebook.class);
if (facebook != null) {
    facebook.setSecret(yourClientId, yourClientSecret);
}

License

shariff-backend-java is released under the terms of the Apache License 2.0.

shariff-backend-java's People

Contributors

shred avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.