Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2012-2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.glassfish.jersey.message.internal;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.net.URI;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Link;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.NewCookie;
import javax.ws.rs.ext.RuntimeDelegate;
import org.glassfish.jersey.CommonProperties;
import org.glassfish.jersey.internal.LocalizationMessages;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import jersey.repackaged.com.google.common.base.Function;
import jersey.repackaged.com.google.common.collect.Collections2;
import jersey.repackaged.com.google.common.collect.Lists;
/**
* Base outbound message context implementation.
*
* @author Marek Potociar (marek.potociar at oracle.com)
*/
public class OutboundMessageContext {
private static final Annotation[] EMPTY_ANNOTATIONS = new Annotation[0];
private final MultivaluedMap headers;
private final CommittingOutputStream committingOutputStream;
private Object entity;
private GenericType> entityType;
private Annotation[] entityAnnotations = EMPTY_ANNOTATIONS;
private OutputStream entityStream;
/**
* The callback interface which is used to get the terminal output stream into which the entity should be
* written and to inform the implementation about the entity size.
*/
public static interface StreamProvider {
/**
* Get the output stream. This method will be called after all the
* {@link javax.ws.rs.ext.WriterInterceptor writer interceptors} are called and written entity is buffered
* into the buffer or the buffer exceeds.
*
* @param contentLength the size of the buffered entity or -1 if the entity exceeded the maximum buffer
* size or if the buffering is disabled.
* @return the adapted output stream into which the serialized entity should be written. May return null
* which will cause ignoring the written entity (in that case the entity will
* still be written by {@link javax.ws.rs.ext.MessageBodyWriter message body writers}
* but the output will be ignored).
* @throws java.io.IOException in case of an IO error.
*/
public OutputStream getOutputStream(int contentLength) throws IOException;
}
/**
* Create new outbound message context.
*/
public OutboundMessageContext() {
this.headers = HeaderUtils.createOutbound();
this.committingOutputStream = new CommittingOutputStream();
this.entityStream = committingOutputStream;
}
/**
* Create new outbound message context copying the content
* of another context.
*
* @param original the original outbound message context.
*/
public OutboundMessageContext(OutboundMessageContext original) {
this.headers = HeaderUtils.createOutbound();
this.headers.putAll(original.headers);
this.committingOutputStream = new CommittingOutputStream();
this.entityStream = committingOutputStream;
this.entity = original.entity;
this.entityType = original.entityType;
this.entityAnnotations = original.entityAnnotations;
}
/**
* Replace all headers.
*
* @param headers new headers.
*/
public void replaceHeaders(MultivaluedMap headers) {
getHeaders().clear();
if (headers != null) {
getHeaders().putAll(headers);
}
}
/**
* Get a multi-valued map representing outbound message headers with their values converted
* to strings.
*
* @return multi-valued map of outbound message header names to their string-converted values.
*/
public MultivaluedMap getStringHeaders() {
return HeaderUtils.asStringHeaders(headers);
}
/**
* Get a message header as a single string value.
*
* Each single header value is converted to String using a
* {@link javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate} if one is available
* via {@link javax.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class)}
* for the header value class or using its {@code toString} method if a header
* delegate is not available.
*
* @param name the message header.
* @return the message header value. If the message header is not present then
* {@code null} is returned. If the message header is present but has no
* value then the empty string is returned. If the message header is present
* more than once then the values of joined together and separated by a ','
* character.
*/
public String getHeaderString(String name) {
return HeaderUtils.asHeaderString(headers.get(name), RuntimeDelegate.getInstance());
}
/**
* Get a single typed header value.
*
* @param header value type.
* @param name header name.
* @param valueType header value class.
* @param converter from string conversion function. Is expected to throw {@link ProcessingException}
* if conversion fails.
* @param convertNull if {@code true} this method calls the provided converter even for {@code null}. Otherwise this
* method returns the {@code null} without calling the converter.
* @return value of the header, or (possibly converted) {@code null} if not present.
*/
private T singleHeader(String name, Class valueType, Function converter, boolean convertNull) {
final List