我試圖讓一個swagger-codgen生成的澤西API庫與https(SSL)一起飛行。適用於MIME媒體類型text/html的閱讀器; charset =未找到UTF-8
這是工作的罰款,只有HTTP這樣的:
public ApiClient rebuildHttpClient() {
// Add the JSON serialization support to Jersey
JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
DefaultClientConfig conf = new DefaultClientConfig();
conf.getSingletons().add(jsonProvider);
Client client = Client.create(conf);
if (debugging) {
client.addFilter(new LoggingFilter());
}
this.httpClient = client;
return this;
}
但後來我試圖建立SSL這樣
public ApiClient rebuildHttpClient() {
// Add the JSON serialization support to Jersey
JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
TrustManager[] byPassTrustManagers = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
public void checkClientTrusted(X509Certificate[] chain, String authType) { }
public void checkServerTrusted(X509Certificate[] chain, String authType) { }
} };
HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
ClientConfig config = new DefaultClientConfig();
SSLContext ctx = null;
try {
ctx = SSLContext.getInstance("SSL");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
try {
ctx.init(null, byPassTrustManagers, null);
} catch (KeyManagementException e) {
e.printStackTrace();
}
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hostnameVerifier, ctx));
config.getSingletons().add(jsonProvider);
Client client = Client.create(config);
if (debugging) {
client.addFilter(new LoggingFilter());
}
this.httpClient = client;
return this;
}
它建立罰款,但執行的時候,我得到這個錯誤
用於Java類java.lang.String和Java類型類java.lang.String和MIME媒體類型text/html的消息體讀取器;未找到charset = UTF-8 08-12 13:43:41.230 12544-12861/com.xxxxxx.app.xxxxx E/ClientResponse:與MIME媒體類型兼容的已註冊郵件正文閱讀器爲: / - > com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider
在我ApiClient執行該方法時(嘗試驗證)
private void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
for (String authName : authNames) {
Authentication auth = authentications.get(authName);
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
auth.applyToParams(queryParams, headerParams);
}
}
當我測試與招搖-UI服務器響應它顯示它是在正確的類型應用程序/ json
它與服務器端有什麼關係要做?因爲它工作好幾天,然後突然出現錯誤,我改變了代碼客戶端。
沒有證書,我已經測試成功對模擬API。 – emmanuel2004