Skip to content

Instantly share code, notes, and snippets.

View altfatterz's full-sized avatar
👨‍💻
Playing

Zoltan Altfatter altfatterz

👨‍💻
Playing
View GitHub Profile
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(auth.getAuthorities());
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
Authentication newAuth = new UsernamePasswordAuthenticationToken(auth.getPrincipal(), auth.getCredentials(), authorities);
SecurityContextHolder.getContext().setAuthentication(newAuth);
var request = { url: document.location.toString() + 'event',
contentType : "application/json",
logLevel : 'debug',
transport : 'websocket',
fallbackTransport : 'long-polling' ,
trackMessageLength : true,
reconnectInterval : 5000,
enableXDR: true,
timeout : 60000,
headers : {sessionId : sessionId} // 0 for firefox, 1 for chrome, 2 for IE
<servlet>
<description>AtmosphereServlet</description>
<servlet-name>AtmosphereServlet</servlet-name>
<servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
<!-- limit classpath scanning for ManagedService instances to speed up boostrapping -->
<init-param>
<param-name>org.atmosphere.cpr.packages</param-name>
<param-value>com.backbase.progfun.atmosphere</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="timer://foo?fixedRate=true&amp;period=10s"/>
<process ref="accountBalanceProcessor" />
<to uri="bean:atmospherePublishService?method=publish"/>
</route>
</camelContext>
public enum Event {
ACCOUNT_DEBITED, ACCOUNT_CREDITED, ACCOUNT_LOCKED
}
git clone https://github.com/altfatterz/atmosphere-fun
cd atmosphere-fun
mvn clean install
mvn jetty:run
BroadcasterFactory broadcasterFactory = BroadcasterFactory.getDefault();
Broadcaster eventBroadcaster = broadcasterFactory.lookup("/event");
Collection<AtmosphereResource> atmosphereResources = eventBroadcaster.getAtmosphereResources();
for (AtmosphereResource atmosphereResource : atmosphereResources) {
if (message.getSessionId().equals(getSessionId(atmosphereResource))) {
eventBroadcaster.broadcast(message, atmosphereResource);
}
}
@Singleton
@ManagedService(path = "/event")
public class EventService {
}
public class Message {
private Event event;
private String sessionId;
private long time;
}
$ heroku ps:scale web=0 //scale the web dynos down to zero which effectively takes all your app http-processes offline
$ heroku logout