org.apache.cxf.jaxrs.impl.ResponseImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cxf-bundle-minimal Show documentation
Show all versions of cxf-bundle-minimal Show documentation
Apache CXF Minimal Bundle Jar
The newest version!
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cxf.jaxrs.impl;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.net.URI;
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 javax.ws.rs.MessageProcessingException;
import javax.ws.rs.core.EntityTag;
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.core.Response;
import javax.ws.rs.core.Response.Status.Family;
import javax.ws.rs.ext.ReaderInterceptor;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.provider.ProviderFactory;
import org.apache.cxf.jaxrs.utils.HttpUtils;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageUtils;
public final class ResponseImpl extends Response {
private int status;
private Object entity;
private Annotation[] entityAnnotations;
private MultivaluedMap metadata;
private Message responseMessage;
private boolean entityClosed;
private boolean entityBufferred;
private Object lastEntity;
ResponseImpl(int s) {
this.status = s;
}
ResponseImpl(int s, Object e) {
this.status = s;
this.entity = e;
}
void addMetadata(MultivaluedMap meta) {
this.metadata = meta;
}
public void setStatus(int s) {
this.status = s;
}
public void setEntity(Object e, Annotation[] anns) {
this.entity = e;
this.entityAnnotations = anns;
}
public void setEntityAnnotations(Annotation[] anns) {
this.entityAnnotations = anns;
}
public Annotation[] getEntityAnnotations() {
return entityAnnotations;
}
//TODO: This method is needed because on the client side the
// Response processing is done after the chain completes, thus
// PhaseInterceptorChain.getCurrentMessage() returns null.
// The refactoring will be required
public void setMessage(Message message) {
this.responseMessage = message;
}
public int getStatus() {
return status;
}
public StatusType getStatusInfo() {
return new Response.StatusType() {
public Family getFamily() {
return Response.Status.Family.familyOf(ResponseImpl.this.status);
}
public String getReasonPhrase() {
Response.Status statusEnum = Response.Status.fromStatusCode(ResponseImpl.this.status);
return statusEnum != null ? statusEnum.getReasonPhrase() : "";
}
public int getStatusCode() {
return ResponseImpl.this.status;
}
};
}
public Object getEntity() {
return lastEntity != null ? lastEntity : entity;
}
public boolean hasEntity() {
return getEntity() != null;
}
public MultivaluedMap getMetadata() {
return getHeaders();
}
public MultivaluedMap getHeaders() {
return metadata;
}
public MultivaluedMap getStringHeaders() {
MetadataMap headers = new MetadataMap(metadata.size());
for (Map.Entry> entry : metadata.entrySet()) {
headers.put(entry.getKey(), toListOfStrings(entry.getValue()));
}
return headers;
}
private String getHeader(String header) {
Object value = metadata.getFirst(header);
return value == null ? null : value.toString();
}
public String getHeaderString(String header) {
List