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
| List list = Arrays.asList("foo", "bar"); | |
| assertThat(list, is(not(empty()))); | |
| assertThat(list.get(0), is("foo")); | |
| assertThat(list, hasItem("bar")); |
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
| @RequestScoped | |
| public class MyCdiBean { | |
| private boolean flag = true; | |
| @Inject | |
| private MyService service; | |
| public void doSomething() { | |
| if (!flag) { | |
| service.callMethod(); |
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
| // The Annotation | |
| @InterceptorBinding | |
| @Retention(RetentionPolicy.RUNTIME) | |
| @Target({FIELD, METHOD, PARAMETER, TYPE}) | |
| @Qualifier | |
| public @interface RunInRequestScope { | |
| } | |
| // The Interceptor for the annotation |
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
| Map<String, Object> requestDataStore = new HashMap<String, Object>(); | |
| boundRequestContext.associate(requestDataStore); | |
| boundRequestContext.activate(); | |
| useRequestScopeInHere(); | |
| try { | |
| boundRequestContext.invalidate(); | |
| boundRequestContext.deactivate(); | |
| } finally { | |
| boundRequestContext.dissociate(requestDataStore); | |
| } |
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 MyWebSocketApplication extends WebSocketApplication { | |
| public boolean isApplicationRequest(Request request) { | |
| // determine if this application is responsible for this websocket request (identification by incoming request) | |
| return request.toString().contains("/mywebsocketapp/myspecializedsocket/do.connect"); | |
| } | |
| public WebSocket createWebSocket(ProtocolHandler protocolHandler, WebSocketListener... listeners) { | |
| // create a new WebSocket and add it to the list of Sockets hold by this app | |
| WebSocket socket = new MyWebSocket(protocolHandler, listeners); |
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
| var messageReceived = function(event) { | |
| var eventData = event.data.toString(); | |
| console.log("Received via socket: "+eventData); | |
| }; | |
| var socket = new WebSocket("ws://www.example.com/mywebsocketapp/myspecializedsocket/do.connect"); | |
| socket.onmessage = messageReceived; | |
| //send text to server | |
| socket.send("testtext"); |
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
| private BigDecimal processNumberInput(String numberString) | |
| throws ParseException { | |
| Number number = numFormatGerman.parse(numberString); | |
| ... | |
| String internalAmountString = numFormatEnglish.format(number); | |
| ... | |
| return new BigDecimal(internalAmountString); | |
| } |
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
| // Das Attribut 'format' wird als 'ThreadLocal' definiert: | |
| private static ThreadLocal<SimpleDateFormat> format = new ThreadLocal<SimpleDateFormat>(); | |
| // Beim ersten Zugriff innerhalb eines Threads wird das Objekt initialisiert | |
| private SimpleDateFormat getFormat() { | |
| if (format.get() == null) { | |
| format.set(new SimpleDateFormat("yyyy-MM-dd")); | |
| } | |
| return format.get(); | |
| } |
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
| private static SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd"); | |
| ... | |
| @Override | |
| public XMLGregorianCalendar unmarshal(String value)throws Exception { | |
| ... | |
| Date date=format.parse(value); | |
| GregorianCalendar calendar=new GregorianCalendar(); |
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
| @XmlJavaTypeAdapter(DateAdapter.class) | |
| protected XMLGregorianCalendar dateOfBirth; |