Skip to content

Improve error response processing in Mark Logic Java Client API #434

Closed
@josvanroosmalen

Description

@josvanroosmalen

Hi,

I am working on some quick POC-code to get data into MarkLogic using Java, and I found out that the response processing is not properly working (or I am not correctly using :-) ).

If I run the PUT-operation (see snippet at the end of this message), I get the following not really informative error. Even if I enable/set request logging on (see snippet), I only get this (The AppServer log does not tell much more than http 409):

com.marklogic.client.FailedRequestException: Local message: failed to write resource at resources/ingest-trade: Conflict. Server Message: null
[..]
LogBuffer 0
null

So I cloned the sourcecode from GitHub and I changed:

JerseyServices.java-> lline 415: client = ApacheHttpClient4.create(config);

to:

line 415: client = ApacheHttpClient4.create(config);
line 416: client.addFilter(new LoggingFilter(System.err));

Now I get suddenly much more interesting info (XPTY0004):

1 * Client out-bound request
1 > HEAD http://localhost:8003/v1/ping
1 * Client in-bound response
1 < 401
1 < Server: MarkLogic
(....)
3 * Client out-bound request
3 > PUT http://localhost:8003/v1/resources/ingest-trade?rs:message-id=1333&rs:source=MX
3 * Client in-bound response
3 < 409
3 < Server: MarkLogic
3 < Content-Type: application/xml; charset=UTF-8
3 < Content-Length: 226
3 < Connection: Keep-Alive
3 < Keep-Alive: timeout=5
3 < 
<?xml version="1.0" encoding="UTF-8"?>
<status elapsed-time="PT0.005S">Exception detected for message with Id=1333 Reason: {"ingestion":"XDMP-AS: (err:XPTY0004) $compiled as node() -- Invalid coercion: () as node()"}</status>

Because the response is XML, I thought it would help to add:

StringHandle result = new StringHandle().withFormat(Format.XML);

But that did not help.

Can someone tell what (1) I did wrong (how to get this (XML) error message in the output handler or (2) when this will be fixed?

Original Test Snippet:

public void ingestTrade(DatabaseClient client,String source,String messageId,String messageContent) throws Exception { 
    RequestParameters params = new RequestParameters();
    params.add("message-id", messageId);
    params.add("source", source);
    StringHandle result = new StringHandle().withFormat(Format.XML);
    StringHandle h = new StringHandle(messageContent).withFormat(Format.XML);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try { 
    // trying to get it out with the request logger. 
    RequestLogger logger = client.newLogger(out);
    getServices().startLogging(logger);
    logger.setEnabled(true);
    getServices().put(params,new StringHandle(messageContent).withFormat(Format.XML),result);
    } catch (Exception e) { 
        e.printStackTrace();
    }
    System.err.println("LogBuffer "+out.size()); 
        System.err.println(result);
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions