├── .gitignore ├── 8.5-java11 └── Dockerfile ├── 8.5-jre8 └── Dockerfile ├── 9.0-java11 └── Dockerfile ├── 9.0-jre8 └── Dockerfile ├── LICENSE ├── README.md ├── samples └── spring-framework-petclinic │ ├── .editorconfig │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── .travis.yml │ ├── deployApp.ps1 │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ ├── readme.md │ ├── sonar-project.properties │ └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── springframework │ │ │ └── samples │ │ │ └── petclinic │ │ │ ├── PetclinicInitializer.java │ │ │ ├── model │ │ │ ├── BaseEntity.java │ │ │ ├── NamedEntity.java │ │ │ ├── Owner.java │ │ │ ├── Person.java │ │ │ ├── Pet.java │ │ │ ├── PetType.java │ │ │ ├── Specialty.java │ │ │ ├── Vet.java │ │ │ ├── Vets.java │ │ │ ├── Visit.java │ │ │ └── package-info.java │ │ │ ├── repository │ │ │ ├── OwnerRepository.java │ │ │ ├── PetRepository.java │ │ │ ├── VetRepository.java │ │ │ ├── VisitRepository.java │ │ │ ├── jdbc │ │ │ │ ├── JdbcOwnerRepositoryImpl.java │ │ │ │ ├── JdbcPet.java │ │ │ │ ├── JdbcPetRepositoryImpl.java │ │ │ │ ├── JdbcPetRowMapper.java │ │ │ │ ├── JdbcPetVisitExtractor.java │ │ │ │ ├── JdbcVetRepositoryImpl.java │ │ │ │ ├── JdbcVisitRepositoryImpl.java │ │ │ │ ├── JdbcVisitRowMapper.java │ │ │ │ └── package-info.java │ │ │ ├── jpa │ │ │ │ ├── JpaOwnerRepositoryImpl.java │ │ │ │ ├── JpaPetRepositoryImpl.java │ │ │ │ ├── JpaVetRepositoryImpl.java │ │ │ │ ├── JpaVisitRepositoryImpl.java │ │ │ │ └── package-info.java │ │ │ └── springdatajpa │ │ │ │ ├── SpringDataOwnerRepository.java │ │ │ │ ├── SpringDataPetRepository.java │ │ │ │ ├── SpringDataVetRepository.java │ │ │ │ └── SpringDataVisitRepository.java │ │ │ ├── service │ │ │ ├── ClinicService.java │ │ │ └── ClinicServiceImpl.java │ │ │ ├── util │ │ │ ├── CallMonitoringAspect.java │ │ │ └── EntityUtils.java │ │ │ └── web │ │ │ ├── CrashController.java │ │ │ ├── OwnerController.java │ │ │ ├── PetController.java │ │ │ ├── PetTypeFormatter.java │ │ │ ├── PetValidator.java │ │ │ ├── VetController.java │ │ │ ├── VisitController.java │ │ │ └── package-info.java │ ├── resources │ │ ├── cache │ │ │ ├── ehcache.xml │ │ │ └── ehcache.xsd │ │ ├── db │ │ │ ├── hsqldb │ │ │ │ ├── initDB.sql │ │ │ │ └── populateDB.sql │ │ │ ├── mysql │ │ │ │ ├── initDB.sql │ │ │ │ ├── petclinic_db_setup_mysql.txt │ │ │ │ └── populateDB.sql │ │ │ └── postgresql │ │ │ │ ├── initDB.sql │ │ │ │ ├── petclinic_db_setup_postgresql.txt │ │ │ │ └── populateDB.sql │ │ ├── logback.xml │ │ ├── messages │ │ │ ├── messages.properties │ │ │ ├── messages_de.properties │ │ │ └── messages_en.properties │ │ └── spring │ │ │ ├── business-config.xml │ │ │ ├── data-access.properties │ │ │ ├── datasource-config.xml │ │ │ ├── mvc-core-config.xml │ │ │ ├── mvc-view-config.xml │ │ │ └── tools-config.xml │ ├── webapp │ │ ├── WEB-INF │ │ │ ├── jetty-web.xml │ │ │ ├── jsp │ │ │ │ ├── exception.jsp │ │ │ │ ├── owners │ │ │ │ │ ├── createOrUpdateOwnerForm.jsp │ │ │ │ │ ├── findOwners.jsp │ │ │ │ │ ├── ownerDetails.jsp │ │ │ │ │ └── ownersList.jsp │ │ │ │ ├── pets │ │ │ │ │ ├── createOrUpdatePetForm.jsp │ │ │ │ │ └── createOrUpdateVisitForm.jsp │ │ │ │ ├── vets │ │ │ │ │ └── vetList.jsp │ │ │ │ └── welcome.jsp │ │ │ ├── no-spring-config-files-there.txt │ │ │ └── tags │ │ │ │ ├── bodyHeader.tag │ │ │ │ ├── footer.tag │ │ │ │ ├── htmlHeader.tag │ │ │ │ ├── inputField.tag │ │ │ │ ├── layout.tag │ │ │ │ ├── localDate.tag │ │ │ │ ├── menu.tag │ │ │ │ ├── menuItem.tag │ │ │ │ ├── pivotal.tag │ │ │ │ └── selectField.tag │ │ └── resources │ │ │ ├── fonts │ │ │ ├── montserrat-webfont.eot │ │ │ ├── montserrat-webfont.svg │ │ │ ├── montserrat-webfont.ttf │ │ │ ├── montserrat-webfont.woff │ │ │ ├── varela_round-webfont.eot │ │ │ ├── varela_round-webfont.svg │ │ │ ├── varela_round-webfont.ttf │ │ │ └── varela_round-webfont.woff │ │ │ ├── images │ │ │ ├── favicon.png │ │ │ ├── pets.png │ │ │ ├── platform-bg.png │ │ │ ├── spring-logo-dataflow-mobile.png │ │ │ ├── spring-logo-dataflow.png │ │ │ └── spring-pivotal-logo.png │ │ │ └── less │ │ │ ├── header.less │ │ │ ├── petclinic.less │ │ │ ├── responsive.less │ │ │ └── typography.less │ └── wro │ │ ├── wro.properties │ │ └── wro.xml │ └── test │ ├── java │ └── org │ │ └── springframework │ │ └── samples │ │ └── petclinic │ │ ├── model │ │ └── ValidatorTests.java │ │ ├── service │ │ ├── AbstractClinicServiceTests.java │ │ ├── ClinicServiceJdbcTests.java │ │ ├── ClinicServiceJpaTests.java │ │ └── ClinicServiceSpringDataJpaTests.java │ │ └── web │ │ ├── CrashControllerTests.java │ │ ├── OwnerControllerTests.java │ │ ├── PetControllerTests.java │ │ ├── PetTypeFormatterTests.java │ │ ├── VetControllerTests.java │ │ └── VisitControllerTests.java │ ├── jmeter │ └── petclinic_test_plan.jmx │ └── resources │ └── spring │ └── mvc-test-config.xml ├── scripts ├── deployAndRunApp.ps1 ├── publishStage1.ps1 ├── publishStage2.ps1 ├── setup.ps1 └── setup.sh └── shared ├── app_insights ├── AI-Agent.xml └── ApplicationInsights.xml ├── appservice └── azure.appservice.jar ├── easyauth └── azure.appservice.easyauth.jar ├── misc ├── Dockerfile ├── index.jsp ├── init_container.sh └── sshd_config └── tomcat ├── 8.5 ├── catalina.properties ├── context.xml ├── logging.properties ├── server.xml ├── web-appservice-ai.xml └── web-appservice.xml ├── 9.0 ├── catalina.properties ├── context.xml ├── logging.properties ├── server.xml ├── web-appservice-ai.xml └── web-appservice.xml └── common └── setenv.sh /.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | home 3 | 4 | -------------------------------------------------------------------------------- /8.5-java11/Dockerfile: -------------------------------------------------------------------------------- 1 | ######################################################## 2 | ### ***DO NOT EDIT*** This is an auto-generated file ### 3 | ######################################################## 4 | ARG BASE_IMAGE=mcr.microsoft.com/java/jre-headless:11u3-zulu-alpine-with-tools 5 | ARG GIT_COMMIT=unspecified 6 | FROM $BASE_IMAGE 7 | 8 | # Re-define ARG to make the build argument available for use in the rest of the Dockerfile 9 | ARG GIT_COMMIT 10 | 11 | LABEL maintainer="Azure App Services Container Images " 12 | 13 | ENV AI_VERSION 2.1.2 14 | ENV TOMCAT_VERSION 8.5.41 15 | ENV TOMCAT_MAJOR 8 16 | ENV GIT_COMMIT $GIT_COMMIT 17 | ENV APPINSIGHTS_ENABLED 0 18 | 19 | ENV PORT 80 20 | ENV SSH_PORT 2222 21 | 22 | ENV PATH /usr/local/tomcat/bin:$PATH 23 | 24 | # Remove the sample webapps provided by Tomcat 25 | RUN rm -rf /usr/local/tomcat/webapps/ 26 | 27 | COPY tmp/shared/misc/init_container.sh /bin/init_container.sh 28 | COPY tmp/shared/tomcat/8.5/web-appservice-ai.xml /tmp/tomcat/conf/web-appservice-ai.xml 29 | COPY tmp/shared/misc/index.jsp /tmp/tomcat/webapps/ROOT/index.jsp 30 | COPY tmp/shared/misc/sshd_config /etc/ssh/ 31 | COPY tmp/shared/app_insights/AI-Agent.xml /usr/local/app_insights/aiagent/ 32 | COPY tmp/shared/app_insights/ApplicationInsights.xml /usr/local/app_insights/tomcat_lib/ 33 | 34 | RUN apk add --update openssh-server bash openrc \ 35 | && rm -rf /var/cache/apk/* \ 36 | # Remove unnecessary services 37 | && rm -f /etc/init.d/hwdrivers \ 38 | /etc/init.d/hwclock \ 39 | /etc/init.d/mtab \ 40 | /etc/init.d/bootmisc \ 41 | /etc/init.d/modules \ 42 | /etc/init.d/modules-load \ 43 | /etc/init.d/modloop \ 44 | # Can't do cgroups 45 | && sed -i 's/\tcgroup_add_service/\t#cgroup_add_service/g' /lib/rc/sh/openrc-run.sh \ 46 | && echo "root:Docker!" | chpasswd \ 47 | && wget -O /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz https://archive.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz --no-verbose \ 48 | && tar xvzf /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz -C /tmp \ 49 | && mv /tmp/apache-tomcat-$TOMCAT_VERSION /usr/local/tomcat \ 50 | && rm -rf /usr/local/tomcat/webapps \ 51 | && rm -f /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz \ 52 | && wget -O /usr/local/app_insights/tomcat_lib/applicationinsights-core-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-core-$AI_VERSION.jar --no-verbose \ 53 | && wget -O /usr/local/app_insights/tomcat_lib/applicationinsights-web-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-web-$AI_VERSION.jar --no-verbose \ 54 | && wget -O /usr/local/app_insights/aiagent/applicationinsights-agent-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-agent-$AI_VERSION.jar --no-verbose \ 55 | && chmod 755 /bin/init_container.sh 56 | 57 | COPY tmp/shared/tomcat/8.5/server.xml /usr/local/tomcat/conf/server.xml 58 | COPY tmp/shared/tomcat/8.5/catalina.properties /usr/local/tomcat/conf/catalina.properties 59 | COPY tmp/shared/tomcat/8.5/context.xml /usr/local/tomcat/conf/context.xml 60 | COPY tmp/shared/tomcat/8.5/logging.properties /usr/local/tomcat/conf/logging.properties 61 | COPY tmp/shared/tomcat/8.5/web-appservice.xml /usr/local/tomcat/conf/web.xml 62 | COPY tmp/shared/easyauth/azure.appservice.easyauth.jar /usr/local/tomcat/lib/ 63 | COPY tmp/shared/appservice/azure.appservice.jar /usr/local/tomcat/lib/ 64 | COPY tmp/shared/tomcat/common/setenv.sh /usr/local/tomcat/bin/ 65 | 66 | EXPOSE 80 2222 67 | 68 | ENTRYPOINT ["/bin/init_container.sh"] 69 | ######################################################## 70 | ### ***DO NOT EDIT*** This is an auto-generated file ### 71 | ######################################################## 72 | 73 | -------------------------------------------------------------------------------- /8.5-jre8/Dockerfile: -------------------------------------------------------------------------------- 1 | ######################################################## 2 | ### ***DO NOT EDIT*** This is an auto-generated file ### 3 | ######################################################## 4 | ARG BASE_IMAGE=mcr.microsoft.com/java/jre-headless:8u212-zulu-alpine-with-tools 5 | ARG GIT_COMMIT=unspecified 6 | FROM $BASE_IMAGE 7 | 8 | # Re-define ARG to make the build argument available for use in the rest of the Dockerfile 9 | ARG GIT_COMMIT 10 | 11 | LABEL maintainer="Azure App Services Container Images " 12 | 13 | ENV AI_VERSION 2.1.2 14 | ENV TOMCAT_VERSION 8.5.41 15 | ENV TOMCAT_MAJOR 8 16 | ENV GIT_COMMIT $GIT_COMMIT 17 | ENV APPINSIGHTS_ENABLED 1 18 | 19 | ENV PORT 80 20 | ENV SSH_PORT 2222 21 | 22 | ENV PATH /usr/local/tomcat/bin:$PATH 23 | 24 | # Remove the sample webapps provided by Tomcat 25 | RUN rm -rf /usr/local/tomcat/webapps/ 26 | 27 | COPY tmp/shared/misc/init_container.sh /bin/init_container.sh 28 | COPY tmp/shared/tomcat/8.5/web-appservice-ai.xml /tmp/tomcat/conf/web-appservice-ai.xml 29 | COPY tmp/shared/misc/index.jsp /tmp/tomcat/webapps/ROOT/index.jsp 30 | COPY tmp/shared/misc/sshd_config /etc/ssh/ 31 | COPY tmp/shared/app_insights/AI-Agent.xml /usr/local/app_insights/aiagent/ 32 | COPY tmp/shared/app_insights/ApplicationInsights.xml /usr/local/app_insights/tomcat_lib/ 33 | 34 | RUN apk add --update openssh-server bash openrc \ 35 | && rm -rf /var/cache/apk/* \ 36 | # Remove unnecessary services 37 | && rm -f /etc/init.d/hwdrivers \ 38 | /etc/init.d/hwclock \ 39 | /etc/init.d/mtab \ 40 | /etc/init.d/bootmisc \ 41 | /etc/init.d/modules \ 42 | /etc/init.d/modules-load \ 43 | /etc/init.d/modloop \ 44 | # Can't do cgroups 45 | && sed -i 's/\tcgroup_add_service/\t#cgroup_add_service/g' /lib/rc/sh/openrc-run.sh \ 46 | && echo "root:Docker!" | chpasswd \ 47 | && wget -O /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz https://archive.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz --no-verbose \ 48 | && tar xvzf /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz -C /tmp \ 49 | && mv /tmp/apache-tomcat-$TOMCAT_VERSION /usr/local/tomcat \ 50 | && rm -rf /usr/local/tomcat/webapps \ 51 | && rm -f /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz \ 52 | && wget -O /usr/local/app_insights/tomcat_lib/applicationinsights-core-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-core-$AI_VERSION.jar --no-verbose \ 53 | && wget -O /usr/local/app_insights/tomcat_lib/applicationinsights-web-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-web-$AI_VERSION.jar --no-verbose \ 54 | && wget -O /usr/local/app_insights/aiagent/applicationinsights-agent-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-agent-$AI_VERSION.jar --no-verbose \ 55 | && chmod 755 /bin/init_container.sh 56 | 57 | COPY tmp/shared/tomcat/8.5/server.xml /usr/local/tomcat/conf/server.xml 58 | COPY tmp/shared/tomcat/8.5/catalina.properties /usr/local/tomcat/conf/catalina.properties 59 | COPY tmp/shared/tomcat/8.5/context.xml /usr/local/tomcat/conf/context.xml 60 | COPY tmp/shared/tomcat/8.5/logging.properties /usr/local/tomcat/conf/logging.properties 61 | COPY tmp/shared/tomcat/8.5/web-appservice.xml /usr/local/tomcat/conf/web.xml 62 | COPY tmp/shared/easyauth/azure.appservice.easyauth.jar /usr/local/tomcat/lib/ 63 | COPY tmp/shared/appservice/azure.appservice.jar /usr/local/tomcat/lib/ 64 | COPY tmp/shared/tomcat/common/setenv.sh /usr/local/tomcat/bin/ 65 | 66 | EXPOSE 80 2222 67 | 68 | ENTRYPOINT ["/bin/init_container.sh"] 69 | ######################################################## 70 | ### ***DO NOT EDIT*** This is an auto-generated file ### 71 | ######################################################## 72 | 73 | -------------------------------------------------------------------------------- /9.0-java11/Dockerfile: -------------------------------------------------------------------------------- 1 | ######################################################## 2 | ### ***DO NOT EDIT*** This is an auto-generated file ### 3 | ######################################################## 4 | ARG BASE_IMAGE=mcr.microsoft.com/java/jre-headless:11u3-zulu-alpine-with-tools 5 | ARG GIT_COMMIT=unspecified 6 | FROM $BASE_IMAGE 7 | 8 | # Re-define ARG to make the build argument available for use in the rest of the Dockerfile 9 | ARG GIT_COMMIT 10 | 11 | LABEL maintainer="Azure App Services Container Images " 12 | 13 | ENV AI_VERSION 2.1.2 14 | ENV TOMCAT_VERSION 9.0.20 15 | ENV TOMCAT_MAJOR 9 16 | ENV GIT_COMMIT $GIT_COMMIT 17 | ENV APPINSIGHTS_ENABLED 0 18 | 19 | ENV PORT 80 20 | ENV SSH_PORT 2222 21 | 22 | ENV PATH /usr/local/tomcat/bin:$PATH 23 | 24 | # Remove the sample webapps provided by Tomcat 25 | RUN rm -rf /usr/local/tomcat/webapps/ 26 | 27 | COPY tmp/shared/misc/init_container.sh /bin/init_container.sh 28 | COPY tmp/shared/tomcat/9.0/web-appservice-ai.xml /tmp/tomcat/conf/web-appservice-ai.xml 29 | COPY tmp/shared/misc/index.jsp /tmp/tomcat/webapps/ROOT/index.jsp 30 | COPY tmp/shared/misc/sshd_config /etc/ssh/ 31 | COPY tmp/shared/app_insights/AI-Agent.xml /usr/local/app_insights/aiagent/ 32 | COPY tmp/shared/app_insights/ApplicationInsights.xml /usr/local/app_insights/tomcat_lib/ 33 | 34 | RUN apk add --update openssh-server bash openrc \ 35 | && rm -rf /var/cache/apk/* \ 36 | # Remove unnecessary services 37 | && rm -f /etc/init.d/hwdrivers \ 38 | /etc/init.d/hwclock \ 39 | /etc/init.d/mtab \ 40 | /etc/init.d/bootmisc \ 41 | /etc/init.d/modules \ 42 | /etc/init.d/modules-load \ 43 | /etc/init.d/modloop \ 44 | # Can't do cgroups 45 | && sed -i 's/\tcgroup_add_service/\t#cgroup_add_service/g' /lib/rc/sh/openrc-run.sh \ 46 | && echo "root:Docker!" | chpasswd \ 47 | && wget -O /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz https://archive.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz --no-verbose \ 48 | && tar xvzf /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz -C /tmp \ 49 | && mv /tmp/apache-tomcat-$TOMCAT_VERSION /usr/local/tomcat \ 50 | && rm -rf /usr/local/tomcat/webapps \ 51 | && rm -f /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz \ 52 | && wget -O /usr/local/app_insights/tomcat_lib/applicationinsights-core-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-core-$AI_VERSION.jar --no-verbose \ 53 | && wget -O /usr/local/app_insights/tomcat_lib/applicationinsights-web-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-web-$AI_VERSION.jar --no-verbose \ 54 | && wget -O /usr/local/app_insights/aiagent/applicationinsights-agent-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-agent-$AI_VERSION.jar --no-verbose \ 55 | && chmod 755 /bin/init_container.sh 56 | 57 | COPY tmp/shared/tomcat/9.0/server.xml /usr/local/tomcat/conf/server.xml 58 | COPY tmp/shared/tomcat/9.0/catalina.properties /usr/local/tomcat/conf/catalina.properties 59 | COPY tmp/shared/tomcat/9.0/context.xml /usr/local/tomcat/conf/context.xml 60 | COPY tmp/shared/tomcat/9.0/logging.properties /usr/local/tomcat/conf/logging.properties 61 | COPY tmp/shared/tomcat/9.0/web-appservice.xml /usr/local/tomcat/conf/web.xml 62 | COPY tmp/shared/easyauth/azure.appservice.easyauth.jar /usr/local/tomcat/lib/ 63 | COPY tmp/shared/appservice/azure.appservice.jar /usr/local/tomcat/lib/ 64 | COPY tmp/shared/tomcat/common/setenv.sh /usr/local/tomcat/bin/ 65 | 66 | EXPOSE 80 2222 67 | 68 | ENTRYPOINT ["/bin/init_container.sh"] 69 | ######################################################## 70 | ### ***DO NOT EDIT*** This is an auto-generated file ### 71 | ######################################################## 72 | 73 | -------------------------------------------------------------------------------- /9.0-jre8/Dockerfile: -------------------------------------------------------------------------------- 1 | ######################################################## 2 | ### ***DO NOT EDIT*** This is an auto-generated file ### 3 | ######################################################## 4 | ARG BASE_IMAGE=mcr.microsoft.com/java/jre-headless:8u212-zulu-alpine-with-tools 5 | ARG GIT_COMMIT=unspecified 6 | FROM $BASE_IMAGE 7 | 8 | # Re-define ARG to make the build argument available for use in the rest of the Dockerfile 9 | ARG GIT_COMMIT 10 | 11 | LABEL maintainer="Azure App Services Container Images " 12 | 13 | ENV AI_VERSION 2.1.2 14 | ENV TOMCAT_VERSION 9.0.20 15 | ENV TOMCAT_MAJOR 9 16 | ENV GIT_COMMIT $GIT_COMMIT 17 | ENV APPINSIGHTS_ENABLED 1 18 | 19 | ENV PORT 80 20 | ENV SSH_PORT 2222 21 | 22 | ENV PATH /usr/local/tomcat/bin:$PATH 23 | 24 | # Remove the sample webapps provided by Tomcat 25 | RUN rm -rf /usr/local/tomcat/webapps/ 26 | 27 | COPY tmp/shared/misc/init_container.sh /bin/init_container.sh 28 | COPY tmp/shared/tomcat/9.0/web-appservice-ai.xml /tmp/tomcat/conf/web-appservice-ai.xml 29 | COPY tmp/shared/misc/index.jsp /tmp/tomcat/webapps/ROOT/index.jsp 30 | COPY tmp/shared/misc/sshd_config /etc/ssh/ 31 | COPY tmp/shared/app_insights/AI-Agent.xml /usr/local/app_insights/aiagent/ 32 | COPY tmp/shared/app_insights/ApplicationInsights.xml /usr/local/app_insights/tomcat_lib/ 33 | 34 | RUN apk add --update openssh-server bash openrc \ 35 | && rm -rf /var/cache/apk/* \ 36 | # Remove unnecessary services 37 | && rm -f /etc/init.d/hwdrivers \ 38 | /etc/init.d/hwclock \ 39 | /etc/init.d/mtab \ 40 | /etc/init.d/bootmisc \ 41 | /etc/init.d/modules \ 42 | /etc/init.d/modules-load \ 43 | /etc/init.d/modloop \ 44 | # Can't do cgroups 45 | && sed -i 's/\tcgroup_add_service/\t#cgroup_add_service/g' /lib/rc/sh/openrc-run.sh \ 46 | && echo "root:Docker!" | chpasswd \ 47 | && wget -O /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz https://archive.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz --no-verbose \ 48 | && tar xvzf /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz -C /tmp \ 49 | && mv /tmp/apache-tomcat-$TOMCAT_VERSION /usr/local/tomcat \ 50 | && rm -rf /usr/local/tomcat/webapps \ 51 | && rm -f /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz \ 52 | && wget -O /usr/local/app_insights/tomcat_lib/applicationinsights-core-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-core-$AI_VERSION.jar --no-verbose \ 53 | && wget -O /usr/local/app_insights/tomcat_lib/applicationinsights-web-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-web-$AI_VERSION.jar --no-verbose \ 54 | && wget -O /usr/local/app_insights/aiagent/applicationinsights-agent-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-agent-$AI_VERSION.jar --no-verbose \ 55 | && chmod 755 /bin/init_container.sh 56 | 57 | COPY tmp/shared/tomcat/9.0/server.xml /usr/local/tomcat/conf/server.xml 58 | COPY tmp/shared/tomcat/9.0/catalina.properties /usr/local/tomcat/conf/catalina.properties 59 | COPY tmp/shared/tomcat/9.0/context.xml /usr/local/tomcat/conf/context.xml 60 | COPY tmp/shared/tomcat/9.0/logging.properties /usr/local/tomcat/conf/logging.properties 61 | COPY tmp/shared/tomcat/9.0/web-appservice.xml /usr/local/tomcat/conf/web.xml 62 | COPY tmp/shared/easyauth/azure.appservice.easyauth.jar /usr/local/tomcat/lib/ 63 | COPY tmp/shared/appservice/azure.appservice.jar /usr/local/tomcat/lib/ 64 | COPY tmp/shared/tomcat/common/setenv.sh /usr/local/tomcat/bin/ 65 | 66 | EXPOSE 80 2222 67 | 68 | ENTRYPOINT ["/bin/init_container.sh"] 69 | ######################################################## 70 | ### ***DO NOT EDIT*** This is an auto-generated file ### 71 | ######################################################## 72 | 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apache Tomcat on Azure App Service 2 | 3 | This repository contains Docker images for Apache Tomcat for running on Azure App Service. 4 | 5 | ## Build 6 | Run the following commands in powershell: 7 | ```powershell 8 | .\scripts\setup.ps1 # On Linux: ./scripts/setup.sh 9 | cd # Example: cd 8.5-jre8 10 | docker build --no-cache -t tomcat . 11 | ``` 12 | To change the base image that is used, you can run: 13 | ``` 14 | docker build --no-cache [--build-arg BASE_IMAGE=] -t tomcat . 15 | ``` 16 | 17 | If you are building on Windows, make sure you configure git as follows to avoid CRLF issues: `git config --global core.autocrlf false` 18 | 19 | ## Run the image locally 20 | 21 | ``` 22 | docker run tomcat 23 | ``` 24 | 25 | ## Deploy and run the sample app to Azure 26 | Run the following commands in powershell: 27 | ```powershell 28 | cd .\samples\spring-framework-petclinic 29 | ..\..\scripts\deployAndRunApp.ps1 -imageName [-webAppName ] [-appInsightsInstrumentationKey ] 30 | 31 | # Example: ..\..\scripts\deployAndRunApp.ps1 -imageName myrepo/myimage:mytag 32 | ``` 33 | 34 | ## SSH to the Docker container 35 | 36 | ``` 37 | container_ip=IP_OF_THE_DOCKER_CONTAINER 38 | ssh root@$container_ip -p 2222 39 | ``` 40 | 41 | The username is `root` and password is `Docker!`. For detailed documentation, refer https://docs.microsoft.com/en-us/azure/app-service/containers/tutorial-custom-docker-image. 42 | 43 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_style = space 9 | 10 | [*.{java,xml}] 11 | indent_size = 4 12 | trim_trailing_whitespace = true 13 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse 2 | .settings/ 3 | .classpath 4 | .project 5 | bin/ 6 | 7 | # IntelliJ IDEA 8 | .idea 9 | *.iml 10 | 11 | # Maven 12 | target/ 13 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip 2 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: oraclejdk8 3 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/deployApp.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | Param( 3 | [Parameter(Mandatory=$True, HelpMessage="Example: perftest1. This will create a web app http://perftest1.azurewebsites.net")] 4 | [string]$webAppName, 5 | 6 | [Parameter(Mandatory=$True, HelpMessage="Example: myrepo/tomcat:8.5-jre8")] 7 | [string]$imageName, 8 | 9 | [Parameter(Mandatory=$False, HelpMessage="Example: A Valid GUID key OR Empty")] 10 | [string]$appInsightsInstrumentationKey 11 | ) 12 | 13 | $env:RESOURCEGROUP_NAME='tomcat-perftest' 14 | $env:WEBAPP_NAME=$webAppName 15 | $env:WEBAPP_PLAN_NAME=$webAppName # use the same name for the web app and app service plan 16 | $env:IMAGE_NAME=$imageName 17 | $env:APPINSIGHTS_INSTRUMENTATIONKEY=$appInsightsInstrumentationKey 18 | $env:REGION='westus' 19 | 20 | Write-Host -ForegroundColor Green "Deploying to '$env:WEBAPP_NAME'" 21 | Write-Host -ForegroundColor Green "Container Name: '$env:IMAGE_NAME'" 22 | Write-Host -ForegroundColor Green "Resource group: '$env:RESOURCEGROUP_NAME'" 23 | Write-Host -ForegroundColor Green "APPINSIGHTS_INSTRUMENTATIONKEY: '$env:APPINSIGHTS_INSTRUMENTATIONKEY'" 24 | 25 | mvn package 26 | mvn azure-webapp:deploy 27 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/sonar-project.properties: -------------------------------------------------------------------------------- 1 | # Required metadata 2 | sonar.projectKey=java-sonar-runner-simple 3 | sonar.projectName=Simple Java project analyzed with the SonarQube Runner 4 | sonar.projectVersion=1.0 5 | 6 | # Comma-separated paths to directories with sources (required) 7 | sonar.sources=src 8 | 9 | # Language 10 | sonar.language=java 11 | 12 | # Encoding of the source files 13 | sonar.sourceEncoding=UTF-8 -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/PetclinicInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic; 17 | 18 | import org.springframework.web.context.WebApplicationContext; 19 | import org.springframework.web.context.support.XmlWebApplicationContext; 20 | import org.springframework.web.filter.CharacterEncodingFilter; 21 | import org.springframework.web.servlet.DispatcherServlet; 22 | import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer; 23 | 24 | import javax.servlet.Filter; 25 | import javax.servlet.ServletContext; 26 | 27 | 28 | /** 29 | * In Servlet 3.0+ environments, this class replaces the traditional {@code web.xml}-based approach in order to configure the 30 | * {@link ServletContext} programmatically. 31 | *

32 | * Create the Spring "root" application context.
33 | * Register a {@link DispatcherServlet} in the servlet context.
34 | * For both servlets, register a {@link CharacterEncodingFilter}. 35 | *

36 | * 37 | * @author Antoine Rey 38 | */ 39 | public class PetclinicInitializer extends AbstractDispatcherServletInitializer { 40 | 41 | /** 42 | * Spring profile used to choose the persistence layer implementation. 43 | *

44 | * When using Spring jpa, use: jpa 45 | * When using Spring JDBC, use: jdbc 46 | * When using Spring Data JPA, use: spring-data-jpa 47 | *

48 | *

49 | * You also may use the -Dspring.profiles.active=jdbc VM options to change 50 | * default jpa Spring profile. 51 | */ 52 | private static final String SPRING_PROFILE = "jpa"; 53 | 54 | @Override 55 | protected WebApplicationContext createRootApplicationContext() { 56 | XmlWebApplicationContext rootAppContext = new XmlWebApplicationContext(); 57 | rootAppContext.setConfigLocations("classpath:spring/business-config.xml", "classpath:spring/tools-config.xml"); 58 | rootAppContext.getEnvironment().setDefaultProfiles(SPRING_PROFILE); 59 | return rootAppContext; 60 | } 61 | 62 | @Override 63 | protected WebApplicationContext createServletApplicationContext() { 64 | XmlWebApplicationContext webAppContext = new XmlWebApplicationContext(); 65 | webAppContext.setConfigLocation("classpath:spring/mvc-core-config.xml"); 66 | return webAppContext; 67 | } 68 | 69 | @Override 70 | protected String[] getServletMappings() { 71 | return new String[]{"/"}; 72 | } 73 | 74 | @Override 75 | protected Filter[] getServletFilters() { 76 | // Used to provide the ability to enter Chinese characters inside the Owner Form 77 | CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter("UTF-8", true); 78 | return new Filter[]{characterEncodingFilter}; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import javax.persistence.GeneratedValue; 19 | import javax.persistence.GenerationType; 20 | import javax.persistence.Id; 21 | import javax.persistence.MappedSuperclass; 22 | 23 | /** 24 | * Simple JavaBean domain object with an id property. Used as a base class for objects needing this property. 25 | * 26 | * @author Ken Krebs 27 | * @author Juergen Hoeller 28 | */ 29 | @MappedSuperclass 30 | public class BaseEntity { 31 | @Id 32 | @GeneratedValue(strategy = GenerationType.IDENTITY) 33 | protected Integer id; 34 | 35 | public Integer getId() { 36 | return id; 37 | } 38 | 39 | public void setId(Integer id) { 40 | this.id = id; 41 | } 42 | 43 | public boolean isNew() { 44 | return this.id == null; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import javax.persistence.Column; 19 | import javax.persistence.MappedSuperclass; 20 | 21 | 22 | /** 23 | * Simple JavaBean domain object adds a name property to BaseEntity. Used as a base class for objects 24 | * needing these properties. 25 | * 26 | * @author Ken Krebs 27 | * @author Juergen Hoeller 28 | */ 29 | @MappedSuperclass 30 | public class NamedEntity extends BaseEntity { 31 | 32 | @Column(name = "name") 33 | private String name; 34 | 35 | public String getName() { 36 | return this.name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return this.getName(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/model/Person.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import javax.persistence.Column; 19 | import javax.persistence.MappedSuperclass; 20 | 21 | import org.hibernate.validator.constraints.NotEmpty; 22 | 23 | /** 24 | * Simple JavaBean domain object representing an person. 25 | * 26 | * @author Ken Krebs 27 | */ 28 | @MappedSuperclass 29 | public class Person extends BaseEntity { 30 | 31 | @Column(name = "first_name") 32 | @NotEmpty 33 | protected String firstName; 34 | 35 | @Column(name = "last_name") 36 | @NotEmpty 37 | protected String lastName; 38 | 39 | public String getFirstName() { 40 | return this.firstName; 41 | } 42 | 43 | public void setFirstName(String firstName) { 44 | this.firstName = firstName; 45 | } 46 | 47 | public String getLastName() { 48 | return this.lastName; 49 | } 50 | 51 | public void setLastName(String lastName) { 52 | this.lastName = lastName; 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/model/Pet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import org.springframework.beans.support.MutableSortDefinition; 19 | import org.springframework.beans.support.PropertyComparator; 20 | import org.springframework.format.annotation.DateTimeFormat; 21 | 22 | import javax.persistence.CascadeType; 23 | import javax.persistence.Column; 24 | import javax.persistence.Entity; 25 | import javax.persistence.FetchType; 26 | import javax.persistence.JoinColumn; 27 | import javax.persistence.ManyToOne; 28 | import javax.persistence.OneToMany; 29 | import javax.persistence.Table; 30 | 31 | import java.time.LocalDate; 32 | import java.util.ArrayList; 33 | import java.util.Collections; 34 | import java.util.HashSet; 35 | import java.util.List; 36 | import java.util.Set; 37 | 38 | /** 39 | * Simple business object representing a pet. 40 | * 41 | * @author Ken Krebs 42 | * @author Juergen Hoeller 43 | * @author Sam Brannen 44 | */ 45 | @Entity 46 | @Table(name = "pets") 47 | public class Pet extends NamedEntity { 48 | 49 | @Column(name = "birth_date") 50 | @DateTimeFormat(pattern = "yyyy/MM/dd") 51 | private LocalDate birthDate; 52 | 53 | @ManyToOne 54 | @JoinColumn(name = "type_id") 55 | private PetType type; 56 | 57 | @ManyToOne 58 | @JoinColumn(name = "owner_id") 59 | private Owner owner; 60 | 61 | @OneToMany(cascade = CascadeType.ALL, mappedBy = "pet", fetch = FetchType.EAGER) 62 | private Set visits; 63 | 64 | 65 | public void setBirthDate(LocalDate birthDate) { 66 | this.birthDate = birthDate; 67 | } 68 | 69 | public LocalDate getBirthDate() { 70 | return this.birthDate; 71 | } 72 | 73 | public PetType getType() { 74 | return this.type; 75 | } 76 | 77 | public void setType(PetType type) { 78 | this.type = type; 79 | } 80 | 81 | public Owner getOwner() { 82 | return this.owner; 83 | } 84 | 85 | protected void setOwner(Owner owner) { 86 | this.owner = owner; 87 | } 88 | 89 | protected Set getVisitsInternal() { 90 | if (this.visits == null) { 91 | this.visits = new HashSet<>(); 92 | } 93 | return this.visits; 94 | } 95 | 96 | protected void setVisitsInternal(Set visits) { 97 | this.visits = visits; 98 | } 99 | 100 | public List getVisits() { 101 | List sortedVisits = new ArrayList<>(getVisitsInternal()); 102 | PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false)); 103 | return Collections.unmodifiableList(sortedVisits); 104 | } 105 | 106 | public void addVisit(Visit visit) { 107 | getVisitsInternal().add(visit); 108 | visit.setPet(this); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/model/PetType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import javax.persistence.Entity; 19 | import javax.persistence.Table; 20 | 21 | /** 22 | * @author Juergen Hoeller 23 | * Can be Cat, Dog, Hamster... 24 | */ 25 | @Entity 26 | @Table(name = "types") 27 | public class PetType extends NamedEntity { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/model/Specialty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import javax.persistence.Entity; 19 | import javax.persistence.Table; 20 | 21 | /** 22 | * Models a {@link Vet Vet's} specialty (for example, dentistry). 23 | * 24 | * @author Juergen Hoeller 25 | */ 26 | @Entity 27 | @Table(name = "specialties") 28 | public class Specialty extends NamedEntity { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/model/Vet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Collections; 20 | import java.util.HashSet; 21 | import java.util.List; 22 | import java.util.Set; 23 | 24 | import javax.persistence.Entity; 25 | import javax.persistence.FetchType; 26 | import javax.persistence.JoinColumn; 27 | import javax.persistence.JoinTable; 28 | import javax.persistence.ManyToMany; 29 | import javax.persistence.Table; 30 | import javax.xml.bind.annotation.XmlElement; 31 | 32 | import org.springframework.beans.support.MutableSortDefinition; 33 | import org.springframework.beans.support.PropertyComparator; 34 | 35 | /** 36 | * Simple JavaBean domain object representing a veterinarian. 37 | * 38 | * @author Ken Krebs 39 | * @author Juergen Hoeller 40 | * @author Sam Brannen 41 | * @author Arjen Poutsma 42 | */ 43 | @Entity 44 | @Table(name = "vets") 45 | public class Vet extends Person { 46 | 47 | @ManyToMany(fetch = FetchType.EAGER) 48 | @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), 49 | inverseJoinColumns = @JoinColumn(name = "specialty_id")) 50 | private Set specialties; 51 | 52 | protected Set getSpecialtiesInternal() { 53 | if (this.specialties == null) { 54 | this.specialties = new HashSet<>(); 55 | } 56 | return this.specialties; 57 | } 58 | 59 | protected void setSpecialtiesInternal(Set specialties) { 60 | this.specialties = specialties; 61 | } 62 | 63 | @XmlElement 64 | public List getSpecialties() { 65 | List sortedSpecs = new ArrayList<>(getSpecialtiesInternal()); 66 | PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true)); 67 | return Collections.unmodifiableList(sortedSpecs); 68 | } 69 | 70 | public int getNrOfSpecialties() { 71 | return getSpecialtiesInternal().size(); 72 | } 73 | 74 | public void addSpecialty(Specialty specialty) { 75 | getSpecialtiesInternal().add(specialty); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/model/Vets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import javax.xml.bind.annotation.XmlElement; 22 | import javax.xml.bind.annotation.XmlRootElement; 23 | 24 | /** 25 | * Simple domain object representing a list of veterinarians. Mostly here to be used for the 'vets' {@link 26 | * org.springframework.web.servlet.view.xml.MarshallingView}. 27 | * 28 | * @author Arjen Poutsma 29 | */ 30 | @XmlRootElement 31 | public class Vets { 32 | 33 | private List vets; 34 | 35 | @XmlElement 36 | public List getVetList() { 37 | if (vets == null) { 38 | vets = new ArrayList<>(); 39 | } 40 | return vets; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/model/Visit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.model; 17 | 18 | import org.hibernate.validator.constraints.NotEmpty; 19 | import org.springframework.format.annotation.DateTimeFormat; 20 | 21 | import javax.persistence.Column; 22 | import javax.persistence.Entity; 23 | import javax.persistence.JoinColumn; 24 | import javax.persistence.ManyToOne; 25 | import javax.persistence.Table; 26 | import java.time.LocalDate; 27 | 28 | /** 29 | * Simple JavaBean domain object representing a visit. 30 | * 31 | * @author Ken Krebs 32 | */ 33 | @Entity 34 | @Table(name = "visits") 35 | public class Visit extends BaseEntity { 36 | 37 | /** 38 | * Holds value of property date. 39 | */ 40 | @Column(name = "visit_date") 41 | @DateTimeFormat(pattern = "yyyy/MM/dd") 42 | private LocalDate date; 43 | 44 | /** 45 | * Holds value of property description. 46 | */ 47 | @NotEmpty 48 | @Column(name = "description") 49 | private String description; 50 | 51 | /** 52 | * Holds value of property pet. 53 | */ 54 | @ManyToOne 55 | @JoinColumn(name = "pet_id") 56 | private Pet pet; 57 | 58 | 59 | /** 60 | * Creates a new instance of Visit for the current date 61 | */ 62 | public Visit() { 63 | this.date = LocalDate.now(); 64 | } 65 | 66 | 67 | /** 68 | * Getter for property date. 69 | * 70 | * @return Value of property date. 71 | */ 72 | public LocalDate getDate() { 73 | return this.date; 74 | } 75 | 76 | /** 77 | * Setter for property date. 78 | * 79 | * @param date New value of property date. 80 | */ 81 | public void setDate(LocalDate date) { 82 | this.date = date; 83 | } 84 | 85 | /** 86 | * Getter for property description. 87 | * 88 | * @return Value of property description. 89 | */ 90 | public String getDescription() { 91 | return this.description; 92 | } 93 | 94 | /** 95 | * Setter for property description. 96 | * 97 | * @param description New value of property description. 98 | */ 99 | public void setDescription(String description) { 100 | this.description = description; 101 | } 102 | 103 | /** 104 | * Getter for property pet. 105 | * 106 | * @return Value of property pet. 107 | */ 108 | public Pet getPet() { 109 | return this.pet; 110 | } 111 | 112 | /** 113 | * Setter for property pet. 114 | * 115 | * @param pet New value of property pet. 116 | */ 117 | public void setPet(Pet pet) { 118 | this.pet = pet; 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/model/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The classes in this package represent PetClinic's business layer. 3 | */ 4 | package org.springframework.samples.petclinic.model; 5 | 6 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository; 17 | 18 | import java.util.Collection; 19 | 20 | import org.springframework.dao.DataAccessException; 21 | import org.springframework.samples.petclinic.model.BaseEntity; 22 | import org.springframework.samples.petclinic.model.Owner; 23 | 24 | /** 25 | * Repository class for Owner domain objects All method names are compliant with Spring Data naming 26 | * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation 27 | * 28 | * @author Ken Krebs 29 | * @author Juergen Hoeller 30 | * @author Sam Brannen 31 | * @author Michael Isvy 32 | */ 33 | public interface OwnerRepository { 34 | 35 | /** 36 | * Retrieve Owners from the data store by last name, returning all owners whose last name starts 37 | * with the given name. 38 | * 39 | * @param lastName Value to search for 40 | * @return a Collection of matching Owners (or an empty Collection if none 41 | * found) 42 | */ 43 | Collection findByLastName(String lastName) throws DataAccessException; 44 | 45 | /** 46 | * Retrieve an Owner from the data store by id. 47 | * 48 | * @param id the id to search for 49 | * @return the Owner if found 50 | * @throws org.springframework.dao.DataRetrievalFailureException if not found 51 | */ 52 | Owner findById(int id) throws DataAccessException; 53 | 54 | 55 | /** 56 | * Save an Owner to the data store, either inserting or updating it. 57 | * 58 | * @param owner the Owner to save 59 | * @see BaseEntity#isNew 60 | */ 61 | void save(Owner owner) throws DataAccessException; 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository; 17 | 18 | import java.util.List; 19 | 20 | import org.springframework.dao.DataAccessException; 21 | import org.springframework.samples.petclinic.model.BaseEntity; 22 | import org.springframework.samples.petclinic.model.Pet; 23 | import org.springframework.samples.petclinic.model.PetType; 24 | 25 | /** 26 | * Repository class for Pet domain objects All method names are compliant with Spring Data naming 27 | * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation 28 | * 29 | * @author Ken Krebs 30 | * @author Juergen Hoeller 31 | * @author Sam Brannen 32 | * @author Michael Isvy 33 | */ 34 | public interface PetRepository { 35 | 36 | /** 37 | * Retrieve all PetTypes from the data store. 38 | * 39 | * @return a Collection of PetTypes 40 | */ 41 | List findPetTypes() throws DataAccessException; 42 | 43 | /** 44 | * Retrieve a Pet from the data store by id. 45 | * 46 | * @param id the id to search for 47 | * @return the Pet if found 48 | * @throws org.springframework.dao.DataRetrievalFailureException if not found 49 | */ 50 | Pet findById(int id) throws DataAccessException; 51 | 52 | /** 53 | * Save a Pet to the data store, either inserting or updating it. 54 | * 55 | * @param pet the Pet to save 56 | * @see BaseEntity#isNew 57 | */ 58 | void save(Pet pet) throws DataAccessException; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/VetRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository; 17 | 18 | import java.util.Collection; 19 | 20 | import org.springframework.dao.DataAccessException; 21 | import org.springframework.samples.petclinic.model.Vet; 22 | 23 | /** 24 | * Repository class for Vet domain objects All method names are compliant with Spring Data naming 25 | * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation 26 | * 27 | * @author Ken Krebs 28 | * @author Juergen Hoeller 29 | * @author Sam Brannen 30 | * @author Michael Isvy 31 | */ 32 | public interface VetRepository { 33 | 34 | /** 35 | * Retrieve all Vets from the data store. 36 | * 37 | * @return a Collection of Vets 38 | */ 39 | Collection findAll() throws DataAccessException; 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/VisitRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository; 17 | 18 | import java.util.List; 19 | 20 | import org.springframework.dao.DataAccessException; 21 | import org.springframework.samples.petclinic.model.BaseEntity; 22 | import org.springframework.samples.petclinic.model.Visit; 23 | 24 | /** 25 | * Repository class for Visit domain objects All method names are compliant with Spring Data naming 26 | * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation 27 | * 28 | * @author Ken Krebs 29 | * @author Juergen Hoeller 30 | * @author Sam Brannen 31 | * @author Michael Isvy 32 | */ 33 | public interface VisitRepository { 34 | 35 | /** 36 | * Save a Visit to the data store, either inserting or updating it. 37 | * 38 | * @param visit the Visit to save 39 | * @see BaseEntity#isNew 40 | */ 41 | void save(Visit visit) throws DataAccessException; 42 | 43 | List findByPetId(Integer petId); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jdbc; 17 | 18 | import org.springframework.samples.petclinic.model.Pet; 19 | 20 | /** 21 | * Subclass of Pet that carries temporary id properties which are only relevant for a JDBC implementation of the 22 | * PetRepository. 23 | * 24 | * @author Juergen Hoeller 25 | */ 26 | class JdbcPet extends Pet { 27 | 28 | private int typeId; 29 | 30 | private int ownerId; 31 | 32 | public int getTypeId() { 33 | return this.typeId; 34 | } 35 | 36 | public void setTypeId(int typeId) { 37 | this.typeId = typeId; 38 | } 39 | 40 | public int getOwnerId() { 41 | return this.ownerId; 42 | } 43 | 44 | public void setOwnerId(int ownerId) { 45 | this.ownerId = ownerId; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jdbc; 17 | 18 | import java.sql.ResultSet; 19 | import java.sql.SQLException; 20 | import java.time.LocalDate; 21 | import java.util.Date; 22 | 23 | import org.springframework.jdbc.core.RowMapper; 24 | 25 | /** 26 | * {@link RowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties 27 | * of the {@link JdbcPet} class. 28 | */ 29 | class JdbcPetRowMapper implements RowMapper { 30 | 31 | @Override 32 | public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException { 33 | JdbcPet pet = new JdbcPet(); 34 | pet.setId(rs.getInt("pets.id")); 35 | pet.setName(rs.getString("name")); 36 | pet.setBirthDate(rs.getObject("birth_date", LocalDate.class)); 37 | pet.setTypeId(rs.getInt("type_id")); 38 | pet.setOwnerId(rs.getInt("owner_id")); 39 | return pet; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jdbc; 17 | 18 | import org.springframework.data.jdbc.core.OneToManyResultSetExtractor; 19 | import org.springframework.jdbc.core.ResultSetExtractor; 20 | import org.springframework.samples.petclinic.model.Visit; 21 | 22 | import java.sql.ResultSet; 23 | import java.sql.SQLException; 24 | 25 | /** 26 | * {@link ResultSetExtractor} implementation by using the 27 | * {@link OneToManyResultSetExtractor} of Spring Data Core JDBC Extensions. 28 | */ 29 | public class JdbcPetVisitExtractor extends 30 | OneToManyResultSetExtractor { 31 | 32 | public JdbcPetVisitExtractor() { 33 | super(new JdbcPetRowMapper(), new JdbcVisitRowMapper()); 34 | } 35 | 36 | @Override 37 | protected Integer mapPrimaryKey(ResultSet rs) throws SQLException { 38 | return rs.getInt("pets.id"); 39 | } 40 | 41 | @Override 42 | protected Integer mapForeignKey(ResultSet rs) throws SQLException { 43 | if (rs.getObject("visits.pet_id") == null) { 44 | return null; 45 | } else { 46 | return rs.getInt("visits.pet_id"); 47 | } 48 | } 49 | 50 | @Override 51 | protected void addChild(JdbcPet root, Visit child) { 52 | root.addVisit(child); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jdbc; 17 | 18 | import java.sql.ResultSet; 19 | import java.sql.SQLException; 20 | import java.util.ArrayList; 21 | import java.util.Collection; 22 | import java.util.List; 23 | 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | import org.springframework.dao.DataAccessException; 26 | import org.springframework.jdbc.core.BeanPropertyRowMapper; 27 | import org.springframework.jdbc.core.JdbcTemplate; 28 | import org.springframework.samples.petclinic.model.Specialty; 29 | import org.springframework.samples.petclinic.model.Vet; 30 | import org.springframework.samples.petclinic.repository.VetRepository; 31 | import org.springframework.samples.petclinic.util.EntityUtils; 32 | import org.springframework.stereotype.Repository; 33 | 34 | /** 35 | * A simple JDBC-based implementation of the {@link VetRepository} interface. 36 | * 37 | * @author Ken Krebs 38 | * @author Juergen Hoeller 39 | * @author Rob Harrop 40 | * @author Sam Brannen 41 | * @author Thomas Risberg 42 | * @author Mark Fisher 43 | * @author Michael Isvy 44 | */ 45 | @Repository 46 | public class JdbcVetRepositoryImpl implements VetRepository { 47 | 48 | private JdbcTemplate jdbcTemplate; 49 | 50 | @Autowired 51 | public JdbcVetRepositoryImpl(JdbcTemplate jdbcTemplate) { 52 | this.jdbcTemplate = jdbcTemplate; 53 | } 54 | 55 | /** 56 | * Refresh the cache of Vets that the ClinicService is holding. 57 | */ 58 | @Override 59 | public Collection findAll() throws DataAccessException { 60 | List vets = new ArrayList<>(); 61 | // Retrieve the list of all vets. 62 | vets.addAll(this.jdbcTemplate.query( 63 | "SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name", 64 | BeanPropertyRowMapper.newInstance(Vet.class))); 65 | 66 | // Retrieve the list of all possible specialties. 67 | final List specialties = this.jdbcTemplate.query( 68 | "SELECT id, name FROM specialties", 69 | BeanPropertyRowMapper.newInstance(Specialty.class)); 70 | 71 | // Build each vet's list of specialties. 72 | for (Vet vet : vets) { 73 | final List vetSpecialtiesIds = this.jdbcTemplate.query( 74 | "SELECT specialty_id FROM vet_specialties WHERE vet_id=?", 75 | new BeanPropertyRowMapper() { 76 | @Override 77 | public Integer mapRow(ResultSet rs, int row) throws SQLException { 78 | return rs.getInt(1); 79 | } 80 | }, 81 | vet.getId()); 82 | for (int specialtyId : vetSpecialtiesIds) { 83 | Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId); 84 | vet.addSpecialty(specialty); 85 | } 86 | } 87 | return vets; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jdbc; 17 | 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.dao.DataAccessException; 20 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; 21 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 22 | import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 23 | import org.springframework.samples.petclinic.model.Visit; 24 | import org.springframework.samples.petclinic.repository.VisitRepository; 25 | import org.springframework.stereotype.Repository; 26 | 27 | import javax.sql.DataSource; 28 | 29 | import java.util.HashMap; 30 | import java.util.List; 31 | import java.util.Map; 32 | 33 | /** 34 | * A simple JDBC-based implementation of the {@link VisitRepository} interface. 35 | * 36 | * @author Ken Krebs 37 | * @author Juergen Hoeller 38 | * @author Rob Harrop 39 | * @author Sam Brannen 40 | * @author Thomas Risberg 41 | * @author Mark Fisher 42 | * @author Michael Isvy 43 | */ 44 | @Repository 45 | public class JdbcVisitRepositoryImpl implements VisitRepository { 46 | 47 | private NamedParameterJdbcTemplate jdbcTemplate; 48 | 49 | private SimpleJdbcInsert insertVisit; 50 | 51 | @Autowired 52 | public JdbcVisitRepositoryImpl(DataSource dataSource) { 53 | this.jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); 54 | 55 | this.insertVisit = new SimpleJdbcInsert(dataSource) 56 | .withTableName("visits") 57 | .usingGeneratedKeyColumns("id"); 58 | } 59 | 60 | 61 | @Override 62 | public void save(Visit visit) throws DataAccessException { 63 | if (visit.isNew()) { 64 | Number newKey = this.insertVisit.executeAndReturnKey( 65 | createVisitParameterSource(visit)); 66 | visit.setId(newKey.intValue()); 67 | } else { 68 | throw new UnsupportedOperationException("Visit update not supported"); 69 | } 70 | } 71 | 72 | 73 | /** 74 | * Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Visit} instance. 75 | */ 76 | private MapSqlParameterSource createVisitParameterSource(Visit visit) { 77 | return new MapSqlParameterSource() 78 | .addValue("id", visit.getId()) 79 | .addValue("visit_date", visit.getDate()) 80 | .addValue("description", visit.getDescription()) 81 | .addValue("pet_id", visit.getPet().getId()); 82 | } 83 | 84 | @Override 85 | public List findByPetId(Integer petId) { 86 | Map params = new HashMap<>(); 87 | params.put("id", petId); 88 | JdbcPet pet = this.jdbcTemplate.queryForObject( 89 | "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id", 90 | params, 91 | new JdbcPetRowMapper()); 92 | 93 | List visits = this.jdbcTemplate.query( 94 | "SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=:id", 95 | params, new JdbcVisitRowMapper()); 96 | 97 | for (Visit visit: visits) { 98 | visit.setPet(pet); 99 | } 100 | 101 | return visits; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jdbc; 17 | 18 | 19 | import org.springframework.jdbc.core.RowMapper; 20 | import org.springframework.samples.petclinic.model.Visit; 21 | 22 | import java.sql.ResultSet; 23 | import java.sql.SQLException; 24 | import java.time.LocalDate; 25 | import java.util.Date; 26 | 27 | /** 28 | * {@link RowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties 29 | * of the {@link Visit} class. 30 | */ 31 | class JdbcVisitRowMapper implements RowMapper { 32 | 33 | @Override 34 | public Visit mapRow(ResultSet rs, int row) throws SQLException { 35 | Visit visit = new Visit(); 36 | visit.setId(rs.getInt("visit_id")); 37 | visit.setDate(rs.getObject("visit_date", LocalDate.class)); 38 | visit.setDescription(rs.getString("description")); 39 | return visit; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jdbc/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The classes in this package represent the JDBC implementation 3 | * of PetClinic's persistence layer. 4 | */ 5 | package org.springframework.samples.petclinic.repository.jdbc; 6 | 7 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jpa; 17 | 18 | import java.util.Collection; 19 | 20 | import javax.persistence.EntityManager; 21 | import javax.persistence.PersistenceContext; 22 | import javax.persistence.Query; 23 | 24 | import org.springframework.orm.hibernate5.support.OpenSessionInViewFilter; 25 | import org.springframework.samples.petclinic.model.Owner; 26 | import org.springframework.samples.petclinic.repository.OwnerRepository; 27 | import org.springframework.stereotype.Repository; 28 | 29 | /** 30 | * JPA implementation of the {@link OwnerRepository} interface. 31 | * 32 | * @author Mike Keith 33 | * @author Rod Johnson 34 | * @author Sam Brannen 35 | * @author Michael Isvy 36 | * @since 22.4.2006 37 | */ 38 | @Repository 39 | public class JpaOwnerRepositoryImpl implements OwnerRepository { 40 | 41 | @PersistenceContext 42 | private EntityManager em; 43 | 44 | 45 | /** 46 | * Important: in the current version of this method, we load Owners with all their Pets and Visits while 47 | * we do not need Visits at all and we only need one property from the Pet objects (the 'name' property). 48 | * There are some ways to improve it such as: 49 | * - creating a Ligtweight class (example here: https://community.jboss.org/wiki/LightweightClass) 50 | * - Turning on lazy-loading and using {@link OpenSessionInViewFilter} 51 | */ 52 | @SuppressWarnings("unchecked") 53 | public Collection findByLastName(String lastName) { 54 | // using 'join fetch' because a single query should load both owners and pets 55 | // using 'left join fetch' because it might happen that an owner does not have pets yet 56 | Query query = this.em.createQuery("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName"); 57 | query.setParameter("lastName", lastName + "%"); 58 | return query.getResultList(); 59 | } 60 | 61 | @Override 62 | public Owner findById(int id) { 63 | // using 'join fetch' because a single query should load both owners and pets 64 | // using 'left join fetch' because it might happen that an owner does not have pets yet 65 | Query query = this.em.createQuery("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id"); 66 | query.setParameter("id", id); 67 | return (Owner) query.getSingleResult(); 68 | } 69 | 70 | 71 | @Override 72 | public void save(Owner owner) { 73 | if (owner.getId() == null) { 74 | this.em.persist(owner); 75 | } else { 76 | this.em.merge(owner); 77 | } 78 | 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jpa; 17 | 18 | import java.util.List; 19 | 20 | import javax.persistence.EntityManager; 21 | import javax.persistence.PersistenceContext; 22 | 23 | import org.springframework.samples.petclinic.model.Pet; 24 | import org.springframework.samples.petclinic.model.PetType; 25 | import org.springframework.samples.petclinic.repository.PetRepository; 26 | import org.springframework.stereotype.Repository; 27 | 28 | /** 29 | * JPA implementation of the {@link PetRepository} interface. 30 | * 31 | * @author Mike Keith 32 | * @author Rod Johnson 33 | * @author Sam Brannen 34 | * @author Michael Isvy 35 | * @since 22.4.2006 36 | */ 37 | @Repository 38 | public class JpaPetRepositoryImpl implements PetRepository { 39 | 40 | @PersistenceContext 41 | private EntityManager em; 42 | 43 | @Override 44 | @SuppressWarnings("unchecked") 45 | public List findPetTypes() { 46 | return this.em.createQuery("SELECT ptype FROM PetType ptype ORDER BY ptype.name").getResultList(); 47 | } 48 | 49 | @Override 50 | public Pet findById(int id) { 51 | return this.em.find(Pet.class, id); 52 | } 53 | 54 | @Override 55 | public void save(Pet pet) { 56 | if (pet.getId() == null) { 57 | this.em.persist(pet); 58 | } else { 59 | this.em.merge(pet); 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVetRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jpa; 17 | 18 | import org.springframework.samples.petclinic.model.Vet; 19 | import org.springframework.samples.petclinic.repository.VetRepository; 20 | import org.springframework.stereotype.Repository; 21 | 22 | import javax.persistence.EntityManager; 23 | import javax.persistence.PersistenceContext; 24 | import java.util.Collection; 25 | 26 | /** 27 | * JPA implementation of the {@link VetRepository} interface. 28 | * 29 | * @author Mike Keith 30 | * @author Rod Johnson 31 | * @author Sam Brannen 32 | * @author Michael Isvy 33 | * @since 22.4.2006 34 | */ 35 | @Repository 36 | public class JpaVetRepositoryImpl implements VetRepository { 37 | 38 | @PersistenceContext 39 | private EntityManager em; 40 | 41 | 42 | @Override 43 | @SuppressWarnings("unchecked") 44 | public Collection findAll() { 45 | return this.em.createQuery("SELECT distinct vet FROM Vet vet left join fetch vet.specialties ORDER BY vet.lastName, vet.firstName").getResultList(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.jpa; 17 | 18 | import java.util.List; 19 | 20 | import javax.persistence.EntityManager; 21 | import javax.persistence.PersistenceContext; 22 | import javax.persistence.Query; 23 | 24 | import org.springframework.samples.petclinic.model.Visit; 25 | import org.springframework.samples.petclinic.repository.VisitRepository; 26 | import org.springframework.stereotype.Repository; 27 | 28 | /** 29 | * JPA implementation of the ClinicService interface using EntityManager. 30 | *

31 | *

The mappings are defined in "orm.xml" located in the META-INF directory. 32 | * 33 | * @author Mike Keith 34 | * @author Rod Johnson 35 | * @author Sam Brannen 36 | * @author Michael Isvy 37 | * @since 22.4.2006 38 | */ 39 | @Repository 40 | public class JpaVisitRepositoryImpl implements VisitRepository { 41 | 42 | @PersistenceContext 43 | private EntityManager em; 44 | 45 | 46 | @Override 47 | public void save(Visit visit) { 48 | if (visit.getId() == null) { 49 | this.em.persist(visit); 50 | } else { 51 | this.em.merge(visit); 52 | } 53 | } 54 | 55 | 56 | @Override 57 | @SuppressWarnings("unchecked") 58 | public List findByPetId(Integer petId) { 59 | Query query = this.em.createQuery("SELECT v FROM Visit v where v.pet.id= :id"); 60 | query.setParameter("id", petId); 61 | return query.getResultList(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/jpa/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The classes in this package represent the JPA implementation 3 | * of PetClinic's persistence layer. 4 | */ 5 | package org.springframework.samples.petclinic.repository.jpa; 6 | 7 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.springdatajpa; 17 | 18 | import java.util.Collection; 19 | 20 | import org.springframework.data.jpa.repository.Query; 21 | import org.springframework.data.repository.Repository; 22 | import org.springframework.data.repository.query.Param; 23 | import org.springframework.samples.petclinic.model.Owner; 24 | import org.springframework.samples.petclinic.repository.OwnerRepository; 25 | 26 | /** 27 | * Spring Data JPA specialization of the {@link OwnerRepository} interface 28 | * 29 | * @author Michael Isvy 30 | * @since 15.1.2013 31 | */ 32 | public interface SpringDataOwnerRepository extends OwnerRepository, Repository { 33 | 34 | @Override 35 | @Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%") 36 | public Collection findByLastName(@Param("lastName") String lastName); 37 | 38 | @Override 39 | @Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id") 40 | public Owner findById(@Param("id") int id); 41 | } 42 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataPetRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.springdatajpa; 17 | 18 | import java.util.List; 19 | 20 | import org.springframework.dao.DataAccessException; 21 | import org.springframework.data.jpa.repository.Query; 22 | import org.springframework.data.repository.Repository; 23 | import org.springframework.samples.petclinic.model.Pet; 24 | import org.springframework.samples.petclinic.model.PetType; 25 | import org.springframework.samples.petclinic.repository.PetRepository; 26 | 27 | /** 28 | * Spring Data JPA specialization of the {@link PetRepository} interface 29 | * 30 | * @author Michael Isvy 31 | * @since 15.1.2013 32 | */ 33 | public interface SpringDataPetRepository extends PetRepository, Repository { 34 | 35 | @Override 36 | @Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name") 37 | List findPetTypes() throws DataAccessException; 38 | } 39 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVetRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.springdatajpa; 17 | 18 | import org.springframework.data.repository.Repository; 19 | import org.springframework.samples.petclinic.model.Vet; 20 | import org.springframework.samples.petclinic.repository.VetRepository; 21 | 22 | /** 23 | * Spring Data JPA specialization of the {@link VetRepository} interface 24 | * 25 | * @author Michael Isvy 26 | * @since 15.1.2013 27 | */ 28 | public interface SpringDataVetRepository extends VetRepository, Repository { 29 | } 30 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVisitRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.repository.springdatajpa; 17 | 18 | import org.springframework.data.repository.Repository; 19 | import org.springframework.samples.petclinic.model.Visit; 20 | import org.springframework.samples.petclinic.repository.VisitRepository; 21 | 22 | /** 23 | * Spring Data JPA specialization of the {@link VisitRepository} interface 24 | * 25 | * @author Michael Isvy 26 | * @since 15.1.2013 27 | */ 28 | public interface SpringDataVisitRepository extends VisitRepository, Repository { 29 | } 30 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/service/ClinicService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.service; 17 | 18 | import java.util.Collection; 19 | 20 | import org.springframework.dao.DataAccessException; 21 | import org.springframework.samples.petclinic.model.Owner; 22 | import org.springframework.samples.petclinic.model.Pet; 23 | import org.springframework.samples.petclinic.model.PetType; 24 | import org.springframework.samples.petclinic.model.Vet; 25 | import org.springframework.samples.petclinic.model.Visit; 26 | 27 | 28 | /** 29 | * Mostly used as a facade so all controllers have a single point of entry 30 | * 31 | * @author Michael Isvy 32 | */ 33 | public interface ClinicService { 34 | 35 | Collection findPetTypes() throws DataAccessException; 36 | 37 | Owner findOwnerById(int id) throws DataAccessException; 38 | 39 | Pet findPetById(int id) throws DataAccessException; 40 | 41 | void savePet(Pet pet) throws DataAccessException; 42 | 43 | void saveVisit(Visit visit) throws DataAccessException; 44 | 45 | Collection findVets() throws DataAccessException; 46 | 47 | void saveOwner(Owner owner) throws DataAccessException; 48 | 49 | Collection findOwnerByLastName(String lastName) throws DataAccessException; 50 | 51 | Collection findVisitsByPetId(int petId); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.service; 17 | 18 | import java.util.Collection; 19 | 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.cache.annotation.Cacheable; 22 | import org.springframework.dao.DataAccessException; 23 | import org.springframework.samples.petclinic.model.Owner; 24 | import org.springframework.samples.petclinic.model.Pet; 25 | import org.springframework.samples.petclinic.model.PetType; 26 | import org.springframework.samples.petclinic.model.Vet; 27 | import org.springframework.samples.petclinic.model.Visit; 28 | import org.springframework.samples.petclinic.repository.OwnerRepository; 29 | import org.springframework.samples.petclinic.repository.PetRepository; 30 | import org.springframework.samples.petclinic.repository.VetRepository; 31 | import org.springframework.samples.petclinic.repository.VisitRepository; 32 | import org.springframework.stereotype.Service; 33 | import org.springframework.transaction.annotation.Transactional; 34 | 35 | /** 36 | * Mostly used as a facade for all Petclinic controllers 37 | * Also a placeholder for @Transactional and @Cacheable annotations 38 | * 39 | * @author Michael Isvy 40 | */ 41 | @Service 42 | public class ClinicServiceImpl implements ClinicService { 43 | 44 | private PetRepository petRepository; 45 | private VetRepository vetRepository; 46 | private OwnerRepository ownerRepository; 47 | private VisitRepository visitRepository; 48 | 49 | @Autowired 50 | public ClinicServiceImpl(PetRepository petRepository, VetRepository vetRepository, OwnerRepository ownerRepository, VisitRepository visitRepository) { 51 | this.petRepository = petRepository; 52 | this.vetRepository = vetRepository; 53 | this.ownerRepository = ownerRepository; 54 | this.visitRepository = visitRepository; 55 | } 56 | 57 | @Override 58 | @Transactional(readOnly = true) 59 | public Collection findPetTypes() throws DataAccessException { 60 | return petRepository.findPetTypes(); 61 | } 62 | 63 | @Override 64 | @Transactional(readOnly = true) 65 | public Owner findOwnerById(int id) throws DataAccessException { 66 | return ownerRepository.findById(id); 67 | } 68 | 69 | @Override 70 | @Transactional(readOnly = true) 71 | public Collection findOwnerByLastName(String lastName) throws DataAccessException { 72 | return ownerRepository.findByLastName(lastName); 73 | } 74 | 75 | @Override 76 | @Transactional 77 | public void saveOwner(Owner owner) throws DataAccessException { 78 | ownerRepository.save(owner); 79 | } 80 | 81 | 82 | @Override 83 | @Transactional 84 | public void saveVisit(Visit visit) throws DataAccessException { 85 | visitRepository.save(visit); 86 | } 87 | 88 | 89 | @Override 90 | @Transactional(readOnly = true) 91 | public Pet findPetById(int id) throws DataAccessException { 92 | return petRepository.findById(id); 93 | } 94 | 95 | @Override 96 | @Transactional 97 | public void savePet(Pet pet) throws DataAccessException { 98 | petRepository.save(pet); 99 | } 100 | 101 | @Override 102 | @Transactional(readOnly = true) 103 | @Cacheable(value = "vets") 104 | public Collection findVets() throws DataAccessException { 105 | return vetRepository.findAll(); 106 | } 107 | 108 | @Override 109 | public Collection findVisitsByPetId(int petId) { 110 | return visitRepository.findByPetId(petId); 111 | } 112 | 113 | 114 | } 115 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/util/CallMonitoringAspect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.util; 17 | 18 | import org.aspectj.lang.ProceedingJoinPoint; 19 | import org.aspectj.lang.annotation.Around; 20 | import org.aspectj.lang.annotation.Aspect; 21 | import org.springframework.jmx.export.annotation.ManagedAttribute; 22 | import org.springframework.jmx.export.annotation.ManagedOperation; 23 | import org.springframework.jmx.export.annotation.ManagedResource; 24 | import org.springframework.util.StopWatch; 25 | 26 | /** 27 | * Simple aspect that monitors call count and call invocation time. It uses JMX annotations and therefore can be 28 | * monitored using any JMX console such as the jConsole 29 | *

30 | * This is only useful if you use JPA or JDBC. Spring-data-jpa doesn't have any correctly annotated classes to join on 31 | * 32 | * @author Rob Harrop 33 | * @author Juergen Hoeller 34 | * @author Michael Isvy 35 | * @since 2.5 36 | */ 37 | @ManagedResource("petclinic:type=CallMonitor") 38 | @Aspect 39 | public class CallMonitoringAspect { 40 | 41 | private boolean enabled = true; 42 | 43 | private int callCount = 0; 44 | 45 | private long accumulatedCallTime = 0; 46 | 47 | @ManagedAttribute 48 | public boolean isEnabled() { 49 | return enabled; 50 | } 51 | 52 | @ManagedAttribute 53 | public void setEnabled(boolean enabled) { 54 | this.enabled = enabled; 55 | } 56 | 57 | @ManagedOperation 58 | public void reset() { 59 | this.callCount = 0; 60 | this.accumulatedCallTime = 0; 61 | } 62 | 63 | @ManagedAttribute 64 | public int getCallCount() { 65 | return callCount; 66 | } 67 | 68 | @ManagedAttribute 69 | public long getCallTime() { 70 | if (this.callCount > 0) 71 | return this.accumulatedCallTime / this.callCount; 72 | else 73 | return 0; 74 | } 75 | 76 | 77 | @Around("within(@org.springframework.stereotype.Repository *)") 78 | public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable { 79 | if (this.enabled) { 80 | StopWatch sw = new StopWatch(joinPoint.toShortString()); 81 | 82 | sw.start("invoke"); 83 | try { 84 | return joinPoint.proceed(); 85 | } finally { 86 | sw.stop(); 87 | synchronized (this) { 88 | this.callCount++; 89 | this.accumulatedCallTime += sw.getTotalTimeMillis(); 90 | } 91 | } 92 | } else { 93 | return joinPoint.proceed(); 94 | } 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/util/EntityUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.samples.petclinic.util; 18 | 19 | import java.util.Collection; 20 | 21 | import org.springframework.orm.ObjectRetrievalFailureException; 22 | import org.springframework.samples.petclinic.model.BaseEntity; 23 | 24 | /** 25 | * Utility methods for handling entities. Separate from the BaseEntity class mainly because of dependency on the 26 | * ORM-associated ObjectRetrievalFailureException. 27 | * 28 | * @author Juergen Hoeller 29 | * @author Sam Brannen 30 | * @see org.springframework.samples.petclinic.model.BaseEntity 31 | * @since 29.10.2003 32 | */ 33 | public abstract class EntityUtils { 34 | 35 | /** 36 | * Look up the entity of the given class with the given id in the given collection. 37 | * 38 | * @param entities the collection to search 39 | * @param entityClass the entity class to look up 40 | * @param entityId the entity id to look up 41 | * @return the found entity 42 | * @throws ObjectRetrievalFailureException if the entity was not found 43 | */ 44 | public static T getById(Collection entities, Class entityClass, int entityId) 45 | throws ObjectRetrievalFailureException { 46 | for (T entity : entities) { 47 | if (entity.getId() == entityId && entityClass.isInstance(entity)) { 48 | return entity; 49 | } 50 | } 51 | throw new ObjectRetrievalFailureException(entityClass, entityId); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/web/CrashController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.web; 17 | 18 | import org.springframework.stereotype.Controller; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RequestMethod; 21 | 22 | /** 23 | * Controller used to showcase what happens when an exception is thrown 24 | * 25 | * @author Michael Isvy 26 | *

27 | * Also see how the bean of type 'SimpleMappingExceptionResolver' has been declared inside 28 | * /WEB-INF/mvc-core-config.xml 29 | */ 30 | @Controller 31 | public class CrashController { 32 | 33 | @RequestMapping(value = "/oups", method = RequestMethod.GET) 34 | public String triggerException() { 35 | throw new RuntimeException("Expected: controller used to showcase what " + 36 | "happens when an exception is thrown"); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/web/PetTypeFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.web; 17 | 18 | 19 | import java.text.ParseException; 20 | import java.util.Collection; 21 | import java.util.Locale; 22 | 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.format.Formatter; 25 | import org.springframework.samples.petclinic.model.PetType; 26 | import org.springframework.samples.petclinic.service.ClinicService; 27 | 28 | /** 29 | * Instructs Spring MVC on how to parse and print elements of type 'PetType'. Starting from Spring 3.0, Formatters have 30 | * come as an improvement in comparison to legacy PropertyEditors. See the following links for more details: - The 31 | * Spring ref doc: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/validation.html#format-Formatter-SPI 32 | * - A nice blog entry from Gordon Dickens: http://gordondickens.com/wordpress/2010/09/30/using-spring-3-0-custom-type-converter/ 33 | *

34 | * Also see how the bean 'conversionService' has been declared inside /WEB-INF/mvc-core-config.xml 35 | * 36 | * @author Mark Fisher 37 | * @author Juergen Hoeller 38 | * @author Michael Isvy 39 | */ 40 | public class PetTypeFormatter implements Formatter { 41 | 42 | private final ClinicService clinicService; 43 | 44 | 45 | @Autowired 46 | public PetTypeFormatter(ClinicService clinicService) { 47 | this.clinicService = clinicService; 48 | } 49 | 50 | @Override 51 | public String print(PetType petType, Locale locale) { 52 | return petType.getName(); 53 | } 54 | 55 | @Override 56 | public PetType parse(String text, Locale locale) throws ParseException { 57 | Collection findPetTypes = this.clinicService.findPetTypes(); 58 | for (PetType type : findPetTypes) { 59 | if (type.getName().equals(text)) { 60 | return type; 61 | } 62 | } 63 | throw new ParseException("type not found: " + text, 0); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.web; 17 | 18 | import org.springframework.samples.petclinic.model.Pet; 19 | import org.springframework.util.StringUtils; 20 | import org.springframework.validation.Errors; 21 | import org.springframework.validation.Validator; 22 | 23 | /** 24 | * Validator for Pet forms. 25 | *

26 | * We're not using Bean Validation annotations here because it is easier to define such validation rule in Java. 27 | *

28 | * 29 | * @author Ken Krebs 30 | * @author Juergen Hoeller 31 | */ 32 | public class PetValidator implements Validator { 33 | 34 | private static final String REQUIRED = "required"; 35 | 36 | @Override 37 | public void validate(Object obj, Errors errors) { 38 | Pet pet = (Pet) obj; 39 | String name = pet.getName(); 40 | // name validation 41 | if (!StringUtils.hasLength(name)) { 42 | errors.rejectValue("name", REQUIRED, REQUIRED); 43 | } 44 | 45 | // type validation 46 | if (pet.isNew() && pet.getType() == null) { 47 | errors.rejectValue("type", REQUIRED, REQUIRED); 48 | } 49 | 50 | // birth date validation 51 | if (pet.getBirthDate() == null) { 52 | errors.rejectValue("birthDate", REQUIRED, REQUIRED); 53 | } 54 | } 55 | 56 | /** 57 | * This Validator validates *just* Pet instances 58 | */ 59 | @Override 60 | public boolean supports(Class clazz) { 61 | return Pet.class.isAssignableFrom(clazz); 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/web/VetController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.web; 17 | 18 | import java.util.Map; 19 | 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.samples.petclinic.model.Vets; 22 | import org.springframework.samples.petclinic.service.ClinicService; 23 | import org.springframework.stereotype.Controller; 24 | import org.springframework.web.bind.annotation.RequestMapping; 25 | import org.springframework.web.bind.annotation.ResponseBody; 26 | 27 | /** 28 | * @author Juergen Hoeller 29 | * @author Mark Fisher 30 | * @author Ken Krebs 31 | * @author Arjen Poutsma 32 | */ 33 | @Controller 34 | public class VetController { 35 | 36 | private final ClinicService clinicService; 37 | 38 | 39 | @Autowired 40 | public VetController(ClinicService clinicService) { 41 | this.clinicService = clinicService; 42 | } 43 | 44 | @RequestMapping(value = { "/vets.html"}) 45 | public String showVetList(Map model) { 46 | // Here we are returning an object of type 'Vets' rather than a collection of Vet objects 47 | // so it is simpler for Object-Xml mapping 48 | Vets vets = new Vets(); 49 | vets.getVetList().addAll(this.clinicService.findVets()); 50 | model.put("vets", vets); 51 | return "vets/vetList"; 52 | } 53 | 54 | @RequestMapping(value = { "/vets.json", "/vets.xml"}) 55 | public 56 | @ResponseBody 57 | Vets showResourcesVetList() { 58 | // Here we are returning an object of type 'Vets' rather than a collection of Vet objects 59 | // so it is simpler for JSon/Object mapping 60 | Vets vets = new Vets(); 61 | vets.getVetList().addAll(this.clinicService.findVets()); 62 | return vets; 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/web/VisitController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.web; 17 | 18 | import java.util.Map; 19 | 20 | import javax.validation.Valid; 21 | 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.samples.petclinic.model.Pet; 24 | import org.springframework.samples.petclinic.model.Visit; 25 | import org.springframework.samples.petclinic.service.ClinicService; 26 | import org.springframework.stereotype.Controller; 27 | import org.springframework.validation.BindingResult; 28 | import org.springframework.web.bind.WebDataBinder; 29 | import org.springframework.web.bind.annotation.InitBinder; 30 | import org.springframework.web.bind.annotation.ModelAttribute; 31 | import org.springframework.web.bind.annotation.PathVariable; 32 | import org.springframework.web.bind.annotation.RequestMapping; 33 | import org.springframework.web.bind.annotation.RequestMethod; 34 | 35 | /** 36 | * @author Juergen Hoeller 37 | * @author Ken Krebs 38 | * @author Arjen Poutsma 39 | * @author Michael Isvy 40 | */ 41 | @Controller 42 | public class VisitController { 43 | 44 | private final ClinicService clinicService; 45 | 46 | 47 | @Autowired 48 | public VisitController(ClinicService clinicService) { 49 | this.clinicService = clinicService; 50 | } 51 | 52 | @InitBinder 53 | public void setAllowedFields(WebDataBinder dataBinder) { 54 | dataBinder.setDisallowedFields("id"); 55 | } 56 | 57 | /** 58 | * Called before each and every @RequestMapping annotated method. 59 | * 2 goals: 60 | * - Make sure we always have fresh data 61 | * - Since we do not use the session scope, make sure that Pet object always has an id 62 | * (Even though id is not part of the form fields) 63 | * 64 | * @param petId 65 | * @return Pet 66 | */ 67 | @ModelAttribute("visit") 68 | public Visit loadPetWithVisit(@PathVariable("petId") int petId) { 69 | Pet pet = this.clinicService.findPetById(petId); 70 | Visit visit = new Visit(); 71 | pet.addVisit(visit); 72 | return visit; 73 | } 74 | 75 | // Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called 76 | @RequestMapping(value = "/owners/*/pets/{petId}/visits/new", method = RequestMethod.GET) 77 | public String initNewVisitForm(@PathVariable("petId") int petId, Map model) { 78 | return "pets/createOrUpdateVisitForm"; 79 | } 80 | 81 | // Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is called 82 | @RequestMapping(value = "/owners/{ownerId}/pets/{petId}/visits/new", method = RequestMethod.POST) 83 | public String processNewVisitForm(@Valid Visit visit, BindingResult result) { 84 | if (result.hasErrors()) { 85 | return "pets/createOrUpdateVisitForm"; 86 | } else { 87 | this.clinicService.saveVisit(visit); 88 | return "redirect:/owners/{ownerId}"; 89 | } 90 | } 91 | 92 | @RequestMapping(value = "/owners/*/pets/{petId}/visits", method = RequestMethod.GET) 93 | public String showVisits(@PathVariable int petId, Map model) { 94 | model.put("visits", this.clinicService.findPetById(petId).getVisits()); 95 | return "visitList"; 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/java/org/springframework/samples/petclinic/web/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The classes in this package represent PetClinic's web presentation layer. 3 | */ 4 | package org.springframework.samples.petclinic.web; 5 | 6 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/cache/ehcache.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/db/hsqldb/initDB.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE vet_specialties IF EXISTS; 2 | DROP TABLE vets IF EXISTS; 3 | DROP TABLE specialties IF EXISTS; 4 | DROP TABLE visits IF EXISTS; 5 | DROP TABLE pets IF EXISTS; 6 | DROP TABLE types IF EXISTS; 7 | DROP TABLE owners IF EXISTS; 8 | 9 | 10 | CREATE TABLE vets ( 11 | id INTEGER IDENTITY PRIMARY KEY, 12 | first_name VARCHAR(30), 13 | last_name VARCHAR(30) 14 | ); 15 | CREATE INDEX vets_last_name ON vets (last_name); 16 | 17 | CREATE TABLE specialties ( 18 | id INTEGER IDENTITY PRIMARY KEY, 19 | name VARCHAR(80) 20 | ); 21 | CREATE INDEX specialties_name ON specialties (name); 22 | 23 | CREATE TABLE vet_specialties ( 24 | vet_id INTEGER NOT NULL, 25 | specialty_id INTEGER NOT NULL 26 | ); 27 | ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_vets FOREIGN KEY (vet_id) REFERENCES vets (id); 28 | ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_specialties FOREIGN KEY (specialty_id) REFERENCES specialties (id); 29 | 30 | CREATE TABLE types ( 31 | id INTEGER IDENTITY PRIMARY KEY, 32 | name VARCHAR(80) 33 | ); 34 | CREATE INDEX types_name ON types (name); 35 | 36 | CREATE TABLE owners ( 37 | id INTEGER IDENTITY PRIMARY KEY, 38 | first_name VARCHAR(30), 39 | last_name VARCHAR_IGNORECASE(30), 40 | address VARCHAR(255), 41 | city VARCHAR(80), 42 | telephone VARCHAR(20) 43 | ); 44 | CREATE INDEX owners_last_name ON owners (last_name); 45 | 46 | CREATE TABLE pets ( 47 | id INTEGER IDENTITY PRIMARY KEY, 48 | name VARCHAR(30), 49 | birth_date DATE, 50 | type_id INTEGER NOT NULL, 51 | owner_id INTEGER NOT NULL 52 | ); 53 | ALTER TABLE pets ADD CONSTRAINT fk_pets_owners FOREIGN KEY (owner_id) REFERENCES owners (id); 54 | ALTER TABLE pets ADD CONSTRAINT fk_pets_types FOREIGN KEY (type_id) REFERENCES types (id); 55 | CREATE INDEX pets_name ON pets (name); 56 | 57 | CREATE TABLE visits ( 58 | id INTEGER IDENTITY PRIMARY KEY, 59 | pet_id INTEGER NOT NULL, 60 | visit_date DATE, 61 | description VARCHAR(255) 62 | ); 63 | ALTER TABLE visits ADD CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets (id); 64 | CREATE INDEX visits_pet_id ON visits (pet_id); 65 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/db/hsqldb/populateDB.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO vets VALUES (1, 'James', 'Carter'); 2 | INSERT INTO vets VALUES (2, 'Helen', 'Leary'); 3 | INSERT INTO vets VALUES (3, 'Linda', 'Douglas'); 4 | INSERT INTO vets VALUES (4, 'Rafael', 'Ortega'); 5 | INSERT INTO vets VALUES (5, 'Henry', 'Stevens'); 6 | INSERT INTO vets VALUES (6, 'Sharon', 'Jenkins'); 7 | 8 | INSERT INTO specialties VALUES (1, 'radiology'); 9 | INSERT INTO specialties VALUES (2, 'surgery'); 10 | INSERT INTO specialties VALUES (3, 'dentistry'); 11 | 12 | INSERT INTO vet_specialties VALUES (2, 1); 13 | INSERT INTO vet_specialties VALUES (3, 2); 14 | INSERT INTO vet_specialties VALUES (3, 3); 15 | INSERT INTO vet_specialties VALUES (4, 2); 16 | INSERT INTO vet_specialties VALUES (5, 1); 17 | 18 | INSERT INTO types VALUES (1, 'cat'); 19 | INSERT INTO types VALUES (2, 'dog'); 20 | INSERT INTO types VALUES (3, 'lizard'); 21 | INSERT INTO types VALUES (4, 'snake'); 22 | INSERT INTO types VALUES (5, 'bird'); 23 | INSERT INTO types VALUES (6, 'hamster'); 24 | 25 | INSERT INTO owners VALUES (1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023'); 26 | INSERT INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749'); 27 | INSERT INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763'); 28 | INSERT INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198'); 29 | INSERT INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765'); 30 | INSERT INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654'); 31 | INSERT INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387'); 32 | INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683'); 33 | INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435'); 34 | INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487'); 35 | 36 | INSERT INTO pets VALUES (1, 'Leo', '2010-09-07', 1, 1); 37 | INSERT INTO pets VALUES (2, 'Basil', '2012-08-06', 6, 2); 38 | INSERT INTO pets VALUES (3, 'Rosy', '2011-04-17', 2, 3); 39 | INSERT INTO pets VALUES (4, 'Jewel', '2010-03-07', 2, 3); 40 | INSERT INTO pets VALUES (5, 'Iggy', '2010-11-30', 3, 4); 41 | INSERT INTO pets VALUES (6, 'George', '2010-01-20', 4, 5); 42 | INSERT INTO pets VALUES (7, 'Samantha', '2012-09-04', 1, 6); 43 | INSERT INTO pets VALUES (8, 'Max', '2012-09-04', 1, 6); 44 | INSERT INTO pets VALUES (9, 'Lucky', '2011-08-06', 5, 7); 45 | INSERT INTO pets VALUES (10, 'Mulligan', '2007-02-24', 2, 8); 46 | INSERT INTO pets VALUES (11, 'Freddy', '2010-03-09', 5, 9); 47 | INSERT INTO pets VALUES (12, 'Lucky', '2010-06-24', 2, 10); 48 | INSERT INTO pets VALUES (13, 'Sly', '2012-06-08', 1, 10); 49 | 50 | INSERT INTO visits VALUES (1, 7, '2013-01-01', 'rabies shot'); 51 | INSERT INTO visits VALUES (2, 8, '2013-01-02', 'rabies shot'); 52 | INSERT INTO visits VALUES (3, 8, '2013-01-03', 'neutered'); 53 | INSERT INTO visits VALUES (4, 7, '2013-01-04', 'spayed'); 54 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/db/mysql/initDB.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS petclinic; 2 | 3 | ALTER DATABASE petclinic 4 | DEFAULT CHARACTER SET utf8 5 | DEFAULT COLLATE utf8_general_ci; 6 | 7 | GRANT ALL PRIVILEGES ON petclinic.* TO pc@localhost IDENTIFIED BY 'pc'; 8 | 9 | USE petclinic; 10 | 11 | CREATE TABLE IF NOT EXISTS vets ( 12 | id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 13 | first_name VARCHAR(30), 14 | last_name VARCHAR(30), 15 | INDEX(last_name) 16 | ) engine=InnoDB; 17 | 18 | CREATE TABLE IF NOT EXISTS specialties ( 19 | id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 20 | name VARCHAR(80), 21 | INDEX(name) 22 | ) engine=InnoDB; 23 | 24 | CREATE TABLE IF NOT EXISTS vet_specialties ( 25 | vet_id INT(4) UNSIGNED NOT NULL, 26 | specialty_id INT(4) UNSIGNED NOT NULL, 27 | FOREIGN KEY (vet_id) REFERENCES vets(id), 28 | FOREIGN KEY (specialty_id) REFERENCES specialties(id), 29 | UNIQUE (vet_id,specialty_id) 30 | ) engine=InnoDB; 31 | 32 | CREATE TABLE IF NOT EXISTS types ( 33 | id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 34 | name VARCHAR(80), 35 | INDEX(name) 36 | ) engine=InnoDB; 37 | 38 | CREATE TABLE IF NOT EXISTS owners ( 39 | id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 40 | first_name VARCHAR(30), 41 | last_name VARCHAR(30), 42 | address VARCHAR(255), 43 | city VARCHAR(80), 44 | telephone VARCHAR(20), 45 | INDEX(last_name) 46 | ) engine=InnoDB; 47 | 48 | CREATE TABLE IF NOT EXISTS pets ( 49 | id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 50 | name VARCHAR(30), 51 | birth_date DATE, 52 | type_id INT(4) UNSIGNED NOT NULL, 53 | owner_id INT(4) UNSIGNED NOT NULL, 54 | INDEX(name), 55 | FOREIGN KEY (owner_id) REFERENCES owners(id), 56 | FOREIGN KEY (type_id) REFERENCES types(id) 57 | ) engine=InnoDB; 58 | 59 | CREATE TABLE IF NOT EXISTS visits ( 60 | id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 61 | pet_id INT(4) UNSIGNED NOT NULL, 62 | visit_date DATE, 63 | description VARCHAR(255), 64 | FOREIGN KEY (pet_id) REFERENCES pets(id) 65 | ) engine=InnoDB; 66 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | === Spring PetClinic sample application - MySQL Configuration === 3 | ================================================================================ 4 | 5 | @author Sam Brannen 6 | @author Costin Leau 7 | 8 | -------------------------------------------------------------------------------- 9 | 10 | 1) Download and install the MySQL database (e.g., MySQL Community Server 5.7.x), 11 | which can be found here: http://dev.mysql.com/downloads/mysql/ 12 | Alternatively, you may use the official MySQL docker image. Refer to the 13 | README.md for the Docker command line. 14 | 15 | 2) Dependency for Connector/J, the MySQL JDBC driver (e.g., Connector/J 5.1.x) is 16 | included in Petclinic pom.xml file. See the MySQL maven profile. 17 | Alternatively, download Connector/J JDBC driver from here: 18 | http://dev.mysql.com/downloads/connector/j/ 19 | and copy the MySQL JDBC driver JAR file (e.g., mysql-connector-java-5.1.5-bin.jar). 20 | 21 | 3) Change connection parameters into the MySQL profile of the pom.xml. 22 | Build and starth the web app with the MySQL profile: 23 | ./mvnw tomcat7:run -P MySQL 24 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/db/mysql/populateDB.sql: -------------------------------------------------------------------------------- 1 | INSERT IGNORE INTO vets VALUES (1, 'James', 'Carter'); 2 | INSERT IGNORE INTO vets VALUES (2, 'Helen', 'Leary'); 3 | INSERT IGNORE INTO vets VALUES (3, 'Linda', 'Douglas'); 4 | INSERT IGNORE INTO vets VALUES (4, 'Rafael', 'Ortega'); 5 | INSERT IGNORE INTO vets VALUES (5, 'Henry', 'Stevens'); 6 | INSERT IGNORE INTO vets VALUES (6, 'Sharon', 'Jenkins'); 7 | 8 | INSERT IGNORE INTO specialties VALUES (1, 'radiology'); 9 | INSERT IGNORE INTO specialties VALUES (2, 'surgery'); 10 | INSERT IGNORE INTO specialties VALUES (3, 'dentistry'); 11 | 12 | INSERT IGNORE INTO vet_specialties VALUES (2, 1); 13 | INSERT IGNORE INTO vet_specialties VALUES (3, 2); 14 | INSERT IGNORE INTO vet_specialties VALUES (3, 3); 15 | INSERT IGNORE INTO vet_specialties VALUES (4, 2); 16 | INSERT IGNORE INTO vet_specialties VALUES (5, 1); 17 | 18 | INSERT IGNORE INTO types VALUES (1, 'cat'); 19 | INSERT IGNORE INTO types VALUES (2, 'dog'); 20 | INSERT IGNORE INTO types VALUES (3, 'lizard'); 21 | INSERT IGNORE INTO types VALUES (4, 'snake'); 22 | INSERT IGNORE INTO types VALUES (5, 'bird'); 23 | INSERT IGNORE INTO types VALUES (6, 'hamster'); 24 | 25 | INSERT IGNORE INTO owners VALUES (1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023'); 26 | INSERT IGNORE INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749'); 27 | INSERT IGNORE INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763'); 28 | INSERT IGNORE INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198'); 29 | INSERT IGNORE INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765'); 30 | INSERT IGNORE INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654'); 31 | INSERT IGNORE INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387'); 32 | INSERT IGNORE INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683'); 33 | INSERT IGNORE INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435'); 34 | INSERT IGNORE INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487'); 35 | 36 | INSERT IGNORE INTO pets VALUES (1, 'Leo', '2000-09-07', 1, 1); 37 | INSERT IGNORE INTO pets VALUES (2, 'Basil', '2002-08-06', 6, 2); 38 | INSERT IGNORE INTO pets VALUES (3, 'Rosy', '2001-04-17', 2, 3); 39 | INSERT IGNORE INTO pets VALUES (4, 'Jewel', '2000-03-07', 2, 3); 40 | INSERT IGNORE INTO pets VALUES (5, 'Iggy', '2000-11-30', 3, 4); 41 | INSERT IGNORE INTO pets VALUES (6, 'George', '2000-01-20', 4, 5); 42 | INSERT IGNORE INTO pets VALUES (7, 'Samantha', '1995-09-04', 1, 6); 43 | INSERT IGNORE INTO pets VALUES (8, 'Max', '1995-09-04', 1, 6); 44 | INSERT IGNORE INTO pets VALUES (9, 'Lucky', '1999-08-06', 5, 7); 45 | INSERT IGNORE INTO pets VALUES (10, 'Mulligan', '1997-02-24', 2, 8); 46 | INSERT IGNORE INTO pets VALUES (11, 'Freddy', '2000-03-09', 5, 9); 47 | INSERT IGNORE INTO pets VALUES (12, 'Lucky', '2000-06-24', 2, 10); 48 | INSERT IGNORE INTO pets VALUES (13, 'Sly', '2002-06-08', 1, 10); 49 | 50 | INSERT IGNORE INTO visits VALUES (1, 7, '2010-03-04', 'rabies shot'); 51 | INSERT IGNORE INTO visits VALUES (2, 8, '2011-03-04', 'rabies shot'); 52 | INSERT IGNORE INTO visits VALUES (3, 8, '2009-06-04', 'neutered'); 53 | INSERT IGNORE INTO visits VALUES (4, 7, '2008-09-04', 'spayed'); 54 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/db/postgresql/initDB.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS vets ( 2 | id SERIAL, 3 | first_name VARCHAR(30), 4 | last_name VARCHAR(30), 5 | CONSTRAINT pk_vets PRIMARY KEY (id) 6 | ); 7 | 8 | CREATE INDEX IF NOT EXISTS idx_vets_last_name ON vets (last_name); 9 | 10 | ALTER SEQUENCE vets_id_seq RESTART WITH 100; 11 | 12 | 13 | CREATE TABLE IF NOT EXISTS specialties ( 14 | id SERIAL, 15 | name VARCHAR(80), 16 | CONSTRAINT pk_specialties PRIMARY KEY (id) 17 | ); 18 | 19 | CREATE INDEX IF NOT EXISTS idx_specialties_name ON specialties (name); 20 | 21 | ALTER SEQUENCE specialties_id_seq RESTART WITH 100; 22 | 23 | 24 | CREATE TABLE IF NOT EXISTS vet_specialties ( 25 | vet_id INT NOT NULL, 26 | specialty_id INT NOT NULL, 27 | FOREIGN KEY (vet_id) REFERENCES vets(id), 28 | FOREIGN KEY (specialty_id) REFERENCES specialties(id), 29 | CONSTRAINT unique_ids UNIQUE (vet_id,specialty_id) 30 | ); 31 | 32 | 33 | 34 | CREATE TABLE IF NOT EXISTS types ( 35 | id SERIAL, 36 | name VARCHAR(80), 37 | CONSTRAINT pk_types PRIMARY KEY (id) 38 | ); 39 | 40 | CREATE INDEX IF NOT EXISTS idx_types_name ON types (name); 41 | 42 | ALTER SEQUENCE types_id_seq RESTART WITH 100; 43 | 44 | CREATE TABLE IF NOT EXISTS owners ( 45 | id SERIAL, 46 | first_name VARCHAR(30), 47 | last_name VARCHAR(30), 48 | address VARCHAR(255), 49 | city VARCHAR(80), 50 | telephone VARCHAR(20), 51 | CONSTRAINT pk_owners PRIMARY KEY (id) 52 | ); 53 | 54 | CREATE INDEX IF NOT EXISTS idx_owners_last_name ON owners (last_name); 55 | 56 | ALTER SEQUENCE owners_id_seq RESTART WITH 100; 57 | 58 | 59 | CREATE TABLE IF NOT EXISTS pets ( 60 | id SERIAL, 61 | name VARCHAR(30), 62 | birth_date DATE, 63 | type_id INT NOT NULL, 64 | owner_id INT NOT NULL, 65 | FOREIGN KEY (owner_id) REFERENCES owners(id), 66 | FOREIGN KEY (type_id) REFERENCES types(id), 67 | CONSTRAINT pk_pets PRIMARY KEY (id) 68 | ); 69 | 70 | CREATE INDEX IF NOT EXISTS idx_pets_name ON pets (name); 71 | 72 | ALTER SEQUENCE pets_id_seq RESTART WITH 100; 73 | 74 | 75 | CREATE TABLE IF NOT EXISTS visits ( 76 | id SERIAL, 77 | pet_id INT NOT NULL, 78 | visit_date DATE, 79 | description VARCHAR(255), 80 | FOREIGN KEY (pet_id) REFERENCES pets(id), 81 | CONSTRAINT pk_visits PRIMARY KEY (id) 82 | ); 83 | 84 | ALTER SEQUENCE visits_id_seq RESTART WITH 100; 85 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/db/postgresql/petclinic_db_setup_postgresql.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | === Spring PetClinic sample application - PostgreSQL Configuration === 3 | ================================================================================ 4 | 5 | @author Sam Brannen 6 | @author Costin Leau 7 | 8 | -------------------------------------------------------------------------------- 9 | 10 | 1) Download and install the PostgreSQL database, 11 | which can be found here: https://www.postgresql.org/download/ 12 | 13 | 2) Dependency for postgresql-driver included in Petclinic pom.xml file. 14 | See the PostgreSQL maven profile. 15 | Alternatively, download PostgreSQL JDBC driver from here: https://jdbc.postgresql.org/download.html 16 | and copy the PostgreSQL JDBC driver JAR file (e.g., postgresql-9.4.1211.jre7.jar) into 17 | the db/postgesql directory. 18 | 19 | 3) Open psql and create the PetClinic database: 20 | 21 | CREATE DATABASE petclinic 22 | WITH OWNER = postgres 23 | ENCODING = 'UTF8' 24 | TABLESPACE = pg_default 25 | CONNECTION LIMIT = -1; 26 | 27 | 4) If required, change connection parameters into the PostgreSQL profile of the pom.xml. 28 | Build and starth the web app with the PostgreSQL profile: 29 | ./mvnw tomcat7:run -P PostgreSQL 30 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/db/postgresql/populateDB.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO vets VALUES (1, 'James', 'Carter') ON CONFLICT DO NOTHING; 2 | INSERT INTO vets VALUES (2, 'Helen', 'Leary') ON CONFLICT DO NOTHING; 3 | INSERT INTO vets VALUES (3, 'Linda', 'Douglas') ON CONFLICT DO NOTHING; 4 | INSERT INTO vets VALUES (4, 'Rafael', 'Ortega') ON CONFLICT DO NOTHING; 5 | INSERT INTO vets VALUES (5, 'Henry', 'Stevens') ON CONFLICT DO NOTHING; 6 | INSERT INTO vets VALUES (6, 'Sharon', 'Jenkins') ON CONFLICT DO NOTHING; 7 | 8 | INSERT INTO specialties VALUES (1, 'radiology') ON CONFLICT DO NOTHING; 9 | INSERT INTO specialties VALUES (2, 'surgery') ON CONFLICT DO NOTHING; 10 | INSERT INTO specialties VALUES (3, 'dentistry') ON CONFLICT DO NOTHING; 11 | 12 | INSERT INTO vet_specialties VALUES (2, 1) ON CONFLICT DO NOTHING; 13 | INSERT INTO vet_specialties VALUES (3, 2) ON CONFLICT DO NOTHING; 14 | INSERT INTO vet_specialties VALUES (3, 3) ON CONFLICT DO NOTHING; 15 | INSERT INTO vet_specialties VALUES (4, 2) ON CONFLICT DO NOTHING; 16 | INSERT INTO vet_specialties VALUES (5, 1) ON CONFLICT DO NOTHING; 17 | 18 | INSERT INTO types VALUES (1, 'cat') ON CONFLICT DO NOTHING; 19 | INSERT INTO types VALUES (2, 'dog') ON CONFLICT DO NOTHING; 20 | INSERT INTO types VALUES (3, 'lizard') ON CONFLICT DO NOTHING; 21 | INSERT INTO types VALUES (4, 'snake') ON CONFLICT DO NOTHING; 22 | INSERT INTO types VALUES (5, 'bird') ON CONFLICT DO NOTHING; 23 | INSERT INTO types VALUES (6, 'hamster') ON CONFLICT DO NOTHING; 24 | 25 | INSERT INTO owners VALUES (1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023') ON CONFLICT DO NOTHING; 26 | INSERT INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749') ON CONFLICT DO NOTHING; 27 | INSERT INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763') ON CONFLICT DO NOTHING; 28 | INSERT INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198') ON CONFLICT DO NOTHING; 29 | INSERT INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765') ON CONFLICT DO NOTHING; 30 | INSERT INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654') ON CONFLICT DO NOTHING; 31 | INSERT INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387') ON CONFLICT DO NOTHING; 32 | INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683') ON CONFLICT DO NOTHING; 33 | INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435') ON CONFLICT DO NOTHING; 34 | INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487') ON CONFLICT DO NOTHING; 35 | 36 | INSERT INTO pets VALUES (1, 'Leo', '2000-09-07', 1, 1) ON CONFLICT DO NOTHING; 37 | INSERT INTO pets VALUES (2, 'Basil', '2002-08-06', 6, 2) ON CONFLICT DO NOTHING; 38 | INSERT INTO pets VALUES (3, 'Rosy', '2001-04-17', 2, 3) ON CONFLICT DO NOTHING; 39 | INSERT INTO pets VALUES (4, 'Jewel', '2000-03-07', 2, 3) ON CONFLICT DO NOTHING; 40 | INSERT INTO pets VALUES (5, 'Iggy', '2000-11-30', 3, 4) ON CONFLICT DO NOTHING; 41 | INSERT INTO pets VALUES (6, 'George', '2000-01-20', 4, 5) ON CONFLICT DO NOTHING; 42 | INSERT INTO pets VALUES (7, 'Samantha', '1995-09-04', 1, 6) ON CONFLICT DO NOTHING; 43 | INSERT INTO pets VALUES (8, 'Max', '1995-09-04', 1, 6) ON CONFLICT DO NOTHING; 44 | INSERT INTO pets VALUES (9, 'Lucky', '1999-08-06', 5, 7) ON CONFLICT DO NOTHING; 45 | INSERT INTO pets VALUES (10, 'Mulligan', '1997-02-24', 2, 8) ON CONFLICT DO NOTHING; 46 | INSERT INTO pets VALUES (11, 'Freddy', '2000-03-09', 5, 9) ON CONFLICT DO NOTHING; 47 | INSERT INTO pets VALUES (12, 'Lucky', '2000-06-24', 2, 10) ON CONFLICT DO NOTHING; 48 | INSERT INTO pets VALUES (13, 'Sly', '2002-06-08', 1, 10) ON CONFLICT DO NOTHING; 49 | 50 | INSERT INTO visits VALUES (1, 7, '2010-03-04', 'rabies shot') ON CONFLICT DO NOTHING; 51 | INSERT INTO visits VALUES (2, 8, '2011-03-04', 'rabies shot') ON CONFLICT DO NOTHING; 52 | INSERT INTO visits VALUES (3, 8, '2009-06-04', 'neutered') ON CONFLICT DO NOTHING; 53 | INSERT INTO visits VALUES (4, 7, '2008-09-04', 'spayed') ON CONFLICT DO NOTHING; 54 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | true 8 | 9 | 10 | 11 | 12 | %-5level %logger{0} - %msg%n 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/messages/messages.properties: -------------------------------------------------------------------------------- 1 | welcome=Welcome 2 | required=is required 3 | notFound=has not been found 4 | duplicate=is already in use 5 | nonNumeric=must be all numeric 6 | duplicateFormSubmission=Duplicate form submission is not allowed 7 | typeMismatch.date=invalid date 8 | typeMismatch.birthDate=invalid date 9 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/messages/messages_de.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/resources/messages/messages_de.properties -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/messages/messages_en.properties: -------------------------------------------------------------------------------- 1 | # This file is intentionally empty. Message look-ups will fall back to the default "messages.properties" file. -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/spring/data-access.properties: -------------------------------------------------------------------------------- 1 | # Properties file with JDBC and JPA settings. 2 | # 3 | # Applied by from 4 | # various application context XML files (e.g., "applicationContext-*.xml"). 5 | # Targeted at system administrators, to avoid touching the context XML files. 6 | 7 | # Properties that control the population of schema and data for a new data source 8 | jdbc.initLocation=classpath:db/${db.script}/initDB.sql 9 | jdbc.dataLocation=classpath:db/${db.script}/populateDB.sql 10 | 11 | jpa.showSql=true 12 | 13 | jdbc.driverClassName=${jdbc.driverClassName} 14 | jdbc.url=${jdbc.url} 15 | jdbc.username=${jdbc.username} 16 | jdbc.password=${jdbc.password} 17 | 18 | # Property that determines which database to use with an AbstractJpaVendorAdapter 19 | jpa.database=${jpa.database} 20 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/spring/datasource-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/spring/mvc-core-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 16 | 17 | 18 | 19 | 22 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/spring/mvc-view-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 10 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/resources/spring/tools-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 18 | 19 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 42 | 43 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/jetty-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | true 7 | 8 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/jsp/exception.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false" trimDirectiveWhitespaces="true" %> 2 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 3 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 4 | 5 | 6 | 7 | 8 | 9 | 10 |

Something happened...

11 | 12 |

${exception.message}

13 | 14 |
15 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false" trimDirectiveWhitespaces="true" %> 2 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 3 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 6 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 7 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 8 | 9 | 10 |

11 | New Owner 12 |

13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 |
21 |
22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
32 |
33 |
34 |
35 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false" trimDirectiveWhitespaces="true" %> 2 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 3 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 4 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 5 | <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 6 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 |

Find Owners

11 | 12 | 13 | 15 |
16 |
17 | 18 |
19 | 20 | 21 |
22 |
23 |
24 |
25 |
26 | 27 |
28 |
29 | 30 |
31 | 32 |
33 | Add Owner 34 |
35 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false" trimDirectiveWhitespaces="true" %> 2 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 3 | <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 6 | 7 | 8 | 9 |

Owner Information

10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
Name
Address
City
Telephone
30 | 31 | 32 | 33 | 34 | Edit Owner 35 | 36 | 37 | 38 | 39 | Add New Pet 40 | 41 |
42 |
43 |
44 |

Pets and Visits

45 | 46 | 47 | 48 | 49 | 50 | 60 | 92 | 93 | 94 | 95 |
51 |
52 |
Name
53 |
54 |
Birth Date
55 |
56 |
Type
57 |
58 |
59 |
61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 82 | 89 | 90 |
Visit DateDescription
76 | 77 | 78 | 79 | 80 | Edit Pet 81 | 83 | 84 | 85 | 86 | 87 | Add Visit 88 |
91 |
96 | 97 |
98 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false" trimDirectiveWhitespaces="true" %> 2 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 3 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 6 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 |

Owners

10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 33 | 36 | 39 | 44 | 45 | 46 | 47 |
NameAddressCityTelephonePets
25 | 26 | 27 | 28 | 29 | 31 | 32 | 34 | 35 | 37 | 38 | 40 | 41 | 42 | 43 |
48 |
49 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false" trimDirectiveWhitespaces="true" %> 2 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 5 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 6 | 7 | 8 | 9 | 14 | 15 | 16 |

17 | New Pet 18 |

19 | 21 | 22 |
23 |
24 | 25 |
26 | 27 |
28 |
29 | 30 | 31 |
32 | 33 |
34 |
35 |
36 |
37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 |
48 | 49 | 50 |
51 |
52 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false" trimDirectiveWhitespaces="true" %> 2 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 5 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 6 | 7 | 8 | 9 | 10 | 15 | 16 | 17 |

New Visit

18 | 19 | Pet 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
NameBirth DateTypeOwner
36 | 37 | 38 |
39 | 40 | 41 |
42 | 43 |
44 |
45 | 46 | 47 |
48 |
49 |
50 | 51 |
52 | Previous Visits 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
DateDescription
67 |
68 | 69 |
70 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false" trimDirectiveWhitespaces="true" %> 2 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 3 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 6 | 7 | 8 |

Veterinarians

9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 29 | 30 | 31 | 32 |
NameSpecialties
21 | 22 | 24 | 25 | 26 | 27 | none 28 |
33 | 34 | 35 | 36 | 39 | 42 | 43 |
37 | ">View as XML 38 | 40 | ">View as JSON 41 |
44 |
45 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/jsp/welcome.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false" trimDirectiveWhitespaces="true" %> 2 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 3 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 4 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 5 | 6 | 7 |

8 |
9 |
10 | 11 | 12 |
13 |
14 |
15 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/no-spring-config-files-there.txt: -------------------------------------------------------------------------------- 1 | All Spring config files (including Spring MVC ones) are inside src/main/resource. 2 | There are mostly 2 reasons to that: 3 | - All Spring config files are grouped into one single place 4 | - It is simpler to reference them from inside JUnit tests -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/tags/bodyHeader.tag: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 2 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 3 | 4 | <%@ attribute name="menuName" required="true" rtexprvalue="true" 5 | description="Name of the active menu: home, owners, vets or error" %> 6 | 7 | 8 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/tags/footer.tag: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 2 | 3 | <%-- Placed at the end of the document so the pages load faster --%> 4 | 5 | 6 | 7 | <%-- jquery-ui.js file is really big so we only load what we need instead of loading everything --%> 8 | 9 | 10 | 11 | <%-- Bootstrap --%> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/tags/htmlHeader.tag: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 2 | 3 | <%-- 4 | PetClinic :: a Spring Framework demonstration 5 | --%> 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%-- The above 4 meta tags *must* come first in the head; any other head content must come *after* these tags --%> 13 | 14 | 15 | 16 | 17 | PetClinic :: a Spring Framework demonstration 18 | 19 | <%-- CSS generated from LESS --%> 20 | 21 | 22 | 23 | 24 | <%-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --%> 25 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/tags/inputField.tag: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@ attribute name="name" required="true" rtexprvalue="true" 5 | description="Name of corresponding property in bean object" %> 6 | <%@ attribute name="label" required="true" rtexprvalue="true" 7 | description="Label appears in red color if input is considered as invalid after submission" %> 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 | ${status.errorMessage} 23 | 24 |
25 |
26 |
27 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/tags/layout.tag: -------------------------------------------------------------------------------- 1 | <%@ tag trimDirectiveWhitespaces="true" %> 2 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 3 | 4 | <%@ attribute name="pageName" required="true" %> 5 | <%@ attribute name="customScript" required="false" fragment="true"%> 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 20 |
21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/tags/localDate.tag: -------------------------------------------------------------------------------- 1 | <%@ tag body-content="empty" pageEncoding="UTF-8" trimDirectiveWhitespaces="true" %> 2 | 3 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | 6 | <%@ attribute name="date" required="true" type="java.time.LocalDate" %> 7 | <%@ attribute name="pattern" required="true" type="java.lang.String" %> 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/tags/menu.tag: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> 4 | <%@ attribute name="name" required="true" rtexprvalue="true" 5 | description="Name of the active menu: home, owners, vets or error" %> 6 | 7 | 46 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/tags/menuItem.tag: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 2 | <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 3 | 4 | <%@ attribute name="active" required="true" rtexprvalue="true" %> 5 | <%@ attribute name="url" required="true" rtexprvalue="true" %> 6 | <%@ attribute name="title" required="false" rtexprvalue="true" %> 7 | 8 |
  • 9 | " 10 | title="${fn:escapeXml(title)}"> 11 | 12 | 13 |
  • 14 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/tags/pivotal.tag: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 2 | 3 |
    4 |
    5 |
    6 |
    7 |
    " 8 | alt="Sponsored by Pivotal"/>
    9 |
    10 |
    11 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/WEB-INF/tags/selectField.tag: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@ attribute name="name" required="true" rtexprvalue="true" 5 | description="Name of corresponding property in bean object" %> 6 | <%@ attribute name="label" required="true" rtexprvalue="true" 7 | description="Label appears in red color if input is considered as invalid after submission" %> 8 | <%@ attribute name="names" required="true" rtexprvalue="true" type="java.util.List" 9 | description="Names in the list" %> 10 | <%@ attribute name="size" required="true" rtexprvalue="true" 11 | description="Size of Select" %> 12 | 13 | 14 | 15 | 16 |
    17 | 18 | 19 |
    20 | 21 | 22 | 23 | 24 | 25 | 26 | ${status.errorMessage} 27 | 28 |
    29 |
    30 |
    31 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/fonts/montserrat-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/webapp/resources/fonts/montserrat-webfont.eot -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/fonts/montserrat-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/webapp/resources/fonts/montserrat-webfont.ttf -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/fonts/montserrat-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/webapp/resources/fonts/montserrat-webfont.woff -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/fonts/varela_round-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/webapp/resources/fonts/varela_round-webfont.eot -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/fonts/varela_round-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/webapp/resources/fonts/varela_round-webfont.ttf -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/fonts/varela_round-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/webapp/resources/fonts/varela_round-webfont.woff -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/images/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/webapp/resources/images/favicon.png -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/images/pets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/webapp/resources/images/pets.png -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/images/platform-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/webapp/resources/images/platform-bg.png -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/images/spring-logo-dataflow-mobile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/webapp/resources/images/spring-logo-dataflow-mobile.png -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/images/spring-logo-dataflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/webapp/resources/images/spring-logo-dataflow.png -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/images/spring-pivotal-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/samples/spring-framework-petclinic/src/main/webapp/resources/images/spring-pivotal-logo.png -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/less/header.less: -------------------------------------------------------------------------------- 1 | .navbar { 2 | border-top: 4px solid #6db33f; 3 | background-color: #34302d; 4 | margin-bottom: 0px; 5 | border-bottom: 0; 6 | border-left: 0; 7 | border-right: 0; 8 | } 9 | 10 | .navbar a.navbar-brand { 11 | background: url("../images/spring-logo-dataflow.png") -1px -1px no-repeat; 12 | margin: 12px 0 6px; 13 | width: 229px; 14 | height: 46px; 15 | display: inline-block; 16 | text-decoration: none; 17 | padding: 0; 18 | } 19 | 20 | .navbar a.navbar-brand span { 21 | display: block; 22 | width: 229px; 23 | height: 46px; 24 | background: url("../images/spring-logo-dataflow.png") -1px -48px no-repeat; 25 | opacity: 0; 26 | -moz-transition: opacity 0.12s ease-in-out; 27 | -webkit-transition: opacity 0.12s ease-in-out; 28 | -o-transition: opacity 0.12s ease-in-out; 29 | } 30 | 31 | .navbar a:hover.navbar-brand span { 32 | opacity: 1; 33 | } 34 | 35 | .navbar li > a, .navbar-text { 36 | font-family: "montserratregular", sans-serif; 37 | text-shadow: none; 38 | font-size: 14px; 39 | 40 | /* line-height: 14px; */ 41 | padding: 28px 20px; 42 | transition: all 0.15s; 43 | -webkit-transition: all 0.15s; 44 | -moz-transition: all 0.15s; 45 | -o-transition: all 0.15s; 46 | -ms-transition: all 0.15s; 47 | } 48 | 49 | .navbar li > a { 50 | text-transform: uppercase; 51 | } 52 | 53 | .navbar .navbar-text { 54 | margin-top: 0; 55 | margin-bottom: 0; 56 | } 57 | .navbar li:hover > a { 58 | color: #eeeeee; 59 | background-color: #6db33f; 60 | } 61 | 62 | .navbar-toggle { 63 | border-width: 0; 64 | 65 | .icon-bar + .icon-bar { 66 | margin-top: 3px; 67 | } 68 | .icon-bar { 69 | width: 19px; 70 | height: 3px; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/less/responsive.less: -------------------------------------------------------------------------------- 1 | @media (max-width: 768px) { 2 | .navbar-toggle { 3 | position:absolute; 4 | z-index: 9999; 5 | left:0px; 6 | top:0px; 7 | } 8 | 9 | .navbar a.navbar-brand { 10 | display: block; 11 | margin: 0 auto 0 auto; 12 | width: 148px; 13 | height: 50px; 14 | float: none; 15 | background: url("../images/spring-logo-dataflow-mobile.png") 0 center no-repeat; 16 | } 17 | 18 | .homepage-billboard .homepage-subtitle { 19 | font-size: 21px; 20 | line-height: 21px; 21 | } 22 | 23 | .navbar a.navbar-brand span { 24 | display: none; 25 | } 26 | 27 | .navbar { 28 | border-top-width: 0; 29 | } 30 | 31 | .xd-container { 32 | margin-top: 20px; 33 | margin-bottom: 30px; 34 | } 35 | 36 | .index-page--subtitle { 37 | margin-top: 10px; 38 | margin-bottom: 30px; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/webapp/resources/less/typography.less: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'varela_roundregular'; 3 | 4 | src: url('../fonts/varela_round-webfont.eot'); 5 | src: url('../fonts/varela_round-webfont.eot?#iefix') format('embedded-opentype'), 6 | url('../fonts/varela_round-webfont.woff') format('woff'), 7 | url('../fonts/varela_round-webfont.ttf') format('truetype'), 8 | url('../fonts/varela_round-webfont.svg#varela_roundregular') format('svg'); 9 | font-weight: normal; 10 | font-style: normal; 11 | } 12 | 13 | @font-face { 14 | font-family: 'montserratregular'; 15 | src: url('../fonts/montserrat-webfont.eot'); 16 | src: url('../fonts/montserrat-webfont.eot?#iefix') format('embedded-opentype'), 17 | url('../fonts/montserrat-webfont.woff') format('woff'), 18 | url('../fonts/montserrat-webfont.ttf') format('truetype'), 19 | url('../fonts/montserrat-webfont.svg#montserratregular') format('svg'); 20 | font-weight: normal; 21 | font-style: normal; 22 | } 23 | 24 | body, h1, h2, h3, p, input { 25 | margin: 0; 26 | font-weight: 400; 27 | font-family: "varela_roundregular", sans-serif; 28 | color: #34302d; 29 | } 30 | 31 | h1 { 32 | font-size: 24px; 33 | line-height: 30px; 34 | font-family: "montserratregular", sans-serif; 35 | } 36 | 37 | h2 { 38 | font-size: 18px; 39 | font-weight: 700; 40 | line-height: 24px; 41 | margin-bottom: 10px; 42 | font-family: "montserratregular", sans-serif; 43 | } 44 | 45 | h3 { 46 | font-size: 16px; 47 | line-height: 24px; 48 | margin-bottom: 10px; 49 | font-weight: 700; 50 | } 51 | 52 | p { 53 | //font-size: 15px; 54 | //line-height: 24px; 55 | } 56 | 57 | strong { 58 | font-weight: 700; 59 | font-family: "montserratregular", sans-serif; 60 | } 61 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/wro/wro.properties: -------------------------------------------------------------------------------- 1 | #List of preProcessors 2 | preProcessors=lessCssImport 3 | #List of postProcessors 4 | postProcessors=less4j -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/main/wro/wro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | classpath:META-INF/resources/webjars/bootstrap/3.3.6/less/bootstrap.less 4 | /petclinic.less 5 | 6 | 7 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.model; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.util.Locale; 6 | import java.util.Set; 7 | 8 | import javax.validation.ConstraintViolation; 9 | import javax.validation.Validator; 10 | 11 | import org.junit.Test; 12 | import org.springframework.context.i18n.LocaleContextHolder; 13 | import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; 14 | 15 | /** 16 | * @author Michael Isvy 17 | * Simple test to make sure that Bean Validation is working 18 | * (useful when upgrading to a new version of Hibernate Validator/ Bean Validation) 19 | */ 20 | public class ValidatorTests { 21 | 22 | private Validator createValidator() { 23 | LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean(); 24 | localValidatorFactoryBean.afterPropertiesSet(); 25 | return localValidatorFactoryBean; 26 | } 27 | 28 | @Test 29 | public void shouldNotValidateWhenFirstNameEmpty() { 30 | 31 | LocaleContextHolder.setLocale(Locale.ENGLISH); 32 | Person person = new Person(); 33 | person.setFirstName(""); 34 | person.setLastName("smith"); 35 | 36 | Validator validator = createValidator(); 37 | Set> constraintViolations = validator.validate(person); 38 | 39 | assertThat(constraintViolations.size()).isEqualTo(1); 40 | ConstraintViolation violation = constraintViolations.iterator().next(); 41 | assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName"); 42 | assertThat(violation.getMessage()).isEqualTo("may not be empty"); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.service; 17 | 18 | import org.junit.runner.RunWith; 19 | import org.springframework.test.context.ActiveProfiles; 20 | import org.springframework.test.context.ContextConfiguration; 21 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 22 | 23 | /** 24 | *

    Integration test using the jdbc profile. 25 | * 26 | * @author Thomas Risberg 27 | * @author Michael Isvy 28 | * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details.

    29 | */ 30 | @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) 31 | @RunWith(SpringJUnit4ClassRunner.class) 32 | @ActiveProfiles("jdbc") 33 | public class ClinicServiceJdbcTests extends AbstractClinicServiceTests { 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.service; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.test.context.ActiveProfiles; 5 | import org.springframework.test.context.ContextConfiguration; 6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 7 | 8 | /** 9 | *

    Integration test using the jpa profile. 10 | * 11 | * @author Rod Johnson 12 | * @author Sam Brannen 13 | * @author Michael Isvy 14 | * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details.

    15 | */ 16 | 17 | @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @ActiveProfiles("jpa") 20 | public class ClinicServiceJpaTests extends AbstractClinicServiceTests { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.service; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.test.context.ActiveProfiles; 5 | import org.springframework.test.context.ContextConfiguration; 6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 7 | 8 | /** 9 | *

    Integration test using the 'Spring Data' profile. 10 | * 11 | * @author Michael Isvy 12 | * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details.

    13 | */ 14 | 15 | @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) 16 | @RunWith(SpringJUnit4ClassRunner.class) 17 | @ActiveProfiles("spring-data-jpa") 18 | public class ClinicServiceSpringDataJpaTests extends AbstractClinicServiceTests { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/test/java/org/springframework/samples/petclinic/web/CrashControllerTests.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.web; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.ActiveProfiles; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | import org.springframework.test.context.web.WebAppConfiguration; 11 | import org.springframework.test.web.servlet.MockMvc; 12 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 13 | import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver; 14 | 15 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 16 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; 17 | 18 | /** 19 | * Test class for {@link CrashController} 20 | * 21 | * @author Colin But 22 | */ 23 | @RunWith(SpringJUnit4ClassRunner.class) 24 | @ContextConfiguration({"classpath:spring/mvc-core-config.xml", "classpath:spring/mvc-test-config.xml"}) 25 | @WebAppConfiguration 26 | public class CrashControllerTests { 27 | 28 | @Autowired 29 | private CrashController crashController; 30 | 31 | @Autowired 32 | private SimpleMappingExceptionResolver simpleMappingExceptionResolver; 33 | 34 | private MockMvc mockMvc; 35 | 36 | @Before 37 | public void setup() { 38 | this.mockMvc = MockMvcBuilders 39 | .standaloneSetup(crashController) 40 | .setHandlerExceptionResolvers(simpleMappingExceptionResolver) 41 | .build(); 42 | } 43 | 44 | @Test 45 | public void testTriggerException() throws Exception { 46 | mockMvc.perform(get("/oups")) 47 | .andExpect(view().name("exception")) 48 | .andExpect(model().attributeExists("exception")) 49 | .andExpect(forwardedUrl("exception")) 50 | .andExpect(status().isOk()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/test/java/org/springframework/samples/petclinic/web/PetTypeFormatterTests.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.web; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.mockito.Mock; 7 | import org.mockito.Mockito; 8 | import org.mockito.junit.MockitoJUnitRunner; 9 | import org.springframework.samples.petclinic.model.PetType; 10 | import org.springframework.samples.petclinic.service.ClinicService; 11 | 12 | import java.text.ParseException; 13 | import java.util.*; 14 | 15 | import static org.junit.Assert.assertEquals; 16 | 17 | /** 18 | * Test class for {@link PetTypeFormatter} 19 | * 20 | * @author Colin But 21 | */ 22 | @RunWith(MockitoJUnitRunner.class) 23 | public class PetTypeFormatterTests { 24 | 25 | @Mock 26 | private ClinicService clinicService; 27 | 28 | private PetTypeFormatter petTypeFormatter; 29 | 30 | @Before 31 | public void setup() { 32 | petTypeFormatter = new PetTypeFormatter(clinicService); 33 | } 34 | 35 | @Test 36 | public void testPrint() { 37 | PetType petType = new PetType(); 38 | petType.setName("Hamster"); 39 | String petTypeName = petTypeFormatter.print(petType, Locale.ENGLISH); 40 | assertEquals("Hamster", petTypeName); 41 | } 42 | 43 | @Test 44 | public void shouldParse() throws ParseException { 45 | Mockito.when(clinicService.findPetTypes()).thenReturn(makePetTypes()); 46 | PetType petType = petTypeFormatter.parse("Bird", Locale.ENGLISH); 47 | assertEquals("Bird", petType.getName()); 48 | } 49 | 50 | @Test(expected = ParseException.class) 51 | public void shouldThrowParseException() throws ParseException { 52 | Mockito.when(clinicService.findPetTypes()).thenReturn(makePetTypes()); 53 | petTypeFormatter.parse("Fish", Locale.ENGLISH); 54 | } 55 | 56 | /** 57 | * Helper method to produce some sample pet types just for test purpose 58 | * 59 | * @return {@link Collection} of {@link PetType} 60 | */ 61 | private Collection makePetTypes() { 62 | Collection petTypes = new ArrayList<>(); 63 | petTypes.add(new PetType(){ 64 | { 65 | setName("Dog"); 66 | } 67 | }); 68 | petTypes.add(new PetType(){ 69 | { 70 | setName("Bird"); 71 | } 72 | }); 73 | return petTypes; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.web; 2 | 3 | import org.assertj.core.util.Lists; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.samples.petclinic.model.Specialty; 10 | import org.springframework.samples.petclinic.model.Vet; 11 | import org.springframework.samples.petclinic.service.ClinicService; 12 | import org.springframework.test.context.ContextConfiguration; 13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 14 | import org.springframework.test.context.web.WebAppConfiguration; 15 | import org.springframework.test.web.servlet.MockMvc; 16 | import org.springframework.test.web.servlet.ResultActions; 17 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 18 | 19 | import static org.hamcrest.xml.HasXPath.hasXPath; 20 | import static org.mockito.BDDMockito.given; 21 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 22 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; 23 | 24 | /** 25 | * Test class for the {@link VetController} 26 | */ 27 | @RunWith(SpringJUnit4ClassRunner.class) 28 | @ContextConfiguration({"classpath:spring/mvc-core-config.xml", "classpath:spring/mvc-test-config.xml"}) 29 | @WebAppConfiguration 30 | public class VetControllerTests { 31 | 32 | @Autowired 33 | private VetController vetController; 34 | 35 | @Autowired 36 | private ClinicService clinicService; 37 | 38 | private MockMvc mockMvc; 39 | 40 | @Before 41 | public void setup() { 42 | this.mockMvc = MockMvcBuilders.standaloneSetup(vetController).build(); 43 | 44 | Vet james = new Vet(); 45 | james.setFirstName("James"); 46 | james.setLastName("Carter"); 47 | james.setId(1); 48 | Vet helen = new Vet(); 49 | helen.setFirstName("Helen"); 50 | helen.setLastName("Leary"); 51 | helen.setId(2); 52 | Specialty radiology = new Specialty(); 53 | radiology.setId(1); 54 | radiology.setName("radiology"); 55 | helen.addSpecialty(radiology); 56 | given(this.clinicService.findVets()).willReturn(Lists.newArrayList(james, helen)); 57 | } 58 | 59 | @Test 60 | public void testShowVetListHtml() throws Exception { 61 | mockMvc.perform(get("/vets.html")) 62 | .andExpect(status().isOk()) 63 | .andExpect(model().attributeExists("vets")) 64 | .andExpect(view().name("vets/vetList")); 65 | } 66 | 67 | @Test 68 | public void testShowResourcesVetList() throws Exception { 69 | ResultActions actions = mockMvc.perform(get("/vets.json").accept(MediaType.APPLICATION_JSON)) 70 | .andExpect(status().isOk()); 71 | actions.andExpect(content().contentType("application/json;charset=UTF-8")) 72 | .andExpect(jsonPath("$.vetList[0].id").value(1)); 73 | } 74 | 75 | @Test 76 | public void testShowVetListXml() throws Exception { 77 | mockMvc.perform(get("/vets.xml").accept(MediaType.APPLICATION_XML)) 78 | .andExpect(status().isOk()) 79 | .andExpect(content().contentType(MediaType.APPLICATION_XML_VALUE)) 80 | .andExpect(content().node(hasXPath("/vets/vetList[id=1]/id"))); 81 | } 82 | 83 | } 84 | 85 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.web; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.samples.petclinic.model.Pet; 8 | import org.springframework.samples.petclinic.service.ClinicService; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 14 | 15 | import static org.mockito.BDDMockito.given; 16 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 17 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; 18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; 19 | 20 | /** 21 | * Test class for {@link VisitController} 22 | * 23 | * @author Colin But 24 | */ 25 | @RunWith(SpringJUnit4ClassRunner.class) 26 | @ContextConfiguration({"classpath:spring/mvc-core-config.xml", "classpath:spring/mvc-test-config.xml"}) 27 | @WebAppConfiguration 28 | public class VisitControllerTests { 29 | 30 | private static final int TEST_PET_ID = 1; 31 | 32 | @Autowired 33 | private VisitController visitController; 34 | 35 | @Autowired 36 | private ClinicService clinicService; 37 | 38 | private MockMvc mockMvc; 39 | 40 | @Before 41 | public void setup() { 42 | this.mockMvc = MockMvcBuilders.standaloneSetup(visitController).build(); 43 | 44 | given(this.clinicService.findPetById(TEST_PET_ID)).willReturn(new Pet()); 45 | } 46 | 47 | @Test 48 | public void testInitNewVisitForm() throws Exception { 49 | mockMvc.perform(get("/owners/*/pets/{petId}/visits/new", TEST_PET_ID)) 50 | .andExpect(status().isOk()) 51 | .andExpect(view().name("pets/createOrUpdateVisitForm")); 52 | } 53 | 54 | @Test 55 | public void testProcessNewVisitFormSuccess() throws Exception { 56 | mockMvc.perform(post("/owners/*/pets/{petId}/visits/new", TEST_PET_ID) 57 | .param("name", "George") 58 | .param("description", "Visit Description") 59 | ) 60 | .andExpect(status().is3xxRedirection()) 61 | .andExpect(view().name("redirect:/owners/{ownerId}")); 62 | } 63 | 64 | @Test 65 | public void testProcessNewVisitFormHasErrors() throws Exception { 66 | mockMvc.perform(post("/owners/*/pets/{petId}/visits/new", TEST_PET_ID) 67 | .param("name", "George") 68 | ) 69 | .andExpect(model().attributeHasErrors("visit")) 70 | .andExpect(status().isOk()) 71 | .andExpect(view().name("pets/createOrUpdateVisitForm")); 72 | } 73 | 74 | @Test 75 | public void testShowVisits() throws Exception { 76 | mockMvc.perform(get("/owners/*/pets/{petId}/visits", TEST_PET_ID)) 77 | .andExpect(status().isOk()) 78 | .andExpect(model().attributeExists("visits")) 79 | .andExpect(view().name("visitList")); 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /samples/spring-framework-petclinic/src/test/resources/spring/mvc-test-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /scripts/publishStage1.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | Param( 3 | [Parameter(Mandatory=$True, HelpMessage="Example: appsvctest")] 4 | [string]$repoName 5 | ) 6 | 7 | $ErrorActionPreference = "Stop" 8 | 9 | function GetImage 10 | { 11 | param([string]$version, [string]$timestamp) 12 | 13 | $image = $RepoName + '/tomcat:' + $version + '_' + $timestamp 14 | 15 | return $image 16 | } 17 | 18 | function Build 19 | { 20 | param([string]$directory, [string]$version, [string]$timestamp) 21 | 22 | .\scripts\setup.ps1 -version $version 23 | 24 | $image = GetImage -version $version -timestamp $timestamp 25 | $gitcommit=(git log -1 --pretty=%H) 26 | 27 | Write-Host -ForegroundColor Green Building $image 28 | 29 | $buildcmd = "docker build --pull --no-cache --build-arg GIT_COMMIT=$gitcommit -t $image $directory" 30 | Write-Host -ForegroundColor Green $buildcmd 31 | 32 | # Run the build command 33 | Invoke-Expression -Command $buildcmd 34 | } 35 | 36 | function Publish 37 | { 38 | param([string]$version, [string]$timestamp) 39 | 40 | $timestamp1=$timestamp 41 | $timestamp2='0000000000' 42 | 43 | $image1 = GetImage -version $version -timestamp $timestamp1 44 | $image2 = GetImage -version $version -timestamp $timestamp2 45 | 46 | Write-Host -ForegroundColor Green **Pushing** $image1 47 | docker push $image1 48 | 49 | docker tag $image1 $image2 50 | 51 | Write-Host -ForegroundColor Green **Pushing** $image2 52 | docker push $image2 53 | } 54 | 55 | 56 | ### Main 57 | 58 | if ($repoName -eq 'appsvc') 59 | { 60 | $msg='ERROR: Parameter $repoName=' + $repoName + ' not allowed. Use some other repoName value as parameter!' 61 | Write-Host -ForegroundColor Red $msg 62 | return; 63 | } 64 | 65 | $localTime=get-date 66 | $utcTime=$localTime.ToUniversalTime() 67 | 68 | $timestamp = $utcTime.ToString('yyMMddHHmm') 69 | 70 | Build -directory '8.5-jre8' -version '8.5-jre8' -timestamp $timestamp 71 | Build -directory '9.0-jre8' -version '9.0-jre8' -timestamp $timestamp 72 | Build -directory '8.5-java11' -version '8.5-java11' -timestamp $timestamp 73 | Build -directory '9.0-java11' -version '9.0-java11' -timestamp $timestamp 74 | 75 | Publish -version '8.5-jre8' -timestamp $timestamp 76 | Publish -version '9.0-jre8' -timestamp $timestamp 77 | Publish -version '8.5-java11' -timestamp $timestamp 78 | Publish -version '9.0-java11' -timestamp $timestamp 79 | -------------------------------------------------------------------------------- /scripts/publishStage2.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | Param( 3 | [Parameter(Mandatory=$True, HelpMessage="Example: 1809132007")] 4 | [string]$timestamp, 5 | 6 | [Parameter(Mandatory=$True, HelpMessage="Example: appsvctest")] 7 | [string]$sourceRepoName, 8 | 9 | [Parameter(Mandatory=$True, HelpMessage="Example: appsvc")] 10 | [string]$targetRepoName, 11 | 12 | [Parameter(Mandatory=$True, HelpMessage="If this is true, it will push not only the _0000000000 tag, but also the original (sourceRepoName) tag")] 13 | [bool]$pushOriginalTag 14 | ) 15 | 16 | $ErrorActionPreference = "Stop" 17 | 18 | function GetImage 19 | { 20 | param([string]$repoName, [string]$version, [string]$timestamp) 21 | 22 | $image = $repoName + '/tomcat:' + $version + '_' + $timestamp 23 | 24 | return $image 25 | } 26 | 27 | function Publish 28 | { 29 | param([string]$version, [string]$timestamp, [bool]$pushOriginalTag) 30 | 31 | $sourceImage = GetImage -repoName $sourceRepoName -version $version -timestamp $timestamp 32 | $destinationImageOriginalTagName = GetImage -repoName $targetRepoName -version $version -timestamp $timestamp 33 | $destinationImageZeroTagName = GetImage -repoName $targetRepoName -version $version -timestamp '0000000000' 34 | 35 | if ($pushOriginalTag) 36 | { 37 | # Just an extra precaution 38 | docker rmi -f $destinationImageOriginalTagName 39 | 40 | Write-Host -ForegroundColor Green Tagging $destinationImageOriginalTagName 41 | docker tag $sourceImage $destinationImageOriginalTagName 42 | 43 | Write-Host -ForegroundColor Green **Pushing** $destinationImageOriginalTagName 44 | docker push $destinationImageOriginalTagName 45 | } 46 | 47 | Write-Host -ForegroundColor Green Pulling $sourceImage 48 | docker pull $sourceImage 49 | 50 | # Just an extra precaution 51 | docker rmi -f $destinationImageZeroTagName 52 | 53 | Write-Host -ForegroundColor Green Tagging $destinationImageZeroTagName 54 | docker tag $sourceImage $destinationImageZeroTagName 55 | 56 | Write-Host -ForegroundColor Green **Pushing** $destinationImageZeroTagName 57 | docker push $destinationImageZeroTagName 58 | } 59 | 60 | ### Main 61 | 62 | if ($timestamp -eq '0000000000') 63 | { 64 | $msg='ERROR: Parameter $timestamp=' + $timestamp + ' not allowed. Use some other timestamp value as parameter!' 65 | Write-Host -ForegroundColor Red $msg 66 | return; 67 | } 68 | 69 | Publish -version '8.5-jre8' -timestamp $timestamp -pushOriginalTag $pushOriginalTag 70 | Publish -version '9.0-jre8' -timestamp $timestamp -pushOriginalTag $pushOriginalTag 71 | Publish -version '8.5-java11' -timestamp $timestamp -pushOriginalTag $pushOriginalTag 72 | Publish -version '9.0-java11' -timestamp $timestamp -pushOriginalTag $pushOriginalTag 73 | -------------------------------------------------------------------------------- /scripts/setup.ps1: -------------------------------------------------------------------------------- 1 | function setup 2 | { 3 | param([string]$version) 4 | 5 | # Remove tmp directory 6 | $dirpath = $version + '/tmp/shared' 7 | If (Test-Path $dirpath) 8 | { 9 | remove-item -recurse -force $dirpath 10 | } 11 | 12 | # Copy the shared files to the target directory 13 | copy-item -recurse shared "$dirpath" 14 | 15 | $dockerFileTemplatePath = '.\shared\misc\Dockerfile' 16 | $dockerFileOutPath = "$version\Dockerfile" 17 | 18 | # Generate the Dockerfile from the template and place it in the target directory 19 | # Also, copy Tomcat version specific files to the target directory 20 | switch ($version) 21 | { 22 | '8.5-jre8' 23 | { 24 | $content = ((Get-Content -path $dockerFileTemplatePath -Raw) ` 25 | -replace '__PLACEHOLDER_BASEIMAGE__','mcr.microsoft.com/java/jre-headless:8u212-zulu-alpine-with-tools') ` 26 | -replace '__PLACEHOLDER_AI_VERSION__','2.1.2' ` 27 | -replace '__PLACEHOLDER_APPINSIGHTS_ENABLED__','1' ` 28 | -replace '__PLACEHOLDER_TOMCAT_VERSION__','8.5.41' ` 29 | -replace '__PLACEHOLDER_TOMCAT_MAJOR__','8' ` 30 | -replace '__PLACEHOLDER_TOMCAT_MAJOR_MINOR__', '8.5' 31 | break 32 | } 33 | 34 | '8.5-java11' 35 | { 36 | $content = ((Get-Content -path $dockerFileTemplatePath -Raw) ` 37 | -replace '__PLACEHOLDER_BASEIMAGE__','mcr.microsoft.com/java/jre-headless:11u3-zulu-alpine-with-tools') ` 38 | -replace '__PLACEHOLDER_AI_VERSION__','2.1.2' ` 39 | -replace '__PLACEHOLDER_APPINSIGHTS_ENABLED__','0' ` 40 | -replace '__PLACEHOLDER_TOMCAT_VERSION__','8.5.41' ` 41 | -replace '__PLACEHOLDER_TOMCAT_MAJOR__','8' ` 42 | -replace '__PLACEHOLDER_TOMCAT_MAJOR_MINOR__', '8.5' 43 | break 44 | } 45 | 46 | '9.0-jre8' 47 | { 48 | $content = ((Get-Content -path $dockerFileTemplatePath -Raw) ` 49 | -replace '__PLACEHOLDER_BASEIMAGE__','mcr.microsoft.com/java/jre-headless:8u212-zulu-alpine-with-tools') ` 50 | -replace '__PLACEHOLDER_AI_VERSION__','2.1.2' ` 51 | -replace '__PLACEHOLDER_APPINSIGHTS_ENABLED__','1' ` 52 | -replace '__PLACEHOLDER_TOMCAT_VERSION__','9.0.20' ` 53 | -replace '__PLACEHOLDER_TOMCAT_MAJOR__','9' ` 54 | -replace '__PLACEHOLDER_TOMCAT_MAJOR_MINOR__', '9.0' 55 | break 56 | } 57 | 58 | '9.0-java11' 59 | { 60 | $content = ((Get-Content -path $dockerFileTemplatePath -Raw) ` 61 | -replace '__PLACEHOLDER_BASEIMAGE__','mcr.microsoft.com/java/jre-headless:11u3-zulu-alpine-with-tools') ` 62 | -replace '__PLACEHOLDER_AI_VERSION__','2.1.2' ` 63 | -replace '__PLACEHOLDER_APPINSIGHTS_ENABLED__','0' ` 64 | -replace '__PLACEHOLDER_TOMCAT_VERSION__','9.0.20' ` 65 | -replace '__PLACEHOLDER_TOMCAT_MAJOR__','9' ` 66 | -replace '__PLACEHOLDER_TOMCAT_MAJOR_MINOR__', '9.0' 67 | break 68 | } 69 | } 70 | $headerFooter = "########################################################`n### ***DO NOT EDIT*** This is an auto-generated file ###`n########################################################`n" 71 | $content = $headerFooter + $content + $headerFooter 72 | Set-Content -Value $content -Path $dockerFileOutPath 73 | } 74 | 75 | setup -version '8.5-jre8' 76 | setup -version '9.0-jre8' 77 | setup -version '8.5-java11' 78 | setup -version '9.0-java11' 79 | -------------------------------------------------------------------------------- /scripts/setup.sh: -------------------------------------------------------------------------------- 1 | rm -rf 8.5-jre8/tmp/shared 2 | mkdir -p 8.5-jre8/tmp 3 | cp -r shared 8.5-jre8/tmp/shared 4 | 5 | rm -rf 8.5-jre8-alpine/tmp/shared 6 | mkdir -p 8.5-jre8-alpine/tmp 7 | cp -r shared 8.5-jre8-alpine/tmp/shared 8 | 9 | rm -rf 9.0-jre8-alpine/tmp/shared 10 | mkdir -p 9.0-jre8-alpine/tmp 11 | cp -r shared 9.0-jre8-alpine/tmp/shared 12 | 13 | rm -rf 9.0-jre8/tmp/shared 14 | mkdir -p 9.0-jre8/tmp 15 | cp -r shared 9.0-jre8/tmp/shared 16 | -------------------------------------------------------------------------------- /shared/app_insights/AI-Agent.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 1000 13 | 14 | 15 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /shared/app_insights/ApplicationInsights.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | false 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /shared/appservice/azure.appservice.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/shared/appservice/azure.appservice.jar -------------------------------------------------------------------------------- /shared/easyauth/azure.appservice.easyauth.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-App-Service/tomcat/ffe31b6bc2bb2570faae3f1dc6b7b9e24a27277f/shared/easyauth/azure.appservice.easyauth.jar -------------------------------------------------------------------------------- /shared/misc/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG BASE_IMAGE=__PLACEHOLDER_BASEIMAGE__ 2 | ARG GIT_COMMIT=unspecified 3 | FROM $BASE_IMAGE 4 | 5 | # Re-define ARG to make the build argument available for use in the rest of the Dockerfile 6 | ARG GIT_COMMIT 7 | 8 | LABEL maintainer="Azure App Services Container Images " 9 | 10 | ENV AI_VERSION __PLACEHOLDER_AI_VERSION__ 11 | ENV TOMCAT_VERSION __PLACEHOLDER_TOMCAT_VERSION__ 12 | ENV TOMCAT_MAJOR __PLACEHOLDER_TOMCAT_MAJOR__ 13 | ENV GIT_COMMIT $GIT_COMMIT 14 | ENV APPINSIGHTS_ENABLED __PLACEHOLDER_APPINSIGHTS_ENABLED__ 15 | 16 | ENV PORT 80 17 | ENV SSH_PORT 2222 18 | 19 | ENV PATH /usr/local/tomcat/bin:$PATH 20 | 21 | # Remove the sample webapps provided by Tomcat 22 | RUN rm -rf /usr/local/tomcat/webapps/ 23 | 24 | COPY tmp/shared/misc/init_container.sh /bin/init_container.sh 25 | COPY tmp/shared/tomcat/__PLACEHOLDER_TOMCAT_MAJOR_MINOR__/web-appservice-ai.xml /tmp/tomcat/conf/web-appservice-ai.xml 26 | COPY tmp/shared/misc/index.jsp /tmp/tomcat/webapps/ROOT/index.jsp 27 | COPY tmp/shared/misc/sshd_config /etc/ssh/ 28 | COPY tmp/shared/app_insights/AI-Agent.xml /usr/local/app_insights/aiagent/ 29 | COPY tmp/shared/app_insights/ApplicationInsights.xml /usr/local/app_insights/tomcat_lib/ 30 | 31 | RUN apk add --update openssh-server bash openrc \ 32 | && rm -rf /var/cache/apk/* \ 33 | # Remove unnecessary services 34 | && rm -f /etc/init.d/hwdrivers \ 35 | /etc/init.d/hwclock \ 36 | /etc/init.d/mtab \ 37 | /etc/init.d/bootmisc \ 38 | /etc/init.d/modules \ 39 | /etc/init.d/modules-load \ 40 | /etc/init.d/modloop \ 41 | # Can't do cgroups 42 | && sed -i 's/\tcgroup_add_service/\t#cgroup_add_service/g' /lib/rc/sh/openrc-run.sh \ 43 | && echo "root:Docker!" | chpasswd \ 44 | && wget -O /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz https://archive.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz --no-verbose \ 45 | && tar xvzf /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz -C /tmp \ 46 | && mv /tmp/apache-tomcat-$TOMCAT_VERSION /usr/local/tomcat \ 47 | && rm -rf /usr/local/tomcat/webapps \ 48 | && rm -f /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz \ 49 | && wget -O /usr/local/app_insights/tomcat_lib/applicationinsights-core-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-core-$AI_VERSION.jar --no-verbose \ 50 | && wget -O /usr/local/app_insights/tomcat_lib/applicationinsights-web-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-web-$AI_VERSION.jar --no-verbose \ 51 | && wget -O /usr/local/app_insights/aiagent/applicationinsights-agent-$AI_VERSION.jar https://github.com/Microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-agent-$AI_VERSION.jar --no-verbose \ 52 | && chmod 755 /bin/init_container.sh 53 | 54 | COPY tmp/shared/tomcat/__PLACEHOLDER_TOMCAT_MAJOR_MINOR__/server.xml /usr/local/tomcat/conf/server.xml 55 | COPY tmp/shared/tomcat/__PLACEHOLDER_TOMCAT_MAJOR_MINOR__/catalina.properties /usr/local/tomcat/conf/catalina.properties 56 | COPY tmp/shared/tomcat/__PLACEHOLDER_TOMCAT_MAJOR_MINOR__/context.xml /usr/local/tomcat/conf/context.xml 57 | COPY tmp/shared/tomcat/__PLACEHOLDER_TOMCAT_MAJOR_MINOR__/logging.properties /usr/local/tomcat/conf/logging.properties 58 | COPY tmp/shared/tomcat/__PLACEHOLDER_TOMCAT_MAJOR_MINOR__/web-appservice.xml /usr/local/tomcat/conf/web.xml 59 | COPY tmp/shared/easyauth/azure.appservice.easyauth.jar /usr/local/tomcat/lib/ 60 | COPY tmp/shared/appservice/azure.appservice.jar /usr/local/tomcat/lib/ 61 | COPY tmp/shared/tomcat/common/setenv.sh /usr/local/tomcat/bin/ 62 | 63 | EXPOSE 80 2222 64 | 65 | ENTRYPOINT ["/bin/init_container.sh"] 66 | -------------------------------------------------------------------------------- /shared/misc/sshd_config: -------------------------------------------------------------------------------- 1 | # This is ssh server systemwide configuration file. 2 | # 3 | # /etc/sshd_config 4 | 5 | Port SSH_PORT 6 | ListenAddress 0.0.0.0 7 | LoginGraceTime 180 8 | X11Forwarding yes 9 | Ciphers aes128-cbc,3des-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr 10 | MACs hmac-sha1,hmac-sha1-96 11 | StrictModes yes 12 | SyslogFacility DAEMON 13 | PasswordAuthentication yes 14 | PermitEmptyPasswords no 15 | PermitRootLogin yes 16 | Subsystem sftp internal-sftp -------------------------------------------------------------------------------- /shared/tomcat/8.5/context.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | WEB-INF/web.xml 24 | /home/site/deployments/active 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /shared/tomcat/9.0/context.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | WEB-INF/web.xml 24 | WEB-INF/tomcat-web.xml 25 | /home/site/deployments/active 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /shared/tomcat/common/setenv.sh: -------------------------------------------------------------------------------- 1 | ##### This file will be called from catalina.sh ##### 2 | 3 | # Starting tomcat 8.5, by default the files created by tomcat doesn’t grant read access to “others”, this includes log files. 4 | # Override Tomcat's default UMASK of 0027 (rw-r-----) with 0022 (-rw-r--r--). 5 | export UMASK="0022" 6 | 7 | # JARs added to $CATALINA_HOME/lib (and other paths supported by the Common class loader) are available for use by Tomcat. 8 | # However, tomcat-juli.jar (which contains Tomcat's enhancements to java.util.logging) is loaded by the System class 9 | # loader, not the Common class loader. Refer https://tomcat.apache.org/tomcat-9.0-doc/class-loader-howto.html for more details. 10 | # 11 | # As azure.appservice.jar contains formatters that tomcat-juli.jar needs to see, azure.appservice.jar needs to be added to 12 | # a path supported by the System class loader, not the Common class loader. This implies that we need to make all dependencies 13 | # of azure.appservice.jar available to System class loader as well. 14 | # 15 | # To make jars available to System class loader, they need to be added to CLASSPATH in setenv.sh (this file). 16 | # Update the CLASSPATH to load the AzMon formatter jar and its dependency servlet-api.jar. 17 | CLASSPATH=$CATALINA_BASE/lib/servlet-api.jar:$CATALINA_BASE/lib/azure.appservice.jar 18 | --------------------------------------------------------------------------------