This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@ComponentScan("cz.swsamuraj.wicketspring") | |
public class SpringRestConfiguration { | |
@Bean | |
public AnnotationMethodHandlerAdapter annotationMethodHandlerAdapter() { | |
AnnotationMethodHandlerAdapter adapter = new AnnotationMethodHandlerAdapter(); | |
HttpMessageConverter<?>[] converters = { new MappingJackson2HttpMessageConverter()}; | |
adapter.setMessageConverters(converters); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class WicketApplication extends WebApplication { | |
@Override | |
protected void init() { | |
super.init(); | |
WebApplicationContext ctx = WebApplicationContextUtils | |
.getRequiredWebApplicationContext(getServletContext()); | |
getComponentInstantiationListeners().add(new SpringComponentInjector(this, ctx)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@WebFilter(value = "/*", | |
initParams = { | |
@WebInitParam(name = "applicationFactoryClassName", | |
value = "org.apache.wicket.spring.SpringWebApplicationFactory") | |
}) | |
public class WicketAppFilter extends JavaxWebSocketFilter { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; "Classical" middleware wrapping | |
(middleware-3 (middleware-2 (middleware-1 handler))) | |
; Middleware wrapping via threading macro | |
(-> handler (middleware-1) (middleware-2) (middleware-3)) |