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 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.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
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.internal.LocalizationMessages;
import org.glassfish.jersey.internal.ProcessingException;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
/**
* Base outbound message context implementation.
*
* @author Marek Potociar (marek.potociar at oracle.com)
*/
// TODO revise - remove unused methods, fix warnings etc.
public class OutboundMessageContext {
private static final Annotation[] EMPTY_ANNOTATIONS = new Annotation[0];
private final MultivaluedMap headers;
private final CommittingOutputStream rootStream;
private Object entity;
private GenericType entityType;
private Annotation[] entityAnnotations = EMPTY_ANNOTATIONS;
private OutputStream entityStream;
/**
* Output stream provider.
*/
public static interface StreamProvider {
/**
* Get the output stream.
*
* The method is called once as part of a "commit" operation immediately after
* the {@link #commit()} method has been invoked.
*
* @return the adapted output stream.
* @throws java.io.IOException in case of an IO error.
*/
public OutputStream getOutputStream() throws IOException;
/**
* Perform the commit functionality.
*
* The method is called once as part of a "commit" operation before the first byte
* is written to the provider stream.
*
* @throws java.io.IOException in case of an IO error.
*/
public void commit() throws IOException;
}
/**
* Create new outbound message context.
*/
public OutboundMessageContext() {
this.headers = HeadersFactory.createOutbound();
this.rootStream = new CommittingOutputStream();
this.entityStream = rootStream;
}
/**
* Create new outbound message context copying the content
* of another context.
*
* @param original the original outbound message context.
*/
public OutboundMessageContext(OutboundMessageContext original) {
this.headers = HeadersFactory.createOutbound();
this.headers.putAll(original.headers);
this.rootStream = new CommittingOutputStream();
this.entityStream = rootStream;
this.entity = original.entity;
this.entityType = original.entityType;
this.entityAnnotations = original.entityAnnotations;
}
// Message headers
/**
* Add a new header value.
*
* @param name header name.
* @param value header value.
* @return updated context.
*/
public OutboundMessageContext header(String name, Object value) {
headers.add(name, value);
return this;
}
/**
* Add new header values.
*
* @param name header name.
* @param values header values.
* @return updated context.
*/
public OutboundMessageContext headers(String name, Object... values) {
headers.addAll(name, values);
return this;
}
/**
* Add new header values.
*
* @param name header name.
* @param values header values.
* @return updated context.
*/
public OutboundMessageContext headers(String name, Iterable values) {
headers.addAll(name, iterableToList(values));
return this;
}
/**
* Add new headers.
*
* @param headers new headers.
* @return updated context.
*/
public OutboundMessageContext headers(MultivaluedMap headers) {
headers.putAll(headers);
return this;
}
/**
* Remove a header.
*
* @param name header name.
* @return updated context.
*/
public OutboundMessageContext remove(String name) {
headers.remove(name);
return this;
}
/**
* Replace header values with a new single header value.
*
* @param name header name.
* @param value new single header value.
* @return updated context.
*/
public OutboundMessageContext replace(String name, Object value) {
headers.putSingle(name, value);
return this;
}
/**
* Replace header values.
*
* @param name header name.
* @param values new header values.
* @return updated context.
*/
public OutboundMessageContext replace(String name, Iterable values) {
headers.remove(name);
headers.put(name, iterableToList(values));
return this;
}
/**
* Replace all headers.
*
* @param headers new headers.
* @return updated context.
*/
public OutboundMessageContext replaceAll(MultivaluedMap headers) {
headers.clear();
headers.putAll(headers);
return this;
}
private List