java

please delete

How to test a mail service without SMTP-server (Java)

To test if a mail was successfully sent using Java you would normally need an SMTP-server to check. If it happens that you don’t have a server available, you can use mailtrap. To setup mailtrap, following code is used: Properties prop = new Properties(); prop.put("mail.smtp.auth", true); prop.put("mail.smtp.starttls.enable", "true"); prop.put("mail.smtp.host", "smtp.mailtrap.io"); prop.put("mail.smtp.port", "25"); prop.put("mail.smtp.ssl.trust", "smtp.mailtrap.io"); session = Session.getInstance(prop, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("YYY", "XXX"); } }); Mails sent using this session token end up in webservice that you can check.

Dealing with circular reference in Java

In an uni project we had a complex data structure with 2 circular references. We built an android app with a maven spring java backend using docker. The problem was that we could not load all the informations in an entity with cicular references. In this cases we always only got null if we tried to get the correct values from our backend.

Java Async testing

A Java Spring Boot powered REST Api has operations, which require minutes to finish, because of multiple HTTP connections and database queries with lots of data. These tasks are executed Asynchronously. 
The functionality needs to be tested in the integration tests (using less data, so the operation runs in seconds). Now we use Thread.sleep(…) and the tests take 10minutes to finish every time, while we see the operations finished sometimes for 2-3 seconds and the overall required time would be 5minutes. Bu we also observe flakey tests from time to time, because the operations take 100ms more than out waiting time.
 How can we test waiting time that is close to the real waiting time and remove the cause of the flakey tests?

Circumvent a license key

A friend developed an application, that was protected by a license key. Since I was curious how he implemented the key-checking and the application overall I decided to hack the app and write a key generator to use the app. The application was written in java, I looked out for a java decompiler and finally used the „java decompiler“ application. As a result I had a lot of java files. The only problem is, that the naming wasn’t useful at all. For example „class a“ doesn’t say anything about the class. So it took me a while to understand the main parts of the code. I used the information that the UI of the application provides for example certain strings to get a clue where the key verification took place. After i found the key verification it was quite easy to write a key generator, since there it was based on simple math.

Broken caching in a web application

In a Spring Boot Java Web App we had caching set up for several computationally expensive methods. After some time I discovered that the mechanism was apparently broken for those methods, but implementing a new cached method in a completely new service class worked. At first I tried to exclude simple errors as culprits. Method signatures of the cacheable methods were simplified, the @Cacheable method annotation was moved between interface and implementation methods as well as between data repositories and service classes. Another potential error may have come from Springs proxy functionality, which should create a proxy doing the caching for our service. This proved to be the problem - the needed proxy wasn’t generated and I had no clue why. I discovered some warning messages in the application startup logs like 'Bean XYZ is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)'. The proxy stuff for @Cacheable methods is also done via a BeanPostProcessors. It seemed that Spring initialized our service beans long before it manages to initialize the caching mechanism, which deprived them of the caching functionality. By setting a watcher in debug mode in the according class on this log message and tracing back the call stack of our service bean I was able to find out where and understand why our beans were prematurely initialized. In those two resulting classes I implemented a LazyInit feature that initialized our beans after the caching functionality has been initialized and caching started to work again.

XML Parsing Library in a JIRA Plugin does not work

When developing a JIRA Plugin and trying to parse XML data from external sources and displaying it, the parsing with the commonly used Woodstox library failed with the following error: javax.xml.stream.FactoryFinder$ConfigurationError: Provider com.ctc.wstx.stax.WstxInputFactory not found Debugging took a considerable amount of time as the library was actually added into maven but was not available once installing the plugin in JIRA. The problem relied in OSGi class loading and a problem with the xml parsing library architecture which has its root in an IBM architecture decision. Unfortunately I cannot find the link anymore which explained it in more detail. The only solution was to switch from STAX parsing to DOM parsing if XML parsing is inevitable. Even alternative XML parsers will not work who work with STAX.

How to mock a new instance

Which kind of possibility do we have in order to mock a new instance in the class which we want to test.

what is the mainly characters of Object oriented programming language

Nowadays, the concept of the Object oriented programming becomes more and more popular. What is the mainly characters of it?

Manage server restarts by (administrator) user through web interface

The (privileged/administrator) user without particular system administration knowledge and specific direct access rights to the server should be able to manage server restarts through web interface. The operating system of the server is Debian, the HTTP web server is Apache Tomcat, and the user access Java application. It should be possible that the respective user knows the next scheduled restart time, postpones or re-schedules the restart times. On the one side, it is required to allow fine-grained configuration of the exact restart times: on which dates of the month, on which days of the week, at which hour/minute, etc. On the other side, the feature should be as simple as possible: to be able to learn and to understand it within at most of ca. half an hour.

Pages

Subscribe to java