Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C20DC9B11 for ; Fri, 2 Dec 2011 17:15:18 +0000 (UTC) Received: (qmail 58943 invoked by uid 500); 2 Dec 2011 17:15:18 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 58826 invoked by uid 500); 2 Dec 2011 17:15:18 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 58817 invoked by uid 99); 2 Dec 2011 17:15:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Dec 2011 17:15:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Dec 2011 17:15:17 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C051B2388A36 for ; Fri, 2 Dec 2011 17:14:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1209591 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ Date: Fri, 02 Dec 2011 17:14:55 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111202171455.C051B2388A36@eris.apache.org> Author: sergeyb Date: Fri Dec 2 17:14:55 2011 New Revision: 1209591 URL: http://svn.apache.org/viewvc?rev=1209591&view=rev Log: Merged revisions 1209588 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1209588 | sergeyb | 2011-12-02 17:08:58 +0000 (Fri, 02 Dec 2011) | 1 line [CXF-3950] Adding XMLInstruction annotation - no substitution is supported at the moment ........ Added: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLInstruction.java - copied unchanged from r1209588, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLInstruction.java Modified: cxf/branches/2.4.x-fixes/ (props changed) cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ svn:mergeinfo = /cxf/trunk:1209588 Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1209591&r1=1209590&r2=1209591&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java (original) +++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java Fri Dec 2 17:14:55 2011 @@ -56,7 +56,9 @@ import javax.xml.transform.Source; import org.apache.cxf.helpers.CastUtils; import org.apache.cxf.jaxb.NamespaceMapper; import org.apache.cxf.jaxrs.ext.MessageContext; +import org.apache.cxf.jaxrs.ext.xml.XMLInstruction; import org.apache.cxf.jaxrs.ext.xml.XMLSource; +import org.apache.cxf.jaxrs.utils.AnnotationUtils; import org.apache.cxf.jaxrs.utils.HttpUtils; import org.apache.cxf.jaxrs.utils.InjectionUtils; import org.apache.cxf.jaxrs.utils.JAXBUtils; @@ -71,6 +73,7 @@ import org.apache.cxf.staxutils.transfor @Provider public class JAXBElementProvider extends AbstractJAXBProvider { private static final String XML_PI_START = " MARSHALLER_PROPERTIES = Arrays.asList(new String[] {Marshaller.JAXB_ENCODING, Marshaller.JAXB_FORMATTED_OUTPUT, @@ -234,7 +237,7 @@ public class JAXBElementProvider extends Object actualObject = checkAdapter(obj, cls, anns, true); Class actualClass = obj != actualObject || cls.isInterface() ? actualObject.getClass() : cls; - marshal(actualObject, actualClass, genericType, encoding, os, m); + marshal(actualObject, actualClass, genericType, encoding, os, m, anns); } } catch (JAXBException e) { handleJAXBException(e); @@ -344,6 +347,12 @@ public class JAXBElementProvider extends protected void marshal(Object obj, Class cls, Type genericType, String enc, OutputStream os, MediaType mt) throws Exception { + marshal(obj, cls, genericType, enc, os, mt, new Annotation[]{}); + } + + protected void marshal(Object obj, Class cls, Type genericType, + String enc, OutputStream os, MediaType mt, + Annotation[] anns) throws Exception { obj = convertToJaxbElementIfNeeded(obj, cls, genericType); if (obj instanceof JAXBElement && cls != JAXBElement.class) { cls = JAXBElement.class; @@ -354,9 +363,24 @@ public class JAXBElementProvider extends setNamespaceMapper(ms, nsPrefixes); } addAttachmentMarshaller(ms); + addProcessingInstructions(ms, anns); marshal(obj, cls, genericType, enc, os, mt, ms); } + private void addProcessingInstructions(Marshaller ms, Annotation[] anns) throws Exception { + XMLInstruction pi = AnnotationUtils.getAnnotation(anns, XMLInstruction.class); + if (pi != null) { + String value = pi.value(); + // Should we even consider adding a base URI here ? + // Relative references may be resolved OK, to be verified + try { + ms.setProperty("com.sun.xml.bind.xmlHeaders", value); + } catch (PropertyException ex) { + ms.setProperty("com.sun.xml.internal.bind.xmlHeaders", value); + } + } + } + protected void addAttachmentMarshaller(Marshaller ms) { Collection attachments = getAttachments(true); if (attachments != null) { Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1209591&r1=1209590&r2=1209591&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original) +++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Fri Dec 2 17:14:55 2011 @@ -78,6 +78,7 @@ import org.apache.cxf.helpers.XMLUtils; import org.apache.cxf.jaxrs.ext.Oneway; import org.apache.cxf.jaxrs.ext.search.SearchCondition; import org.apache.cxf.jaxrs.ext.search.SearchContext; +import org.apache.cxf.jaxrs.ext.xml.XMLInstruction; import org.apache.cxf.phase.PhaseInterceptorChain; @Path("/bookstore") @@ -208,6 +209,7 @@ public class BookStore { @GET @Path("name-in-query") @Produces("application/xml") + @XMLInstruction("") public Book getBookFromQuery(@QueryParam("name") String name) { return new Book(name, 321L); } Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1209591&r1=1209590&r2=1209591&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original) +++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Fri Dec 2 17:14:55 2011 @@ -134,6 +134,19 @@ public class JAXRSClientServerBookTest e } @Test + public void testProcessingInstruction() throws Exception { + + String endpointAddress = + "http://localhost:" + PORT + "/bookstore/name-in-query"; + WebClient wc = WebClient.create(endpointAddress); + String name = "Many spaces"; + wc.query("name", name); + String content = wc.get(String.class); + assertTrue(content.contains("")); + assertTrue(content.contains("")); + } + + @Test public void testGetBookWithColonMarks() throws Exception { // URLEncoder will turn ":" into "%3A" but ':' is actually