DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

The Latest Languages Topics

article thumbnail
Fix for “Could Not Connect to the Debugger” While Deploying Xamarin Forms Apps to the Visual Studio Android Emulator
If you've encountered this issue before, author Joost van Schalk discusses how to correct the problem so you can move on with your debugging!
February 26, 2016
by Joost van Schaik
· 18,263 Views · 3 Likes
article thumbnail
Page Objects Refactored: SOLID Steps to the Screenplay/Journey Pattern
Automated web tests should follow good object-oriented design principles, too.
February 24, 2016
by Antony Marcano
· 57,144 Views · 14 Likes
article thumbnail
Generate Database Scripts With Data In SQL Server
In this post, let's take a look at how we can generate SQL Server scripts of our database with existing data.
February 24, 2016
by Sibeesh Venu
· 306,775 Views · 7 Likes
article thumbnail
Choosing a Microservices Deployment Strategy Part 6
Here's part 6 of our microservices architecture, with a focus on deployment strategy!
February 23, 2016
by Chris Richardson
· 45,033 Views · 9 Likes
article thumbnail
A Second Generation Reactive Foundation for the JVM
Awesome new reactive platform for JVM development.
February 22, 2016
by Josh Long
· 11,611 Views · 9 Likes
article thumbnail
Insights From Stackoverflow: Most Voted for Spring 4 Questions
Spring 4 is widely used, but as with any technology, there are loads of questions. Here are the most asked and answered questions on Stackoverflow, like differences in component and controller annotations, and what the Spring framework is actually used for.
February 20, 2016
by Alex Theedom
· 12,326 Views · 15 Likes
article thumbnail
Don't be Careless With Groovy (Un)checked Exceptions
Groovy language introduced many interesting features from Java programmer's point of view. One of them is the lack of differentiation between checked and unchecked exceptions - a nice quality for programmers who struggled with checked exceptions requirements. It turns out, however, that using this neat Groovy feature with existing frameworks can sometimes be tricky which I've experienced lately. I worked with relatively straightforward microservice written in Groovy. It was built on top of Spring Boot 1.3. Among others, it used @RestController to define REST endpoints and @ControllerAdvice to handle exceptions thrown by the controller or its internals. Very simplified example code looks like this (complete source code can be downloaded from https://github.com/yu55/groovy-undeclared-throwable-demo ): import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @RestController class ExampleRestController { @RequestMapping(value = '/get') String get() { /* Lets imagine this exception is thrown somewhere from deepest layers of our service code and we don't have to be immediately aware of this. */ throw new ExampleRestControllerException() } } Controller advice: import org.springframework.web.bind.annotation.ControllerAdvice import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.ResponseBody @ControllerAdvice class ExampleRestControllerAdvice { @ExceptionHandler(value = ExampleRestControllerException.class) @ResponseBody String onExampleRestControllerException() { return 'ExampleRestControllerException handled in ControllerAdvice' } @ExceptionHandler(value = Exception.class) @ResponseBody String onException() { return 'Exception handled in ControllerAdvice' } } Simple checked exception: class ExampleRestControllerException extends Exception { } When ExampleRestControllerException was thrown, it was handled by onExampleRestControllerException() method in ExampleRestControllerAdvice class. And this worked perfectly fine. But I had to add a simple aspect after the returning of get() method in ExampleRestController to do some additional stuff. @Aspect @Component class RestControllerAspect { @AfterReturning('execution(* org.yu55.ued.controller.ExampleRestController.get())') public void logServiceAccess(JoinPoint joinPoint) { // empty implementation for clarity reasons } With this simple aspect introduced, the microservice began to behave strangely. ExampleRestControllerAdvice started calling the onException() method instead of onExampleRestControllerException() when ExampleRestControllerException was thrown. I didn't expect that. What happened? When the aspect for ExampleRestController.get() method is defined, the Spring generates a proxy for ExampleRestController. Since ExampleRestController doesn't implement any interface, Spring uses CGLIB library instead of java.lang.reflect.Proxy for a dynamic proxy generation [1]. Generated proxy class name is similar to ExampleRestController$$EnhancerBySpringCGLIB$$8d751c8@4481 and it's an ExampleRestController subclass which intercepts all methods calls. There is also another dynamically generated class created: ExampleRestController$$FastClassBySpringCGLIB$$b01891ea which is a ExampleRestController class wrapper. This wrapper class promises faster methods invocations than the Java reflection API [2]. Spring is invoking get() method (via sun.reflect reflection classes) on enhancer class which then invokes get() method (via CGLIB MethodProxy) on fast class instance. When controllers get() method throws ExampleRestControllerException it's rethrown by fast class to an enhancer class and then the enhancer class get() method throwsjava.lang.reflect.UndeclaredThrowableException (which contains ExampleRestControllerException inside). This results in ExampleRestControllerAdvice matchingUndeclaredThrowableException with Exception class and firing handler method different than expected. But why UndeclaredThrowableException is thrown? Because the get() method written in Groovy in fact didn't declare any checked exceptions that it could potentially throw. The proxy doesn't know anything about that controller is written in Groovy and no throws declared means that checked exception may still occur. This behaviour also corresponds to Proxy documentation [3]. The issue can be fixed easily by adding checked exceptions to get() method definition or defining ExampleRestControllerException as runtime exception. Former solution technically works but isn't 'groovy' though and the latter is an approach that Spring prefers and is currently considered to be best practice for exception handling [4]. At the end, I would not blame Groovy for this situation. Instead, I would rather point that despite the fact that Groovy simply don't care about checked exceptions, it doesn't mean that other libraries also don't care. This is not what most programmers think of first when using Groovy. A similar situation may happen with any other JVM language that 'ignores' checked exceptions. The best thing we can do to protect ourselves from situations like this is to prepare tests carefully. Imagine no controller tests for ExampleRestControllerException case - whole application builds and runs perfectly on production until this special case occurs and controller simply returns a wrong answer to the client. A bug like this may not be so obvious and fast to track or fix.
February 19, 2016
by Marcin Pilaczynski
· 20,092 Views · 10 Likes
article thumbnail
Fully Dynamic Classes With ASM
ASM is a Java bytecode manipulation library. Mocking frameworks and runtime code generators use it to dynamically generate Java classes. Here is an introduction to how it works.
February 19, 2016
by Alan Hohn
· 40,781 Views · 16 Likes
article thumbnail
Loading Data Into Azure SQL Data Warehouse
I’m not an ETL expert. In fact, I haven’t done any professional ETL work for several years. My skills are, at best, rusty. With this in mind, I knew I’d have a hard time extracting data from a local database in order to move it up to Azure SQL Data Warehouse. Read on to hear about my journey.
February 18, 2016
by Grant Fritchey
· 14,251 Views · 6 Likes
article thumbnail
Gradle Goodness: Running Groovy Scripts Using Groovy Command Line
In a previous post, we showed how to execute a Groovy script in our source directories. But, what if we want to use the Groovy command line to execute a Groovy script? Read on and see how it's done.
February 18, 2016
by Hubert Klein Ikkink
· 16,471 Views · 1 Like
article thumbnail
Making the Impossible Possible with Tachyon: Accelerate Spark Jobs from Hours to Seconds
Barclays Data Scientist Gianmario Spacagna and Harry Powell, Head of Advanced Analytics, describe how they iteratively process raw data directly from the central data warehouse into Spark and how Tachyon is their key enabling technology.
February 16, 2016
by Henry Powell
· 38,058 Views · 8 Likes
article thumbnail
Serialization Must Die
Security issues and problems with serialization of random objects.
February 16, 2016
by Arshan Dabirsiaghi
· 26,884 Views · 18 Likes
article thumbnail
Write JUnit Tests in Spring With Mocked and Real Objects
How to use mocked and non-mocked data to write unit tests using the free and open source JUnit framework.
February 16, 2016
by Saravanan Kandasamy
· 17,243 Views · 7 Likes
article thumbnail
How to Solve "The Server Responded With a Status of 405 (Method Not Allowed)"
I was working with Web API for one of my new projects, when suddenly I got this error message: "the server responded with a status of 405 (method not allowed)" when I tried to delete a record through API. I began to scratch my head, and finally, I came up with a solution.
February 16, 2016
by Sibeesh Venu
· 50,661 Views · 3 Likes
article thumbnail
CXF SOAP Header Basic Authentication Interceptors Java Without Spring
Here's a great guide to authentication interceptors in Java without using Spring!
February 16, 2016
by Bosco Ferrao
· 17,344 Views · 4 Likes
article thumbnail
Traits in Java 8: Semantic, DRY-compliant, Interface-first Code
Learn how you can master the Trait pattern and how it can be realized in Java 8.
February 15, 2016
by Emil Forslund
· 35,230 Views · 11 Likes
article thumbnail
Interpreting jstat's Garbage Collection Events
Measuring with jstat is great, but interpreting jstat is even better. Here's a neat look at interpreting jstat numbers of garbage collection events.
February 11, 2016
by Kamil Szymański
· 14,509 Views · 4 Likes
article thumbnail
Create a JSON API REST Service With Spring Boot and Elide
Learn how to make a HSON API REST service using Elide and Spring Boot in this awesome tutorial. The JSON API is a great specification for developers, and is getting much more popular.
February 11, 2016
by Matthew Casperson
· 71,762 Views · 10 Likes
article thumbnail
Introducing Dynamic Modules in NGINX 1.9.11 - NGINX
The open source NGINX v. 1.9.11 is out, and features an awesome addition: dynamic modules. These let you load separate shared object files at runtime. Learn more about the latest open source NGINX 1.9.11 release!
February 10, 2016
by Patrick Nommensen
· 17,751 Views · 1 Like
article thumbnail
ES6 Math Functions You Can Use Today
In this article, we'll discuss the various math functions—what they are and how they work—available in ECMAScript 2015 (ES6). Read on to learn more.
February 10, 2016
by Josh Anderson
· 7,514 Views · 2 Likes
  • Previous
  • ...
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • ...
  • Next
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook
×