[GeoNetwork-users] API: HttpMediaTypeNotAcceptableException

Hi,

I’m getting HttpMediaTypeNotAcceptableException when trying to enter a new record through the API. My GN is v3.4.3.0 and the metadata XML file was prepared by exporting an existing entry.

The command I’m running:
curl -v -X POST "http://localhost:8080/geonetwork/srv/api/0.1/records?metadataType=METADATA&uuidProcessing=GENERATEUUID&rejectIfInvalid=false&publishToAll=true&assignToCatalog=false&transformWith=_none_" -H "accept: */*" -H "Content-Type: text/xml" -H "X-XSRF-TOKEN: c214a165-b862-82db-29c7-267676f4a895" --user admin:admin -b /tmp/cookie -d @path/to/metadata.xml

Log I’m getting:
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'admin'

POST /geonetwork/srv/api/0.1/records?metadataType=METADATA&uuidProcessing=GENERATEUUID&rejectIfInvalid=false&publishToAll=true&assignToCatalog=false&transformWith=_none_ HTTP/1.1
Host: localhost:8080
Authorization: Basic YWRtaW46YWRtaW4=
User-Agent: curl/7.47.0
Cookie: XSRF-TOKEN=c214a165-b862-82db-29c7-267676f4a895
accept: */*
Content-Type: text/xml
X-XSRF-TOKEN: c214a165-b862-82db-29c7-267676f4a895
Content-Length: 10433
Expect: 100-continue

< HTTP/1.1 400 Bad Request
* Added cookie JSESSIONID="1vx9xfl6nv0tm1sm6otlczq1zx" for domain localhost, path /geonetwork, expire 0
< Set-Cookie: JSESSIONID=1vx9xfl6nv0tm1sm6otlczq1zx;Path=/geonetwork
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
* Added cookie serverTime="1542713381944" for domain localhost, path /, expire 0
< Set-Cookie: serverTime=1542713381944;Path=/
* Added cookie sessionExpiry="1542713381944" for domain localhost, path /, expire 0
< Set-Cookie: sessionExpiry=1542713381944;Path=/
< X-Frame-Options: DENY
< Content-Security-Policy: frame-ancestors 'none'
< Content-Type: application/xml
< Connection: close
< Server: Jetty(9.2.14.v20151106)
<
* Closing connection 0

The response I’m getting:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><apiError><code>runtime_exception</code><description>Could not find acceptable representation</description><message>HttpMediaTypeNotAcceptableException</message></apiError>

I’ve been fiddling with the Content-Type header, but to no avail. I don’t know what I’m doing wrong and don’t know what to try to solve my problem. Any clues or help would be appreciated!

Thanks!
Marko

On Wed, Nov 21, 2018 at 8:22 AM Marko Praprotnik <marko.praprotnik@anonymised.com..>
wrote:

Hi,

I’m getting HttpMediaTypeNotAcceptableException when trying to enter a new
record through the API. My GN is v3.4.3.0 and the metadata XML file was
prepared by exporting an existing entry.

The command I’m running:
curl -v -X POST "
http://localhost:8080/geonetwork/srv/api/0.1/records?metadataType=METADATA&uuidProcessing=GENERATEUUID&rejectIfInvalid=false&publishToAll=true&assignToCatalog=false&transformWith=_none_&quot;
-H "accept: */*" -H "Content-Type: text/xml" -H "X-XSRF-TOKEN:
c214a165-b862-82db-29c7-267676f4a895" --user admin:admin -b /tmp/cookie -d
@path/to/metadata.xml

I haven't tried, but have you checked if sending -H "Content-Type:
application/xml" works?

--

*Vriendelijke groeten / Kind regards,Juan Luis Rodríguez.
<http://www.geocat.net/&gt;Veenderweg 136721 WD BennekomThe NetherlandsT: +31
(0)318 416664 <+31318416664> <https://www.facebook.com/geocatbv&gt;
<https://twitter.com/geocat_bv&gt;
<https://plus.google.com/u/1/+GeocatNetbv/posts&gt;Please consider the
environment before printing this email.*

Thanks for replying, and sorry for my late reply … yes, I’ve tried also the application/xml content type, but it produces the same error.

Any other ideas?

Not sure if it’s related in any way, but I’m running GN on Jetty 9

Thanks and kind regards,
Marko

On 21 Nov 2018, at 11:29, Juan Luis Rodríguez Ponce <juanluisrp@anonymised.com44...> wrote:

On Wed, Nov 21, 2018 at 8:22 AM Marko Praprotnik <marko.praprotnik@anonymised.com1...>
wrote:

Hi,

I’m getting HttpMediaTypeNotAcceptableException when trying to enter a new
record through the API. My GN is v3.4.3.0 and the metadata XML file was
prepared by exporting an existing entry.

The command I’m running:
curl -v -X POST "
http://localhost:8080/geonetwork/srv/api/0.1/records?metadataType=METADATA&uuidProcessing=GENERATEUUID&rejectIfInvalid=false&publishToAll=true&assignToCatalog=false&transformWith=_none_&quot;
-H "accept: */*" -H "Content-Type: text/xml" -H "X-XSRF-TOKEN:
c214a165-b862-82db-29c7-267676f4a895" --user admin:admin -b /tmp/cookie -d
@path/to/metadata.xml

I haven't tried, but have you checked if sending -H "Content-Type:
application/xml" works?

--

*Vriendelijke groeten / Kind regards,Juan Luis Rodríguez.
<http://www.geocat.net/&gt;Veenderweg 136721 WD BennekomThe NetherlandsT: +31
(0)318 416664 <+31318416664> <https://www.facebook.com/geocatbv&gt;
<https://twitter.com/geocat_bv&gt;
<https://plus.google.com/u/1/+GeocatNetbv/posts&gt;Please consider the
environment before printing this email.*

_______________________________________________
GeoNetwork-users mailing list
GeoNetwork-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geonetwork-users
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork

On Mon, Nov 26, 2018 at 3:26 PM Marko Praprotnik <marko.praprotnik@anonymised.com..>
wrote:

Thanks for replying, and sorry for my late reply … yes, I’ve tried also
the application/xml content type, but it produces the same error.

Any other ideas?

Not sure if it’s related in any way, but I’m running GN on Jetty 9

Although requesting "Accept: */*" should work it doesn't. You have to
request "Accept: application/json". For example:

curl -X POST \
  '
http://localhost:8080/geonetwork/srv/api/0.1/records?metadataType=METADATA&uuidProcessing=GENERATEUUID&rejectIfInvalid=false&publishToAll=true&assignToCatalog=false&transformWith=_none_
\
  *-H 'Accept: application/json'* \
  -H 'Authorization: Basic YWRtaW46YWRtaW4=' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'X-XSRF-TOKEN: e4fadc4d-4299-478d-849a-1627e7684c33' \
  -b /tmp/cookie
  -d @/path/to/metadata.xml

Regards,
Juan Luis.

--

*Vriendelijke groeten / Kind regards,Juan Luis Rodríguez.
<http://www.geocat.net/&gt;Veenderweg 136721 WD BennekomThe NetherlandsT: +31
(0)318 416664 <+31318416664> <https://www.facebook.com/geocatbv&gt;
<https://twitter.com/geocat_bv&gt;
<https://plus.google.com/u/1/+GeocatNetbv/posts&gt;Please consider the
environment before printing this email.*

Thanks Juan,

however, I'm still not able to create a record throug API.

If I use "Accept: application/json" header, I get the following exception:
{"message":"MultipartException","code":"unsatisfied_request_parameter","description":"The current request is not a multipart request"}

If I set this header to "Accept: application/xml", I get the same error as with "Accept: */*":
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><apiError><code>runtime_exception</code><description>Could not find acceptable representation</description><message>HttpMediaTypeNotAcceptableException</message></apiError>

I see that you are also using the -H "Authorization: Basic YWRtaW46YWRtaW4=", which I haven't set. If I copy/paste this header literally, nothing changes.

Thanks!

Kind regards,
Marko

From: "Juan Luis Rodríguez Ponce" <juanluisrp@anonymised.com>
To: "marko praprotnik" <marko.praprotnik@anonymised.com>
Cc: "Geonetwork-Users@anonymised.com" <geonetwork-users@lists.sourceforge.net>
Sent: Monday, November 26, 2018 4:43:38 PM
Subject: Re: [GeoNetwork-users] API: HttpMediaTypeNotAcceptableException

On Mon, Nov 26, 2018 at 3:26 PM Marko Praprotnik < [ mailto:marko.praprotnik@anonymised.com | marko.praprotnik@anonymised.com ] > wrote:

Thanks for replying, and sorry for my late reply … yes, I’ve tried also the application/xml content type, but it produces the same error.

Any other ideas?

Not sure if it’s related in any way, but I’m running GN on Jetty 9

Although requesting "Accept: */*" should work it doesn't. You have to request "Accept: application/json". For example:

curl -X POST \
' [ http://localhost:8080/geonetwork/srv/api/0.1/records?metadataType=METADATA&uuidProcessing=GENERATEUUID&rejectIfInvalid=false&publishToAll=true&assignToCatalog=false&transformWith=_none_ | http://localhost:8080/geonetwork/srv/api/0.1/records?metadataType=METADATA&uuidProcessing=GENERATEUUID&rejectIfInvalid=false&publishToAll=true&assignToCatalog=false&transformWith=_none_ ] ' \
-H 'Accept: application/json' \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'X-XSRF-TOKEN: e4fadc4d-4299-478d-849a-1627e7684c33' \
-b /tmp/cookie
-d @/path/to/metadata.xml

Regards,
Juan Luis.

--
Vriendelijke groeten / Kind regards,

Juan Luis Rodríguez.

[ http://www.geocat.net/ ]
Veenderweg 13
6721 WD Bennekom
The Netherlands
T: [ tel:+31318416664 | +31 (0)318 416664 ]

[ https://www.facebook.com/geocatbv ] [ https://twitter.com/geocat_bv ] [ https://plus.google.com/u/1/+GeocatNetbv/posts ]

Please consider the environment before printing this email.

On Tue, Nov 27, 2018 at 12:46 PM Marko Praprotnik <marko.praprotnik@anonymised.com...>
wrote:

Thanks Juan,

however, I'm still not able to create a record throug API.

If I use "Accept: application/json" header, I get the following exception:
{"message":"MultipartException","code":"unsatisfied_request_parameter","description":"The
current request is not a multipart request"}

If I set this header to "Accept: application/xml", I get the same error as
with "Accept: */*":
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><apiError><code>runtime_exception</code><description>Could
not find acceptable
representation</description><message>HttpMediaTypeNotAcceptableException</message></apiError>

I see that you are also using the -H "Authorization: Basic
YWRtaW46YWRtaW4=", which I haven't set. If I copy/paste this header
literally, nothing changes.

This header is the same that using "--user admin:admin" in curl so it
doesn't matter. The problem is that you must send the data as a Multipart
Form. Using curl the command would be like

curl -X POST \
  '
http://localhost:8080/geonetwork/srv/api/0.1/records?metadataType=METADATA&uuidProcessing=GENERATEUUID&rejectIfInvalid=false&publishToAll=true&assignToCatalog=false&transformWith=_none_
\
  -H 'Accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'X-XSRF-TOKEN: e4fadc4d-4299-478d-849a-1627e7684c33' \
  -H 'content-type: multipart/form-data' \
  -b /tmp/cookie \
  --user admin:admin \
  -F xml=@/path/to/metadata.xml

--

*Vriendelijke groeten / Kind regards,Juan Luis Rodríguez.
<http://www.geocat.net/&gt;Veenderweg 136721 WD BennekomThe NetherlandsT: +31
(0)318 416664 <+31318416664> <https://www.facebook.com/geocatbv&gt;
<https://twitter.com/geocat_bv&gt;
<https://plus.google.com/u/1/+GeocatNetbv/posts&gt;Please consider the
environment before printing this email.*

Ok, thanks for explaining that! And thanks for solving my problem with HttpMediaTypeNotAcceptableException! :slight_smile:

If I add 2 content-type headers, as you suggest, I get:
{"message":"MultipartException","code":"unsatisfied_request_parameter","description":"The current request is not a multipart request"}

If I ommit the 'Content-Type: application/x-www-form-urlencoded' header, I get:
{"message":"MultipartException","code":"unsatisfied_request_parameter","description":"Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found"}

Then, if I add a random boundary to the 'content-type: multipart/form-data' header, I get no error:
{"errors":,"infos":,"uuid":"6e5b9bfe-9124-4864-98c8-f1c68cfdec80","metadata":,"metadataErrors":{},"metadataInfos":{},"numberOfRecordNotFound":0,"numberOfRecordsNotEditable":0,"numberOfNullRecords":0,"numberOfRecords":0,"numberOfRecordsProcessed":0,"numberOfRecordsWithErrors":0,"running":false,"startIsoDateTime":"2018-11-27T12:30:40","endIsoDateTime":"2018-11-27T12:30:40","ellapsedTimeInSeconds":0,"totalTimeInSeconds":0,"type":"SimpleMetadataProcessingReport"}

I can't find the record in GeoNetwork by searching for the title I entered in the xml or by loading metadata for the uuid I got back from the API. But I guess it's because I was actually trying to import a slightly modified record of an existing entry in my GN (I only changed the title). I will prepare a new XML from scratch and report back.

Thanks again, Juan!

Regards,
Marko

From: "Juan Luis Rodríguez Ponce" <juanluisrp@anonymised.com>
To: "marko praprotnik" <marko.praprotnik@anonymised.com>
Cc: "Geonetwork-Users@anonymised.com" <geonetwork-users@lists.sourceforge.net>
Sent: Tuesday, November 27, 2018 1:01:45 PM
Subject: Re: [GeoNetwork-users] API: HttpMediaTypeNotAcceptableException

On Tue, Nov 27, 2018 at 12:46 PM Marko Praprotnik < [ mailto:marko.praprotnik@anonymised.com | marko.praprotnik@anonymised.com ] > wrote:

Thanks Juan,

however, I'm still not able to create a record throug API.

If I use "Accept: application/json" header, I get the following exception:
{"message":"MultipartException","code":"unsatisfied_request_parameter","description":"The current request is not a multipart request"}

If I set this header to "Accept: application/xml", I get the same error as with "Accept: */*":
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><apiError><code>runtime_exception</code><description>Could not find acceptable representation</description><message>HttpMediaTypeNotAcceptableException</message></apiError>

I see that you are also using the -H "Authorization: Basic YWRtaW46YWRtaW4=", which I haven't set. If I copy/paste this header literally, nothing changes.

This header is the same that using "--user admin:admin" in curl so it doesn't matter. The problem is that you must send the data as a Multipart Form. Using curl the command would be like

curl -X POST \
' [ http://localhost:8080/geonetwork/srv/api/0.1/records?metadataType=METADATA&uuidProcessing=GENERATEUUID&rejectIfInvalid=false&publishToAll=true&assignToCatalog=false&transformWith=_none_ | http://localhost:8080/geonetwork/srv/api/0.1/records?metadataType=METADATA&uuidProcessing=GENERATEUUID&rejectIfInvalid=false&publishToAll=true&assignToCatalog=false&transformWith=_none_ ] ' \
-H 'Accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'X-XSRF-TOKEN: e4fadc4d-4299-478d-849a-1627e7684c33' \
-H 'content-type: multipart/form-data' \
-b /tmp/cookie \
--user admin:admin \
-F xml=@/path/to/metadata.xml

--
Vriendelijke groeten / Kind regards,

Juan Luis Rodríguez.

[ http://www.geocat.net/ ]
Veenderweg 13
6721 WD Bennekom
The Netherlands
T: [ tel:+31318416664 | +31 (0)318 416664 ]

[ https://www.facebook.com/geocatbv ] [ https://twitter.com/geocat_bv ] [ https://plus.google.com/u/1/+GeocatNetbv/posts ]

Please consider the environment before printing this email.

Hi,

-F xml=@/path/to/metadata.xml
should probably be
-F file=@/path/to/metadata.xml

See http://localhost:8080/geonetwork/doc/api/#/records/insertFile and check
the parameters name

HTH

Francois

Le mar. 27 nov. 2018 à 13:51, Marko Praprotnik <marko.praprotnik@anonymised.com01...> a
écrit :

Ok, thanks for explaining that! And thanks for solving my problem with
HttpMediaTypeNotAcceptableException! :slight_smile:

If I add 2 content-type headers, as you suggest, I get:
{"message":"MultipartException","code":"unsatisfied_request_parameter","description":"The
current request is not a multipart request"}

If I ommit the 'Content-Type: application/x-www-form-urlencoded' header, I
get:
{"message":"MultipartException","code":"unsatisfied_request_parameter","description":"Could
not parse multipart servlet request; nested exception is
org.apache.commons.fileupload.FileUploadException: the request was rejected
because no multipart boundary was found"}

Then, if I add a random boundary to the 'content-type:
multipart/form-data' header, I get no error:
{"errors":,"infos":,"uuid":"6e5b9bfe-9124-4864-98c8-f1c68cfdec80","metadata":,"metadataErrors":{},"metadataInfos":{},"numberOfRecordNotFound":0,"numberOfRecordsNotEditable":0,"numberOfNullRecords":0,"numberOfRecords":0,"numberOfRecordsProcessed":0,"numberOfRecordsWithErrors":0,"running":false,"startIsoDateTime":"2018-11-27T12:30:40","endIsoDateTime":"2018-11-27T12:30:40","ellapsedTimeInSeconds":0,"totalTimeInSeconds":0,"type":"SimpleMetadataProcessingReport"}

I can't find the record in GeoNetwork by searching for the title I entered
in the xml or by loading metadata for the uuid I got back from the API. But
I guess it's because I was actually trying to import a slightly modified
record of an existing entry in my GN (I only changed the title). I will
prepare a new XML from scratch and report back.

Thanks again, Juan!

Regards,
Marko

From: "Juan Luis Rodríguez Ponce" <juanluisrp@anonymised.com>
To: "marko praprotnik" <marko.praprotnik@anonymised.com>
Cc: "Geonetwork-Users@anonymised.com" <
geonetwork-users@lists.sourceforge.net>
Sent: Tuesday, November 27, 2018 1:01:45 PM
Subject: Re: [GeoNetwork-users] API: HttpMediaTypeNotAcceptableException

On Tue, Nov 27, 2018 at 12:46 PM Marko Praprotnik < [ mailto:
marko.praprotnik@anonymised.com | marko.praprotnik@anonymised.com ] > wrote:

Thanks Juan,

however, I'm still not able to create a record throug API.

If I use "Accept: application/json" header, I get the following exception:
{"message":"MultipartException","code":"unsatisfied_request_parameter","description":"The
current request is not a multipart request"}

If I set this header to "Accept: application/xml", I get the same error as
with "Accept: */*":
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><apiError><code>runtime_exception</code><description>Could
not find acceptable
representation</description><message>HttpMediaTypeNotAcceptableException</message></apiError>

I see that you are also using the -H "Authorization: Basic
YWRtaW46YWRtaW4=", which I haven't set. If I copy/paste this header
literally, nothing changes.

This header is the same that using "--user admin:admin" in curl so it
doesn't matter. The problem is that you must send the data as a Multipart
Form. Using curl the command would be like

curl -X POST \
' [
http://localhost:8080/geonetwork/srv/api/0.1/records?metadataType=METADATA&uuidProcessing=GENERATEUUID&rejectIfInvalid=false&publishToAll=true&assignToCatalog=false&transformWith=_none_
|
http://localhost:8080/geonetwork/srv/api/0.1/records?metadataType=METADATA&uuidProcessing=GENERATEUUID&rejectIfInvalid=false&publishToAll=true&assignToCatalog=false&transformWith=_none_
] ' \
-H 'Accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'X-XSRF-TOKEN: e4fadc4d-4299-478d-849a-1627e7684c33' \
-H 'content-type: multipart/form-data' \
-b /tmp/cookie \
--user admin:admin \
-F xml=@/path/to/metadata.xml

--
Vriendelijke groeten / Kind regards,

Juan Luis Rodríguez.

[ http://www.geocat.net/ ]
Veenderweg 13
6721 WD Bennekom
The Netherlands
T: [ tel:+31318416664 | +31 (0)318 416664 ]

[ https://www.facebook.com/geocatbv ] [ https://twitter.com/geocat_bv ] [
https://plus.google.com/u/1/+GeocatNetbv/posts ]

Please consider the environment before printing this email.

_______________________________________________
GeoNetwork-users mailing list
GeoNetwork-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geonetwork-users
GeoNetwork OpenSource is maintained at
http://sourceforge.net/projects/geonetwork