0

I'm calling SAOP Webservice via a main method and it works fine.. But when i invoke the same method via a browser called method it give me the following error.

Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: 

------------Working Code as Follows---------------------------

public class WSConnectionUtil {


    private static final WSConnectionUtil INSTANCE = new WSConnectionUtil();

    public SynchronizationServiceWSImpl getSyncServicePort(){
        SynchronizationServiceWSImplService service = new SynchronizationServiceWSImplService();

        SynchronizationServiceWSImpl servicePort = service.getSynchronizationServiceWSImplPort();

        ((BindingProvider) servicePort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,getInstance().getSyncUrl());

        return servicePort;
    }

    public static WSConnectionUtil getInstance() {
        return INSTANCE;
    }

    private String getSyncUrl(){    
        String url = "http://10.2.241.33/synchronize?wsdl";
        return url;
    }
}


public void syncAll(){

System.out.println("===========syncAll======"+new Date());
SynchronizationRequest request = new SynchronizationRequest();
WSConnectionUtil wsCon = WSConnectionUtil.getInstance();

request.setPosCode("TNCB");
SynchronizationResponse response = wsCon.getSyncServicePort().synchronize(request);

List<String> types = response.getUpdateTypes();
System.out.println("===========types======"+types.size());
}

----------Error Code---------------------

/**
     * 
     * service for login execution
     *      - user : Contains user id & password 
     * @param user
     * @return
     * 
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public @ResponseBody ModelMap login(@ModelAttribute ("User")User user ){
        String username = user.getName();
        String password = user.getPassword();
        ModelMap model = new ModelMap();

        Boolean status = loginService.login(username, password);

        if(status == true){
            model.put("status", true);
        }

        return model;
    }

    public boolean login(String loginUser,String password){

            Steward steward = new Steward();
            steward.setStewardId(Integer.parseInt(loginUser));
            //List<Steward> stewardsList = stewardDao.getStewardsByCriteria(steward);
            //if(stewardsList!=null && stewardsList.size()>0){
            //  steward = stewardsList.get(0);
            //}else{
            //  LOG.error("Cannot Find a Steward for Login : "+loginUser);
            //  return false;
            //}
            TouchPosApplication.getApplication().setUser("SYSTEM");
            TouchPosApplication.getApplication().setOutletCode("A");
            TouchPosApplication.getApplication().setLoginUserId(loginUser);

    //      final SynchronizationServiceImpl impl = new SynchronizationServiceImpl();   
    //      impl.syncAll();

            new Thread(new Runnable() {

                private static final long serialVersionUID = -4094418102152819603L;

                @Override
                public void run() {
                    while (true) {
                        long i =0;
                        try {
                            i = 1000 * 60 * 1;
                            Thread.sleep(i);
                        } catch (InterruptedException e) {
                            System.out.println("===InterruptedException==========="+e);
                        }                   
                        SyncUtil.synchronizeAutomatic(true);

                    }
                }
            }).start();

            LOG.info("::::: Successfuly Logged In :"+loginUser);

            return true;
        }
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Charitha
  • 317
  • 2
  • 4
  • 17
  • How do you call your SOAP method using a browser? Do you use some REST plugin in a browser? – Sqeezer Jun 11 '13 at 09:15
  • yes im using rest Services @RequestMapping(value = "/login", method = RequestMethod.POST) public @ResponseBody ModelMap login(@ModelAttribute ("User")User user ){ String username = user.getName(); String password = user.getPassword(); ModelMap model = new ModelMap(); Boolean status = loginService.login(username, password); if(status == true){ model.put("status", true); } return model; } – Charitha Jun 11 '13 at 09:16
  • Since your method is waiting for POST request, you must use POST method while invoking the REST service. 'User' parameter must be passed in the POST body and not as a query parameters. I'm using RESTClient Firefox plugin for these kind of purposes, where you can form the request as much as flexible as you want. – Sqeezer Jun 11 '13 at 09:24
  • As far as I can see the URL must be http://10.2.241.33/login – Sqeezer Jun 11 '13 at 09:31

0 Answers0