(Migrated) Problems with server-to-server JSON POST through Zato

(This message has been automatically imported from the retired mailing list)

Hello,

Attempting to post JSON content to a Zato Plain HTTP channel, and then have
that forward on through an outgoing Plain HTTP connection, is causing some
issues for me. I must be doing something wrong here.

Here is my service:

from zato.server.service import Service

class UpdateTemplateServer(Service):
def handle(self):
tmplsrv =3D self.outgoing.plain_http.get(‘update_templates’)
self.logger.info(self.request.payload)
tmplsrv.conn.post(self.cid, self.request.payload)
self.response.payload =3D “OK”

Here is the log:

=3D=3D> /opt/zato/prod/test-1/server1/logs/server.log <=3D=3D
2015-03-25 00:22:44,432 - INFO - 1874:Dummy-23665 -
tmpl-svc.update-template-server:22 - {u’urls’: {u’lpsrv|/greetings’:
u’greeting’}}
2015-03-25 00:22:44,432 - INFO - 1874:Dummy-23665 -
zato.server.connection.http_soap.outgoing:22 -
CID:[K06SEG5YX2ZGMFKDG390FDYHF9NW], address:[http://lpsrv/update],
qs_params:[{}], auth:[None], kwargs:[{}]
2015-03-25 00:22:44,435 - WARNING - 1874:Dummy-23665 -
zato.server.service:22 - Traceback (most recent call last):
File “/opt/zato/2.0.2/zato-server/src/zato/server/service/init.py”,
line 402, in update_handle
self._invoke(service, channel)
File “/opt/zato/2.0.2/zato-server/src/zato/server/service/init.py”,
line 345, in _invoke
service.handle()
File “/opt/zato/prod/test-1/server1/work/hot-deploy/current/tmpl_svc.py”,
line 7, in handle
tmplsrv.conn.post(self.cid, self.request.payload)
File
"/opt/zato/2.0.2/zato-server/src/zato/server/connection/http_soap/outgoing.=
py",
line 326, in post
return self.http_request(‘POST’, cid, data, params, *args, **kwargs)
File
"/opt/zato/2.0.2/zato-server/src/zato/server/connection/http_soap/outgoing.=
py",
line 308, in http_request
response.data =3D loads(response.text)
File “/usr/lib/python2.7/json/init.py”, line 338, in loads
return _default_decoder.decode(s)
File “/usr/lib/python2.7/json/decoder.py”, line 366, in decode
obj, end =3D self.raw_decode(s, idx=3D_w(s, 0).end())
File “/usr/lib/python2.7/json/decoder.py”, line 384, in raw_decode
raise ValueError(“No JSON object could be decoded”)
ValueError: No JSON object could be decoded

2015-03-25 00:22:44,435 - ERROR - 1874:Dummy-23665 -
zato.server.connection.http_soap.channel:22 - Caught an exception,
cid:[K06SEG5YX2ZGMFKDG390FDYHF9NW], status_code:[500],
_format_exc:[Traceback (most recent call last):
File
"/opt/zato/2.0.2/zato-server/src/zato/server/connection/http_soap/channel.p=
y",
line 198, in dispatch
payload, worker_store, self.simple_io_config, post_data)
File
"/opt/zato/2.0.2/zato-server/src/zato/server/connection/http_soap/channel.p=
y",
line 351, in handle
params_priority=3Dchannel_item.params_pri)
File “/opt/zato/2.0.2/zato-server/src/zato/server/service/init.py”,
line 423, in update_handle
raise e
ValueError: No JSON object could be decoded
]

The outgoing Plain HTTP connection:
update_templatesYeshttp://lpsrv/updateNo security definition
The incoming Plain HTTP channel:
Update Template Server
<http://z.simplur.com:8183/zato/http-soap/details/channel/plain_http/533/Up=
date%20Template%20Server/1/>
Yes/tmplsrv/updatetmpl-svc.update-template-server
<http://z.simplur.com:8183/zato/service/overview/tmpl-svc.update-template-s=
erver/?cluster=3D1>No
security definition

After setting up auditing on the Plain HTTP channel, I received the
following from the audit log:

[image: Zato samurai helmet logo]ZatoMy settings
http://z.simplur.com:8183/account/settings/basic/ Log out (admin)
http://z.simplur.com:8183/logout/

Update Template Server : Audit log : K06SEG5YX2ZGMFKDG390FDYHF9NW
Overview
<http://z.simplur.com:8183/zato/http-soap/details/channel/plain_http/533/Up=
date%20Template%20Server/1/>
Audit log
<http://z.simplur.com:8183/zato/http-soap/audit/log/channel/plain_http/533/=
Update%20Template%20Server/1/>
RequestHeadersPayloadResponseHeadersPayload

Any help is appreciated.

Thanks,

Bobby

On 25/03/15 01:34, Bobby wrote:

2015-03-25 00:22:44,432 - INFO - 1874:Dummy-23665 -
zato.server.connection.http_soap.outgoing:22 -
CID:[K06SEG5YX2ZGMFKDG390FDYHF9NW], address:[http://lpsrv/update],
qs_params:[{}], auth:[None], kwargs:[{}]

return self.http_request(‘POST’, cid, data, params, *args,
**kwargs)
File “/opt/zato/2.0.2/zato-server/src/zato/server/connection
/http_soap/outgoing.py”, line 308, in http_request
response.data = loads(response.text)

ValueError: No JSON object could be decoded

Hi Bobby,

conversion from JSON to Python fails when POST-ing to http://lpsrv/update.

Can you confirm the response that endpoint produces is actually JSON?

Hi Dariusz,

That was the issue, thanks!

On another note, the reason that the server was not producing JSON was
because it was expecting the “Content-Type: application/json” header. I
went ahead and set it manually from the service for this request, but is
there a way to set this automatically (or, is that even preferable) on the
outgoing connection, rather than from the code?

Thanks,

Bobby

On Wed, Mar 25, 2015 at 12:47 AM, Dariusz Suchojad dsuch@zato.io wrote:

On 25/03/15 01:34, Bobby wrote:

2015-03-25 00:22:44,432 - INFO - 1874:Dummy-23665 -
zato.server.connection.http_soap.outgoing:22 -
CID:[K06SEG5YX2ZGMFKDG390FDYHF9NW], address:[http://lpsrv/update],
qs_params:[{}], auth:[None], kwargs:[{}]

return self.http_request(‘POST’, cid, data, params, *args,
**kwargs)
File “/opt/zato/2.0.2/zato-server/src/zato/server/connection
/http_soap/outgoing.py”, line 308, in http_request
response.data = loads(response.text)

ValueError: No JSON object could be decoded

Hi Bobby,

conversion from JSON to Python fails when POST-ing to http://lpsrv/update.

Can you confirm the response that endpoint produces is actually JSON?

On 25/03/15 17:20, Bobby wrote:

is there a way to set this automatically (or, is that even preferable)
on the outgoing connection, rather than from the code?

There isn’t right now but it sure makes sense to have it directly in a
connection’s definition.

Please subscribe to the ticket below so you can be notified when it’s done.

Thanks for suggesting it!