diff --git a/.gitignore b/.gitignore index 20b1e94..f40631d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,9 @@ hs_err_pid* # working folders /temp +/lib +/sql +/web # Project Genereated files .pmd diff --git a/Dockerfile b/Dockerfile index 8875db4..df82b1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -FROM java:8 +FROM tomcat:latest -COPY ./temp/spring-server-generated/target/swagger-spring-1.0.0.jar reso.jar +COPY ./target/RESOservice-1.0.war /usr/local/tomcat/webapps/ -ENTRYPOINT ["java","-jar","reso.jar"] \ No newline at end of file +CMD ["catalina.sh", "run"] \ No newline at end of file diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 894a6d2..0000000 --- a/build.gradle +++ /dev/null @@ -1,23 +0,0 @@ -plugins { - id 'java' -} - -group 'org.example' -version '1.0-SNAPSHOT' - -repositories { - mavenCentral() -} - -dependencies { - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' - implementation('org.apache.olingo:odata-server-api:4.5.0') - implementation('org.apache.olingo:odata-server-core:4.5.0') - implementation('org.apache.olingo:odata-commons-api:4.5.0') - implementation('org.apache.olingo:odata-commons-core:4.5.0') -} - -test { - useJUnitPlatform() -} \ No newline at end of file diff --git a/build.sh b/build.sh index 97153a3..2aa91ab 100644 --- a/build.sh +++ b/build.sh @@ -1,9 +1,7 @@ #!/bin/bash -unzip temp/resources/spring-server-generated.zip -d temp/spring-server-generated - -mvn -f temp/spring-server-generated compile -mvn -f temp/spring-server-generated package +mvn compile +mvn package docker-compose build rm -rf temp/spring-server-generated diff --git a/docker-compose.yml b/docker-compose.yml index 101c2fb..bdb4537 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,10 +4,10 @@ services: restart: on-failure build: ./ expose: - - "10222" + - "8080" ports: - - 10222:10222 + - 8080:8080 environment: - WAIT_HOSTS - depends_on: - - docker-mysql +# depends_on: +# - docker-mysql diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index e708b1c..0000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index be52383..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew deleted file mode 100644 index 4f906e0..0000000 --- a/gradlew +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed 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 -# -# https://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. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index 107acd3..0000000 --- a/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..cebec99 --- /dev/null +++ b/pom.xml @@ -0,0 +1,89 @@ + + + 4.0.0 + + org.reso + RESOservice + 1.0 + RESOservice + war + + + 1.8 + 1.8 + 5.7.0 + 2.5 + 4.6.0 + 1.7.7 + + + + javax.servlet + javax.servlet-api + 4.0.1 + provided + + + + org.apache.olingo + odata-server-api + ${odata.version} + + + org.apache.olingo + odata-server-core + ${odata.version} + runtime + + + + org.apache.olingo + odata-commons-api + ${odata.version} + + + org.apache.olingo + odata-commons-core + ${odata.version} + + + + org.slf4j + slf4j-simple + ${slf4j.version} + runtime + + + org.slf4j + slf4j-api + 1.7.11 + compile + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.0 + + + + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 0719459..0000000 --- a/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'WebApi' - diff --git a/src/main/java/org/reso/service/data/LookupEntityCollectionProcessor.java b/src/main/java/org/reso/service/data/LookupEntityCollectionProcessor.java new file mode 100644 index 0000000..cedbf2b --- /dev/null +++ b/src/main/java/org/reso/service/data/LookupEntityCollectionProcessor.java @@ -0,0 +1,111 @@ +package org.reso.service.data; + +import org.apache.olingo.commons.api.data.*; +import org.apache.olingo.commons.api.edm.EdmEntitySet; +import org.apache.olingo.commons.api.edm.EdmEntityType; +import org.apache.olingo.commons.api.ex.ODataRuntimeException; +import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.http.HttpHeader; +import org.apache.olingo.commons.api.http.HttpStatusCode; +import org.apache.olingo.server.api.*; +import org.apache.olingo.server.api.processor.EntityCollectionProcessor; +import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions; +import org.apache.olingo.server.api.serializer.ODataSerializer; +import org.apache.olingo.server.api.serializer.SerializerException; +import org.apache.olingo.server.api.serializer.SerializerResult; +import org.apache.olingo.server.api.uri.UriInfo; +import org.apache.olingo.server.api.uri.UriResource; +import org.apache.olingo.server.api.uri.UriResourceEntitySet; +import org.reso.service.edmprovider.LookupEdmProvider; + +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; + +public class LookupEntityCollectionProcessor implements EntityCollectionProcessor +{ + private OData odata; + private ServiceMetadata serviceMetadata; + + public void init(OData odata, ServiceMetadata serviceMetadata) { + this.odata = odata; + this.serviceMetadata = serviceMetadata; + } + + public void readEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat) + throws ODataApplicationException, SerializerException + { + + // 1st we have retrieve the requested EntitySet from the uriInfo object (representation of the parsed service URI) + List resourcePaths = uriInfo.getUriResourceParts(); + UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); // in our example, the first segment is the EntitySet + EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet(); + + // 2nd: fetch the data from backend for this requested EntitySetName + // it has to be delivered as EntitySet object + EntityCollection entitySet = getData(edmEntitySet); + + // 3rd: create a serializer based on the requested format (json) + ODataSerializer serializer = odata.createSerializer(responseFormat); + + // 4th: Now serialize the content: transform from the EntitySet object to InputStream + EdmEntityType edmEntityType = edmEntitySet.getEntityType(); + ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build(); + + final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName(); + EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with().id(id).contextURL(contextUrl).build(); + SerializerResult serializerResult = serializer.entityCollection(serviceMetadata, edmEntityType, entitySet, opts); + InputStream serializedContent = serializerResult.getContent(); + + // Finally: configure the response object: set the body, headers and status code + response.setContent(serializedContent); + response.setStatusCode(HttpStatusCode.OK.getStatusCode()); + response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString()); + } + + private EntityCollection getData(EdmEntitySet edmEntitySet){ + + EntityCollection lookupsCollection = new EntityCollection(); + // check for which EdmEntitySet the data is requested + if(LookupEdmProvider.ES_LOOKUPS_NAME.equals(edmEntitySet.getName())) { + List productList = lookupsCollection.getEntities(); + + // add some sample product entities + final Entity e1 = new Entity() + .addProperty(new Property(null, "LookupKey", ValueType.PRIMITIVE, "ABC123")) + .addProperty(new Property(null, "LookupName", ValueType.PRIMITIVE, "CountyOrParish")) + .addProperty(new Property(null, "LookupValue", ValueType.PRIMITIVE, + "Los Angeles County")); + e1.setId(createId("Lookups", 1)); + productList.add(e1); + + final Entity e2 = new Entity() + .addProperty(new Property(null, "LookupKey", ValueType.PRIMITIVE, "BCD124")) + .addProperty(new Property(null, "LookupName", ValueType.PRIMITIVE, "CountyOrParish")) + .addProperty(new Property(null, "LookupValue", ValueType.PRIMITIVE, + "Ventura County")); + e2.setId(createId("Lookups", 1)); + productList.add(e2); + + final Entity e3 = new Entity() + .addProperty(new Property(null, "LookupKey", ValueType.PRIMITIVE, "CDE125")) + .addProperty(new Property(null, "LookupName", ValueType.PRIMITIVE, "CountyOrParish")) + .addProperty(new Property(null, "LookupValue", ValueType.PRIMITIVE, + "Contra Costa County")); + e3.setId(createId("Lookups", 1)); + productList.add(e3); + } + + return lookupsCollection; + } + + private URI createId(String entitySetName, Object id) { + try { + return new URI(entitySetName + "(" + String.valueOf(id) + ")"); + } catch (URISyntaxException e) { + throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e); + } + } + +} diff --git a/src/main/java/org/reso/service/edmprovider/LookupEdmProvider.java b/src/main/java/org/reso/service/edmprovider/LookupEdmProvider.java new file mode 100644 index 0000000..7831656 --- /dev/null +++ b/src/main/java/org/reso/service/edmprovider/LookupEdmProvider.java @@ -0,0 +1,119 @@ +package org.reso.service.edmprovider; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.api.edm.provider.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + + +public class LookupEdmProvider extends CsdlAbstractEdmProvider +{ + // Service Namespace + public static final String NAMESPACE = "RESO.OData.Metadata"; + + // EDM Container + public static final String CONTAINER_NAME = "Container"; + public static final FullQualifiedName CONTAINER = new FullQualifiedName(NAMESPACE, CONTAINER_NAME); + + // Entity Types Names + public static final String ET_LOOKUP_NAME = "Lookup"; + public static final FullQualifiedName ET_LOOKUP_FQN = new FullQualifiedName(NAMESPACE, ET_LOOKUP_NAME); + + // Entity Set Names + public static final String ES_LOOKUPS_NAME = "Lookups"; + + public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) { + + // this method is called for one of the EntityTypes that are configured in the Schema + if(entityTypeName.equals(ET_LOOKUP_FQN)){ + + //create EntityType properties + CsdlProperty key = new CsdlProperty().setName("LookupKey").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); + CsdlProperty name = new CsdlProperty().setName("LookupName").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); + CsdlProperty value = new CsdlProperty().setName("LookupValue").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); + + CsdlProperty stdvalue = new CsdlProperty().setName("StandardLookupValue").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); + CsdlProperty legacy = new CsdlProperty().setName("LegacyODataValue").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); + CsdlProperty timestamp = new CsdlProperty().setName("ModificationTimestamp").setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName()); + + // create CsdlPropertyRef for Key element + CsdlPropertyRef propertyRef = new CsdlPropertyRef(); + propertyRef.setName("LookupKey"); + + // configure EntityType + CsdlEntityType entityType = new CsdlEntityType(); + entityType.setName(ET_LOOKUP_NAME); + entityType.setProperties(Arrays.asList(key, name , value, stdvalue, legacy, timestamp)); + entityType.setKey(Collections.singletonList(propertyRef)); + + return entityType; + } + + return null; + } + + public CsdlEntitySet getEntitySet(FullQualifiedName entityContainer, String entitySetName) { + + if(entityContainer.equals(CONTAINER)){ + if(entitySetName.equals(ES_LOOKUPS_NAME)){ + CsdlEntitySet entitySet = new CsdlEntitySet(); + entitySet.setName(ES_LOOKUPS_NAME); + entitySet.setType(ET_LOOKUP_FQN); + + return entitySet; + } + } + + return null; + } + + public CsdlEntityContainer getEntityContainer() { + + // create EntitySets + List entitySets = new ArrayList(); + entitySets.add(getEntitySet(CONTAINER, ES_LOOKUPS_NAME)); + + // create EntityContainer + CsdlEntityContainer entityContainer = new CsdlEntityContainer(); + entityContainer.setName(CONTAINER_NAME); + entityContainer.setEntitySets(entitySets); + + return entityContainer; + } + + public List getSchemas() { + + // create Schema + CsdlSchema schema = new CsdlSchema(); + schema.setNamespace(NAMESPACE); + + // add EntityTypes + List entityTypes = new ArrayList(); + entityTypes.add(getEntityType(ET_LOOKUP_FQN)); + schema.setEntityTypes(entityTypes); + + // add EntityContainer + schema.setEntityContainer(getEntityContainer()); + + // finally + List schemas = new ArrayList(); + schemas.add(schema); + + return schemas; + } + + public CsdlEntityContainerInfo getEntityContainerInfo(FullQualifiedName entityContainerName) { + + // This method is invoked when displaying the Service Document at e.g. http://localhost:8080/DemoService/DemoService.svc + if (entityContainerName == null || entityContainerName.equals(CONTAINER)) { + CsdlEntityContainerInfo entityContainerInfo = new CsdlEntityContainerInfo(); + entityContainerInfo.setContainerName(CONTAINER); + return entityContainerInfo; + } + + return null; + } +} diff --git a/src/main/java/org/reso/service/servlet/RESOservlet.java b/src/main/java/org/reso/service/servlet/RESOservlet.java new file mode 100644 index 0000000..a7f80e3 --- /dev/null +++ b/src/main/java/org/reso/service/servlet/RESOservlet.java @@ -0,0 +1,39 @@ +package org.reso.service.servlet; + + +import org.apache.olingo.commons.api.edmx.EdmxReference; +import org.apache.olingo.server.api.OData; +import org.apache.olingo.server.api.ODataHttpHandler; +import org.apache.olingo.server.api.ServiceMetadata; +import org.reso.service.data.LookupEntityCollectionProcessor; +import org.reso.service.edmprovider.LookupEdmProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.util.ArrayList; +import javax.servlet.ServletException; +import javax.servlet.http.*; + +public class RESOservlet extends HttpServlet +{ + private static final long serialVersionUID = 1L; + private static final Logger LOG = LoggerFactory.getLogger(RESOservlet.class); + + protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { + try { + // create odata handler and configure it with CsdlEdmProvider and Processor + OData odata = OData.newInstance(); + ServiceMetadata edm = odata.createServiceMetadata(new LookupEdmProvider(), new ArrayList()); + ODataHttpHandler handler = odata.createHandler(edm); + handler.register(new LookupEntityCollectionProcessor()); + + // let the handler do the work + handler.process(req, resp); + + } catch (RuntimeException e) { + LOG.error("Server Error occurred in ExampleServlet", e); + throw new ServletException(e); + } + } +} \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..c708639 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,17 @@ + + + + RESOservlet + org.reso.service.servlet.RESOservlet + 1 + + + + RESOservlet + /* + + \ No newline at end of file