# \[Java Agent\] - apm-server replies with http400 - Problem validating JSON document

**URL:** <https://discuss.elastic.co/t/java-agent-apm-server-replies-with-http400-problem-validating-json-document/129439>\
**Category:** APM\
**Created:** [April 25, 2018, 8:58am UTC](https://discuss.elastic.co/t/java-agent-apm-server-replies-with-http400-problem-validating-json-document/129439 "2018-04-25T08:58:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcoAbi](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MarcoAbi](https://discuss.elastic.co/u/MarcoAbi)\
**Post date:** [April 25, 2018, 8:58am UTC](https://discuss.elastic.co/t/java-agent-apm-server-replies-with-http400-problem-validating-json-document/129439/1 "2018-04-25T08:58:02Z")

</div>

Hello,

I'm trying to send a custom transaction to apm through the Java Agent.  
However I'm experiencing problems and for every transaction I close, the server replies http400 with this error on console:

`ERROR	[request]	beater/handlers.go:384	error handling request	{"request_id": "3be3e112-466c-463a-b011-61284ed52d31", "error": "Problem validating JSON document against schema: I[#] S[#] doesn't validate with \"transaction#\"\n I[#/transactions/0/context/request] S[#/properties/transactions/items/properties/context/properties/request/required] missing properties: \"method\""}`

this is how I'm instrumenting and starting the Agent:

```
private static ElasticApm elasticApm;

...

Transaction apmTransaction = elasticApm.startTransaction();
apmTransaction.setName("testTransaction");
apmTransaction.setType("test");
apmTransaction.setUser("auto", "auto@example.com", "auto");

//Business Code

apmTransaction.close();

```

while elasticapm.properties looks like this:

```
service_name=kpicalculator
service_version=1.0.0
application_packages=a.b.c
environment=sand
server_url=http://xxx.xxx.xxx.xxx:8200

```

Now I'm using apm-server v6.2.4 with docker, however the same issue happens with all the server versions (I've tried from 6.0.0 to 6.2.4)

Am I missing something with the configuration?

Thanks a lot for your help!

Best  
Marco

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [April 25, 2018, 9:06am UTC](https://discuss.elastic.co/t/java-agent-apm-server-replies-with-http400-problem-validating-json-document/129439/2 "2018-04-25T09:06:36Z")

</div>

This is fixed in master, which contains a complete overhaul of the JSON serialization.

The problem is that the Java agent pre-allocates the `Transaction.context.request` object. But if this object is not `null`, the JSON schema requires the `method` to be set. In the current version on `master`, `Transaction.context.request` is only serialized if it actually `hasContent`.

Are you ok with building the Java agent from source?

FYI: when you enable `TRACE` logs for `co.elastic.apm`, you can see the actual JSON sent to the APM-server.

---

<div class="post-metadata">

**Author:** ![MarcoAbi](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MarcoAbi](https://discuss.elastic.co/u/MarcoAbi)\
**Post date:** [April 25, 2018, 1:04pm UTC](https://discuss.elastic.co/t/java-agent-apm-server-replies-with-http400-problem-validating-json-document/129439/3 "2018-04-25T13:04:59Z")

</div>

Thanks Felix for your help.  
I've tried to build from source but I'm experiencing problems due to Java 9.  
I'll have time to deal with it during the next days.

Thanks again!  
Marco

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [April 25, 2018, 4:14pm UTC](https://discuss.elastic.co/t/java-agent-apm-server-replies-with-http400-problem-validating-json-document/129439/4 "2018-04-25T16:14:57Z")

</div>

I'd suggest installing Java 10 as it will soon be required to build the agent. The agent itself is still Java 7 compatible btw.

---

<div class="post-metadata">

**Author:** ![MarcoAbi](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MarcoAbi](https://discuss.elastic.co/u/MarcoAbi)\
**Post date:** [April 26, 2018, 9:13pm UTC](https://discuss.elastic.co/t/java-agent-apm-server-replies-with-http400-problem-validating-json-document/129439/5 "2018-04-26T21:13:14Z")

</div>

Installed Java 10 & built master.  
Now works perfectly.  
Thanks a lot!

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [April 27, 2018, 6:37am UTC](https://discuss.elastic.co/t/java-agent-apm-server-replies-with-http400-problem-validating-json-document/129439/6 "2018-04-27T06:37:53Z")

</div>

That's great news 🙂  
Just tell me if there is anything else I can help you with.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 18, 2018, 2:38am UTC](https://discuss.elastic.co/t/java-agent-apm-server-replies-with-http400-problem-validating-json-document/129439/7 "2018-05-18T02:38:22Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
