1

Have written a spring controller Get method and trying to call that with postman but getting error

Could not get any response
There was an error connecting to https://localhost:8081/MyPortal/shared?video0=14&video1=15.

Even when I try to debug, the call is not going to the controller method. Not sure what is happening.

Here is the controller code:

@Controller
public class SharedLinkController {

@Autowired
VideoService videoService;

@RequestMapping("/shared")
public  ModelAndView getSharedVideo(HttpServletRequest request, HttpServletResponse response,
        @RequestParam(value="video0", required=false) Long video0,
        @RequestParam(value="video1", required=false) Long video1,
        @RequestParam(value="video2", required=false) Long video2,
        @RequestParam(value="video3", required=false) Long video3){

    List<Lab> videos = new ArrayList<Lab>();

        // some processing with video0, video1 etc....

    ModelAndView model = new ModelAndView("index");
    model.addObject("videos", videos);
    return model;

}

}

And this is how am trying to call the API:

https://localhost:8081/MyPortal/shared?video0=14&video1=15

Am not trying to make it a RestController as I need to redirect the call to a webpage. Is there anything wrong with the code?

Please suggest.

8
  • Where have you set mapping for /MyPortal? Commented May 4, 2018 at 9:03
  • "There was an error connecting to https", I would investigate https configuration (start with port number?), also include spring boot output. Commented May 4, 2018 at 9:08
  • you need to give some more information about how you setup your application. the controller looks fine Commented May 4, 2018 at 9:08
  • Its a web application running on Tomcat. Commented May 4, 2018 at 9:08
  • How do we specify /MyPortal ? Commented May 4, 2018 at 9:09

3 Answers 3

1

Do you have a class that scans basepackages and registers your controller as a bean, like the following?

@SpringBootApplication(scanBasePackages= "se.yourpackage.src")
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {

        SpringApplication.run(Application.class, args);

    }

Nevermind the RestController, but you need to add the requestmapping

@RequestMapping("/MyPortal")
public class SharedLinkController {

You might also need to add the path of the view files in your file called

application.properties

for example:

spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
Sign up to request clarification or add additional context in comments.

1 Comment

This is a Spring Boot application so there is not .xml to define mappings.
1

You need to set the context to youe spring boot application, try setting

server.context-path=/MyPortal

This way you can define the root context to your application as

http:localhost:8081/MyPortal/

Comments

0

I suggest to check your url and your view name.

You try to connect url : connecting to http://localhost:8081/yourPortal/shared?video0=14&video1=15

@Controller
public class SharedLinkController {

   @Autowired
   VideoService videoService;

   @RequestMapping("/shared")
   public ModelAndView getSharedVideo(ModelAndView mav,
        @RequestParam(value="video0", required=false) Long video0,
        @RequestParam(value="video1", required=false) Long video1,
        @RequestParam(value="video2", required=false) Long video2,
        @RequestParam(value="video3", required=false) Long video3){

        List<Lab> videos = new ArrayList<Lab>();
        // ...

        mav.addObject("videos", videos);    
        mav.setViewName("index");

        return mav;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.