0

Hi All i am working on spring3.0 restful webservice.i am able to invoke my method when i am calling the method from the same server(i.e my weblogic server).but if i want to consume\hit the same method from another server(i.e my jboss server) then it is not hitting my rest method which is on weblogic server.

in the below code if this code i am writing in weblogic jsp page and calling it is returnig me correct value and i can display the same on my web page.but if i am copying the same code to jsp in JBOSS server(my different project to access my rest service) then it is not hitting my method. ---------------------------------------

$.ajax({
    url: "http://test.abc.org:7001/SpringRestService/restful/products/ALL/ALL/ALL/ALL.json",
    type: "GET",
    processdata: true,
    dataType: "json",
    contentType: "application/json;",
    beforeSend: function () { },
    headers : 
    {
        "Content-Type"  : "application/json",
        "Accept" : "application/json",
        "Access-Control-Allow-Origin":"http://its-ims002.neahq.nearoot.org:7001/"
    },
    success: function (data) 
    {             
            bindEvent.loadGridData(data);
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) 
    {
        try 
        {
            alert(JSON.stringify(XMLHttpRequest) + "\n" + textStatus + "\n" + errorThrown);
        }
        catch (ex) { alert("Exception occured.. "); }
        finally { }
    }
});

below is my java code which i have kept in my weblogic server and this i have to hit from jboss server using my ajax call.

---------------------------------



@Controller
public class HelloWorldController1 {

@RequestMapping(value = "/products/{userName}/{year}/{status}/{stateId}", method = RequestMethod.GET,consumes="application/text")
    public ModelAndView getTextFromURL(@PathVariable("userName") String userName, @PathVariable("year") String year,
            @PathVariable("status") String status, @PathVariable("stateId") String stateId) {
        List<Abc> list= new ArrayList<Abc>();

        list= service.products(userName, year, status, stateId);

        ProductList productList = new ProductList (list);   

        ModelAndView mav = new ModelAndView();
        mav.setViewName("index1");
        mav.addObject("list", productList );

        return mav; 

    }

}
user1913611
  • 59
  • 1
  • 7

1 Answers1

0

Even though you have 'Access-Control-Allow-Origin' specified for the other(jboss) server, the browser might not allow this as this breaches the 'same origin policy'

If your service returns json, you can easily do this by making use of script utilities such as "dojo.io.script" as json or javascript is not affected by 'same origin policy'.

If its not json, there might not be any other option other than "dojo.io.iframe" if that suits you. hope this helps ...

EDIT: I see that your service returns JSON, have you tried using dojo.io.script ? or any other similar utilities that your JS framework has.

user1057653
  • 176
  • 1
  • 8