[OLINGO-704] Fix: OData Server supports only odata.metadata=minimal
This commit is contained in:
parent
9998ba6748
commit
e32034bd54
|
@ -309,7 +309,7 @@ public class ActionImportITCase extends AbstractBaseTestITCase {
|
|||
@Override
|
||||
protected ODataClient getClient() {
|
||||
ODataClient odata = ODataClientFactory.getClient();
|
||||
odata.getConfiguration().setDefaultPubFormat(ContentType.JSON_NO_METADATA);
|
||||
odata.getConfiguration().setDefaultPubFormat(ContentType.JSON);
|
||||
return odata;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,85 +51,99 @@ import org.apache.olingo.server.core.uri.UriHelperImpl;
|
|||
|
||||
public class ODataImpl extends OData {
|
||||
|
||||
@Override
|
||||
public ODataSerializer createSerializer(final ContentType contentType) throws SerializerException {
|
||||
ODataSerializer serializer;
|
||||
|
||||
// odata.metadata=none, odata.metadata=minimal, odata.metadata=full
|
||||
if(contentType.isCompatible(ContentType.APPLICATION_JSON)) {
|
||||
serializer = new ODataJsonSerializer(contentType);
|
||||
} else if(contentType.isCompatible(ContentType.APPLICATION_XML)) {
|
||||
serializer = new ODataXmlSerializerImpl();
|
||||
} else {
|
||||
throw new SerializerException("Unsupported format: " + contentType.toContentTypeString(),
|
||||
SerializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
|
||||
}
|
||||
@Override
|
||||
public ODataSerializer createSerializer(final ContentType contentType)
|
||||
throws SerializerException {
|
||||
ODataSerializer serializer;
|
||||
|
||||
return serializer;
|
||||
}
|
||||
// odata.metadata=none, odata.metadata=minimal, odata.metadata=full
|
||||
if (contentType.isCompatible(ContentType.APPLICATION_JSON)
|
||||
&& ContentType.VALUE_ODATA_METADATA_MINIMAL
|
||||
.equals(contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA))) {
|
||||
serializer = new ODataJsonSerializer(contentType);
|
||||
} else if (contentType.isCompatible(ContentType.APPLICATION_XML)) {
|
||||
serializer = new ODataXmlSerializerImpl();
|
||||
} else {
|
||||
throw new SerializerException("Unsupported format: "
|
||||
+ contentType.toContentTypeString(),
|
||||
SerializerException.MessageKeys.UNSUPPORTED_FORMAT,
|
||||
contentType.toContentTypeString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FixedFormatSerializer createFixedFormatSerializer() {
|
||||
return new FixedFormatSerializerImpl();
|
||||
}
|
||||
return serializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataHttpHandler createHandler(final ServiceMetadata edm) {
|
||||
return new ODataHttpHandlerImpl(this, edm);
|
||||
}
|
||||
@Override
|
||||
public FixedFormatSerializer createFixedFormatSerializer() {
|
||||
return new FixedFormatSerializerImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceMetadata createServiceMetadata(final CsdlEdmProvider edmProvider,
|
||||
final List<EdmxReference> references) {
|
||||
return createServiceMetadata(edmProvider, references, null);
|
||||
}
|
||||
@Override
|
||||
public ODataHttpHandler createHandler(final ServiceMetadata edm) {
|
||||
return new ODataHttpHandlerImpl(this, edm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceMetadata createServiceMetadata(CsdlEdmProvider edmProvider, List<EdmxReference> references,
|
||||
ServiceMetadataETagSupport serviceMetadataETagSupport) {
|
||||
return new ServiceMetadataImpl(edmProvider, references, serviceMetadataETagSupport);
|
||||
}
|
||||
@Override
|
||||
public ServiceMetadata createServiceMetadata(
|
||||
final CsdlEdmProvider edmProvider,
|
||||
final List<EdmxReference> references) {
|
||||
return createServiceMetadata(edmProvider, references, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FixedFormatDeserializer createFixedFormatDeserializer() {
|
||||
return new FixedFormatDeserializerImpl();
|
||||
}
|
||||
@Override
|
||||
public ServiceMetadata createServiceMetadata(CsdlEdmProvider edmProvider,
|
||||
List<EdmxReference> references,
|
||||
ServiceMetadataETagSupport serviceMetadataETagSupport) {
|
||||
return new ServiceMetadataImpl(edmProvider, references,
|
||||
serviceMetadataETagSupport);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UriHelper createUriHelper() {
|
||||
return new UriHelperImpl();
|
||||
}
|
||||
@Override
|
||||
public FixedFormatDeserializer createFixedFormatDeserializer() {
|
||||
return new FixedFormatDeserializerImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataDeserializer createDeserializer(final ContentType contentType) throws DeserializerException {
|
||||
ODataDeserializer deserializer;
|
||||
|
||||
// odata.metadata=none, odata.metadata=minimal, odata.metadata=full
|
||||
if(contentType.isCompatible(ContentType.JSON)) {
|
||||
deserializer = new ODataJsonDeserializer(contentType);
|
||||
//} else if(contentType.isCompatible(ContentType.APPLICATION_XML)) {
|
||||
// We do not support XML deserialization right now so this must lead to an error.
|
||||
} else {
|
||||
throw new DeserializerException("Unsupported format: " + contentType.toContentTypeString(),
|
||||
DeserializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
|
||||
}
|
||||
|
||||
return deserializer;
|
||||
}
|
||||
@Override
|
||||
public UriHelper createUriHelper() {
|
||||
return new UriHelperImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmPrimitiveType createPrimitiveTypeInstance(final EdmPrimitiveTypeKind kind) {
|
||||
return EdmPrimitiveTypeFactory.getInstance(kind);
|
||||
}
|
||||
@Override
|
||||
public ODataDeserializer createDeserializer(final ContentType contentType)
|
||||
throws DeserializerException {
|
||||
ODataDeserializer deserializer;
|
||||
|
||||
@Override
|
||||
public ETagHelper createETagHelper() {
|
||||
return new ETagHelperImpl();
|
||||
}
|
||||
// odata.metadata=none, odata.metadata=minimal, odata.metadata=full
|
||||
if (contentType.isCompatible(ContentType.JSON)) {
|
||||
deserializer = new ODataJsonDeserializer(contentType);
|
||||
// } else if(contentType.isCompatible(ContentType.APPLICATION_XML))
|
||||
// We do not support XML deserialization right now so this must lead
|
||||
// to an error.
|
||||
// {
|
||||
} else {
|
||||
throw new DeserializerException("Unsupported format: "
|
||||
+ contentType.toContentTypeString(),
|
||||
DeserializerException.MessageKeys.UNSUPPORTED_FORMAT,
|
||||
contentType.toContentTypeString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Preferences createPreferences(final Collection<String> preferHeaders) {
|
||||
return new PreferencesImpl(preferHeaders);
|
||||
}
|
||||
return deserializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmPrimitiveType createPrimitiveTypeInstance(
|
||||
final EdmPrimitiveTypeKind kind) {
|
||||
return EdmPrimitiveTypeFactory.getInstance(kind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ETagHelper createETagHelper() {
|
||||
return new ETagHelperImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Preferences createPreferences(final Collection<String> preferHeaders) {
|
||||
return new PreferencesImpl(preferHeaders);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.olingo.server.core;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ODataImplTest {
|
||||
|
||||
private final OData odata = OData.newInstance();
|
||||
|
||||
@Test(expected=SerializerException.class)
|
||||
public void testJsonSerializerForOdataMetadataNone() throws SerializerException {
|
||||
odata.createSerializer(ContentType.JSON_NO_METADATA);
|
||||
}
|
||||
|
||||
@Test(expected=SerializerException.class)
|
||||
public void testJsonSerializerForODataMetadataFull() throws SerializerException {
|
||||
odata.createSerializer(ContentType.JSON_FULL_METADATA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateJsonSerializerForODataMetadataMinimal() throws SerializerException {
|
||||
final ODataSerializer serializer = odata.createSerializer(ContentType.JSON);
|
||||
|
||||
assertNotNull(serializer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateJsonDeserialierForODataMetadataMinimal() throws DeserializerException {
|
||||
final ODataDeserializer deserializer = odata.createDeserializer(ContentType.JSON);
|
||||
|
||||
assertNotNull(deserializer);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue