[OLINGO-447] Also accept the * accept header

This commit is contained in:
Christian Amend 2014-09-30 17:22:36 +02:00
parent bd4ad859a6
commit 34825ab062
3 changed files with 30 additions and 12 deletions

View File

@ -18,17 +18,19 @@
*/ */
package org.apache.olingo.fit.tecsvc.http; package org.apache.olingo.fit.tecsvc.http;
import org.apache.olingo.commons.api.format.ContentType; import static org.junit.Assert.assertEquals;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
import org.junit.Test;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import static org.junit.Assert.assertEquals; import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.fit.AbstractBaseTestITCase;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
import org.junit.Test;
public class BasicHttpITCase { public class BasicHttpITCase extends AbstractBaseTestITCase{
private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/"; private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/";
@ -114,6 +116,12 @@ public class BasicHttpITCase {
assertEquals("4.0", v); assertEquals("4.0", v);
} }
@Override
protected CommonODataClient<?> getClient() {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.apache.olingo.fit.tecsvc.http; package org.apache.olingo.fit.tecsvc.http;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.fit.AbstractBaseTestITCase;
import org.apache.olingo.fit.tecsvc.TecSvcConst; import org.apache.olingo.fit.tecsvc.TecSvcConst;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -28,7 +30,7 @@ import java.net.URL;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class PingITCase { public class PingITCase extends AbstractBaseTestITCase{
private static final Logger LOG = LoggerFactory.getLogger(PingITCase.class); private static final Logger LOG = LoggerFactory.getLogger(PingITCase.class);
@ -64,4 +66,9 @@ public class PingITCase {
assertEquals(200, code); assertEquals(200, code);
} }
@Override
protected CommonODataClient<?> getClient() {
return null;
}
} }

View File

@ -27,7 +27,7 @@ import java.util.TreeMap;
/** /**
* Internally used {@link AcceptType} for OData library. * Internally used {@link AcceptType} for OData library.
* *
* See RFC 7231, chapter 5.3.2: * See RFC 7231, chapter 5.3.2:
* <pre> * <pre>
* Accept = #( media-range [ accept-params ] ) * Accept = #( media-range [ accept-params ] )
@ -74,11 +74,11 @@ public class AcceptType {
} }
List<String> typeSubtype = new ArrayList<String>(); List<String> typeSubtype = new ArrayList<String>();
parameters = createParameterMap(); parameters = createParameterMap();
parse(type, typeSubtype, parameters); parse(type, typeSubtype, parameters);
this.type = typeSubtype.get(0); this.type = typeSubtype.get(0);
subtype = typeSubtype.get(1); subtype = typeSubtype.get(1);
if (TypeUtil.MEDIA_TYPE_WILDCARD.equals(this.type) && !TypeUtil.MEDIA_TYPE_WILDCARD.equals(subtype)) { if (TypeUtil.MEDIA_TYPE_WILDCARD.equals(this.type) && !TypeUtil.MEDIA_TYPE_WILDCARD.equals(subtype)) {
throw new IllegalArgumentException("Illegal combination of WILDCARD type with NONE WILDCARD subtype."); throw new IllegalArgumentException("Illegal combination of WILDCARD type with NONE WILDCARD subtype.");
} }
@ -97,7 +97,7 @@ public class AcceptType {
private static void parse(final String format, final List<String> typeSubtype, private static void parse(final String format, final List<String> typeSubtype,
final Map<String, String> parameters) { final Map<String, String> parameters) {
final String[] typesAndParameters = format.split(TypeUtil.PARAMETER_SEPARATOR, 2); final String[] typesAndParameters = format.split(TypeUtil.PARAMETER_SEPARATOR, 2);
final String types = typesAndParameters[0]; final String types = typesAndParameters[0];
final String params = (typesAndParameters.length > 1 ? typesAndParameters[1] : null); final String params = (typesAndParameters.length > 1 ? typesAndParameters[1] : null);
@ -112,6 +112,9 @@ public class AcceptType {
typeSubtype.add(tokens[0]); typeSubtype.add(tokens[0]);
typeSubtype.add(tokens[1]); typeSubtype.add(tokens[1]);
} }
} else if (tokens.length == 1 && "*".equals(tokens[0])) {
typeSubtype.add(tokens[0]);
typeSubtype.add(tokens[0]);
} else { } else {
throw new IllegalArgumentException("Not exactly one '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR + throw new IllegalArgumentException("Not exactly one '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR +
"' in format '" + format + "', or it is at the beginning or at the end."); "' in format '" + format + "', or it is at the beginning or at the end.");
@ -135,7 +138,7 @@ public class AcceptType {
} }
sort(result); sort(result);
return result; return result;
} }