Quantcast
Channel: SCN : All Content - SAP Gateway
Viewing all articles
Browse latest Browse all 2823

odata4j and CSRF-Token

$
0
0

Hi everybody,

 

I'm trying to make a CREATE-Request to SAP Netweaver Gateway.

The frontend program is and android application which is using the odata4j library.

When I call the CREATE-Request I always got the error "Validation of CSRF-Token failed"... so I searched a bit and found that you need to fetch the CSRF-Token first and put it as a separate header.

The coding seems to work and looks like the following:

 

public class SAPCSRFBehavior implements JerseyClientBehavior {    private String xcsrfToken = "";        @Override    public ODataClientRequest transform(ODataClientRequest request) {        if(request.getMethod().equals("GET")){            request = request.header("X-CSRF-Token", "Fetch");            return request;        }else{            request = request.header("X-CSRF-Token", this.xcsrfToken);            return request;        }            }    @Override    public void modify(ClientConfig arg0) {        // TODO Auto-generated method stub            }    @Override    public void modifyClientFilters(Filterable client) {        client.addFilter(new ClientFilter(){            @Override            public ClientResponse handle(ClientRequest clientRequest)                    throws ClientHandlerException {                ClientResponse response = this.getNext().handle(clientRequest);                MultivaluedMap<String, String> headers = response.getHeaders();                xcsrfToken = headers.getFirst("X-CSRF-Token");                System.out.println("Token: " + xcsrfToken);                return response;            }         });    }    @Override    public void modifyWebResourceFilters(Filterable arg0) {        // TODO Auto-generated method stub            }
}

When I log the Token I'll get a valid value for it ... but ... somehow I simply get the same error message as before

I really hope somebody has a solution for the problem ... Looking really forward to hearing from you!

 

Greetings

Stef


Viewing all articles
Browse latest Browse all 2823

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>