ronypatil ronypatil - 4 months ago 15
Java Question

passing parameter in webservice API

I am new at webservices and currently able to run my query by calling https://localhost/application/service/v1.0/contacts/account={accountId}
I want to make my url look like https://localhost/application/service/v1.0/contacts?account={accountId}

May I know How to achieve this not using QueryParam ? I am working in spring mvc

@Controller
public class ContactListResponseController extends BaseWebServiceController
{

public static final String PATH = "/v" + VERSION + "/contacts/account={accountId}";

@Autowired
private ContactService contactService;

@RequestMapping(value = PATH, method = RequestMethod.GET)
@ResponseBody
public ContactListResponseBean doGetMyAssignedAccounts (@PathVariable String accountId,
HttpServletRequest request,
HttpSession session,
HttpServletResponse response,
@ModelAttribute(User.USER_REQUEST_VAR) User user)
throws Exception
{

List<ContactSummaryWebServiceBean> contactList = contactService.getContactsListForCallPointWebService(accountId);
ContactListResponseBean result = new ContactListResponseBean(contactList);
return result;
}

}

Answer

It is a simple thing, try this:

@Controller 
public class ContactListResponseController extends BaseWebServiceController 
{ 

 public static final String PATH = "/v" + VERSION + "/contacts"; 

 @Autowired 
 private ContactService contactService; 

 @RequestMapping(value = PATH, method = RequestMethod.GET) 
 @ResponseBody 
 public ContactListResponseBean doGetMyAssignedAccounts (@RequestParam("account") String accountId, 
                                                       HttpServletRequest request, 
                                                       HttpSession session, 
                                                       HttpServletResponse response, 
                                                          @ModelAttribute(User.USER_REQUEST_VAR) User user) 
  throws Exception 
  { 

    List<ContactSummaryWebServiceBean> contactList = contactService.getContactsListForCallPointWebService(accountId); 
    ContactListResponseBean result = new  ContactListResponseBean(contactList); 
    return result; 
  } 

}
Comments