Please help, Olingo Insert Entity Issue (400) Bad Request

Post Reply
User avatar
macsir
MVP
Posts: 785
Joined: Wed May 30, 2012 6:50 am
OLAP Product: TM1
Version: PAL 2.0.9
Excel Version: Office 365
Contact:

Please help, Olingo Insert Entity Issue (400) Bad Request

Post by macsir »

Hi, All
Please help me on this this inserting operation, always get (400) Bad Request from line "req.execute()". Following is the original code and output.

public class OlingoCUD {
public static void main(String[] args) throws Exception {
String SERVICE_ROOT = "http://server:8001/api/v1/";
ODataClient client = ODataClientFactory.getClient();
String authStr = "username:pwd:NamespaceID";
String authEncoded = new String(Base64.encodeBase64(authStr.getBytes()));

ClientEntity newprocess = client.getObjectFactory().newEntity(new FullQualifiedName("ibm.tm1.api.v1.Process"));
newprocess.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Name",client.getObjectFactory().newPrimitiveValueBuilder().buildString("MyProcess")));

URI ProcessURI = client.newURIBuilder(SERVICE_ROOT).appendEntitySetSegment("Processes").build();

ODataEntityCreateRequest<ClientEntity> req = client.getCUDRequestFactory().getEntityCreateRequest(ProcessURI, newprocess);
req.addCustomHeader("Authorization","CAMNamespace " + authEncoded);
req.setFormat(ODataFormat.APPLICATION_JSON);
ODataEntityCreateResponse<ClientEntity> res = req.execute();
System.out.println(res.getHeaderNames());

if (res.getStatusCode()==201) {
System.out.println("Successfully Created!");
}

}
}


Debug OutPut:
main] WARN org.apache.olingo.client.core.communication.header.ODataErrorResponseChecker - Error deserializing error response
java.lang.NullPointerException
at org.apache.olingo.commons.core.serialization.JsonODataErrorDeserializer.doDeserialize(JsonODataErrorDeserializer.java:46)
at org.apache.olingo.commons.core.serialization.JsonDeserializer.toError(JsonDeserializer.java:416)
at org.apache.olingo.client.core.serialization.ClientODataDeserializerImpl.toError(ClientODataDeserializerImpl.java:90)
at org.apache.olingo.client.core.serialization.ODataReaderImpl.readError(ODataReaderImpl.java:85)
at org.apache.olingo.client.core.communication.header.ODataErrorResponseChecker.checkResponse(ODataErrorResponseChecker.java:58)
at org.apache.olingo.client.core.communication.request.AbstractRequest.checkResponse(AbstractRequest.java:54)
at org.apache.olingo.client.core.communication.request.AbstractODataRequest.doExecute(AbstractODataRequest.java:316)
at org.apache.olingo.client.core.communication.request.cud.ODataEntityCreateRequestImpl.execute(ODataEntityCreateRequestImpl.java:88)
at org.apache.olingo.client.core.communication.request.cud.ODataEntityCreateRequestImpl.execute(ODataEntityCreateRequestImpl.java:47)
at Operation.OlingoCUD.main(OlingoCUD.java:62)
Exception in thread "main" org.apache.olingo.client.api.communication.ODataClientErrorException: (400) Bad Request [HTTP/1.1 400 Bad Request]
at org.apache.olingo.client.core.communication.header.ODataErrorResponseChecker.checkResponse(ODataErrorResponseChecker.java:74)
at org.apache.olingo.client.core.communication.request.AbstractRequest.checkResponse(AbstractRequest.java:54)
at org.apache.olingo.client.core.communication.request.AbstractODataRequest.doExecute(AbstractODataRequest.java:316)
at org.apache.olingo.client.core.communication.request.cud.ODataEntityCreateRequestImpl.execute(ODataEntityCreateRequestImpl.java:88)
at org.apache.olingo.client.core.communication.request.cud.ODataEntityCreateRequestImpl.execute(ODataEntityCreateRequestImpl.java:47)
at Operation.OlingoCUD.main(OlingoCUD.java:62)
In TM1,the answer is always yes though sometimes with a but....
http://tm1sir.blogspot.com.au/
User avatar
macsir
MVP
Posts: 785
Joined: Wed May 30, 2012 6:50 am
OLAP Product: TM1
Version: PAL 2.0.9
Excel Version: Office 365
Contact:

Re: Please help, Olingo Insert Entity Issue (400) Bad Reques

Post by macsir »

Anyone has ideas? :idea:
In TM1,the answer is always yes though sometimes with a but....
http://tm1sir.blogspot.com.au/
dr.nybble
MVP
Posts: 160
Joined: Wed Aug 17, 2011 3:51 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: Excel 2007

Re: Please help, Olingo Insert Entity Issue (400) Bad Reques

Post by dr.nybble »

Try to "manually" POST your request through Chrome using the Advanced Rest Client plugin first to ensure you are forming the request correctly.
Trying it without setting any additional headers results in:

{
error: {
code: ""
message: "The content type specified is not supported. Please use JSON (application/json; charset=utf-8) as the content type."
}-
}


OK trying again with the right Content-Type and this body:

{
"Name": "TestProc"
}

Works -- I got 201 Created.

Try http://www.pocketsoap.com/tcpTrace/ to proxy your requests and see all of the traffic going back & forth (or enable wire logging).
Alternatively configure Eclipse to break on Null Pointer Exceptions and see what the response text is that is causing the null pointer exception.
User avatar
macsir
MVP
Posts: 785
Joined: Wed May 30, 2012 6:50 am
OLAP Product: TM1
Version: PAL 2.0.9
Excel Version: Office 365
Contact:

Re: Please help, Olingo Insert Entity Issue (400) Bad Reques

Post by macsir »

dr.nybble wrote:Try to "manually" POST your request through Chrome using the Advanced Rest Client plugin first to ensure you are forming the request correctly.
Trying it without setting any additional headers results in:

{
error: {
code: ""
message: "The content type specified is not supported. Please use JSON (application/json; charset=utf-8) as the content type."
}-
}


OK trying again with the right Content-Type and this body:

{
"Name": "TestProc"
}

Works -- I got 201 Created.

Try http://www.pocketsoap.com/tcpTrace/ to proxy your requests and see all of the traffic going back & forth (or enable wire logging).
Alternatively configure Eclipse to break on Null Pointer Exceptions and see what the response text is that is causing the null pointer exception.
Thanks, Man. Your tool is helpful! I will give it a go!
But I have implemented the new codes successfully using HttpClient and Gson in java for create/delete/update objects on TM1 server! :D :D :D
In TM1,the answer is always yes though sometimes with a but....
http://tm1sir.blogspot.com.au/
dr.nybble
MVP
Posts: 160
Joined: Wed Aug 17, 2011 3:51 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: Excel 2007

Re: Please help, Olingo Insert Entity Issue (400) Bad Reques

Post by dr.nybble »

Good news! We are using Apache HTTP Client and Jackson.
Post Reply