Generate Valid hdiv url in controller

238 Views Asked by At

i have successfully configured Spring Boot 2.0.4 to use spring-security with HDIV. I decided to use jquery datatable as table rendering technology. Here come the problem... For each row of my datatable i'd like to create a detail link signed with _HDIV_STATE_ parameter how can i generate a valid link while iterating my item list in a controller?

A generic Controller:

@Controller
public class ItemController {

   ....

   @GetMapping(value = "/test")
   public @ResponseBody test() {
      List<Item> items = service.getList();
      items.foreach(item -> {
         item.setDetailUrl(HDIV_GENERATED_URL);
      })
    }

   ...

  }

Thanks

2

There are 2 best solutions below

0
gillarramendi On BEST ANSWER

You can inject the LinkUrlProcessor class in the controller.

@autowired
LinkUrlProcessor linkUrlProcessor;

And invoke processUrl method.

String processedUrl linkUrlProcessor.processUrl(request, originalUrl);

The processedUrl will contain the _HDIV_STATE_ parameter.

1
Michele C. On

Ok, this solution work fine only with ulrs with pathvariable.

@Autowired
ServletContext context;

public @ResponseBody String test() {
  int id = 1;
  LinukUrlProcessor lup = HDIVUtil.getLinkUrlProcessor(context);
  RequestContextHolder rch =HDIVUtil.getRequestContext(context);
  //This works perfectly
  String processedWithPath = lup.processUrl(rch, "/test" + id);
  //This produce a _HVID_STATE_ but query param always 0
  String processedWithQuery = lup.processUrl(rch, "/test?id=" + id);
  return ....
}

Any further help generating valid url with query parameters?