[OLINGO-659] more API clean-up

Signed-off-by: Michael Bolz <michael.bolz@sap.com>
This commit is contained in:
Klaus Straubinger 2015-09-11 16:23:30 +02:00 committed by Michael Bolz
parent fcec0c349b
commit 54f6947259
21 changed files with 223 additions and 348 deletions

View File

@ -18,271 +18,162 @@
*/ */
package org.apache.olingo.commons.api.http; package org.apache.olingo.commons.api.http;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
/** /**
* HTTP header constants. * HTTP header constants.
*/ */
public class HttpHeader { public interface HttpHeader {
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1">HTTP/1.1 documentation</a>}.
*/ */
public static final String ACCEPT = "Accept"; String ACCEPT = "Accept";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2">HTTP/1.1 documentation</a>}.
*/ */
public static final String ACCEPT_CHARSET = "Accept-Charset"; String ACCEPT_CHARSET = "Accept-Charset";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3">HTTP/1.1 documentation</a>}.
*/ */
public static final String ACCEPT_ENCODING = "Accept-Encoding"; String ACCEPT_ENCODING = "Accept-Encoding";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4">HTTP/1.1 documentation</a>}.
*/ */
public static final String ACCEPT_LANGUAGE = "Accept-Language"; String ACCEPT_LANGUAGE = "Accept-Language";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7">HTTP/1.1 documentation</a>}.
*/ */
public static final String ALLOW = "Allow"; String ALLOW = "Allow";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.8">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.8">HTTP/1.1 documentation</a>}.
*/ */
public static final String AUTHORIZATION = "Authorization"; String AUTHORIZATION = "Authorization";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9">HTTP/1.1 documentation</a>}.
*/ */
public static final String CACHE_CONTROL = "Cache-Control"; String CACHE_CONTROL = "Cache-Control";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11">HTTP/1.1 documentation</a>}.
*/ */
public static final String CONTENT_ENCODING = "Content-Encoding"; String CONTENT_ENCODING = "Content-Encoding";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.12">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.12">HTTP/1.1 documentation</a>}.
*/ */
public static final String CONTENT_LANGUAGE = "Content-Language"; String CONTENT_LANGUAGE = "Content-Language";
/** See <a href="http://www.rfc-editor.org/rfc/rfc2392.txt">RFC 2392</a>. */ /** See <a href="http://www.rfc-editor.org/rfc/rfc2392.txt">RFC 2392</a>. */
public static final String CONTENT_ID = "Content-ID"; String CONTENT_ID = "Content-ID";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13">HTTP/1.1 documentation</a>}.
*/ */
public static final String CONTENT_LENGTH = "Content-Length"; String CONTENT_LENGTH = "Content-Length";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.14">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.14">HTTP/1.1 documentation</a>}.
*/ */
public static final String CONTENT_LOCATION = "Content-Location"; String CONTENT_LOCATION = "Content-Location";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">HTTP/1.1 documentation</a>}.
*/ */
public static final String CONTENT_TYPE = "Content-Type"; String CONTENT_TYPE = "Content-Type";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18">HTTP/1.1 documentation</a>}.
*/ */
public static final String DATE = "Date"; String DATE = "Date";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19">HTTP/1.1 documentation</a>}.
*/ */
public static final String ETAG = "ETag"; String ETAG = "ETag";
/** See <a href="http://www.rfc-editor.org/rfc/rfc7231.txt">RFC 7231</a>. */ /** See <a href="http://www.rfc-editor.org/rfc/rfc7231.txt">RFC 7231</a>. */
public static final String EXPECT = "Expect"; String EXPECT = "Expect";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21">HTTP/1.1 documentation</a>}.
*/ */
public static final String EXPIRES = "Expires"; String EXPIRES = "Expires";
/** See <a href="http://www.rfc-editor.org/rfc/rfc7231.txt">RFC 7231</a>. */ /** See <a href="http://www.rfc-editor.org/rfc/rfc7231.txt">RFC 7231</a>. */
public static final String FROM = "From"; String FROM = "From";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23">HTTP/1.1 documentation</a>}.
*/ */
public static final String HOST = "Host"; String HOST = "Host";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.24">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.24">HTTP/1.1 documentation</a>}.
*/ */
public static final String IF_MATCH = "If-Match"; String IF_MATCH = "If-Match";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.25">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.25">HTTP/1.1 documentation</a>}.
*/ */
public static final String IF_MODIFIED_SINCE = "If-Modified-Since"; String IF_MODIFIED_SINCE = "If-Modified-Since";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.26">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.26">HTTP/1.1 documentation</a>}.
*/ */
public static final String IF_NONE_MATCH = "If-None-Match"; String IF_NONE_MATCH = "If-None-Match";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.28">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.28">HTTP/1.1 documentation</a>}.
*/ */
public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since"; String IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.29">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.29">HTTP/1.1 documentation</a>}.
*/ */
public static final String LAST_MODIFIED = "Last-Modified"; String LAST_MODIFIED = "Last-Modified";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30">HTTP/1.1 documentation</a>}.
*/ */
public static final String LOCATION = "Location"; String LOCATION = "Location";
/** /**
* See {@link <a href="http://tools.ietf.org/html/rfc5988#page-6">Web Linking (IETF RFC-5988) documentation</a>}. * See {@link <a href="http://tools.ietf.org/html/rfc5988#page-6">Web Linking (IETF RFC-5988) documentation</a>}.
*/ */
public static final String LINK = "Link"; String LINK = "Link";
/** See <a href="http://www.rfc-editor.org/rfc/rfc7231.txt">RFC 7231</a>. */ /** See <a href="http://www.rfc-editor.org/rfc/rfc7231.txt">RFC 7231</a>. */
public static final String MAX_FORWARDS = "Max-Forwards"; String MAX_FORWARDS = "Max-Forwards";
/** /**
* OData Prefer Header. * OData Prefer Header.
* See <a href="http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part1-protocol.html#_Toc406398233"> * See <a href="http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part1-protocol.html#_Toc406398233">
* OData Version 4.0 Part 1: Protocol</a> and <a href="https://www.ietf.org/rfc/rfc7240.txt">RFC 7240</a>. * OData Version 4.0 Part 1: Protocol</a> and <a href="https://www.ietf.org/rfc/rfc7240.txt">RFC 7240</a>.
*/ */
public static final String PREFER = "Prefer"; String PREFER = "Prefer";
/** /**
* OData Preference-Applied Header. * OData Preference-Applied Header.
* See <a href="http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part1-protocol.html#_Toc406398247"> * See <a href="http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part1-protocol.html#_Toc406398247">
* OData Version 4.0 Part 1: Protocol</a> and <a href="https://www.ietf.org/rfc/rfc7240.txt">RFC 7240</a>. * OData Version 4.0 Part 1: Protocol</a> and <a href="https://www.ietf.org/rfc/rfc7240.txt">RFC 7240</a>.
*/ */
public static final String PREFERENCE_APPLIED = "Preference-Applied"; String PREFERENCE_APPLIED = "Preference-Applied";
/** See <a href="http://www.rfc-editor.org/rfc/rfc7233.txt">RFC 7233</a>. */ /** See <a href="http://www.rfc-editor.org/rfc/rfc7233.txt">RFC 7233</a>. */
public static final String RANGE = "Range"; String RANGE = "Range";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.37">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.37">HTTP/1.1 documentation</a>}.
*/ */
public static final String RETRY_AFTER = "Retry-After"; String RETRY_AFTER = "Retry-After";
/** See <a href="http://www.rfc-editor.org/rfc/rfc7230.txt">RFC 7230</a>. */ /** See <a href="http://www.rfc-editor.org/rfc/rfc7230.txt">RFC 7230</a>. */
public static final String TE = "TE"; String TE = "TE";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43">HTTP/1.1 documentation</a>}.
*/ */
public static final String USER_AGENT = "User-Agent"; String USER_AGENT = "User-Agent";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.44">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.44">HTTP/1.1 documentation</a>}.
*/ */
public static final String VARY = "Vary"; String VARY = "Vary";
/** /**
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.47">HTTP/1.1 documentation</a>}. * See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.47">HTTP/1.1 documentation</a>}.
*/ */
public static final String WWW_AUTHENTICATE = "WWW-Authenticate"; String WWW_AUTHENTICATE = "WWW-Authenticate";
/** /**
* See {@link <a href="http://www.ietf.org/rfc/rfc2109.txt">IETF RFC 2109</a>}. * See {@link <a href="http://www.ietf.org/rfc/rfc2109.txt">IETF RFC 2109</a>}.
*/ */
public static final String COOKIE = "Cookie"; String COOKIE = "Cookie";
/** /**
* See {@link <a href="http://www.ietf.org/rfc/rfc2109.txt">IETF RFC 2109</a>}. * See {@link <a href="http://www.ietf.org/rfc/rfc2109.txt">IETF RFC 2109</a>}.
*/ */
public static final String SET_COOKIE = "Set-Cookie"; String SET_COOKIE = "Set-Cookie";
/** Non standard header. */ /** Non standard header. */
public static final String X_HTTP_METHOD = "X-HTTP-Method"; String X_HTTP_METHOD = "X-HTTP-Method";
/** Non standard header. */ /** Non standard header. */
public static final String X_HTTP_METHOD_OVERRIDE = "X-HTTP-Method-Override"; String X_HTTP_METHOD_OVERRIDE = "X-HTTP-Method-Override";
/** Custom Header defined in the OData standard. */ /** Custom Header defined in the OData standard. */
public static final String ODATA_VERSION = "OData-Version"; String ODATA_VERSION = "OData-Version";
/** Custom Header defined in the OData standard. */ /** Custom Header defined in the OData standard. */
public static final String ODATA_MAX_VERSION = "OData-MaxVersion"; String ODATA_MAX_VERSION = "OData-MaxVersion";
/** Custom Header defined in the OData standard. */ /** Custom Header defined in the OData standard. */
public static final String ODATA_ENTITY_ID = "OData-EntityID"; String ODATA_ENTITY_ID = "OData-EntityID";
private final String name;
private final List<String> values;
/**
* Create header for given name
* @param name of header
*/
public HttpHeader(String name) {
this.name = name;
this.values = new ArrayList<String>();
}
/**
* Create header for given name and add given values
* @param name of header
* @param values values for header
*/
public HttpHeader(String name, Collection<String> values) {
this(name);
this.values.addAll(values);
}
/**
* Get name of header (not the canonical name)
* @return name of header
*/
public String getName() {
return name;
}
/**
* Get all values for this header
* @return all header values
*/
public List<String> getValues() {
return Collections.unmodifiableList(values);
}
/**
* Add header value
*
* @param value value to be added
* @return this header object (fluent interface)
*/
public HttpHeader addValue(String value) {
this.values.add(value);
return this;
}
/**
* Add header values
*
* @param values values to be added
* @return this header object (fluent interface)
*/
public HttpHeader addValues(Collection<String> values) {
this.values.addAll(values);
return this;
}
/**
* Get the canonical name of header
* @return canonical name of header
*/
public String getCanonicalName() {
return createCanonicalName(name);
}
/**
* Create the canonical name based on given name parameter
*
* @param name name which is canonicalised
* @return canonical name
*/
public static String createCanonicalName(String name) {
return name.toLowerCase(Locale.ROOT);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
HttpHeader that = (HttpHeader) o;
if (!name.equals(that.name)) {
return false;
}
return values.equals(that.values);
}
@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + values.hashCode();
return result;
}
} }

View File

@ -22,132 +22,111 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.olingo.commons.api.http.HttpHeader;
/** /**
* HttpHeader container * HttpHeader container.
*/ */
public class HttpHeaders { public class HttpHeaders {
private final Map<String, HttpHeader> headers = new LinkedHashMap<String, HttpHeader>(); private final Map<String, List<String>> headers = new LinkedHashMap<String, List<String>>();
/** /**
* Add a header with given name and value. * Adds a header with given name and value.
* If header with name already exists the value is added to this header. * If a header with that name already exists the value is added to this header.
*
* @param name name of header * @param name name of header
* @param value value for header * @param value value for header
* @return this container (fluent interface) * @return this container (fluent interface)
*/ */
public HttpHeaders addHeader(String name, String value) { public HttpHeaders addHeader(final String name, final String value) {
HttpHeader eh = grantHeader(name); final String canonicalName = getCanonicalName(name);
eh.addValue(value); List<String> header = headers.get(canonicalName);
if (header == null) {
header = new ArrayList<String>();
}
header.add(value);
headers.put(canonicalName, header);
return this; return this;
} }
/** /**
* Add a header with given name and values. * Adds a header with the given name and values.
* If header with name already exists the values are added to this header. * If a header with that name already exists the values are added to this header.
*
* @param name name of header * @param name name of header
* @param values values for header * @param values values for header
* @return this container (fluent interface) * @return this container (fluent interface)
*/ */
public HttpHeaders addHeader(String name, Collection<String> values) { public HttpHeaders addHeader(final String name, final List<String> values) {
HttpHeader eh = grantHeader(name); final String canonicalName = getCanonicalName(name);
eh.addValues(values); List<String> header = headers.get(canonicalName);
if (header == null) {
header = new ArrayList<String>();
}
header.addAll(values);
headers.put(canonicalName, header);
return this; return this;
} }
/** /**
* Set a header with given name and value. * Set a header with given name and value.
* If header with name already exists the old header is replaced with the new one. * If a header with that name already exists the old header is replaced with the new one.
*
* @param name name of header * @param name name of header
* @param value value for header * @param value value for header
* @return this container (fluent interface) * @return this container (fluent interface)
*/ */
public HttpHeaders setHeader(String name, String value) { public HttpHeaders setHeader(final String name, final String value) {
removeHeader(name); removeHeader(name);
addHeader(name, value);
HttpHeader eh = grantHeader(name);
eh.addValue(value);
return this; return this;
} }
/** /**
* Get header for given name. * Gets header values for the given name.
*
* @param name name of header requested * @param name name of header requested
* @return corresponding header * @return corresponding header values or null if no values have been found
*/ */
public HttpHeader getHeader(String name) { public List<String> getHeader(final String name) {
return headers.get(HttpHeader.createCanonicalName(name)); final List<String> values = headers.get(getCanonicalName(name));
return values == null || values.isEmpty() ? null : Collections.unmodifiableList(values);
} }
/** /**
* Remove header for given name. * Removes header of the given name.
*
* @param name name of header to be removed * @param name name of header to be removed
* @return header which was removed or null if no header was known for this name * @return removed header values or null if no header was known for this name
*/ */
public HttpHeader removeHeader(String name) { public List<String> removeHeader(final String name) {
return headers.remove(HttpHeader.createCanonicalName(name)); return headers.remove(getCanonicalName(name));
} }
/** /**
* Get all headers. * Gets all headers with the according values.
* * @return an unmodifiable Map of header names/values or an empty collection if no headers have been set
* @return all headers
*/
public Collection<HttpHeader> getHeaders() {
return Collections.unmodifiableCollection(headers.values());
}
/**
* Get all headers with the according values.
*
* @return an unmodifiable Map of header names/values
*/ */
public Map<String, List<String>> getHeaderToValues() { public Map<String, List<String>> getHeaderToValues() {
Map<String, List<String>> result = new HashMap<String, List<String>>(); return headers.isEmpty() ? Collections.<String, List<String>> emptyMap() : Collections.unmodifiableMap(headers);
Collection<HttpHeader> allHeaders = headers.values();
for (HttpHeader header : allHeaders) {
result.put(header.getName(), header.getValues());
}
return Collections.unmodifiableMap(result);
} }
/** /**
* Get all header names. * Gets all header names.
* * @return all header names or an empty collection if no headers have been set
* @return all header names
*/ */
public Collection<String> getHeaderNames() { public Collection<String> getHeaderNames() {
Collection<String> headerNames = new ArrayList<String>(); return headers.isEmpty() ? Collections.<String> emptySet() : Collections.unmodifiableSet(headers.keySet());
for (HttpHeader header : headers.values()) {
headerNames.add(header.getName());
}
return headerNames;
} }
/** /**
* Get or create a header for given name. * The canonical form of a header name is the already-used form regarding case,
* * enabling applications to have pretty-looking headers instead of getting them
* @return new or known header * converted to all lowercase.
* @param name HTTP header name
*/ */
private HttpHeader grantHeader(String name) { private String getCanonicalName(final String name) {
String key = HttpHeader.createCanonicalName(name); for (final String headerName : headers.keySet()) {
HttpHeader eh = headers.get(key); if (headerName.equalsIgnoreCase(name)) {
if(eh == null) { return headerName;
eh = new HttpHeader(name); }
headers.put(key, eh);
} }
return eh; return name;
} }
} }

View File

@ -125,7 +125,7 @@ public abstract class OData {
/** /**
* Creates a new deserializer object for reading content in the specified format. * Creates a new deserializer object for reading content in the specified format.
* Deserializer are used in Processor implementations. * Deserializers are used in Processor implementations.
* *
* @param contentType any content type supported by Olingo (XML, JSON ...) * @param contentType any content type supported by Olingo (XML, JSON ...)
*/ */
@ -151,10 +151,11 @@ public abstract class OData {
public abstract Preferences createPreferences(Collection<String> preferHeaders); public abstract Preferences createPreferences(Collection<String> preferHeaders);
/** /**
* This method creates a DebugResponseHelper for the given debugFormat. If the format is not supported no * Creates a DebugResponseHelper for the given debugFormat.
* exception is thrown. Instead we give back the implementation for the json format. * If the format is not supported no exception is thrown.
* @param debugFormat to be used. * Instead we give back the implementation for the JSON format.
* @return a debug response serializer * @param debugFormat format to be used
* @return a debug-response helper
*/ */
public abstract DebugResponseHelper createDebugResponseHelper(String debugFormat); public abstract DebugResponseHelper createDebugResponseHelper(String debugFormat);
} }

View File

@ -62,13 +62,13 @@ public interface ODataHttpHandler {
void setSplit(int split); void setSplit(int split);
/** /**
* Register this interface to support concurrency control for certain entity sets. * Registers support for concurrency control for certain entity sets.
* @param customETagSupport * @param customETagSupport
*/ */
void register(CustomETagSupport customConcurrencyControlSupport); void register(CustomETagSupport customConcurrencyControlSupport);
/** /**
* Register the debug support handler * Registers the debug support handler.
* @param debugSupport * @param debugSupport
*/ */
void register(DebugSupport debugSupport); void register(DebugSupport debugSupport);

View File

@ -19,11 +19,9 @@
package org.apache.olingo.server.api; package org.apache.olingo.server.api;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpMethod; import org.apache.olingo.commons.api.http.HttpMethod;
/** /**
@ -93,26 +91,22 @@ public class ODataRequest {
} }
/** /**
* Get header values for a given name. * Gets header values for a given name.
* @param name the header name as a case-insensitive key * @param name the header name as a case-insensitive key
* @return the header value(s) or null if not found * @return the header value(s) or null if not found
*/ */
public List<String> getHeaders(final String name) { public List<String> getHeaders(final String name) {
HttpHeader h = headers.getHeader(name); return headers.getHeader(name);
if(h == null) {
return null;
}
return new ArrayList<String>(h.getValues());
} }
/** /**
* Get first header value for a given name. * Gets first header value for a given name.
* @param name the header name as a case-insensitive key * @param name the header name as a case-insensitive key
* @return the first header value or null if not found * @return the first header value or null if not found
*/ */
public String getHeader(final String name) { public String getHeader(final String name) {
final List<String> values = getHeaders(name); final List<String> values = getHeaders(name);
return values == null ? null : values.get(0); return values == null || values.isEmpty() ? null : values.get(0);
} }
/** /**
@ -123,7 +117,6 @@ public class ODataRequest {
return headers.getHeaderToValues(); return headers.getHeaderToValues();
} }
/** /**
* Gets the body of the request. * Gets the body of the request.
* @return the request payload as {@link InputStream} or null * @return the request payload as {@link InputStream} or null

View File

@ -19,11 +19,9 @@
package org.apache.olingo.server.api; package org.apache.olingo.server.api;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.commons.api.http.HttpStatusCode;
/** /**
@ -102,11 +100,7 @@ public class ODataResponse {
* @return the header value(s) or null if not found * @return the header value(s) or null if not found
*/ */
public List<String> getHeaders(final String name) { public List<String> getHeaders(final String name) {
HttpHeader h = headers.getHeader(name); return headers.getHeader(name);
if(h == null) {
return null;
}
return new ArrayList<String>(h.getValues());
} }
/** /**
@ -118,7 +112,7 @@ public class ODataResponse {
*/ */
public String getHeader(final String name) { public String getHeader(final String name) {
final List<String> values = getHeaders(name); final List<String> values = getHeaders(name);
return values == null ? null : values.get(0); return values == null || values.isEmpty() ? null : values.get(0);
} }

View File

@ -25,50 +25,49 @@ import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart; import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
/** /**
* Provides methods to process {@link ODataRequest} and {@link BatchRequestPart}. * <p>Provides methods to process {@link ODataRequest}s and {@link BatchRequestPart}s
* in the context of a batch request.</p>
* *
* Within a {@link org.apache.olingo.server.api.processor.BatchProcessor} implementation BatchRequestsParts * <p>Within a {@link org.apache.olingo.server.api.processor.BatchProcessor BatchProcessor}
* should be passed to {@link BatchFacade#handleBatchRequest(BatchRequestPart)}. * implementation BatchRequestParts should be passed to {@link #handleBatchRequest(BatchRequestPart)}.
* If only if the BatchRequests part represents a change set, the request will be delegated to * Only if the BatchRequestPart represents a change set, the request will be delegated to
* {@link org.apache.olingo.server.api.processor.BatchProcessor#processChangeSet(BatchFacade, java.util.List)}. * {@link org.apache.olingo.server.api.processor.BatchProcessor#processChangeSet(BatchFacade, java.util.List)}.
* Otherwise the requests will be directly executed. * Otherwise the requests will be directly executed.</p>
* *
* The processor implementation could use {@link BatchFacade#handleODataRequest(ODataRequest)} to processes * <p>The processor implementation could use {@link #handleODataRequest(ODataRequest)} to process
* requests in a change set. * requests in a change set.</p>
*/ */
public interface BatchFacade { public interface BatchFacade {
/** /**
* Executes a ODataRequest, which must be a part of a change set. * Executes an ODataRequest, which must be a part of a change set.
* Each requests must have a Content-Id header field, which holds an id that is unique in the whole batch request. * Each request must have a Content-Id header field, which holds an identifier
* * that is unique in the whole batch request.
* @param request ODataRequest to process * @param request ODataRequest to process
* @return Corresponding ODataResult to the given request * @return corresponding ODataResponse to the given request
* @throws ODataApplicationException * @throws ODataApplicationException
* @throws ODataLibraryException * @throws ODataLibraryException
*/ */
public ODataResponse handleODataRequest(ODataRequest request) throws ODataApplicationException, public ODataResponse handleODataRequest(ODataRequest request)
ODataLibraryException; throws ODataApplicationException, ODataLibraryException;
/** /**
* Handles a BatchRequestPart. * Handles a BatchRequestPart.
*
* @param request Request to process * @param request Request to process
* @return Corresponding {@link ODataResponsePart} * @return corresponding {@link ODataResponsePart}
* @throws ODataApplicationException * @throws ODataApplicationException
* @throws ODataLibraryException * @throws ODataLibraryException
*/ */
public ODataResponsePart handleBatchRequest(BatchRequestPart request) throws ODataApplicationException, public ODataResponsePart handleBatchRequest(BatchRequestPart request)
ODataLibraryException; throws ODataApplicationException, ODataLibraryException;
/** /**
* Extracts the boundary of a multipart/mixed header. * Extracts the boundary of a multipart/mixed header.
* See RFC 2046#5.1 * See RFC 2046#5.1
*
* @param contentType Content Type * @param contentType Content Type
* @return Boundary * @return boundary
* @throws ODataApplicationException * @throws ODataApplicationException
* @throws ODataLibraryException * @throws ODataLibraryException
*/ */
public String extractBoundaryFromContentType(String contentType) throws ODataApplicationException, public String extractBoundaryFromContentType(String contentType)
ODataLibraryException; throws ODataApplicationException, ODataLibraryException;
} }

View File

@ -21,18 +21,14 @@ package org.apache.olingo.server.api.debug;
import org.apache.olingo.server.api.ODataResponse; import org.apache.olingo.server.api.ODataResponse;
/** /**
* This class supports applications in creating debug responses. * Support for applications creating debug responses.
*/ */
public interface DebugResponseHelper { public interface DebugResponseHelper {
/** /**
* Creates a debug response based on the given parameters. Will never throw an exception. * Creates a debug response based on the given parameters. Will never throw an exception.
* @param request * @param debugInfo debug information
* @param applicationResponse * @return the debug response or the raw application response in case an exception occurred
* @param exception
* @param serverEnvironmentVaribles
* @param runtimeInformation
* @return the debug response or the raw application response in case an exception occurred.
*/ */
ODataResponse createDebugResponse(DebugInformation debugInfo); ODataResponse createDebugResponse(DebugInformation debugInfo);
} }

View File

@ -30,10 +30,10 @@ import org.apache.olingo.commons.api.edm.EdmProperty;
public interface ODataDeserializer { public interface ODataDeserializer {
/** /**
* Deserializes an entity stream into an {@link org.apache.olingo.commons.api.data.Entity} object. * Deserializes an entity stream into an {@link org.apache.olingo.commons.api.data.Entity Entity} object.
* Validates: property types, no double properties, correct json types * Validates: property types, no double properties, correct json types.
* Returns a deserialized {@link org.apache.olingo.commons.api.data.Entity} object and an * Returns a deserialized {@link org.apache.olingo.commons.api.data.Entity Entity} object and an
* {@link org.apache.olingo.server.api.uri.queryoption.ExpandOption} object * {@link org.apache.olingo.server.api.uri.queryoption.ExpandOption ExpandOption} object.
* @param stream * @param stream
* @param edmEntityType * @param edmEntityType
* @return {@link DeserializerResult#getEntity()} and {@link DeserializerResult#getExpandTree()} * @return {@link DeserializerResult#getEntity()} and {@link DeserializerResult#getExpandTree()}
@ -42,7 +42,8 @@ public interface ODataDeserializer {
DeserializerResult entity(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException; DeserializerResult entity(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
/** /**
* Deserializes an entity collection stream into an {@link org.apache.olingo.commons.api.data.EntityCollection} object * Deserializes an entity collection stream into an
* {@link org.apache.olingo.commons.api.data.EntityCollection EntityCollection} object.
* @param stream * @param stream
* @param edmEntityType * @param edmEntityType
* @return {@link DeserializerResult#getEntityCollection()} * @return {@link DeserializerResult#getEntityCollection()}
@ -51,7 +52,7 @@ public interface ODataDeserializer {
DeserializerResult entityCollection(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException; DeserializerResult entityCollection(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
/** /**
* Deserializes an action-parameters stream into an {@link org.apache.olingo.commons.api.data.Entity} object. * Deserializes an action-parameters stream into a map of key/value pairs.
* Validates: parameter types, no double parameters, correct json types. * Validates: parameter types, no double parameters, correct json types.
* @param stream * @param stream
* @param edmAction * @param edmAction
@ -61,7 +62,7 @@ public interface ODataDeserializer {
DeserializerResult actionParameters(InputStream stream, EdmAction edmAction) throws DeserializerException; DeserializerResult actionParameters(InputStream stream, EdmAction edmAction) throws DeserializerException;
/** /**
* Deserializes the Property or collections of properties (primitive & complex) * Deserializes the Property or collections of properties (primitive & complex).
* @param stream * @param stream
* @param edmProperty * @param edmProperty
* @return {@link DeserializerResult#getProperty()} * @return {@link DeserializerResult#getProperty()}
@ -70,7 +71,7 @@ public interface ODataDeserializer {
DeserializerResult property(InputStream stream, EdmProperty edmProperty) throws DeserializerException; DeserializerResult property(InputStream stream, EdmProperty edmProperty) throws DeserializerException;
/** /**
* Read entity references from the provided document * Reads entity references from the provided document.
* @param stream * @param stream
* @param keys * @param keys
* @return {@link DeserializerResult#getEntityReferences()} * @return {@link DeserializerResult#getEntityReferences()}

View File

@ -22,26 +22,49 @@ import org.apache.olingo.server.api.deserializer.DeserializerException;
public class BatchDeserializerException extends DeserializerException { public class BatchDeserializerException extends DeserializerException {
public static enum MessageKeys implements MessageKey { public static enum MessageKeys implements MessageKey {
/** parameter: line */
INVALID_BOUNDARY, INVALID_BOUNDARY,
/** parameter: line */
INVALID_CHANGESET_METHOD, INVALID_CHANGESET_METHOD,
/** parameter: line */
INVALID_CONTENT, INVALID_CONTENT,
/** parameter: line */
INVALID_CONTENT_LENGTH, INVALID_CONTENT_LENGTH,
/** parameter: line */
INVALID_CONTENT_TRANSFER_ENCODING, INVALID_CONTENT_TRANSFER_ENCODING,
/** parameter: line */
INVALID_CONTENT_TYPE, INVALID_CONTENT_TYPE,
INVALID_HEADER, /** parameters: line, expected content type, actual content type */
UNEXPECTED_CONTENT_TYPE,
/** parameter: line */
INVALID_CONTENT_ID,
/** parameter: line */
INVALID_HTTP_VERSION, INVALID_HTTP_VERSION,
/** parameter: line */
INVALID_METHOD, INVALID_METHOD,
/** parameter: line */
INVALID_QUERY_OPERATION_METHOD, INVALID_QUERY_OPERATION_METHOD,
/** parameter: line */
INVALID_STATUS_LINE, INVALID_STATUS_LINE,
/** parameter: line */
INVALID_URI, INVALID_URI,
/** parameter: line */
MISSING_BLANK_LINE, MISSING_BLANK_LINE,
/** parameter: line */
MISSING_BOUNDARY_DELIMITER, MISSING_BOUNDARY_DELIMITER,
/** parameter: line */
MISSING_CLOSE_DELIMITER, MISSING_CLOSE_DELIMITER,
/** parameter: line */
MISSING_CONTENT_ID, MISSING_CONTENT_ID,
/** parameter: line */
MISSING_CONTENT_TRANSFER_ENCODING, MISSING_CONTENT_TRANSFER_ENCODING,
/** parameter: line */
MISSING_CONTENT_TYPE, MISSING_CONTENT_TYPE,
/** parameter: line */
MISSING_MANDATORY_HEADER, MISSING_MANDATORY_HEADER,
/** parameter: line */
FORBIDDEN_HEADER, FORBIDDEN_HEADER,
/** parameter: line */
INVALID_BASE_URI; INVALID_BASE_URI;
@Override @Override

View File

@ -20,9 +20,8 @@ package org.apache.olingo.server.api.deserializer.batch;
/** /**
* Options for the batch deserializer. * Options for the batch deserializer.
* See * @see org.apache.olingo.server.api.deserializer.FixedFormatDeserializer
* {@link org.apache.olingo.server.api.deserializer.FixedFormatDeserializer * #parseBatchRequest(java.io.InputStream, String, BatchOptions)
* #parseBatchRequest(java.io.InputStream, String, BatchOptions)}
*/ */
public final class BatchOptions { public final class BatchOptions {
private boolean isStrict = true; private boolean isStrict = true;
@ -33,8 +32,7 @@ public final class BatchOptions {
/** /**
* Returns if the batch parsing is strict. * Returns if the batch parsing is strict.
* Default is true * Default is true.
*
* @return true if parsing is strict * @return true if parsing is strict
*/ */
public boolean isStrict() { public boolean isStrict() {
@ -42,22 +40,23 @@ public final class BatchOptions {
} }
/** /**
* See {@link org.apache.olingo.server.api.ODataRequest#getRawBaseUri()} * Gets raw base URI.
* @see org.apache.olingo.server.api.ODataRequest#getRawBaseUri()
*/ */
public String getRawBaseUri() { public String getRawBaseUri() {
return rawBaseUri; return rawBaseUri;
} }
/** /**
* See {@link org.apache.olingo.server.api.ODataRequest#getRawServiceResolutionUri()} * Gets raw service resolution URI.
* @see org.apache.olingo.server.api.ODataRequest#getRawServiceResolutionUri()
*/ */
public String getRawServiceResolutionUri() { public String getRawServiceResolutionUri() {
return rawServiceResolutionUri; return rawServiceResolutionUri;
} }
/** /**
* Creates a new BatchOptions builder * Creates a new BatchOptions builder.
*
* @return new BatchOptions builder instance * @return new BatchOptions builder instance
*/ */
public static Builder with() { public static Builder with() {
@ -76,7 +75,7 @@ public final class BatchOptions {
} }
/** /**
* See {@link BatchOptions#isStrict()} * @see BatchOptions#isStrict()
*/ */
public Builder isStrict(final boolean isStrict) { public Builder isStrict(final boolean isStrict) {
options.isStrict = isStrict; options.isStrict = isStrict;
@ -84,7 +83,7 @@ public final class BatchOptions {
} }
/** /**
* See {@link org.apache.olingo.server.api.ODataRequest#getRawBaseUri()} * @see org.apache.olingo.server.api.ODataRequest#getRawBaseUri()
*/ */
public Builder rawBaseUri(final String baseUri) { public Builder rawBaseUri(final String baseUri) {
options.rawBaseUri = baseUri; options.rawBaseUri = baseUri;
@ -92,7 +91,7 @@ public final class BatchOptions {
} }
/** /**
* See {@link org.apache.olingo.server.api.ODataRequest#getRawServiceResolutionUri()} * @see org.apache.olingo.server.api.ODataRequest#getRawServiceResolutionUri()
*/ */
public Builder rawServiceResolutionUri(final String serviceResolutionUri) { public Builder rawServiceResolutionUri(final String serviceResolutionUri) {
options.rawServiceResolutionUri = serviceResolutionUri; options.rawServiceResolutionUri = serviceResolutionUri;
@ -100,8 +99,7 @@ public final class BatchOptions {
} }
/** /**
* Creates a new BatchOptions instance * Creates a new BatchOptions instance.
*
* @return new BatchOptions instance * @return new BatchOptions instance
*/ */
public BatchOptions build() { public BatchOptions build() {

View File

@ -25,16 +25,14 @@ import java.util.List;
import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ODataRequest;
/** /**
* A BatchPart * Represents a distinct MIME part of a Batch Request body - either a Change Set or a Query Operation
* <p> BatchPart represents a distinct MIME part of a Batch Request body. It can be a ChangeSet or a Query Operation
*/ */
public class BatchRequestPart { public class BatchRequestPart {
private List<ODataRequest> requests = new ArrayList<ODataRequest>(); private List<ODataRequest> requests = new ArrayList<ODataRequest>();
private boolean isChangeSet; private boolean isChangeSet;
/** /**
* Creates a new instance of BachRequestPart * Creates a new instance of BachRequestPart.
*
* @param isChangeSet True, if this instance represents a change set * @param isChangeSet True, if this instance represents a change set
* @param requests A list of {@link ODataRequest} * @param requests A list of {@link ODataRequest}
*/ */
@ -44,8 +42,7 @@ public class BatchRequestPart {
} }
/** /**
* Creates a new instance of BachRequestPart * Creates a new instance of BachRequestPart.
*
* @param isChangeSet True, if this instance represents a change set * @param isChangeSet True, if this instance represents a change set
* @param request A single {@link ODataRequest} * @param request A single {@link ODataRequest}
*/ */
@ -56,7 +53,7 @@ public class BatchRequestPart {
} }
/** /**
* Get the info if a BatchPart is a ChangeSet * Gets the info if a BatchPart is a ChangeSet.
* @return true or false * @return true or false
*/ */
public boolean isChangeSet() { public boolean isChangeSet() {
@ -64,7 +61,7 @@ public class BatchRequestPart {
} }
/** /**
* Get requests. If a BatchPart is a Query Operation, the list contains one request. * Gets all requests of this part. If a BatchPart is a Query Operation, the list contains one request.
* @return a list of {@link ODataRequest} * @return a list of {@link ODataRequest}
*/ */
public List<ODataRequest> getRequests() { public List<ODataRequest> getRequests() {

View File

@ -21,7 +21,7 @@ package org.apache.olingo.server.api.serializer;
import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.server.api.uri.queryoption.CountOption; import org.apache.olingo.server.api.uri.queryoption.CountOption;
/** Options for the OData serializer. */ /** Options to pass as additional information to the reference-collection serializer. */
public final class ReferenceCollectionSerializerOptions { public final class ReferenceCollectionSerializerOptions {
private ContextURL contextURL; private ContextURL contextURL;
private CountOption count; private CountOption count;

View File

@ -21,7 +21,7 @@ package org.apache.olingo.server.api.serializer;
import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.ContextURL;
/** /**
* Use this options calls to pass additional information to the reference serializer. * Options to pass as additional information to the reference serializer.
*/ */
public final class ReferenceSerializerOptions { public final class ReferenceSerializerOptions {
private ContextURL contextURL; private ContextURL contextURL;

View File

@ -93,7 +93,8 @@ public class BatchParserCommon {
return type; return type;
} else { } else {
throw new BatchDeserializerException("Content type is not the expected content type", throw new BatchDeserializerException("Content type is not the expected content type",
BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE, expected.toContentTypeString()); BatchDeserializerException.MessageKeys.UNEXPECTED_CONTENT_TYPE,
Integer.toString(line), expected.toContentTypeString(), type.toContentTypeString());
} }
} }

View File

@ -84,14 +84,14 @@ public class BatchRequestTransformator {
} }
private HeaderField getContentId(final BatchQueryOperation queryOperation) throws BatchDeserializerException { private HeaderField getContentId(final BatchQueryOperation queryOperation) throws BatchDeserializerException {
final HeaderField contentTypeHeader = queryOperation.getHeaders().getHeaderField(HttpHeader.CONTENT_ID); final HeaderField contentIdHeader = queryOperation.getHeaders().getHeaderField(HttpHeader.CONTENT_ID);
if (contentTypeHeader != null) { if (contentIdHeader != null) {
if (contentTypeHeader.getValues().size() == 1) { if (contentIdHeader.getValues().size() == 1) {
return contentTypeHeader; return contentIdHeader;
} else { } else {
throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER, throw new BatchDeserializerException("Invalid Content-ID header", MessageKeys.INVALID_CONTENT_ID,
Integer.toString(contentTypeHeader.getLineNumber())); Integer.toString(contentIdHeader.getLineNumber()));
} }
} }

View File

@ -56,7 +56,8 @@ public class BatchTransformatorCommon {
Integer.toString(headers.getLineNumber())); Integer.toString(headers.getLineNumber()));
} }
} else { } else {
throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER, throw new BatchDeserializerException("Invalid Content-Transfer-Encoding header",
MessageKeys.INVALID_CONTENT_TRANSFER_ENCODING,
Integer.toString(headers.getLineNumber())); Integer.toString(headers.getLineNumber()));
} }
} else { } else {
@ -82,7 +83,7 @@ public class BatchTransformatorCommon {
return contentLength; return contentLength;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new BatchDeserializerException("Invalid header", e, MessageKeys.INVALID_HEADER, throw new BatchDeserializerException("Invalid content length", e, MessageKeys.INVALID_CONTENT_LENGTH,
Integer.toString(contentLengthField.getLineNumber())); Integer.toString(contentLengthField.getLineNumber()));
} }
} }

View File

@ -138,13 +138,13 @@ public class BatchResponseSerializer {
final Map<String, List<String>> header = response.getAllHeaders(); final Map<String, List<String>> header = response.getAllHeaders();
for (final Map.Entry<String, List<String>> entry : header.entrySet()) { for (final Map.Entry<String, List<String>> entry : header.entrySet()) {
// Requests do never has a content id header // Requests never have a content id header.
if (!entry.getKey().equalsIgnoreCase(HttpHeader.CONTENT_ID)) { if (!entry.getKey().equalsIgnoreCase(HttpHeader.CONTENT_ID)) {
appendHeader(entry.getKey(), entry.getValue().get(0), builder); appendHeader(entry.getKey(), entry.getValue().get(0), builder);
} }
} }
appendHeader(HttpHeader.CONTENT_LENGTH, "" + contentLength, builder); appendHeader(HttpHeader.CONTENT_LENGTH, Integer.toString(contentLength), builder);
} }
private void appendBodyPartHeader(final ODataResponse response, final BodyBuilder builder, private void appendBodyPartHeader(final ODataResponse response, final BodyBuilder builder,
@ -153,7 +153,7 @@ public class BatchResponseSerializer {
appendHeader(BatchParserCommon.CONTENT_TRANSFER_ENCODING, BatchParserCommon.BINARY_ENCODING, builder); appendHeader(BatchParserCommon.CONTENT_TRANSFER_ENCODING, BatchParserCommon.BINARY_ENCODING, builder);
if (isChangeSet) { if (isChangeSet) {
if (response.getAllHeaders().get(HttpHeader.CONTENT_ID) != null) { if (response.getHeader(HttpHeader.CONTENT_ID) != null) {
appendHeader(HttpHeader.CONTENT_ID, response.getHeader(HttpHeader.CONTENT_ID), builder); appendHeader(HttpHeader.CONTENT_ID, response.getHeader(HttpHeader.CONTENT_ID), builder);
} else { } else {
throw new BatchSerializerException("Missing content id", MessageKeys.MISSING_CONTENT_ID); throw new BatchSerializerException("Missing content id", MessageKeys.MISSING_CONTENT_ID);

View File

@ -126,14 +126,15 @@ DeserializerException.INVALID_NULL_PARAMETER=The parameter '%1$s' must not be nu
BatchDeserializerException.INVALID_BOUNDARY=Invalid boundary at line '%1$s'. BatchDeserializerException.INVALID_BOUNDARY=Invalid boundary at line '%1$s'.
BatchDeserializerException.INVALID_CHANGESET_METHOD=Invalid method: a ChangeSet cannot contain retrieve requests at line '%1$s'. BatchDeserializerException.INVALID_CHANGESET_METHOD=Invalid method: a ChangeSet cannot contain retrieve requests at line '%1$s'.
BatchDeserializerException.INVALID_CONTENT=Retrieve requests must not contain any body content '%1$s'. BatchDeserializerException.INVALID_CONTENT=The retrieve request at line '%1$s' must not contain any body content.
BatchDeserializerException.INVALID_CONTENT_LENGTH=Invalid content length: content length have to be an integer and positive at line '%1$s'. BatchDeserializerException.INVALID_CONTENT_LENGTH=The value of the Content-Length HTTP header at line '%1$s' must be a positive integer.
BatchDeserializerException.INVALID_CONTENT_TRANSFER_ENCODING=The Content-Transfer-Encoding should be binary: line '%1$s'. BatchDeserializerException.INVALID_CONTENT_TRANSFER_ENCODING=The Content-Transfer-Encoding at line '%1$s' must be binary.
BatchDeserializerException.INVALID_CONTENT_TYPE=Content-Type should be '%1$s'. BatchDeserializerException.INVALID_CONTENT_TYPE=Invalid Content-Type HTTP header at line '%1$s'.
BatchDeserializerException.INVALID_HEADER=Invalid header: '%1$s' at line '%2$s'. BatchDeserializerException.UNEXPECTED_CONTENT_TYPE=Content-Type at line '%1$s' should be '%2$s' but is '%3$s'.
BatchDeserializerException.INVALID_HTTP_VERSION=Invalid HTTP version: The version have to be HTTP/1.1 at line '%1$s'. BatchDeserializerException.INVALID_CONTENT_ID=Invalid Content-ID HTTP header at line '%1$s'.
BatchDeserializerException.INVALID_HTTP_VERSION=The HTTP version must be HTTP/1.1 at line '%1$s'.
BatchDeserializerException.INVALID_METHOD=Invalid HTTP method at line '%1$s'. BatchDeserializerException.INVALID_METHOD=Invalid HTTP method at line '%1$s'.
BatchDeserializerException.INVALID_QUERY_OPERATION_METHOD=Invalid method: a query operation can only contain retrieve requests at line '%1$s'. BatchDeserializerException.INVALID_QUERY_OPERATION_METHOD=The query operation at line '%1$s' can only contain retrieve requests.
BatchDeserializerException.INVALID_STATUS_LINE=Invalid HTTP status line at line '%1$s'. BatchDeserializerException.INVALID_STATUS_LINE=Invalid HTTP status line at line '%1$s'.
BatchDeserializerException.INVALID_URI=Invalid URI at line '%1$s'. BatchDeserializerException.INVALID_URI=Invalid URI at line '%1$s'.
BatchDeserializerException.FORBIDDEN_HEADER=Forbidden header at line '%1$s'. BatchDeserializerException.FORBIDDEN_HEADER=Forbidden header at line '%1$s'.
@ -144,9 +145,9 @@ BatchDeserializerException.MISSING_CONTENT_ID=Missing content-id at line '%1$s'.
BatchDeserializerException.MISSING_CONTENT_TRANSFER_ENCODING=Missing content transfer encoding at line '%1$s'. BatchDeserializerException.MISSING_CONTENT_TRANSFER_ENCODING=Missing content transfer encoding at line '%1$s'.
BatchDeserializerException.MISSING_CONTENT_TYPE=Missing content-type at line '%1$s'. BatchDeserializerException.MISSING_CONTENT_TYPE=Missing content-type at line '%1$s'.
BatchDeserializerException.MISSING_MANDATORY_HEADER=Missing mandatory header at line '%1$s'. BatchDeserializerException.MISSING_MANDATORY_HEADER=Missing mandatory header at line '%1$s'.
BatchDeserializerException.INVALID_BASE_URI=The base URI do not match the service base URI at line '%1$s'. BatchDeserializerException.INVALID_BASE_URI=The base URI does not match the service base URI at line '%1$s'.
BatchSerializerExecption.MISSING_CONTENT_ID=Each request within a change set required exactly one content id. BatchSerializerExecption.MISSING_CONTENT_ID=Each request within a change set requires exactly one content id.
PreconditionException.MISSING_HEADER=The Operation you requested on this Entity requires an if-match or if-none-match header. PreconditionException.MISSING_HEADER=The Operation you requested on this Entity requires an if-match or if-none-match header.
PreconditionException.FAILED=The If-Match precondition is not fulfilled. PreconditionException.FAILED=The If-Match precondition is not fulfilled.

View File

@ -393,7 +393,7 @@ public class BatchRequestParserTest {
} }
@Test @Test
public void testMimeHeaderContentType() throws Exception { public void mimeHeaderContentType() throws Exception {
final String batch = "--batch_8194-cf13-1f56" + CRLF final String batch = "--batch_8194-cf13-1f56" + CRLF
+ "Content-Type: text/plain" + CRLF + "Content-Type: text/plain" + CRLF
+ "Content-Transfer-Encoding: binary" + CRLF + "Content-Transfer-Encoding: binary" + CRLF
@ -403,7 +403,7 @@ public class BatchRequestParserTest {
+ CRLF + CRLF
+ "--batch_8194-cf13-1f56--"; + "--batch_8194-cf13-1f56--";
parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE); parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.UNEXPECTED_CONTENT_TYPE);
} }
@Test @Test
@ -536,7 +536,7 @@ public class BatchRequestParserTest {
} }
@Test @Test
public void testNestedChangeset() throws Exception { public void nestedChangeset() throws Exception {
final String batch = "" final String batch = ""
+ "--batch_8194-cf13-1f56" + CRLF + "--batch_8194-cf13-1f56" + CRLF
+ "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + CRLF + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + CRLF
@ -559,7 +559,7 @@ public class BatchRequestParserTest {
+ CRLF + CRLF
+ "--batch_8194-cf13-1f56--"; + "--batch_8194-cf13-1f56--";
parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE); parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.UNEXPECTED_CONTENT_TYPE);
} }
@Test @Test
@ -801,7 +801,7 @@ public class BatchRequestParserTest {
} }
@Test @Test
public void testNonNumericContentLength() throws Exception { public void nonNumericContentLength() throws Exception {
final String batch = "" final String batch = ""
+ "--batch_8194-cf13-1f56" + CRLF + "--batch_8194-cf13-1f56" + CRLF
+ "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
@ -819,7 +819,7 @@ public class BatchRequestParserTest {
+ CRLF + CRLF
+ "--batch_8194-cf13-1f56--"; + "--batch_8194-cf13-1f56--";
parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_HEADER); parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_LENGTH);
} }
@Test @Test

View File

@ -34,7 +34,7 @@ public class AsyncResponseSerializerTest {
private static final String CRLF = "\r\n"; private static final String CRLF = "\r\n";
@Test @Test
public void testSimpleResponse() throws Exception { public void simpleResponse() throws Exception {
ODataResponse response = new ODataResponse(); ODataResponse response = new ODataResponse();
response.setStatusCode(HttpStatusCode.OK.getStatusCode()); response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString()); response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString());
@ -45,14 +45,14 @@ public class AsyncResponseSerializerTest {
AsyncResponseSerializer serializer = new AsyncResponseSerializer(); AsyncResponseSerializer serializer = new AsyncResponseSerializer();
InputStream in = serializer.serialize(response); InputStream in = serializer.serialize(response);
String result = IOUtils.toString(in); String result = IOUtils.toString(in);
assertEquals("HTTP/1.1 200 OK" + CRLF + assertEquals("HTTP/1.1 200 OK" + CRLF
"Content-Length: 200" + CRLF + + "Content-Type: application/json" + CRLF
"Content-Type: application/json" + CRLF + CRLF + + "Content-Length: 200" + CRLF + CRLF
"Walter Winter" + CRLF, result); + "Walter Winter" + CRLF, result);
} }
@Test @Test
public void testBiggerResponse() throws Exception { public void biggerResponse() throws Exception {
ODataResponse response = new ODataResponse(); ODataResponse response = new ODataResponse();
response.setStatusCode(HttpStatusCode.ACCEPTED.getStatusCode()); response.setStatusCode(HttpStatusCode.ACCEPTED.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString()); response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString());
@ -64,10 +64,10 @@ public class AsyncResponseSerializerTest {
AsyncResponseSerializer serializer = new AsyncResponseSerializer(); AsyncResponseSerializer serializer = new AsyncResponseSerializer();
InputStream in = serializer.serialize(response); InputStream in = serializer.serialize(response);
String result = IOUtils.toString(in); String result = IOUtils.toString(in);
assertEquals("HTTP/1.1 202 Accepted" + CRLF + assertEquals("HTTP/1.1 202 Accepted" + CRLF
"Content-Length: 0" + CRLF + + "Content-Type: application/json" + CRLF
"Content-Type: application/json" + CRLF + CRLF + + "Content-Length: 0" + CRLF + CRLF
testData, result); + testData, result);
} }
private String testData(int amount) { private String testData(int amount) {