minor improvements
Change-Id: Ia9872a613f3221e2de885f9d325a14f3c50b4beb Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
parent
68f51d84d0
commit
f947afc108
|
@ -114,12 +114,10 @@ public class TomcatTestServer {
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(portParam[1]);
|
return Integer.parseInt(portParam[1]);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new IllegalArgumentException("Port parameter (" + portParameter +
|
throw new IllegalArgumentException("Port parameter (" + portParameter + ") could not be parsed.");
|
||||||
") could not be parsed.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Port parameter (" + portParameter +
|
throw new IllegalArgumentException("Port parameter (" + portParameter + ") could not be parsed.");
|
||||||
") could not be parsed.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StaticContent extends HttpServlet {
|
public static class StaticContent extends HttpServlet {
|
||||||
|
@ -152,6 +150,7 @@ public class TomcatTestServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TestServerBuilder builder;
|
private static TestServerBuilder builder;
|
||||||
|
|
||||||
public static TestServerBuilder init(int port) {
|
public static TestServerBuilder init(int port) {
|
||||||
if (builder == null) {
|
if (builder == null) {
|
||||||
builder = new TestServerBuilder(port);
|
builder = new TestServerBuilder(port);
|
||||||
|
@ -240,7 +239,8 @@ public class TomcatTestServer {
|
||||||
return new File(targetURL.getFile());
|
return new File(targetURL.getFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestServerBuilder addServlet(final Class<? extends HttpServlet> factoryClass, String path) throws Exception {
|
public TestServerBuilder addServlet(final Class<? extends HttpServlet> factoryClass, String path)
|
||||||
|
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
|
||||||
if (server != null) {
|
if (server != null) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.fit;
|
package org.apache.olingo.fit;
|
||||||
|
|
||||||
|
import org.apache.catalina.LifecycleException;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.olingo.client.api.CommonODataClient;
|
import org.apache.olingo.client.api.CommonODataClient;
|
||||||
import org.apache.olingo.commons.api.data.Entity;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
|
@ -37,6 +38,7 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
@ -48,12 +50,11 @@ public abstract class AbstractBaseTestITCase {
|
||||||
*/
|
*/
|
||||||
protected static final Logger LOG = LoggerFactory.getLogger(AbstractBaseTestITCase.class);
|
protected static final Logger LOG = LoggerFactory.getLogger(AbstractBaseTestITCase.class);
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
protected abstract CommonODataClient<?> getClient();
|
||||||
protected abstract CommonODataClient getClient();
|
|
||||||
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void init() throws Exception {
|
public static void init()
|
||||||
|
throws LifecycleException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
|
||||||
TomcatTestServer.init(9080)
|
TomcatTestServer.init(9080)
|
||||||
.addServlet(TechnicalServlet.class, "/olingo-server-tecsvc/odata.svc/*")
|
.addServlet(TechnicalServlet.class, "/olingo-server-tecsvc/odata.svc/*")
|
||||||
.addServlet(StaticContent.class, "/olingo-server-tecsvc/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml")
|
.addServlet(StaticContent.class, "/olingo-server-tecsvc/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml")
|
||||||
|
@ -128,8 +129,8 @@ public abstract class AbstractBaseTestITCase {
|
||||||
|
|
||||||
public static class StaticContent extends HttpServlet {
|
public static class StaticContent extends HttpServlet {
|
||||||
private static final long serialVersionUID = -6663569573355398997L;
|
private static final long serialVersionUID = -6663569573355398997L;
|
||||||
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
@Override
|
||||||
throws ServletException, IOException {
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
resp.getOutputStream().write(IOUtils.toByteArray(
|
resp.getOutputStream().write(IOUtils.toByteArray(
|
||||||
Thread.currentThread().getContextClassLoader().getResourceAsStream("org-odata-core-v1.xml")));
|
Thread.currentThread().getContextClassLoader().getResourceAsStream("org-odata-core-v1.xml")));
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,25 +53,16 @@ import org.apache.olingo.commons.api.format.ODataFormat;
|
||||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||||
import org.apache.olingo.fit.AbstractBaseTestITCase;
|
import org.apache.olingo.fit.AbstractBaseTestITCase;
|
||||||
import org.apache.olingo.fit.tecsvc.TecSvcConst;
|
import org.apache.olingo.fit.tecsvc.TecSvcConst;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class BasicITCase extends AbstractBaseTestITCase {
|
public class BasicITCase extends AbstractBaseTestITCase {
|
||||||
|
|
||||||
private static final String SERVICE_URI = TecSvcConst.BASE_URI;
|
private static final String SERVICE_URI = TecSvcConst.BASE_URI;
|
||||||
|
|
||||||
private ODataClient odata;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void before() {
|
|
||||||
odata = ODataClientFactory.getV4();
|
|
||||||
odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readServiceDocument() {
|
public void readServiceDocument() {
|
||||||
ODataServiceDocumentRequest request = odata.getRetrieveRequestFactory().getServiceDocumentRequest(SERVICE_URI);
|
ODataServiceDocumentRequest request = getClient().getRetrieveRequestFactory()
|
||||||
|
.getServiceDocumentRequest(SERVICE_URI);
|
||||||
assertNotNull(request);
|
assertNotNull(request);
|
||||||
|
|
||||||
ODataRetrieveResponse<ODataServiceDocument> response = request.execute();
|
ODataRetrieveResponse<ODataServiceDocument> response = request.execute();
|
||||||
|
@ -87,7 +78,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readMetadata() {
|
public void readMetadata() {
|
||||||
EdmMetadataRequest request = odata.getRetrieveRequestFactory().getMetadataRequest(SERVICE_URI);
|
EdmMetadataRequest request = getClient().getRetrieveRequestFactory().getMetadataRequest(SERVICE_URI);
|
||||||
assertNotNull(request);
|
assertNotNull(request);
|
||||||
|
|
||||||
ODataRetrieveResponse<Edm> response = request.execute();
|
ODataRetrieveResponse<Edm> response = request.execute();
|
||||||
|
@ -104,7 +95,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readEntitySet() {
|
public void readEntitySet() {
|
||||||
final ODataEntitySetRequest<ODataEntitySet> request = odata.getRetrieveRequestFactory()
|
final ODataEntitySetRequest<ODataEntitySet> request = getClient().getRetrieveRequestFactory()
|
||||||
.getEntitySetRequest(getClient().newURIBuilder(SERVICE_URI)
|
.getEntitySetRequest(getClient().newURIBuilder(SERVICE_URI)
|
||||||
.appendEntitySetSegment("ESMixPrimCollComp").build());
|
.appendEntitySetSegment("ESMixPrimCollComp").build());
|
||||||
assertNotNull(request);
|
assertNotNull(request);
|
||||||
|
@ -134,7 +125,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readException() throws Exception {
|
public void readException() throws Exception {
|
||||||
final ODataEntityRequest<ODataEntity> request = odata.getRetrieveRequestFactory()
|
final ODataEntityRequest<ODataEntity> request = getClient().getRetrieveRequestFactory()
|
||||||
.getEntityRequest(getClient().newURIBuilder(SERVICE_URI)
|
.getEntityRequest(getClient().newURIBuilder(SERVICE_URI)
|
||||||
.appendEntitySetSegment("ESMixPrimCollComp").appendKeySegment("42").build());
|
.appendEntitySetSegment("ESMixPrimCollComp").appendKeySegment("42").build());
|
||||||
assertNotNull(request);
|
assertNotNull(request);
|
||||||
|
@ -151,7 +142,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readEntityRawResult() throws IOException {
|
public void readEntityRawResult() throws IOException {
|
||||||
final ODataEntityRequest<ODataEntity> request = odata.getRetrieveRequestFactory()
|
final ODataEntityRequest<ODataEntity> request = getClient().getRetrieveRequestFactory()
|
||||||
.getEntityRequest(getClient().newURIBuilder(SERVICE_URI)
|
.getEntityRequest(getClient().newURIBuilder(SERVICE_URI)
|
||||||
.appendEntitySetSegment("ESCollAllPrim").appendKeySegment(1).build());
|
.appendEntitySetSegment("ESCollAllPrim").appendKeySegment(1).build());
|
||||||
assertNotNull(request);
|
assertNotNull(request);
|
||||||
|
@ -187,7 +178,10 @@ public class BasicITCase extends AbstractBaseTestITCase {
|
||||||
assertEquals(expectedResult, IOUtils.toString(response.getRawResponse(), "UTF-8"));
|
assertEquals(expectedResult, IOUtils.toString(response.getRawResponse(), "UTF-8"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected CommonODataClient<?> getClient() {
|
@Override
|
||||||
return ODataClientFactory.getV4();
|
protected CommonODataClient<?> getClient() {
|
||||||
|
ODataClient odata = ODataClientFactory.getV4();
|
||||||
|
odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON);
|
||||||
|
return odata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,7 +223,7 @@ public class ODataJsonSerializer implements ODataSerializer {
|
||||||
ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems());
|
ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems());
|
||||||
for (final String propertyName : entityType.getPropertyNames()) {
|
for (final String propertyName : entityType.getPropertyNames()) {
|
||||||
if (all || selected.contains(propertyName)) {
|
if (all || selected.contains(propertyName)) {
|
||||||
final EdmProperty edmProperty = (EdmProperty) entityType.getProperty(propertyName);
|
final EdmProperty edmProperty = entityType.getStructuralProperty(propertyName);
|
||||||
final Property property = entity.getProperty(propertyName);
|
final Property property = entity.getProperty(propertyName);
|
||||||
final Set<List<String>> selectedPaths = all || edmProperty.isPrimitive() ? null :
|
final Set<List<String>> selectedPaths = all || edmProperty.isPrimitive() ? null :
|
||||||
ExpandSelectHelper.getSelectedPaths(select.getSelectItems(), propertyName);
|
ExpandSelectHelper.getSelectedPaths(select.getSelectItems(), propertyName);
|
||||||
|
|
|
@ -527,15 +527,18 @@ public class MetadataDocumentXmlSerializer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Appends a reference to the OData Core Vocabulary as defined in the OData specification
|
||||||
|
* and mentioned in its Common Schema Definition Language (CSDL) document.
|
||||||
|
*/
|
||||||
private void appendReference(final XMLStreamWriter writer) throws XMLStreamException {
|
private void appendReference(final XMLStreamWriter writer) throws XMLStreamException {
|
||||||
writer.writeStartElement(NS_EDMX, "Reference");
|
writer.writeStartElement(NS_EDMX, "Reference");
|
||||||
// TODO: Where is this value comming from?
|
// TODO: Which value can we use here?
|
||||||
|
// <http://docs.oasis-open.org/odata/odata/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml>
|
||||||
|
// is an external site we don't want to query each time an EDM-enabled client is used.
|
||||||
writer.writeAttribute("Uri",
|
writer.writeAttribute("Uri",
|
||||||
"http://localhost:9080/olingo-server-tecsvc/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml");
|
"http://localhost:9080/olingo-server-tecsvc/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml");
|
||||||
writer.writeEmptyElement(NS_EDMX, "Include");
|
writer.writeEmptyElement(NS_EDMX, "Include");
|
||||||
// TODO: Where is this value comming from?
|
|
||||||
writer.writeAttribute(XML_NAMESPACE, "Org.OData.Core.V1");
|
writer.writeAttribute(XML_NAMESPACE, "Org.OData.Core.V1");
|
||||||
// TODO: Where is this value comming from?
|
|
||||||
writer.writeAttribute(XML_ALIAS, "Core");
|
writer.writeAttribute(XML_ALIAS, "Core");
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.apache.olingo.server.api.OData;
|
||||||
import org.apache.olingo.server.api.ODataApplicationException;
|
import org.apache.olingo.server.api.ODataApplicationException;
|
||||||
import org.apache.olingo.server.api.ODataRequest;
|
import org.apache.olingo.server.api.ODataRequest;
|
||||||
import org.apache.olingo.server.api.ODataResponse;
|
import org.apache.olingo.server.api.ODataResponse;
|
||||||
import org.apache.olingo.server.api.ODataTranslatedException;
|
|
||||||
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
|
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
|
||||||
import org.apache.olingo.server.api.processor.EntityProcessor;
|
import org.apache.olingo.server.api.processor.EntityProcessor;
|
||||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||||
|
@ -76,12 +75,14 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc
|
||||||
if (entitySet == null) {
|
if (entitySet == null) {
|
||||||
response.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode());
|
response.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode());
|
||||||
} else {
|
} else {
|
||||||
ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
|
final ODataFormat format = ODataFormat.fromContentType(requestedContentType);
|
||||||
|
ODataSerializer serializer = odata.createSerializer(format);
|
||||||
final ExpandOption expand = uriInfo.getExpandOption();
|
final ExpandOption expand = uriInfo.getExpandOption();
|
||||||
final SelectOption select = uriInfo.getSelectOption();
|
final SelectOption select = uriInfo.getSelectOption();
|
||||||
response.setContent(serializer.entitySet(edmEntitySet, entitySet,
|
response.setContent(serializer.entitySet(edmEntitySet, entitySet,
|
||||||
ODataSerializerOptions.with()
|
ODataSerializerOptions.with()
|
||||||
.contextURL(getContextUrl(serializer, edmEntitySet, false, expand, select))
|
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
|
||||||
|
getContextUrl(serializer, edmEntitySet, false, expand, select))
|
||||||
.count(uriInfo.getCountOption())
|
.count(uriInfo.getCountOption())
|
||||||
.expand(expand).select(select)
|
.expand(expand).select(select)
|
||||||
.build()));
|
.build()));
|
||||||
|
@ -90,7 +91,7 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc
|
||||||
}
|
}
|
||||||
} catch (final DataProvider.DataProviderException e) {
|
} catch (final DataProvider.DataProviderException e) {
|
||||||
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
} catch (final ODataTranslatedException e) {
|
} catch (final ODataSerializerException e) {
|
||||||
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
} catch (final ODataApplicationException e) {
|
} catch (final ODataApplicationException e) {
|
||||||
response.setStatusCode(e.getStatusCode());
|
response.setStatusCode(e.getStatusCode());
|
||||||
|
@ -110,21 +111,23 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
response.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode());
|
response.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode());
|
||||||
} else {
|
} else {
|
||||||
ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
|
final ODataFormat format = ODataFormat.fromContentType(requestedContentType);
|
||||||
|
ODataSerializer serializer = odata.createSerializer(format);
|
||||||
final ExpandOption expand = uriInfo.getExpandOption();
|
final ExpandOption expand = uriInfo.getExpandOption();
|
||||||
final SelectOption select = uriInfo.getSelectOption();
|
final SelectOption select = uriInfo.getSelectOption();
|
||||||
response.setContent(serializer.entity(edmEntitySet, entity,
|
response.setContent(serializer.entity(edmEntitySet, entity,
|
||||||
ODataSerializerOptions.with()
|
ODataSerializerOptions.with()
|
||||||
.contextURL(getContextUrl(serializer, edmEntitySet, true, expand, select))
|
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
|
||||||
|
getContextUrl(serializer, edmEntitySet, true, expand, select))
|
||||||
.count(uriInfo.getCountOption())
|
.count(uriInfo.getCountOption())
|
||||||
.expand(uriInfo.getExpandOption()).select(uriInfo.getSelectOption())
|
.expand(expand).select(select)
|
||||||
.build()));
|
.build()));
|
||||||
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
||||||
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
|
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
|
||||||
}
|
}
|
||||||
} catch (final DataProvider.DataProviderException e) {
|
} catch (final DataProvider.DataProviderException e) {
|
||||||
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
} catch (final ODataTranslatedException e) {
|
} catch (final ODataSerializerException e) {
|
||||||
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
} catch (final ODataApplicationException e) {
|
} catch (final ODataApplicationException e) {
|
||||||
response.setStatusCode(e.getStatusCode());
|
response.setStatusCode(e.getStatusCode());
|
||||||
|
|
Loading…
Reference in New Issue