Skip to Content
May 01, 2016 at 07:51 AM

CSRF token validation failed in Odata4j


Hi all,

I'm trying to post the entry to Odata service Url which is created in ABAP backend. When i'm trying to send the data from java code to ABAP system via Odata service, I'm getting CSRF Token validation error. Below is the code snippet for Odata Post service

// TESTCASEXML_ODATA = URL of the Odata service

ODataJerseyConsumer consumer = ODataJerseyConsumer.create(TESTCASEXML_ODATA);

ODataJerseyConsumer.Builder builder = ODataJerseyConsumer.newBuilder(TESTCASEXML_ODATA);

// Authentication

builder.setClientBehaviors(new OClientBehavior(){


public ODataClientRequest transform(ODataClientRequest request) {

String userPassword = USERNAME + ":" + PASSWORD;

String encoded = Base64.encodeBase64String(userPassword.getBytes());

encoded = encoded.replaceAll("\r\n?", "");

// Necessary headers to do PUT and POST operations

request = request.header("X-Requested-With", "XMLHttpRequest")

.header("Authorization", "Basic " + encoded);

return request;


consumer =;

OCreateRequest<OEntity> createRequest = consumer.createEntity("LogSet").properties(OProperties.string("TestplanId", "111")).properties(OProperties.string("ProcessId", "222")).properties(OProperties.string("Seqno", "33"));

// Execute the OData post


Please suggest me the solution to avoid this issue

Thanks and Regards,