{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • Edge/API Management /
avatar image
0
Question by Beal · Aug 19, 2016 at 09:22 PM · 23.4k Views utf-8

How to fix Unsupported Encoding "UTF-8" error?

Wondering if anyone knows how to fix Unsupported Encoding "UTF-8" error?

{"fault":{"detail":{"errorcode":"protocol.http.UnsupportedEncoding"},"faultstring":"Unsupported Encoding \"UTF-8\""}}

This error can be seen through trace session within API Management, just before the request is sent to the target server. The resource on the REST service is encoding the response as UTF-8. The last policy to be acted upon, before the error is thrown, is an AssignMessage policy type designating the target server url among other headers set.

Comment
Add comment Show 5
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Meghdeep Basu ♦ · Aug 20, 2016 at 02:50 AM 0
Link

Hello @Beal,

Would it be possible for you to share the Policy and the Request Trace session ?

avatar image Paul Williams ♦ · Aug 21, 2016 at 04:41 AM 0
Link

It might seem silly, but the correct encoding name is "utf-8" (lower case). Do you have the option to change the uppercase to lowercase?

avatar image Beal · Aug 22, 2016 at 07:14 PM 0
Link

Sorry BASU, I cannot share the request trace on here. Paul I did try and send the encoding back as lowercase utf-8, but got the same error back, just in lowercase utf-8.

avatar image Anil Sagar @ Google ♦♦ Beal   · Aug 29, 2016 at 05:00 AM 0
Link

@Beal , Can you attach a sample proxy to reproduce above issue ? Any pointers to reproduce above issue will be helpful to find a resolution. Keep us posted.

avatar image Beal Anil Sagar @ Google ♦♦ · Aug 29, 2016 at 07:19 PM 0
Link

Here is a sample policy within my proxy I have been working with:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Set-Target">
    <DisplayName>Set-Target</DisplayName>
    <Properties/>
    <Add>
        <Headers>
            <Header name="Target-URL">someHTTPendpoint/one/value</Header>
            <!--<Header name="Content-Type">charset=UTF-8</Header>-->
        </Headers>
    </Add>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Here is a sample of the JAX-RS service provider resource:

@GET
@Path(value = "one/value")
@Produces("application/json")
@ApiOperation(value = "Returns a value", response = Object.class, responseContainer = "Response")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"),
		@ApiResponse(code = 500, message = "Internal error"), })
public Response getValue() {
	JsonObject value=null;
	try{
		value = Json.createObjectBuilder();
	}
	
	catch (Exception e){
		logger.error("Error" , e);	
		return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error").build();
	}
	return Response.status(200).entity(value.toString()).encoding("UTF-8").lastModified(new Date()).build();
}

Looks like the issue has been .encoding("UTF-8") in the service response. Apigee would not accept an incoming request to my Apigee proxy without Content-Type="charset=UTF-8" being set. The problem with that is the service would return a 400 Bad Request error, if the above Content-Type was sent from the proxy to the service provider. The easiest solution to this problem has been to remove the UTF-8 encoding from the service resource.

Close

1 Answer

  • Sort: 
avatar image
0
Best Answer

Answer by Beal · Aug 29, 2016 at 07:20 PM

Here is a snip of the JAX-RS service provider code:

@GET
@Path(value = "one/value")
@Produces("application/json")
@ApiOperation(value = "Returns a value", response = Object.class, responseContainer = "Response")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"),
		@ApiResponse(code = 500, message = "Internal error"), })
public Response getValue() {
	JsonObject value=null;
	try{
		value = Json.createObjectBuilder();
	}
	catch (Exception e){
		logger.error("Error" , e);	
		return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error").build();
	}
	return Response
            .status(200)
            .entity(value.toString())
            .encoding("UTF-8")
            .lastModified(new Date())
            .build();
}

Solution: Remove UTF-8 encoding from the service provider response.

Comment
Add comment Show 4 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mahana3 · Aug 29, 2017 at 08:19 PM 0
Link

I am facing the exact same issue. Did you find a work around for this. I don't have the luxury to change the provider response. Please share if there is any possible solution.

avatar image MAGESHWARANNATHAN mahana3 · Feb 01, 2019 at 12:35 PM 0
Link

Hi Mahana3,

Did you get it fixed?

avatar image Dino-at-Google ♦♦ mahana3   · Jul 10, 2019 at 05:05 PM 0
Link

Nope, Apigee Edge will throw a fault of the response from the backend is not valid according to the HTTP specification.

avatar image Dino-at-Google ♦♦   · Jul 10, 2019 at 05:12 PM 0
Link

yes, per the reference doc on Response.ResponseBuilder, the .encoding() method sets the Content-Encoding header in the response.

And UTF-8 is not a valid value for that header.

See here

and here.

Follow this Question

Answers Answers and Comments

43 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Chinese Character set 1 Answer

XSL transforming UTF8 responses from Service callout fails special characters for only about 50% of the time 1 Answer

Apigee breaks on Content-Encoding utf 8 What is the right encoding ? Apigee alternative 1 Answer

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges