Repository: incubator-juneau Updated Branches: refs/heads/master d8b8e98ce -> 74a90ffa7
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/74a90ffa/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java index 8be3753..676f451 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java @@ -320,17 +320,14 @@ public final class RestRequest extends HttpServletRequestWrapper { * * @return The <code>Content-Type</code> media-type header value on the request. */ - public String getMediaType() { + public MediaType getMediaType() { String cm = getHeader("Content-Type"); if (cm == null) { if (body != null) - return "text/uon"; - return "text/json"; + return MediaType.UON; + return MediaType.JSON; } - int j = cm.indexOf(';'); - if (j != -1) - cm = cm.substring(0, j); - return cm; + return MediaType.forString(cm); } /** @@ -352,7 +349,7 @@ public final class RestRequest extends HttpServletRequestWrapper { * * @return The set of media types registered in the parser group of this request. */ - public List<String> getSupportedMediaTypes() { + public List<MediaType> getSupportedMediaTypes() { return parserGroup.getSupportedMediaTypes(); } @@ -394,7 +391,7 @@ public final class RestRequest extends HttpServletRequestWrapper { if (h != null) { MediaRange[] mr = MediaRange.parse(h); if (mr.length > 0) - return toLocale(mr[0].getType()); + return toLocale(mr[0].getMediaType().getType()); } return super.getLocale(); } @@ -407,7 +404,7 @@ public final class RestRequest extends HttpServletRequestWrapper { if (mr.length > 0) { List<Locale> l = new ArrayList<Locale>(mr.length); for (MediaRange r : mr) - l.add(toLocale(r.getType())); + l.add(toLocale(r.getMediaType().getType())); return enumeration(l); } } @@ -1123,21 +1120,22 @@ public final class RestRequest extends HttpServletRequestWrapper { if (type.isInputStream()) return (T)getInputStream(); - String mediaType = getMediaType(); TimeZone timeZone = getTimeZone(); Locale locale = getLocale(); - Parser p = getParser(); + ParserMatch pm = getParserMatch(); - if (p != null) { + if (pm != null) { + Parser p = pm.getParser(); + MediaType mediaType = pm.getMediaType(); try { properties.append("mediaType", mediaType).append("characterEncoding", getCharacterEncoding()); if (! p.isReaderParser()) { InputStreamParser p2 = (InputStreamParser)p; - ParserSession session = p2.createSession(getInputStream(), properties, getJavaMethod(), getServlet(), locale, timeZone); + ParserSession session = p2.createSession(getInputStream(), properties, getJavaMethod(), getServlet(), locale, timeZone, mediaType); return p2.parse(session, type); } ReaderParser p2 = (ReaderParser)p; - ParserSession session = p2.createSession(getUnbufferedReader(), properties, getJavaMethod(), getServlet(), locale, timeZone); + ParserSession session = p2.createSession(getUnbufferedReader(), properties, getJavaMethod(), getServlet(), locale, timeZone, mediaType); return p2.parse(session, type); } catch (ParseException e) { throw new RestException(SC_BAD_REQUEST, @@ -1549,31 +1547,43 @@ public final class RestRequest extends HttpServletRequestWrapper { } /** - * Returns the parser matching the request <code>Accept</code> header. + * Returns the parser and media type matching the request <code>Content-Type</code> header. * - * @return The parser matching the request <code>Accept</code> header, or <jk>null</jk> + * @return The parser matching the request <code>Content-Type</code> header, or <jk>null</jk> * if no matching parser was found. + * Includes the matching media type. */ - public Parser getParser() { - String mediaType = getMediaType(); - Parser p = parserGroup.getParser(mediaType); + public ParserMatch getParserMatch() { + MediaType mediaType = getMediaType(); + ParserMatch pm = parserGroup.getParserMatch(mediaType); // If no patching parser for URL-encoding, use the one defined on the servlet. - if (p == null && mediaType.equals("application/x-www-form-urlencoded")) - p = urlEncodingParser; + if (pm == null && mediaType.equals("application/x-www-form-urlencoded")) + pm = new ParserMatch(MediaType.URLENCODING, urlEncodingParser); + + return pm; + } - return p; + /** + * Returns the parser matching the request <code>Content-Type</code> header. + * + * @return The parser matching the request <code>Content-Type</code> header, or <jk>null</jk> + * if no matching parser was found. + */ + public Parser getParser() { + ParserMatch pm = getParserMatch(); + return (pm == null ? null : pm.getParser()); } /** - * Returns the reader parser matching the request <code>Accept</code> header. + * Returns the reader parser matching the request <code>Content-Type</code> header. * - * @return The reader parser matching the request <code>Accept</code> header, or <jk>null</jk> + * @return The reader parser matching the request <code>Content-Type</code> header, or <jk>null</jk> * if no matching reader parser was found, or the matching parser was an input stream parser. */ public ReaderParser getReaderParser() { Parser p = getParser(); - if (p.isReaderParser()) + if (p != null && p.isReaderParser()) return (ReaderParser)p; return null; } @@ -1694,22 +1704,22 @@ public final class RestRequest extends HttpServletRequestWrapper { * @param name The name of the resource (i.e. the value normally passed to {@link Class#getResourceAsStream(String)}. * @param resolveVars If <jk>true</jk>, any {@link org.apache.juneau.rest.annotation.Parameter} variables will be resolved by the variable resolver returned * by {@link #getVarResolverSession()}. - * @param contentType The value to set as the <js>"Content-Type"</js> header for this object. + * @param mediaType The value to set as the <js>"Content-Type"</js> header for this object. * @return A new reader resource, or <jk>null</jk> if resource could not be found. * @throws IOException */ - public ReaderResource getReaderResource(String name, boolean resolveVars, String contentType) throws IOException { + public ReaderResource getReaderResource(String name, boolean resolveVars, MediaType mediaType) throws IOException { String s = servlet.getResourceAsString(name, getLocale()); if (s == null) return null; - ReaderResource rr = new ReaderResource(s, contentType); + ReaderResource rr = new ReaderResource(s, mediaType); if (resolveVars) rr.setVarSession(getVarResolverSession()); return rr; } /** - * Same as {@link #getReaderResource(String, boolean, String)} except uses {@link RestServlet#getMimetypesFileTypeMap()} + * Same as {@link #getReaderResource(String, boolean, MediaType)} except uses {@link RestServlet#getMimetypesFileTypeMap()} * to determine the media type. * * @param name The name of the resource (i.e. the value normally passed to {@link Class#getResourceAsStream(String)}. @@ -1719,7 +1729,7 @@ public final class RestRequest extends HttpServletRequestWrapper { * @throws IOException */ public ReaderResource getReaderResource(String name, boolean resolveVars) throws IOException { - return getReaderResource(name, resolveVars, servlet.getMimetypesFileTypeMap().getContentType(name)); + return getReaderResource(name, resolveVars, MediaType.forString(servlet.getMimetypesFileTypeMap().getContentType(name))); } /** @@ -1730,7 +1740,7 @@ public final class RestRequest extends HttpServletRequestWrapper { * @throws IOException */ public ReaderResource getReaderResource(String name) throws IOException { - return getReaderResource(name, false, servlet.getMimetypesFileTypeMap().getContentType(name)); + return getReaderResource(name, false, MediaType.forString(servlet.getMimetypesFileTypeMap().getContentType(name))); } /** http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/74a90ffa/juneau-rest/src/main/java/org/apache/juneau/rest/RestResponse.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestResponse.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestResponse.java index 0800071..5e65648 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestResponse.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestResponse.java @@ -101,10 +101,11 @@ public final class RestResponse extends HttpServletResponseWrapper { charset = defaultCharset; else for (MediaRange r : MediaRange.parse(h)) { if (r.getQValue() > 0) { - if (r.getType().equals("*")) + MediaType mt = r.getMediaType(); + if (mt.getType().equals("*")) charset = defaultCharset; - else if (RestServlet.availableCharsets.containsKey(r.getType())) - charset = r.getType(); + else if (RestServlet.availableCharsets.containsKey(mt.getType())) + charset = mt.getType(); if (charset != null) break; } @@ -129,7 +130,7 @@ public final class RestResponse extends HttpServletResponseWrapper { * * @return The set of media types registered in the parser group of this request. */ - public List<String> getSupportedMediaTypes() { + public List<MediaType> getSupportedMediaTypes() { return serializerGroup.getSupportedMediaTypes(); } @@ -260,7 +261,7 @@ public final class RestResponse extends HttpServletResponseWrapper { String ae = request.getHeader("Accept-Encoding"); if (! (ae == null || ae.isEmpty())) { - String match = encoders != null ? encoders.findMatch(ae) : null; + EncoderMatch match = encoders != null ? encoders.getEncoderMatch(ae) : null; if (match == null) { // Identity should always match unless "identity;q=0" or "*;q=0" is specified. if (ae.matches(".*(identity|\\*)\\s*;\\s*q\\s*=\\s*(0(?!\\.)|0\\.0).*")) { @@ -270,11 +271,12 @@ public final class RestResponse extends HttpServletResponseWrapper { ); } } else { - encoder = encoders.getEncoder(match); + encoder = match.getEncoder(); + String encoding = match.getEncoding().toString(); // Some clients don't recognize identity as an encoding, so don't set it. - if (! match.equals("identity")) - setHeader("content-encoding", match); + if (! encoding.equals("identity")) + setHeader("content-encoding", encoding); } } os = getOutputStream(); @@ -378,15 +380,8 @@ public final class RestResponse extends HttpServletResponseWrapper { * * @return The <code>media-type</code> portion of the <code>Content-Type</code> header. */ - public String getMediaType() { - String contentType = getContentType(); - if (contentType == null) - return null; - int i = contentType.indexOf(';'); - if (i == -1) - return contentType; - return contentType.substring(0, i).trim(); - + public MediaType getMediaType() { + return MediaType.forString(getContentType()); } /** http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/74a90ffa/juneau-rest/src/main/java/org/apache/juneau/rest/RestServlet.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServlet.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestServlet.java index e3e1ec8..5fb405a 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServlet.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestServlet.java @@ -792,7 +792,7 @@ public abstract class RestServlet extends HttpServlet { Swagger s = swaggers.get(locale); if (s == null) { try { - s = getResource(Swagger.class, "text/json", getClass().getSimpleName() + ".json", locale); + s = getResource(Swagger.class, MediaType.JSON, getClass().getSimpleName() + ".json", locale); swaggers.putIfAbsent(locale, s == null ? Swagger.NULL : s); } catch (Exception e) { throw new RestException(SC_INTERNAL_SERVER_ERROR, e); @@ -1407,7 +1407,7 @@ public abstract class RestServlet extends HttpServlet { * @return The list of valid {@code Accept} content types for this resource. * @throws RestServletException */ - public Collection<String> getSupportedAcceptTypes() throws RestServletException { + public Collection<MediaType> getSupportedAcceptTypes() throws RestServletException { return getParsers().getSupportedMediaTypes(); } @@ -1427,7 +1427,7 @@ public abstract class RestServlet extends HttpServlet { * @return The list of valid {@code Content-Type} header values for this resource. * @throws RestServletException */ - public Collection<String> getSupportedContentTypes() throws RestServletException { + public Collection<MediaType> getSupportedContentTypes() throws RestServletException { return getSerializers().getSupportedMediaTypes(); } @@ -3356,7 +3356,7 @@ public abstract class RestServlet extends HttpServlet { * @throws IOException * @throws ServletException */ - public <T> T getResource(Class<T> c, String mediaType, String name, Locale locale) throws IOException, ServletException { + public <T> T getResource(Class<T> c, MediaType mediaType, String name, Locale locale) throws IOException, ServletException { InputStream is = getResource(name, locale); if (is == null) return null; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/74a90ffa/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/BaseProvider.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/BaseProvider.java b/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/BaseProvider.java deleted file mode 100644 index 2381736..0000000 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/BaseProvider.java +++ /dev/null @@ -1,189 +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.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/74a90ffa/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/DefaultProvider.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/DefaultProvider.java b/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/DefaultProvider.java deleted file mode 100644 index 92cc4a1..0000000 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/DefaultProvider.java +++ /dev/null @@ -1,71 +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.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/74a90ffa/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/JuneauProvider.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/JuneauProvider.java b/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/JuneauProvider.java deleted file mode 100644 index b0e54c0..0000000 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/JuneauProvider.java +++ /dev/null @@ -1,96 +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.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/74a90ffa/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/package.html ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/package.html b/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/package.html deleted file mode 100644 index e877328..0000000 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/package.html +++ /dev/null @@ -1,360 +0,0 @@ -<!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/74a90ffa/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/rdf/DefaultJenaProvider.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/rdf/DefaultJenaProvider.java b/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/rdf/DefaultJenaProvider.java deleted file mode 100644 index e4208c9..0000000 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/rdf/DefaultJenaProvider.java +++ /dev/null @@ -1,91 +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.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/74a90ffa/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/rdf/package.html ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/rdf/package.html b/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/rdf/package.html deleted file mode 100644 index 6bb6d97..0000000 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/jaxrs/rdf/package.html +++ /dev/null @@ -1,34 +0,0 @@ -<!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/74a90ffa/juneau-rest/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java b/juneau-rest/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java index 7110014..1e1d1bd 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java @@ -40,15 +40,13 @@ public class DefaultHandler implements ResponseHandler { public boolean handle(RestRequest req, RestResponse res, Object output) throws IOException, RestException { SerializerGroup g = res.getSerializerGroup(); String accept = req.getHeader("Accept", ""); - String matchingAccept = g.findMatch(accept); - if (matchingAccept != null) { - Serializer s = g.getSerializer(matchingAccept); - String contentType = s.getResponseContentType(); - if (contentType == null) - contentType = res.getContentType(); - if (contentType == null) - contentType = matchingAccept; - res.setContentType(contentType); + SerializerMatch sm = g.getSerializerMatch(accept); + if (sm != null) { + Serializer s = sm.getSerializer(); + MediaType mediaType = res.getMediaType(); + if (mediaType == null) + mediaType = sm.getMediaType(); + res.setContentType(mediaType.toString()); ObjectMap headers = s.getResponseHeaders(res.getProperties()); if (headers != null) for (String key : headers.keySet()) @@ -60,17 +58,17 @@ public class DefaultHandler implements ResponseHandler { p.put(SerializerContext.SERIALIZER_useIndentation, true); res.setContentType("text/plain"); } - p.append("mediaType", matchingAccept).append("characterEncoding", res.getCharacterEncoding()); + p.append("mediaType", mediaType).append("characterEncoding", res.getCharacterEncoding()); if (! s.isWriterSerializer()) { OutputStreamSerializer s2 = (OutputStreamSerializer)s; OutputStream os = res.getNegotiatedOutputStream(); - SerializerSession session = s.createSession(os, p, req.getJavaMethod(), req.getLocale(), req.getTimeZone()); + SerializerSession session = s.createSession(os, p, req.getJavaMethod(), req.getLocale(), req.getTimeZone(), mediaType); s2.serialize(session, output); os.close(); } else { WriterSerializer s2 = (WriterSerializer)s; Writer w = res.getNegotiatedWriter(); - SerializerSession session = s.createSession(w, p, req.getJavaMethod(), req.getLocale(), req.getTimeZone()); + SerializerSession session = s.createSession(w, p, req.getJavaMethod(), req.getLocale(), req.getTimeZone(), mediaType); s2.serialize(session, output); w.close(); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/74a90ffa/juneau-rest/src/main/java/org/apache/juneau/rest/response/WritableHandler.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/response/WritableHandler.java b/juneau-rest/src/main/java/org/apache/juneau/rest/response/WritableHandler.java index c6a9598..7d84368 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/response/WritableHandler.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/response/WritableHandler.java @@ -33,9 +33,9 @@ public final class WritableHandler implements ResponseHandler { if (output instanceof Writable) { if (output instanceof ReaderResource) { ReaderResource r = (ReaderResource)output; - String mediaType = r.getMediaType(); + MediaType mediaType = r.getMediaType(); if (mediaType != null) - res.setContentType(mediaType); + res.setContentType(mediaType.toString()); for (Map.Entry<String,String> h : r.getHeaders().entrySet()) res.setHeader(h.getKey(), h.getValue()); }
