jsimple.net.HttpResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsimple-io Show documentation
Show all versions of jsimple-io Show documentation
JSimple cross platform friendly library
The newest version!
/*
* Copyright (c) 2012-2015 Microsoft Mobile. All Rights Reserved.
*
* Licensed 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.
*
*
* This file is based on or incorporates material from Apache Harmony
* http://harmony.apache.org (collectively, "Third Party Code"). Microsoft Mobile
* is not the original author of the Third Party Code. The original copyright
* notice and the license, under which Microsoft Mobile received such Third Party
* Code, are set forth below.
*
*
* Copyright 2006, 2010 The Apache Software Foundation.
*
* 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 jsimple.net;
import jsimple.io.InputStream;
import org.jetbrains.annotations.Nullable;
/**
* This class handles http connectivity. It's based on a subset of the standard Java java.net.HttpURLConnection class,
* with some changes (to improve names, get rid of checked exceptions, etc.).
*
* From the doc for java.net.HttpURLConnection: Each instance of this class is used to make a single request but the
* underlying network connection to the HTTP server may be transparently shared by other instances. Calling the close()
* methods on the InputStream or OutputStream of an HttpURLConnection after a request may free network resources
* associated with this instance but has no effect on any shared persistent connection. Calling the disconnect() method
* may close the underlying socket if a persistent connection is otherwise idle at that time.
*
* This class is platform independent. Platforms (Java, C# for .Net, etc.) should define a subclass with the actual
* implementation.
*
* @author Bret Johnson
* @since 10/6/12 12:58 AM
*/
public abstract class HttpResponse extends jsimple.lang.AutoCloseable {
/**
* Gets the status code from an HTTP response message (e.g. 200, 401, etc.). Returns -1 if no code can be discerned
* from the response (i.e., the response is not valid HTTP).
*
* @return the HTTP Status-Code, or -1
*/
public abstract int getStatusCode();
/**
* Gets the message from the HTTP response status line--the "reason phrase" (which is what the RFC calls it)
* describing the error that comes after the status code.
*
* @return the HTTP reason phrase, from the status line
*/
public abstract String getStatusMessage();
/**
* Returns an input stream that reads from this open connection.
*
* A SocketTimeoutException can be thrown when reading from the returned input stream if the read timeout expires
* before data is available for read.
*
* @return an input stream that reads from this open connection
* @throws jsimple.io.IOException if an I/O error occurs while creating the input stream
*/
public abstract InputStream getBodyStream();
/**
* Get the value of the specified header or null if the header isn't present.
*
* TODO: Handle multivalued headers by returning, in most cases, the first value--that's at least what the Scribe
* code does.
*
* @param headerName HTTP header name
* @return header value or null if not present
*/
public abstract @Nullable String getHeader(String headerName);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy