Return-Path: X-Original-To: apmail-struts-issues-archive@minotaur.apache.org Delivered-To: apmail-struts-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D9FEE183E8 for ; Wed, 20 Jan 2016 15:11:40 +0000 (UTC) Received: (qmail 76262 invoked by uid 500); 20 Jan 2016 15:11:40 -0000 Delivered-To: apmail-struts-issues-archive@struts.apache.org Received: (qmail 76210 invoked by uid 500); 20 Jan 2016 15:11:40 -0000 Mailing-List: contact issues-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list issues@struts.apache.org Received: (qmail 75922 invoked by uid 99); 20 Jan 2016 15:11:40 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jan 2016 15:11:40 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id DB7B82C1F55 for ; Wed, 20 Jan 2016 15:11:39 +0000 (UTC) Date: Wed, 20 Jan 2016 15:11:39 +0000 (UTC) From: "ASF subversion and git services (JIRA)" To: issues@struts.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (WW-4588) Improve the Struts2 Rest plugin to honor Accept header MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/WW-4588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15108679#comment-15108679 ] ASF subversion and git services commented on WW-4588: ----------------------------------------------------- Commit 7899f10d800f0c48cb73d02c93500687717c745e in struts's branch refs/heads/master from petersr [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=7899f10 ] WW-4588: Improve the Struts2 Rest plugin to honor Accept header > Improve the Struts2 Rest plugin to honor Accept header > ------------------------------------------------------ > > Key: WW-4588 > URL: https://issues.apache.org/jira/browse/WW-4588 > Project: Struts 2 > Issue Type: Improvement > Components: Plugin - REST > Affects Versions: 2.3.24 > Environment: tomcat > Reporter: Rich Peters > Labels: rest, struts2 > Fix For: 2.3.25, 2.5 > > Attachments: DefaultContentTypeHandlerManager.java > > > Currently the rest plugin primarily looks at the url extension to connect the proper content type handlers. This should be extended to use the Accept and Content-Type headers to drive the content-type handlers when no extension is present. Note that the plugin currently partially handles the case for input request using the content-type header, but can be overridden by the extension. > In a use case, if a request specifies in the header that the Content-Type is application/json, the input request data is converted to the json data format. If a request specifies the Accept:application/json header , the output data will be converted to json. This is cleaner than specifying the extension in a lot of cases where the application rest urls have to be generated in javascript. > a short unit test shows how the accept header is ignored: > {code:java} > public void testObtainingHandlerForResponseByAcceptHeader() throws Exception { > // given > final DefaultContentTypeHandlerManager handlerManager = new DefaultContentTypeHandlerManager(); > handlerManager.setContainer(new DummyContainer("application/json", "json")); > MockHttpServletRequest request = new MockHttpServletRequest(); > request.setContentType("application/json;charset=UTF-8"); > request.addHeader("accept","application/json;charset=UTF-8"); > request.setRequestURI("/index"); > final MockHttpServletResponse response = new MockHttpServletResponse(); > response.setContentType("application/json;charset=UTF-8"); > // when > ContentTypeHandler handler = handlerManager.getHandlerForResponse(request,response); > // then > assertNotNull(handler); > assertEquals("application/json", handler.getContentType()); > assertEquals("json", handler.getExtension()); > } > {code} > the output show the failure to acquire a handler: > {code:java} > junit.framework.AssertionFailedError: null > at junit.framework.Assert.fail(Assert.java:47) > at junit.framework.Assert.assertTrue(Assert.java:20) > at junit.framework.Assert.assertNotNull(Assert.java:214) > at junit.framework.Assert.assertNotNull(Assert.java:207) > at org.apache.struts2.rest.DefaultContentTypeHandlerManagerTest.testObtainingHandlerForResponseByAcceptHeader(DefaultContentTypeHandlerManagerTest.java:104) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:497) > at junit.framework.TestCase.runTest(TestCase.java:168) > at junit.framework.TestCase.runBare(TestCase.java:134) > at junit.framework.TestResult$1.protect(TestResult.java:110) > at junit.framework.TestResult.runProtected(TestResult.java:128) > at junit.framework.TestResult.run(TestResult.java:113) > at junit.framework.TestCase.run(TestCase.java:124) > at junit.framework.TestSuite.runTest(TestSuite.java:243) > at junit.framework.TestSuite.run(TestSuite.java:238) > at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83) > at org.junit.runner.JUnitCore.run(JUnitCore.java:157) > at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) > at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234) > at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74) > {code} > FWIW: Attached is a modified version of the 2.3.24.1 file that implements this -- This message was sent by Atlassian JIRA (v6.3.4#6332)