Repository: incubator-juneau Updated Branches: refs/heads/master 95d94d01a -> e4dfdf81f
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core/src/test/java/org/apache/juneau/xml/xml1b/T6.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/test/java/org/apache/juneau/xml/xml1b/T6.java b/juneau-core/src/test/java/org/apache/juneau/xml/xml1b/T6.java deleted file mode 100755 index c34126c..0000000 --- a/juneau-core/src/test/java/org/apache/juneau/xml/xml1b/T6.java +++ /dev/null @@ -1,38 +0,0 @@ -// *************************************************************************************************************************** -// * 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.juneau.xml.xml1b; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.xml.annotation.*; - -@Xml(prefix="foo",namespace="http://foo") -@Bean(sort=true) -@SuppressWarnings("javadoc") -public class T6 { - - public int f1 = 1; - - @Xml(prefix="bar",namespace="http://bar") public int f2 = 2; - - private int f3 = 3; - public int getF3() { return f3; } - public void setF3(int f3) { this.f3 = f3; } - - private int f4 = 4; - @Xml(prefix="baz",namespace="http://baz") public int getF4() { return f4; } - public void setF4(int f4) { this.f4 = f4; } - - public boolean equals(T6 x) { - return x.f1 == f1 && x.f2 == f2 && x.f3 == f3 && x.f4 == f4; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core/src/test/java/org/apache/juneau/xml/xml1b/T7.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/test/java/org/apache/juneau/xml/xml1b/T7.java b/juneau-core/src/test/java/org/apache/juneau/xml/xml1b/T7.java deleted file mode 100755 index f2960aa..0000000 --- a/juneau-core/src/test/java/org/apache/juneau/xml/xml1b/T7.java +++ /dev/null @@ -1,37 +0,0 @@ -// *************************************************************************************************************************** -// * 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.juneau.xml.xml1b; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.xml.annotation.*; - -@Bean(sort=true) -@SuppressWarnings("javadoc") -public class T7 { - - @BeanProperty(name="g1") public int f1 = 1; - - @Xml(prefix="bar",namespace="http://bar") @BeanProperty(name="g2") public int f2 = 2; - - private int f3 = 3; - @BeanProperty(name="g3") public int getF3() { return f3; } - @BeanProperty(name="g3") public void setF3(int f3) { this.f3 = f3; } - - private int f4 = 4; - @BeanProperty(name="g4") @Xml(prefix="baz",namespace="http://baz") public int getF4() { return f4; } - @BeanProperty(name="g4") public void setF4(int f4) { this.f4 = f4; } - - public boolean equals(T7 x) { - return x.f1 == f1 && x.f2 == f2 && x.f3 == f3 && x.f4 == f4; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core/src/test/java/org/apache/juneau/xml/xml1b/package-info.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/test/java/org/apache/juneau/xml/xml1b/package-info.java b/juneau-core/src/test/java/org/apache/juneau/xml/xml1b/package-info.java deleted file mode 100755 index 306db1b..0000000 --- a/juneau-core/src/test/java/org/apache/juneau/xml/xml1b/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -// *************************************************************************************************************************** -// * 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. * -// *************************************************************************************************************************** -@XmlSchema(prefix="p1",namespace="http://p1") -package org.apache.juneau.xml.xml1b; -import org.apache.juneau.xml.annotation.*; - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core/src/test/java/org/apache/juneau/xml/xml1c/T8.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/test/java/org/apache/juneau/xml/xml1c/T8.java b/juneau-core/src/test/java/org/apache/juneau/xml/xml1c/T8.java deleted file mode 100755 index 0c383eb..0000000 --- a/juneau-core/src/test/java/org/apache/juneau/xml/xml1c/T8.java +++ /dev/null @@ -1,33 +0,0 @@ -// *************************************************************************************************************************** -// * 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.juneau.xml.xml1c; - -import org.apache.juneau.xml.annotation.*; - -@Xml(prefix="p2") -@SuppressWarnings("javadoc") -public class T8 { - - public int f1 = 1; - - @Xml(prefix="p1") public int f2 = 2; - - @Xml(prefix="c1") public int f3 = 3; - - @Xml(prefix="f1") - public int f4 = 4; - - public boolean equals(T8 x) { - return x.f1 == f1 && x.f2 == f2 && x.f3 == f3 && x.f4 == f4; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core/src/test/java/org/apache/juneau/xml/xml1c/T9.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/test/java/org/apache/juneau/xml/xml1c/T9.java b/juneau-core/src/test/java/org/apache/juneau/xml/xml1c/T9.java deleted file mode 100755 index 7009626..0000000 --- a/juneau-core/src/test/java/org/apache/juneau/xml/xml1c/T9.java +++ /dev/null @@ -1,23 +0,0 @@ -// *************************************************************************************************************************** -// * 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.juneau.xml.xml1c; - -@SuppressWarnings("javadoc") -public class T9 { - - public int f1 = 1; - - public boolean equals(T9 x) { - return x.f1 == f1; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core/src/test/java/org/apache/juneau/xml/xml1c/package-info.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/test/java/org/apache/juneau/xml/xml1c/package-info.java b/juneau-core/src/test/java/org/apache/juneau/xml/xml1c/package-info.java deleted file mode 100755 index e054388..0000000 --- a/juneau-core/src/test/java/org/apache/juneau/xml/xml1c/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -// *************************************************************************************************************************** -// * 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. * -// *************************************************************************************************************************** -@XmlSchema( - prefix="p1", - xmlNs={ - @XmlNs(prefix="p1",namespaceURI="http://p1"), - @XmlNs(prefix="p2",namespaceURI="http://p2"), - @XmlNs(prefix="p3",namespaceURI="http://p3(unused)"), - @XmlNs(prefix="c1",namespaceURI="http://c1"), - @XmlNs(prefix="f1",namespaceURI="http://f1") - } -) -package org.apache.juneau.xml.xml1c; -import org.apache.juneau.xml.annotation.*; - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-rest-client/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-rest-client/pom.xml b/juneau-rest-client/pom.xml index 1fcf4cb..e035942 100644 --- a/juneau-rest-client/pom.xml +++ b/juneau-rest-client/pom.xml @@ -17,7 +17,7 @@ <modelVersion>4.0.0</modelVersion> <artifactId>juneau-rest-client</artifactId> - <name>Apache Juneau Client</name> + <name>Apache Juneau REST Client API</name> <description>REST client API</description> <packaging>bundle</packaging> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-rest-jaxrs/.gitignore ---------------------------------------------------------------------- diff --git a/juneau-rest-jaxrs/.gitignore b/juneau-rest-jaxrs/.gitignore new file mode 100644 index 0000000..c7e3b12 --- /dev/null +++ b/juneau-rest-jaxrs/.gitignore @@ -0,0 +1,4 @@ +/target/ +/.settings/ +/.classpath +/bin/ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-rest-jaxrs/.project ---------------------------------------------------------------------- diff --git a/juneau-rest-jaxrs/.project b/juneau-rest-jaxrs/.project new file mode 100644 index 0000000..b6551cc --- /dev/null +++ b/juneau-rest-jaxrs/.project @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + *************************************************************************************************************************** + * 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. * + *************************************************************************************************************************** +--> +<projectDescription> + <name>juneau-rest</name> + <comment>REST servlet API. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment> + <projects> + <project>juneau-core</project> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-rest-jaxrs/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-rest-jaxrs/pom.xml b/juneau-rest-jaxrs/pom.xml new file mode 100644 index 0000000..0f4115b --- /dev/null +++ b/juneau-rest-jaxrs/pom.xml @@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + *************************************************************************************************************************** + * 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. * + *************************************************************************************************************************** +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <artifactId>juneau-rest-jaxrs</artifactId> + <name>Apache Juneau REST JAX/RS API</name> + <description>REST servlet API</description> + <packaging>bundle</packaging> + + <parent> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau</artifactId> + <version>6.0.2-incubating-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <dependencies> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-core-rdf</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-rest</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>javax.ws.rs</groupId> + <artifactId>jsr311-api</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </dependency> + </dependencies> + + <properties> + <!-- Skip javadoc generation since we generate them in the aggregate pom --> + <maven.javadoc.skip>true</maven.javadoc.skip> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <version>3.0.1</version> + <executions> + <execution> + <id>attach-sources</id> + <phase>verify</phase> + <goals> + <goal>jar-no-fork</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>3.2.0</version> + <extensions>true</extensions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.19.1</version> + <configuration> + <includes> + <include>**/*Test.class</include> + </includes> + </configuration> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/BaseProvider.java ---------------------------------------------------------------------- diff --git a/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/BaseProvider.java b/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/BaseProvider.java new file mode 100644 index 0000000..2381736 --- /dev/null +++ b/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/BaseProvider.java @@ -0,0 +1,189 @@ +// *************************************************************************************************************************** +// * 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.juneau.rest.jaxrs; + +import static javax.servlet.http.HttpServletResponse.*; + +import java.io.*; +import java.lang.annotation.*; +import java.lang.reflect.*; +import java.util.*; + +import javax.ws.rs.*; +import javax.ws.rs.core.*; +import javax.ws.rs.ext.*; + +import org.apache.juneau.*; +import org.apache.juneau.internal.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.serializer.*; + +/** + * Base class for defining JAX-RS providers based on Juneau serializers and parsers. + */ +public class BaseProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object> { + + private SerializerGroup serializers = new SerializerGroup(); + private ParserGroup parsers = new ParserGroup(); + private ObjectMap properties = new ObjectMap(); + + /** + * Constructor. + */ + protected BaseProvider() { + try { + properties = new ObjectMap(); + JuneauProvider jp = getClass().getAnnotation(JuneauProvider.class); + serializers.append(jp.serializers()); + parsers.append(jp.parsers()); + for (Property p : jp.properties()) + properties.put(p.name(), p.value()); + serializers.addBeanFilters(jp.beanFilters()); + parsers.addBeanFilters(jp.beanFilters()); + serializers.addPojoSwaps(jp.pojoSwaps()); + parsers.addPojoSwaps(jp.pojoSwaps()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * Returns properties defined on the specified method through the {@link RestMethod#properties()} + * annotation specified on the method and the {@link JuneauProvider#properties()} annotation + * specified on the provider class. + * + * @param a All annotations defined on the method. + * @return A map of all properties define on the method. + */ + protected ObjectMap getMethodProperties(Annotation[] a) { + ObjectMap m = new ObjectMap().setInner(properties); + for (Annotation aa : a) { + if (aa instanceof RestMethod) { + for (Property p : ((RestMethod)aa).properties()) + m.put(p.name(), p.value()); + } + } + return m; + } + + @Override /* MessageBodyWriter */ + public long getSize(Object o, Class<?> type, Type gType, Annotation[] a, MediaType mediaType) { + return -1; + } + + @Override /* MessageBodyWriter */ + public boolean isWriteable(Class<?> type, Type gType, Annotation[] a, MediaType mediaType) { + return serializers.findMatch(mediaType.toString()) != null; + } + + @Override /* MessageBodyWriter */ + public void writeTo(Object o, Class<?> type, Type gType, Annotation[] a, MediaType mediaType, + MultivaluedMap<String,Object> headers, OutputStream out) throws IOException, WebApplicationException { + try { + String mt = serializers.findMatch(mediaType.toString()); + if (mt == null) + throw new WebApplicationException(SC_NOT_ACCEPTABLE); + Serializer s = serializers.getSerializer(mt); + ObjectMap mp = getMethodProperties(a); + mp.append("mediaType", mediaType.toString()); + Locale locale = getLocale(headers); + TimeZone timeZone = getTimeZone(headers); + if (s.isWriterSerializer()) { + WriterSerializer s2 = (WriterSerializer)s; + OutputStreamWriter w = new OutputStreamWriter(out, IOUtils.UTF8); + SerializerSession session = s.createSession(w, mp, null, locale, timeZone); + s2.serialize(session, o); + w.flush(); + w.close(); + } else { + OutputStreamSerializer s2 = (OutputStreamSerializer)s; + SerializerSession session = s.createSession(s2, mp, null, locale, timeZone); + s2.serialize(session, o); + out.flush(); + out.close(); + } + } catch (SerializeException e) { + throw new IOException(e); + } + } + + @Override /* MessageBodyReader */ + public boolean isReadable(Class<?> type, Type gType, Annotation[] a, MediaType mediaType) { + return parsers.findMatch(mediaType.toString()) != null; + } + + @Override /* MessageBodyReader */ + public Object readFrom(Class<Object> type, Type gType, Annotation[] a, MediaType mediaType, + MultivaluedMap<String,String> headers, InputStream in) throws IOException, WebApplicationException { + try { + String mt = parsers.findMatch(mediaType.toString()); + if (mt == null) + throw new WebApplicationException(SC_UNSUPPORTED_MEDIA_TYPE); + Parser p = parsers.getParser(mt); + BeanContext bc = p.getBeanContext(); + ClassMeta<?> cm = bc.getClassMeta(gType); + ObjectMap mp = getMethodProperties(a); + mp.put("mediaType", mediaType.toString()); + Locale locale = getLocale(headers); + TimeZone timeZone = getTimeZone(headers); + if (p.isReaderParser()) { + ReaderParser p2 = (ReaderParser)p; + InputStreamReader r = new InputStreamReader(in, IOUtils.UTF8); + ParserSession session = p2.createSession(r, mp, null, null, locale, timeZone); + return p2.parse(session, cm); + } + InputStreamParser p2 = (InputStreamParser)p; + ParserSession session = p2.createSession(in, mp, null, null, locale, timeZone); + return p2.parse(session, cm); + } catch (ParseException e) { + throw new IOException(e); + } + } + + @SuppressWarnings("rawtypes") + private static Locale getLocale(MultivaluedMap headers) { + if (headers.containsKey("Accept-Language") && headers.get("Accept-Language") != null) { + String h = String.valueOf(headers.get("Accept-Language")); + if (h != null) { + MediaRange[] mr = MediaRange.parse(h); + if (mr.length > 0) + return toLocale(mr[0].getType()); + } + } + return null; + } + + /* + * Converts an Accept-Language value entry to a Locale. + */ + private static Locale toLocale(String lang) { + String country = ""; + int i = lang.indexOf('-'); + if (i > -1) { + country = lang.substring(i+1).trim(); + lang = lang.substring(0,i).trim(); + } + return new Locale(lang, country); + } + + @SuppressWarnings("rawtypes") + private static TimeZone getTimeZone(MultivaluedMap headers) { + if (headers.containsKey("Time-Zone") && headers.get("Time-Zone") != null) { + String h = String.valueOf(headers.get("Time-Zone")); + return TimeZone.getTimeZone(h); + } + return null; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/DefaultProvider.java ---------------------------------------------------------------------- diff --git a/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/DefaultProvider.java b/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/DefaultProvider.java new file mode 100644 index 0000000..92cc4a1 --- /dev/null +++ b/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/DefaultProvider.java @@ -0,0 +1,71 @@ +// *************************************************************************************************************************** +// * 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.juneau.rest.jaxrs; + +import javax.ws.rs.*; +import javax.ws.rs.ext.*; + +import org.apache.juneau.html.*; +import org.apache.juneau.jso.*; +import org.apache.juneau.json.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.soap.*; +import org.apache.juneau.urlencoding.*; +import org.apache.juneau.xml.*; + +/** + * JAX-RS provider for the same serialize/parse support provided by the {@link RestServletDefault} class. + */ +@Provider +@Produces({ + "application/json", "text/json", // JsonSerializer + "application/json+simple", "text/json+simple", // JsonSerializer.Simple + "application/json+schema", // JsonSchemaSerializer + "text/xml", // XmlDocSerializer + "text/xml+simple", // XmlDocSerializer.Simple + "text/xml+schema", // XmlSchemaDocSerializer + "text/html", // HtmlDocSerializer + "application/x-www-form-urlencoded", // UrlEncodingSerializer + "text/xml+soap", // SoapXmlSerializer + "application/x-java-serialized-object" // JavaSerializedObjectSerializer +}) +@Consumes({ + "application/json", "text/json", // JsonParser + "text/xml", // XmlParser + "text/html", // HtmlParser + "application/x-www-form-urlencoded", // UrlEncodingParser + "application/x-java-serialized-object" // JavaSerializedObjectParser +}) +@JuneauProvider( + serializers={ + JsonSerializer.class, + JsonSerializer.Simple.class, + JsonSchemaSerializer.class, + XmlDocSerializer.class, + XmlDocSerializer.Simple.class, + XmlSchemaDocSerializer.class, + HtmlDocSerializer.class, + UrlEncodingSerializer.class, + SoapXmlSerializer.class, + JavaSerializedObjectSerializer.class + }, + parsers={ + JsonParser.class, + XmlParser.class, + HtmlParser.class, + UrlEncodingParser.class, + JavaSerializedObjectParser.class + } +) +public final class DefaultProvider extends BaseProvider {} + http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/JuneauProvider.java ---------------------------------------------------------------------- diff --git a/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/JuneauProvider.java b/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/JuneauProvider.java new file mode 100644 index 0000000..b0e54c0 --- /dev/null +++ b/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/JuneauProvider.java @@ -0,0 +1,96 @@ +// *************************************************************************************************************************** +// * 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.juneau.rest.jaxrs; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +import java.lang.annotation.*; + +import org.apache.juneau.*; +import org.apache.juneau.json.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.serializer.*; +import org.apache.juneau.transform.*; +import org.apache.juneau.xml.*; + +/** + * Annotations applicable to subclasses of {@link BaseProvider}. + * + * <h6 class='topic'>Description</h6> + * <p> + * Used to associate serializers, parsers, filters, and properties with instances of {@link BaseProvider}. + */ +@Documented +@Target(TYPE) +@Retention(RUNTIME) +@Inherited +public @interface JuneauProvider { + + /** + * Provider-level bean filters. + * <p> + * These filters are applied to all serializers and parsers being used by the provider. + * <p> + * If the specified class is an instance of {@link BeanFilterBuilder}, then a filter built from that builder is added. + * Any other classes are wrapped in a {@link InterfaceBeanFilterBuilder} to indicate that subclasses should + * be treated as the specified class type. + */ + Class<?>[] beanFilters() default {}; + + /** + * Provider-level POJO swaps. + * <p> + * These POJO swaps are applied to all serializers and parsers being used by the provider. + * <p> + * If the specified class is an instance of {@link PojoSwap}, then that swap is added. + * Any other classes are wrapped in a {@link SurrogateSwap}. + */ + Class<?>[] pojoSwaps() default {}; + + /** + * Provider-level properties. + * <p> + * Any of the following property names can be specified: + * <ul> + * <li>{@link RestServletContext} + * <li>{@link BeanContext} + * <li>{@link SerializerContext} + * <li>{@link ParserContext} + * <li>{@link JsonSerializerContext} + * <li>{@link XmlSerializerContext} + * <li>{@link XmlParserContext} + * </ul> + * <p> + * Property values will be converted to the appropriate type. + * <p> + * These properties can be augmented/overridden through the {@link RestMethod#properties()} annotation on the REST method. + */ + Property[] properties() default {}; + + /** + * Specifies a list of {@link Serializer} classes to add to the list of serializers available for this provider. + * <p> + * This annotation can only be used on {@link Serializer} classes that have no-arg constructors. + */ + Class<? extends Serializer>[] serializers() default {}; + + /** + * Specifies a list of {@link Parser} classes to add to the list of parsers available for this provider. + * <p> + * This annotation can only be used on {@link Parser} classes that have no-arg constructors. + */ + Class<? extends Parser>[] parsers() default {}; +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/package.html ---------------------------------------------------------------------- diff --git a/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/package.html b/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/package.html new file mode 100644 index 0000000..e877328 --- /dev/null +++ b/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/package.html @@ -0,0 +1,360 @@ +<!DOCTYPE HTML> +<!-- +/*************************************************************************************************************************** + * 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. + * + ***************************************************************************************************************************/ + --> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <style type="text/css"> + /* For viewing in Page Designer */ + @IMPORT url("../../../../../javadoc.css"); + + /* For viewing in REST interface */ + @IMPORT url("../htdocs/javadoc.css"); + body { + margin: 20px; + } + </style> + <script> + /* Replace all @code and @link tags. */ + window.onload = function() { + document.body.innerHTML = document.body.innerHTML.replace(/\{\@code ([^\}]+)\}/g, '<code>$1</code>'); + document.body.innerHTML = document.body.innerHTML.replace(/\{\@link (([^\}]+)\.)?([^\.\}]+)\}/g, '<code>$3</code>'); + } + </script> +</head> +<body> +<p>JAX-RS / Wink integration components</p> + +<script> + function toggle(x) { + var div = x.nextSibling; + while (div != null && div.nodeType != 1) + div = div.nextSibling; + if (div != null) { + var d = div.style.display; + if (d == 'block' || d == '') { + div.style.display = 'none'; + x.className += " closed"; + } else { + div.style.display = 'block'; + x.className = x.className.replace(/(?:^|\s)closed(?!\S)/g , '' ); + } + } + } +</script> + +<p> + Defines an API and default provides for using Juneau serializers and parsers as JAX-RS providers. +</p> + +<a id='TOC'></a><h5 class='toc'>Table of Contents</h5> +<ol class='toc'> + <li><p><a class='doclink' href='#BaseProvider'>Juneau JAX-RS Provider</a></p> +</ol> + +<!-- ======================================================================================================== --> +<a id="BaseProvider"></a> +<h2 class='topic' onclick='toggle(this)'>1 - Juneau JAX-RS Provider</h2> +<div class='topic'> + <p> + The Juneau framework contains the <code>org.apache.juneau.rest.jaxrs</code> package for performing simple + integration of Juneau serializers and parsers in JAX-RS compliant environments. + </p> + <p> + It should be noted that although some of the functionality of the Juneau Server API is provided through the JAX-RS + integration components, it is not nearly as flexible as using the {@link org.apache.juneau.rest.RestServlet} class directly. + </p> + <p> + What you can do with the Juneau JAX-RS provider classes: + </p> + <ul class='spaced-list'> + <li>Use existing Juneau serializers and parsers for converting streams to POJOs and vis-versa. + <li>Use annotations to specify filters and properties using the {@link org.apache.juneau.rest.annotation.RestMethod} + and {@link org.apache.juneau.rest.jaxrs.JuneauProvider} annotations. + </ul> + <p> + What you can't do with the Juneau JAX-RS provider classes: + </p> + <ul class='spaced-list'> + <li>Specify or override serializers/parsers at the Java class and method levels. + <br>JAX-RS does not provide the capability to use different providers for the same media types + at the class or method levels. + <li>Specify or override filters and properties at the Java class level. + <li>Default stylesheets for the {@link org.apache.juneau.html.HtmlDocSerializer} class. + <br>It will produce HTML, but it won't contain any styles applied. + <br>However, it's possible to specify your own stylesheet using the {@link org.apache.juneau.html.HtmlDocSerializerContext#HTMLDOC_cssUrl} property. + <li>The ability to specify HTTP method, headers, and content using GET parameters. + <br>These make debugging REST interfaces using only a browser possible. + <li>Class or method level encoding. + <li>Class or method level guards. + <li>Class or method level converters. + </ul> + + <h6 class='topic'>Juneau JAX-RS Provider API</h6> + <p> + The Juneau JAX-RS provider API consists of the following classes: + </p> + <ul class='spaced-list'> + <li>{@link org.apache.juneau.rest.jaxrs.BaseProvider} - The base provider class that implements the JAX-RS + <code>MessageBodyReader</code> and <code>MessageBodyWriter</code> interfaces. + <li>{@link org.apache.juneau.rest.jaxrs.JuneauProvider} - Annotation that is applied to subclasses of <code>BaseProvider</code> + to specify the serializers/parsers associated with a provider, and optionally filters and properties to + apply to those serializers and parsers. + <li>{@link org.apache.juneau.rest.jaxrs.DefaultProvider} - A default provider that provides the same level + of media type support as the {@link org.apache.juneau.rest.RestServletDefault} class. + </ul> + <p> + For the most part, when using these components, you'll either use the existing <code>DefaultProvider</code> or + <code>JuneauProvider</code> providers, or define your own by subclassing <code>BaseProvider</code>. + + <h6 class='topic'>Example:</h6> + <p> + The <code>juneau_sample.war</code> project contains a sample <code>HelloWorldResource</code> class that + shows how to use the JAX-RS provider. It uses Wink as the JAX-RS implementation. + </p> + <p> + Wink is configured by registering the following servlet in the <code>web.xml</code> file of the web app: + </p> + <p class='bcode'> + <xt><?xml</xt> <xa>version</xa>=<xs>"1.0"</xs> <xa>encoding</xa>=<xs>"UTF-8"</xs><xt>?></xt> + <xt><web-app</xt> <xa>version</xa>=<xs>"2.3"</xs><xt>></xt> + <xt><servlet></xt> + <xt><servlet-name></xt>WinkService<xt></servlet-name></xt> + <xt><servlet-class></xt>org.apache.wink.server.internal.servlet.RestServlet<xt></servlet-class></xt> + <xt><init-param></xt> + <xt><param-name></xt>applicationConfigLocation<xt></param-name></xt> + <xt><param-value></xt>/WEB-INF/wink.cfg<xt></param-value></xt> + <xt></init-param></xt> + <xt></servlet></xt> + <xt><servlet-mapping></xt> + <xt><servlet-name></xt>WinkService<xt></servlet-name></xt> + <xt><url-pattern></xt>/wink/*<xt></url-pattern></xt> + <xt></servlet-mapping></xt> + <xt></web-app></xt> + </p> + <p> + The <code>wink.cfg</code> file lists our default provider and our sample resource: + </p> + <p class='bcode'> + org.apache.juneau.rest.jaxrs.DefaultProvider + com.foo.sample.jaxrs.HelloWorldResource + </p> + <p> + Interestingly, the <code>DefaultProvider</code> itself is a subclass of <code>BaseProvider</code> + with no code at all. It consists of annotations only: + </p> + <p class='bcode'> + <ja>@Provider</ja> + <ja>@Produces</ja>( + <js>"application/json,text/json,"</js>+ <jc>// JsonSerializer</jc> + <js>"application/json+schema,text/json+schema,"</js>+ <jc>// JsonSchemaSerializer</jc> + <js>"text/xml,"</js>+ <jc>// XmlDocSerializer</jc> + <js>"text/xml+schema,"</js>+ <jc>// XmlDocSerializer</jc> + <js>"text/html,"</js>+ <jc>// HtmlDocSerializer</jc> + <js>"application/x-www-form-urlencoded,"</js>+ <jc>// UrlEncodingSerializer</jc> + <js>"text/xml+soap,"</js>+ <jc>// SoapXmlSerializer</jc> + <js>"text/xml+rdf,"</js>+ <jc>// RdfXmlDocSerializer</jc> + <js>"application/x-java-serialized-object"</js> <jc>// JavaSerializedObjectSerializer</jc> + ) + <ja>@Consumes</ja>( + <js>"application/json,text/json,"</js>+ <jc>// JsonParser</jc> + <js>"text/xml,"</js>+ <jc>// XmlParser</jc> + <js>"text/html,"</js>+ <jc>// HtmlParser</jc> + <js>"application/x-www-form-urlencoded"</js> <jc>// UrlEncodingParser</jc> + ) + <ja>@JuneauProvider</ja>( + serializers={ + JsonSerializer.<jk>class</jk>, + JsonSchemaSerializer.<jk>class</jk>, + XmlDocSerializer.<jk>class</jk>, + XmlSchemaDocSerializer.<jk>class</jk>, + HtmlDocSerializer.<jk>class</jk>, + UrlEncodingSerializer.<jk>class</jk>, + SoapXmlSerializer.<jk>class</jk>, + RdfXmlDocSerializer.<jk>class</jk>, + JavaSerializedObjectSerializer.<jk>class</jk> + }, + parsers={ + JsonParser.<jk>class</jk>, + XmlParser.<jk>class</jk>, + HtmlParser.<jk>class</jk>, + UrlEncodingParser.<jk>class</jk> + } + ) + <jk>public final class</jk> DefaultProvider <jk>extends</jk> BaseProvider {} + </p> + <p> + Similarly, if you're defining your own JAX-RS provider, you can do so using annotations only. + </p> + <p> + <p> + Our sample resource is shown below. + In this example, we've specified a <code><ja>@RestMethod</ja></code> annotation on the + getter to show how properties can be overridden on the serializers/parsers at the method level. + This annotation is optional. + </p> + + <p class='bcode'> + <ja>@Path</ja>(<js>"/helloworld"</js>) + <jk>public class</jk> HelloWorldResource { + + <jc>// Our bean message class</jc> + <jk>public static class</jk> Message { + + <jc>// No-arg bean constructor (needed for parsers)</jc> + <jk>public</jk> Message() {} + + <jk>public</jk> Message(String text, String author) { + <jk>this</jk>.text = text; + <jk>this</jk>.author = author; + } + + <jk>public</jk> String text; + <jk>public</jk> String author; + } + + <jk>private static</jk> Message message = <jk>new</jk> Message(<js>"Hello world"</js>, <js>"John Smith"</js>); + + <ja>@GET</ja> + <ja>@Produces</ja>(<js>"*/*"</js>) + <ja>@RestMethod</ja>( <jc>/* Override some properties */</jc> + properties={ + <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_useIndentation</jsf>, value=<js>"true"</js>), + <ja>@Property</ja>(name=JsonSerializerContext.<jsf>LAX_MODE</jsf>, value=<js>"true"</js>) + } + ) + <jk>public</jk> Message getMessage() { + <jk>return</jk> message; + } + + <ja>@PUT</ja> + <ja>@Produces</ja>(<js>"*/*"</js>) + <ja>@Consumes</ja>(<js>"*/*"</js>) + <jk>public</jk> Message replaceMessage(Message message) { + HelloWorldResource.message = message; + <jk>return</jk> message; + } + } + </p> + <p> + When we start up the servlet, we can interact with the resource using cURL. + In these examples, note that the <jsf>SERIALIZER_useIndentation</jsf> and <jsf>LAX_MODE</jsf> settings + cause the output to be readable instead of condensed. + </p> + <p class='bcode'> + C:\>curl.exe -H "Accept: text/json" -X GET http://localhost:9080/sample/wink/helloworld + <ja>{ + text:"Hello world", + author:"John Smith" + }</ja> + </p> + <p class='bcode'> + C:\>curl.exe -H "Accept: text/html" -X GET http://localhost:9080/sample/wink/helloworld + <ja><html> + <head> + </head> + <body> + <table type="object"> + <tr> + <th> + <string>key</string> + </th> + <th> + <string>value</string> + </th> + </tr> + <tr> + <td> + <string>text</string> + </td> + <td> + <string>Hello world</string> + </td> + </tr> + <tr> + <td> + <string>author</string> + </td> + <td> + <string>John Smith</string> + </td> + </tr> + </table> + </body> + </html></ja> + </p> + <p class='bcode'> + C:\>curl.exe -H "Accept: text/xml" -X GET http://localhost:9080/sample/wink/helloworld + <ja><?xml version="1.0" encoding="UTF-8"?> + <object> + <text>Hello world</text> + <author>John Smith</author> + </object></ja> + </p> + <p class='bcode'> + C:\>curl.exe -H "Accept: application/x-www-form-urlencoded" -X GET http://localhost:9080/sample/wink/helloworld + <ja>text='Hello+world'&author='John+Smith'</ja> + </p> + <p class='bcode'> + C:\>curl.exe -H "Accept: text/xml+schema" -X GET http://localhost:9080/sample/wink/helloworld + <ja><?xml version="1.0" encoding="UTF-8"?> + <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <xs:element name="object" nillable="true"> + <xs:complexType> + <xs:sequence minOccurs="0" maxOccurs="unbounded"> + <xs:element name="text" type="xs:string" nillable="true" minOccurs="0"/> + <xs:element name="author" type="xs:string" nillable="true" minOccurs="0"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="null"/> + </xs:schema></ja> + </p> + <p class='bcode'> + C:\>curl.exe -H "Accept: application/x-java-serialized-object" -X GET http://localhost:9080/sample/wink/helloworld + <ja>detailMessaget âLjava/lang/String;[ ption(Vx ÏÃ¥â¬5â» xr âjava.io.ObjectStreamExceptiondâΣkì9âââ» xr â¼java.io.IOExcept + stackTracet â²[Ljava/lang/StackTraceElement;xpq t /org.apache.juneau.samples.jaxrs.HelloWorldResource$Messageur â²[Ljava.lang.Sta + lineNumberL â«declaringClassq ~ â LfileNameq ~ â L + methodNameq ~ â xp â¦Ã¡t âjava.io.ObjectOutputStreamt â¨ObjectOutputStream.javat âwriteObject0sq ~ â âº[t âjava.io.Obje + 3org.apache.juneau.serializer.OutputStreamSerializert âOutputStreamSerializer.javat serializesq ~ â ^t &com.ib + &t /org.apache.wink.server.handlers.AbstractHandlert ¶AbstractHandler.javat â«handleResponsesq ~ â ât 5org.apache. + sq ~ â Ct 5org.apache.wink.server.handlers.AbstractHandlersChaint âAbstractHandlersChain.javat doChainsq ~ â 't + â handlesq ~ â â¬t 5org.apache.wink.server.handlers.ResponseHandlersChaint âResponseHandlersChain.javat â handlesq ~ + â«handleResponsesq ~ â ât 5org.apache.wink.server.handlers.ResponseHandlersChaint âResponseHandlersChain.javat â ha + tHandlersChain.javat doChainsq ~ â Zt -org.apache.wink.server.internal.log.Responsest â«Responses.javat â«handleResp + eHandlersChain.javat â handlesq ~ â Ct 5org.apache.wink.server.handlers.AbstractHandlersChaint âAbstractHandlersCha + handleRequestsq ~ â |t 3org.apache.wink.server.internal.servlet.RestServlett âºRestServlet.javat servicesq ~ â â»Â£t + handleRequestsq ~ â ât -com.ibm.ws.webcontainer.channel.WCChannelLinkt âWCChannelLink.javat â£readysq ~ â âºât 4com + âºhandleNewRequestsq ~ â âº1t 4com.ibm.ws.http.channel.inbound.impl.HttpInboundLinkt ¶HttpInboundLink.javat â«process + nnectionInitialReadCallback.javat ¶sendToDiscriminatorssq ~ â qt <com.ibm.ws.tcp.channel.impl.NewConnectionInitial + ât $com.ibm.io.async.AbstractAsyncFuturet âAbstractAsyncFuture.javat â«invokeCallbacksq ~ â Ãt #com.ibm.io.async. + t âResultHandler.javatcompletesq ~ â â¥t â²com.ibm.io.async.ResultHandlert âResultHandler.javat â¬runEventProcessingLo + on: java.io.NotSerializableException: org.apache.juneau.samples.jaxrs.HelloWorldResource$Message</ja> + </p> + <p> + The following shows the PUT method being invoked. + In this case, we're passing in the new bean as a JSON object. + Also notice how the response is in standard condensed JSON since we did not override any properties on the REST method. + </p> + <p class='bcode'> + C:\>curl.exe -H "Content-Type: text/json" -H "Accept: text/json" -d "{text:'Hello again',author:'Jane Doe'}" + -X PUT http://localhost:9080/sample/wink/helloworld + <ja>{"text":"Hello again","author":"Jane Doe"}</ja> + </p> +</div> + +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/rdf/DefaultJenaProvider.java ---------------------------------------------------------------------- diff --git a/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/rdf/DefaultJenaProvider.java b/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/rdf/DefaultJenaProvider.java new file mode 100644 index 0000000..e4208c9 --- /dev/null +++ b/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/rdf/DefaultJenaProvider.java @@ -0,0 +1,91 @@ +// *************************************************************************************************************************** +// * 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.juneau.rest.jaxrs.rdf; + +import javax.ws.rs.*; +import javax.ws.rs.ext.*; + +import org.apache.juneau.html.*; +import org.apache.juneau.jena.*; +import org.apache.juneau.jso.*; +import org.apache.juneau.json.*; +import org.apache.juneau.rest.jaxrs.*; +import org.apache.juneau.rest.jena.*; +import org.apache.juneau.soap.*; +import org.apache.juneau.urlencoding.*; +import org.apache.juneau.xml.*; + +/** + * JAX-RS provider for the same serialize/parse support provided by the {@link RestServletJenaDefault} class. + */ +@Provider +@Produces({ + "application/json", "text/json", // JsonSerializer + "application/json+simple","text/json+simple", // JsonSerializer.Simple + "application/json+schema","text/json+schema", // JsonSchemaSerializer + "text/xml", // XmlDocSerializer + "text/xml+simple", // XmlDocSerializer.Simple + "text/xml+schema", // XmlSchemaDocSerializer + "text/html", // HtmlDocSerializer + "application/x-www-form-urlencoded", // UrlEncodingSerializer + "text/xml+soap", // SoapXmlSerializer + "text/xml+rdf", // RdfSerializer.Xml + "text/xml+rdf+abbrev", // RdfSerializer.XmlAbbrev + "text/n-triple", // RdfSerializer.NTriple + "text/turtle", // RdfSerializer.Turtle + "text/n3", // RdfSerializer.N3 + "application/x-java-serialized-object" // JavaSerializedObjectSerializer +}) +@Consumes({ + "application/json", "text/json", // JsonParser + "text/xml", // XmlParser + "text/html", // HtmlParser + "application/x-www-form-urlencoded", // UrlEncodingParser + "text/xml+rdf", // RdfParser.Xml + "text/n-triple", // RdfParser.NTriple + "text/turtle", // RdfParser.Turtle + "text/n3", // RdfParser.N3 + "application/x-java-serialized-object" // JavaSerializedObjectParser +}) +@JuneauProvider( + serializers={ + JsonSerializer.class, + JsonSerializer.Simple.class, + JsonSchemaSerializer.class, + XmlDocSerializer.class, + XmlDocSerializer.Simple.class, + XmlSchemaDocSerializer.class, + HtmlDocSerializer.class, + UrlEncodingSerializer.class, + SoapXmlSerializer.class, + RdfSerializer.Xml.class, + RdfSerializer.XmlAbbrev.class, + RdfSerializer.NTriple.class, + RdfSerializer.Turtle.class, + RdfSerializer.N3.class, + JavaSerializedObjectSerializer.class + }, + parsers={ + JsonParser.class, + XmlParser.class, + HtmlParser.class, + UrlEncodingParser.class, + RdfParser.Xml.class, + RdfParser.NTriple.class, + RdfParser.Turtle.class, + RdfParser.N3.class, + JavaSerializedObjectParser.class, + } +) +public final class DefaultJenaProvider extends BaseProvider {} + http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/rdf/package.html ---------------------------------------------------------------------- diff --git a/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/rdf/package.html b/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/rdf/package.html new file mode 100644 index 0000000..6bb6d97 --- /dev/null +++ b/juneau-rest-jaxrs/src/main/java/org/apache/juneau/rest/jaxrs/rdf/package.html @@ -0,0 +1,34 @@ +<!DOCTYPE HTML> +<!-- +/*************************************************************************************************************************** + * 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. + * + ***************************************************************************************************************************/ + --> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <style type="text/css"> + /* For viewing in Page Designer */ + @IMPORT url("../../../../../../javadoc.css"); + + /* For viewing in REST interface */ + @IMPORT url("../htdocs/javadoc.css"); + body { + margin: 20px; + } + </style> +</head> +<body> +<p>JAX-RS / Wink integration components with RDF support</p> +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-rest-test/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-rest-test/pom.xml b/juneau-rest-test/pom.xml index b86ccab..4ad6f98 100644 --- a/juneau-rest-test/pom.xml +++ b/juneau-rest-test/pom.xml @@ -17,7 +17,7 @@ <modelVersion>4.0.0</modelVersion> <artifactId>juneau-rest-test</artifactId> - <name>Apache Juneau Server Test</name> + <name>Apache Juneau REST Tests</name> <description>Tests for Juneau Client and Server.</description> <parent> @@ -39,6 +39,11 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-rest-jaxrs</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-rest/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-rest/pom.xml b/juneau-rest/pom.xml index 6a07bb1..f3a4be6 100644 --- a/juneau-rest/pom.xml +++ b/juneau-rest/pom.xml @@ -17,7 +17,7 @@ <modelVersion>4.0.0</modelVersion> <artifactId>juneau-rest</artifactId> - <name>Apache Juneau REST Server</name> + <name>Apache Juneau REST Servlet API</name> <description>REST servlet API</description> <packaging>bundle</packaging> @@ -35,6 +35,11 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-core-rdf</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> <optional>true</optional> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 1c1652a..525fa51 100644 --- a/pom.xml +++ b/pom.xml @@ -92,11 +92,14 @@ <modules> <module>juneau-core</module> - <module>juneau-rest-client</module> + <module>juneau-core-rdf</module> + <module>juneau-core-test</module> <module>juneau-rest</module> + <module>juneau-rest-jaxrs</module> + <module>juneau-rest-client</module> + <module>juneau-rest-test</module> <module>juneau-microservice</module> <module>juneau-samples</module> - <module>juneau-rest-test</module> <module>juneau-all</module> <module>juneau-distrib</module> </modules>
