minor improvements

Change-Id: Ia9872a613f3221e2de885f9d325a14f3c50b4beb

Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
Klaus Straubinger 2014-09-25 13:50:32 +02:00 committed by Christian Amend
parent 68f51d84d0
commit f947afc108
6 changed files with 59 additions and 58 deletions

View File

@ -114,12 +114,10 @@ public class TomcatTestServer {
try {
return Integer.parseInt(portParam[1]);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Port parameter (" + portParameter +
") could not be parsed.");
throw new IllegalArgumentException("Port parameter (" + portParameter + ") could not be parsed.");
}
}
throw new IllegalArgumentException("Port parameter (" + portParameter +
") could not be parsed.");
throw new IllegalArgumentException("Port parameter (" + portParameter + ") could not be parsed.");
}
public static class StaticContent extends HttpServlet {
@ -152,6 +150,7 @@ public class TomcatTestServer {
}
private static TestServerBuilder builder;
public static TestServerBuilder init(int port) {
if (builder == null) {
builder = new TestServerBuilder(port);
@ -240,7 +239,8 @@ public class TomcatTestServer {
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) {
return this;
}

View File

@ -18,6 +18,7 @@
*/
package org.apache.olingo.fit;
import org.apache.catalina.LifecycleException;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.CommonODataClient;
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.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
@ -48,12 +50,11 @@ public abstract class AbstractBaseTestITCase {
*/
protected static final Logger LOG = LoggerFactory.getLogger(AbstractBaseTestITCase.class);
@SuppressWarnings("rawtypes")
protected abstract CommonODataClient getClient();
protected abstract CommonODataClient<?> getClient();
@BeforeClass
public static void init() throws Exception {
public static void init()
throws LifecycleException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
TomcatTestServer.init(9080)
.addServlet(TechnicalServlet.class, "/olingo-server-tecsvc/odata.svc/*")
.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 {
private static final long serialVersionUID = -6663569573355398997L;
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getOutputStream().write(IOUtils.toByteArray(
Thread.currentThread().getContextClassLoader().getResourceAsStream("org-odata-core-v1.xml")));
}

View File

@ -53,25 +53,16 @@ import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.fit.AbstractBaseTestITCase;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
import org.junit.Before;
import org.junit.Test;
public class BasicITCase extends AbstractBaseTestITCase {
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
public void readServiceDocument() {
ODataServiceDocumentRequest request = odata.getRetrieveRequestFactory().getServiceDocumentRequest(SERVICE_URI);
ODataServiceDocumentRequest request = getClient().getRetrieveRequestFactory()
.getServiceDocumentRequest(SERVICE_URI);
assertNotNull(request);
ODataRetrieveResponse<ODataServiceDocument> response = request.execute();
@ -87,7 +78,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
@Test
public void readMetadata() {
EdmMetadataRequest request = odata.getRetrieveRequestFactory().getMetadataRequest(SERVICE_URI);
EdmMetadataRequest request = getClient().getRetrieveRequestFactory().getMetadataRequest(SERVICE_URI);
assertNotNull(request);
ODataRetrieveResponse<Edm> response = request.execute();
@ -104,7 +95,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
@Test
public void readEntitySet() {
final ODataEntitySetRequest<ODataEntitySet> request = odata.getRetrieveRequestFactory()
final ODataEntitySetRequest<ODataEntitySet> request = getClient().getRetrieveRequestFactory()
.getEntitySetRequest(getClient().newURIBuilder(SERVICE_URI)
.appendEntitySetSegment("ESMixPrimCollComp").build());
assertNotNull(request);
@ -134,7 +125,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
@Test
public void readException() throws Exception {
final ODataEntityRequest<ODataEntity> request = odata.getRetrieveRequestFactory()
final ODataEntityRequest<ODataEntity> request = getClient().getRetrieveRequestFactory()
.getEntityRequest(getClient().newURIBuilder(SERVICE_URI)
.appendEntitySetSegment("ESMixPrimCollComp").appendKeySegment("42").build());
assertNotNull(request);
@ -151,7 +142,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
@Test
public void readEntityRawResult() throws IOException {
final ODataEntityRequest<ODataEntity> request = odata.getRetrieveRequestFactory()
final ODataEntityRequest<ODataEntity> request = getClient().getRetrieveRequestFactory()
.getEntityRequest(getClient().newURIBuilder(SERVICE_URI)
.appendEntitySetSegment("ESCollAllPrim").appendKeySegment(1).build());
assertNotNull(request);
@ -187,7 +178,10 @@ public class BasicITCase extends AbstractBaseTestITCase {
assertEquals(expectedResult, IOUtils.toString(response.getRawResponse(), "UTF-8"));
}
@Override protected CommonODataClient<?> getClient() {
return ODataClientFactory.getV4();
@Override
protected CommonODataClient<?> getClient() {
ODataClient odata = ODataClientFactory.getV4();
odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON);
return odata;
}
}

View File

@ -223,7 +223,7 @@ public class ODataJsonSerializer implements ODataSerializer {
ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems());
for (final String propertyName : entityType.getPropertyNames()) {
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 Set<List<String>> selectedPaths = all || edmProperty.isPrimitive() ? null :
ExpandSelectHelper.getSelectedPaths(select.getSelectItems(), propertyName);

View File

@ -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 {
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",
"http://localhost:9080/olingo-server-tecsvc/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml");
writer.writeEmptyElement(NS_EDMX, "Include");
// TODO: Where is this value comming from?
writer.writeAttribute(XML_NAMESPACE, "Org.OData.Core.V1");
// TODO: Where is this value comming from?
writer.writeAttribute(XML_ALIAS, "Core");
writer.writeEndElement();
}

View File

@ -32,7 +32,6 @@ import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
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.EntityProcessor;
import org.apache.olingo.server.api.serializer.ODataSerializer;
@ -76,12 +75,14 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc
if (entitySet == null) {
response.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode());
} 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 SelectOption select = uriInfo.getSelectOption();
response.setContent(serializer.entitySet(edmEntitySet, entitySet,
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())
.expand(expand).select(select)
.build()));
@ -90,7 +91,7 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc
}
} catch (final DataProvider.DataProviderException e) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
} catch (final ODataTranslatedException e) {
} catch (final ODataSerializerException e) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
} catch (final ODataApplicationException e) {
response.setStatusCode(e.getStatusCode());
@ -110,21 +111,23 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc
if (entity == null) {
response.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode());
} 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 SelectOption select = uriInfo.getSelectOption();
response.setContent(serializer.entity(edmEntitySet, entity,
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())
.expand(uriInfo.getExpandOption()).select(uriInfo.getSelectOption())
.expand(expand).select(select)
.build()));
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
}
} catch (final DataProvider.DataProviderException e) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
} catch (final ODataTranslatedException e) {
} catch (final ODataSerializerException e) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
} catch (final ODataApplicationException e) {
response.setStatusCode(e.getStatusCode());