Skip to content

Instantly share code, notes, and snippets.

public class PersonPanel extends Panel implements Observer {
@SpringBean
private ObservableCache observableCache;
public PersonPanel(String id) {
super(id);
// Wicket component stuff, e.g. children
setDefaultModel(new CompoundPropertyModel<>(getModel()));
public class PersonPanel extends Panel implements Observer {
public PersonPanel(String id) {
// Wicket stuff omitted.
observableCache.addObserver(this);
}
@Override
public void update(Observable observable, Object o) {
public class ObservableCache extends Observable {
private Map<String, PersonInfo> cache = new HashMap<>();
public void put(String key, PersonInfo person) {
cache.put(key, person);
setChanged();
notifyObservers();
}
@Resource(name = "userCache")
private Map<User, Id> userCache;
private UserStats getUser(String userID) {
String login = userCache
.entrySet()
.stream()
.filter(u -> userID.equals(u.getValue().getId()))
.map(u -> u.getKey().getLogin())
.collect(Collectors.joining());
@Configuration
@ComponentScan("cz.swsamuraj.wicketspring")
public class SpringRestConfiguration {
@Bean
public AnnotationMethodHandlerAdapter annotationMethodHandlerAdapter() {
AnnotationMethodHandlerAdapter adapter = new AnnotationMethodHandlerAdapter();
HttpMessageConverter<?>[] converters = { new MappingJackson2HttpMessageConverter()};
adapter.setMessageConverters(converters);
@Component
public class WicketApplication extends WebApplication {
@Override
protected void init() {
super.init();
WebApplicationContext ctx = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
getComponentInstantiationListeners().add(new SpringComponentInjector(this, ctx));
@WebFilter(value = "/*",
initParams = {
@WebInitParam(name = "applicationFactoryClassName",
value = "org.apache.wicket.spring.SpringWebApplicationFactory")
})
public class WicketAppFilter extends JavaxWebSocketFilter {
}
@sw-samuraj
sw-samuraj / blog-ring-middleware-example-wrap.clj
Created July 11, 2017 09:34
An example of the Ring middleware which wraps two other middlewares (for a blog post).
(defn wrap-put-no-content
"Middleware that returns a 204 No Content
if the request method is PUT, otherwise
a 405 Method Not Allowed."
[handler]
(-> handler
(wrap-no-content)
(wrap-put-allowed)))
@sw-samuraj
sw-samuraj / blog-ring-middleware-example.clj
Last active July 11, 2017 09:29
An example of the Ring middlewares for HTTP statuses 204 and 405 (for a blog post).
(defn wrap-no-content
"Middleware that returns a 204 No Content
from the wrapped handler."
[handler]
(fn [request]
(let [response (handler request)]
(-> response
(assoc :status 204)
(dissoc :body)))))
@sw-samuraj
sw-samuraj / blog-ring-middleware-wrapping.clj
Last active July 11, 2017 08:48
An example of the Ring middleware wrapping (for a blog post).
; "Classical" middleware wrapping
(middleware-3 (middleware-2 (middleware-1 handler)))
; Middleware wrapping via threading macro
(-> handler (middleware-1) (middleware-2) (middleware-3))