Http входящий шлюз сбой незаконной кодировки
Я пытаюсь написать интеграционный тест для службы, созданной с использованием входящего шлюза Http, и он выдает ошибку "java.nio.charset.UnsupportedCharsetException: cesu-8". Есть идеи почему? Этот сервис работает правильно. У нас есть пакетное приложение, которое использует его несколько раз в день. Я хотел бы иметь интеграционный тест, который также может вызвать его. Вот мой тест:
@Test
public void receiveMessage() throws IOException {
final String xml = testUtil.getTestDocumentAsString("/serviceTestData/document.xml");
final RestTemplate template = new RestTemplate();
template.getMessageConverters()
.add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
final HttpHeaders headers = new HttpHeaders();
MediaType mediaType = new MediaType("text", "xml", StandardCharsets.UTF_8);
headers.setContentType(mediaType);
final String credentials = this.user + ":" + this.pass;
final byte[] message = credentials.getBytes("UTF-8");
headers.add("Authorization", "Basic " + DatatypeConverter.printBase64Binary(message));
final HttpEntity request = new HttpEntity(xml, headers);
final ResponseEntity<Ack> result = template.postForEntity(url, request, Ack.class);
System.out.println(result.getBody().getStatus());
}
Ошибка: первопричина ServletException. java.nio.charset.UnsupportedCharsetException: cesu-8 в java.nio.charset.Charset.forName(Charset.java:536) в org.springframework.http.HttpHeaders.getAcceptCharset(HttpHeaders.jwork.spring.5:96) интеграции toHeaders(DefaultHttpHeaderMapper.java:72) при org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.actualDoHandleRequest(HttpRequestHandlingEndpointSupport.java:459) при org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.doHandleRequest(HttpRequestHandlingEndpointSupport.java:399) в org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway.handleRequest(HttpRequestHandlingMessagingGateway.java:103) в org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51) в org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) в org.springbserv.Serv. Java:901) в org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) в org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872Httplet.htp..service(HttpServlet.java:751) в org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) в javax.servlet.http.HttpServlet.service(HttpServlet.java:8 at at).internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280) по адресу weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254) по адресу weblogic.servub.eljServServiceSecurity на weblogic.servlet.internal.ServletStubImpl. выполнить (ServletStubImpl.java:341) в weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25) в weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) в org.springwera.FilterChainProxy..doFilter(FilterSecurityInterceptor.java:91) в org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) в org.springframework.security.web.access.ilil.ExceptionTranslation) по адресу org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) по адресу org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagement:13f).security.web.FilterChainProxy..doFilter (FilterChainProxy.java:331) по адресу org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) в org.springilha.FhaFFF.FraFF.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:215) в org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) в org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) в org.springframework.security.web.header.HeternalWilter.springframework.web.filter.OncePerRequestFilter..async.WebAsyncManagerIntegrationFilter.: 331) на org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) на org.springframework.security.web.FilterChainProxy $ VirtualFilterChai n.doFilter (FilterChainProxy.java:331) в org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) в org.springframework.security.web.FilterChainProxy.jinFat (orF) (orF).springframework.web.filter.:79) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3388) по адресу weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.runv.inl.conl.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) в weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) в weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.jternalserv. atl): at), WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2238) по адресу weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2154) по адресу weblogic.servlet.pptainerConlet ().ServletRequestImpl.run(ServletRequestImpl.java:1564) в weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254) на weblogicThread.Th.ExecuteThread.run(ExecuteThread.java:264)
1 ответ
Я не знаком с Java или Spring, но:
Ошибка: первопричина ServletException. java.nio.charset.UnsupportedCharsetException: cesu-8
в java.nio.charset.Charset.forName(Charset.java:536)
в org.springframework.http.HttpHeaders.getAcceptCharset (HttpHeaders.java:596)
[...]
в org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
Это говорит о том, что ваш тестовый запрос содержит HTTP-заголовок, такой как Accept-Charset: cesu-8
, который ваш сервер не может интерпретировать.
Похоже, ваш запрос сгенерирован RestTemplate
учебный класс. Проверьте, что он делает с заголовками. Ищи Accept-Charset
(или же AcceptCharset
) а также cesu-8
особенно.