-1

I want to simulate scenario that app when connecting to mock gets exception (for example javax.net.ssl). I know how to construct valid or invalid response. I do not know how to response with specific exception that would be interpreted by CXF just like of exception.

In simple words: I want to code sample(or tool) that when asked (by get or SOAP) will return java connection exception.

Code explanation:

curl http://localhost:8088/myservice

In response I want connection exception was thrown(for example javax.net.ssl.SSLException ) just like java app would throw. I know how to throw exceptions still I do not know how to throw them in response to request(for example GET).

SkorpEN
  • 2,491
  • 1
  • 22
  • 28

1 Answers1

0

I find my solution based on simple spring boot app from Hello World spring boot and modify it to specific exception (anyway it will work for other apps as long as we got app or know framework that provide response) :

curl https://start.spring.io/starter.zip \
-d dependencies=web \
-d name=helloworld \
-d artifactId=helloworld \
-o helloworld.zip

unzip helloworld.zip

Then paste it into class:

import javax.net.ssl.SSLException;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class HelloworldApplication {

    @RestController
    class HelloworldController {
        @GetMapping("/") //this will serve get
        String hello() throws SSLException {
            //this will land in Spring error message text
            throw new SSLException("Tested exception javax.net.ssl");
        }
    }

    public static void main(String[] args) {
        SpringApplication.run(HelloworldApplication.class, args);
    }
}

This will return general json error(same technique of adding exception inside processed request could be used inside servlets or other parts of app that produce response).

Response will look like this

{"timestamp":"2018-08-23T09:22:26.691+0000","status":500,"error":"Internal Server Error","message":"Tested exception javax.net.ssl","path":"/"}
SkorpEN
  • 2,491
  • 1
  • 22
  • 28