• Post Reply Bookmark Topic Watch Topic
  • New Topic

In JSON response href is not clickable  RSS feed

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
        I am working wit spring rest.On some error condition in json response i am sending link.But in browser it is not clickable it is in string from.Following is my code





Controller:

@RequestMapping(value="/sendmail", method=RequestMethod.GET)
public ResponseEntity<ConsentManager> home(Locale locale , Model model,HttpServletRequest request){

System.out.println("Location Is:"+locale);
System.out.println("IP Address Is:"+request.getRemoteAddr());

ConsentManager cm = new ConsentManager();
cm.setRole("Admin");
cm.setJuridection("fr");
cm.setConsentType("email");
cm.setEmail("prabhashmishra101@gmail.com");

Map<String, String> result = new HashMap();

    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String key = (String) headerNames.nextElement();
        String value = request.getHeader(key);
        result.put(key, value);
    }

    for (String name: result.keySet()){

            String key =name.toString();
            String value = result.get(name).toString(); 
            System.out.println(key + " " + value); 


}
   
    String customerName="Prabhash";
String recipantEmail="prabhashmishra101@gmail.com";



boolean status=mailService.sendMail("mumbainights101@gmail.com", recipantEmail , "Welcome To Fashioniesta Fashion Store", "Hello"+ " "+customerName+ "\n\n"+ "You Have been successfully registered with Fashioniesta.com."+"\n\n"+"Thanks,"+"\n"+"Team Fashioniesta.");
if(!status){
System.out.println("Inside Fail");
try {
throw new ConsentException("Error Occured While sending mail");
} catch (ConsentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

return  new ResponseEntity<ConsentManager>(cm, HttpStatus.OK);



}

@ExceptionHandler(ConsentException.class)
public ResponseEntity<ConsentErrorResponse> exceptionHandler(Exception ex) {
ConsentErrorResponse error = new ConsentErrorResponse();
error.setErrorCode(HttpStatus.PRECONDITION_FAILED.value());
String uri=ServletUriComponentsBuilder.fromCurrentContextPath().path("/my/additional/path").build().toUriString();
Link link = new Link(uri);
error.setMessageLink(link);
return new ResponseEntity<ConsentErrorResponse>(error, HttpStatus.OK);
}

After getting SMTP error i am sending json error response with link.But in browser it is nor clickable.Can anybody let me know where i am making mistake.

Thanks,
Prabhash
 
Saloon Keeper
Posts: 8457
155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSON is not HTML. If you want a clickable link, you need to send HTML.
 
Prabhash Mishra
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
        But in jax-rs jersey i was able to do it using exceptionmapper class.There using HAETOS i was able to make json link clickable but in rest spring i am not.

Thanks,
Prabhash
 
Ranch Hand
Posts: 62
5
Eclipse IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prabhash Mishra wrote:But in jax-rs jersey i was able to do it using exceptionmapper class.There using HAETOS i was able to make json link clickable but in rest spring i am not.


Sorry but your statement is meaningless. A JSON is a text file. You don't "click" on the elements of a JSON ..... unless the browser renders the JSON in some way, either due to some installed plugin (in the case you have directly opened the JSON) or due to some Javascript manipulation in a web page (in the case the page gets the JSON using AJAX or other tecnique).

So please, explain who and where is using that JSON.
 
Prabhash Mishra
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
    I am getting JSon response once some error encounter.Once this json link received the user have to click that link and after clicking new page will be opened which will have radio button that will be selected by user and submitted.This is the requirement.

Thanks,
Prabhash
 
Sheriff
Posts: 23446
46
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prabhash Mishra wrote:Once this json link received the user have to click that link...



Again, you're going to have to explain how the user is clicking on JSON. Most of us on this thread are assuming that a browser and HTML are involved, but it's up to you to clarify that.
 
Stephan van Hulst
Saloon Keeper
Posts: 8457
155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clickable links are a feature of HTML. That means you need to display a HTML page, not a piece of JSON. There's two major ways you can do this:

  • Instead of serving JSON upon an exception, serve HTML.
  • If you initiated the action with an AJAX request, after the JSON is returned you can insert a link using JavaScript.
  •  
    Stephan van Hulst
    Saloon Keeper
    Posts: 8457
    155
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Note that HATEOAS only specifies that a resource contains information that tells what other resources can be navigated to from the current one. It doesn't mean that that information is in the form of clickable links. It can be, but then the resource MUST BE an HTML page.
     
    The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
    Thread Boost - a very different sort of advertising
    https://coderanch.com/t/674455/Thread-Boost-feature
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!