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 474CE1912B for ; Mon, 11 Apr 2016 06:49:52 +0000 (UTC) Received: (qmail 56528 invoked by uid 500); 11 Apr 2016 06:49:51 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 56461 invoked by uid 500); 11 Apr 2016 06:49:51 -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 56452 invoked by uid 99); 11 Apr 2016 06:49:51 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Apr 2016 06:49:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9A0DEDFC13; Mon, 11 Apr 2016 06:49:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ema@apache.org To: commits@cxf.apache.org Date: Mon, 11 Apr 2016 06:49:52 -0000 Message-Id: <2c5fa9f3642841eeb423c3c1c51fbe6b@git.apache.org> In-Reply-To: <8f80cd3810e54b4ca379988cd4a2d6d4@git.apache.org> References: <8f80cd3810e54b4ca379988cd4a2d6d4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] cxf git commit: [CXF-6861]:Add JAXBProviderTest [CXF-6861]:Add JAXBProviderTest Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e37c00d5 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e37c00d5 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e37c00d5 Branch: refs/heads/master Commit: e37c00d5cc8cf17d6875090654caef6162b363f1 Parents: aed1b1d Author: Jim Ma Authored: Mon Apr 11 14:48:38 2016 +0800 Committer: Jim Ma Committed: Mon Apr 11 14:48:38 2016 +0800 ---------------------------------------------------------------------- .../systest/jaxrs/provider/CXFJaxbProvider.java | 69 +++++++++++++++ .../cxf/systest/jaxrs/provider/CXFResource.java | 33 ++++++++ .../jaxrs/provider/JAXBProviderTest.java | 89 ++++++++++++++++++++ 3 files changed, 191 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/e37c00d5/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFJaxbProvider.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFJaxbProvider.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFJaxbProvider.java new file mode 100644 index 0000000..b4bd527 --- /dev/null +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFJaxbProvider.java @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.systest.jaxrs.provider; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.MessageBodyWriter; +import javax.ws.rs.ext.Provider; +import javax.xml.bind.JAXBElement; + +@Provider +public class CXFJaxbProvider implements MessageBodyReader>, MessageBodyWriter> { + + @Override + public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + return JAXBElement.class.isAssignableFrom(type); + } + + @Override + public long getSize(JAXBElement t, Class type, Type genericType, Annotation[] annotations, + MediaType mediaType) { + return t.getValue().toString().length() + 2; + } + + @Override + public void writeTo(JAXBElement t, Class type, Type genericType, Annotation[] annotations, + MediaType mediaType, MultivaluedMap httpHeaders, + OutputStream entityStream) throws IOException, WebApplicationException { + entityStream.write("WriteInCXFJaxbProvider".getBytes()); + } + + @Override + public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public JAXBElement readFrom(Class> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return null; + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e37c00d5/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFResource.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFResource.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFResource.java new file mode 100644 index 0000000..5f3a7d0 --- /dev/null +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFResource.java @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.systest.jaxrs.provider; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.xml.bind.JAXBElement; + +@Path("resource") +public class CXFResource { + + @Path("jaxb") + @POST + public JAXBElement jaxb(JAXBElement jaxb) { + return jaxb; + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e37c00d5/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/JAXBProviderTest.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/JAXBProviderTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/JAXBProviderTest.java new file mode 100644 index 0000000..a6d6a52 --- /dev/null +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/JAXBProviderTest.java @@ -0,0 +1,89 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.systest.jaxrs.provider; + +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.jaxrs.model.AbstractResourceInfo; +import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; +import org.apache.cxf.testutil.common.AbstractBusTestServerBase; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +public class JAXBProviderTest extends AbstractBusClientServerTestBase { + public static final String PORT = allocatePort(JAXBProviderTest.class); + + @Ignore + public static class Server extends AbstractBusTestServerBase { + protected void run() { + final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); + sf.setResourceClasses(CXFResource.class); + sf.setProvider(new CXFJaxbProvider()); + sf.setAddress("http://localhost:" + PORT + "/"); + sf.create(); + } + + public static void main(String[] args) { + try { + Server s = new Server(); + s.start(); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(-1); + } finally { + System.out.println("done!"); + } + } + } + + @BeforeClass + public static void startServers() throws Exception { + AbstractResourceInfo.clearAllMaps(); + // keep out of process due to stack traces testing failures + assertTrue("server did not launch correctly", launchServer(Server.class, true)); + createStaticBus(); + } + + @Test + public void testNoResultsAreReturned() throws Exception { + WebClient client = WebClient.create("http://localhost:" + PORT + "/resource/jaxb"); + WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(3000000); + + List values = new ArrayList(); + values.add(MediaType.APPLICATION_XML); + client.getHeaders().put("content-type", values); + JAXBElement test = new JAXBElement(new QName("org.apache.cxf", "jaxbelement"), + String.class, "test"); + Response response = client.post(test); + String result = response.readEntity(String.class); + Assert.assertTrue(result.contains("test")); + Assert.assertFalse(result.contains("WriteInCXFJaxbProvider")); + } +}