Angular 4.3.4 - HTTP 415 Usupported Media Type on POST

6,179 views
Skip to first unread message

nicolas duminil

unread,
Aug 25, 2017, 8:31:43 AM8/25/17
to Angular and AngularJS discussion
Greetings,

I have a JAX-RS resource which signature is as follows:

  @POST
  @Path("myPath")
  @Produces({MediaType.APPLICATION_OCTET_STREAM})
  @Consumes(MediaType.APPLICATION_JSON)
  public Response myResource(MyObject) throws Exception { ... }

where MyObject is defined as:

@XmlRootElement
public class MyObject
{
  @XmlElement
  private String[] params1;
  @XmlElement
  private String[] params2;
  
  public MyObject() 
  {
  }

  public String[] getParams1()
  {
    return params1;
  }

  public void setParams1(String[] params1)
  {
    this.params1 = params1;
  }

  public String[] getParams2()
  {
    return params2;
  }

  public void setParams2(String[] params2)
  {
    this.params2 = params2;
  }
}


I'm trying to call it as follows:

public myPost (params1: Array<String>, params2: Array<String>): Observable<Response> {
return this.http.post<Response>(this.url, JSON.stringify({params1: params1, params2: params2}));
}

The hole stuff is packaged as an EAR file and deployed on WebLogic 11g. The JAX-RS stack is Apache Jersey 1.9 which comes with the app server. Using another release of Jersey than the one comming with the app server is not an option.

Calling the endpoint as shown above raises HTTP 415 Unsuported Media Type. here is the console log.

    1. Request URL:
    2. Request Method:
      POST
    3. Status Code:
      415 Unsupported Media Type
    4. Remote Address:
      [::1]:7001
    5. Referrer Policy:
      no-referrer-when-downgrade
  1. Response Headersview source
    1. Content-Length:
      0
    2. Date:
      Fri, 25 Aug 2017 12:18:25 GMT
    3. X-Powered-By:
      Servlet/2.5 JSP/2.1
  2. Request Headersview source
    1. Accept:
      application/json, text/plain, */*
    2. Accept-Encoding:
      gzip, deflate, br
    3. Accept-Language:
      fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
    4. Connection:
      keep-alive
    5. Content-Length:
      48
    6. Content-Type:
      text/plain
    7. Cookie:
      ADMINCONSOLESESSION=Y5MpZf5QQnzkcxJg6Yndy2vmvc49VMXzzY2ZJyxnRzfhk19TXZb0!-1658407021
    8. Host:
      localhost:7001
    9. Origin:
    10. Referer:
    11. User-Agent:
      Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36
  3. Request Payloadview source
      1. {params1: ["DynamicBundle"], params2: ["en"]}
Calling the endpoint from an equivalent JAX-RS client works properly. What coud be the problem here ?

Many thanks in advance,
Nicolas 

Lucas Lacroix

unread,
Aug 25, 2017, 8:35:01 AM8/25/17
to Angular and AngularJS discussion

You need to set the content type appropriately. It looks like you're sending JSON but leaving the default content type of "text/plain" which your server does not appear to support.


--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
--
Lucas Lacroix
Computer Scientist
Advanced Technology Division, MEDITECH

nicolas duminil

unread,
Aug 25, 2017, 8:52:47 AM8/25/17
to Angular and AngularJS discussion
I thought that application/json was the default value as I have different other cases where I don't have to specify it explicitly. But yeah, it works, thanks. 
Reply all
Reply to author
Forward
0 new messages