<!-- for vdm generator -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<plugin>
<groupId>com.sap.cloud.sdk.datamodel</groupId>
<artifactId>odata-generator-maven-plugin</artifactId>
<version>3.15.1</version>
<executions>
<execution>
<id>generate-consumption</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputDirectory>${project.basedir}/edmx</inputDirectory>
<outputDirectory>${project.build.directory}/vdm</outputDirectory>
<deleteOutputDirectory>true</deleteOutputDirectory>
<packageName>com.vdm</packageName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/vdm</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
# from application directory
mvn clean package
package com.sap.cloud.sdk;
import com.google.gson.Gson;
import com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor;
import com.sap.cloud.sdk.odatav2.connectivity.ODataException;
import com.sap.cloud.sdk.s4hana.connectivity.DefaultErpHttpDestination;
import com.sap.cloud.sdk.s4hana.connectivity.ErpHttpDestination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
// generated by SAP Cloud SDK VDM generator
import com.vdm.namespaces.bank.Bank;
import com.vdm.services.DefaultBankService;
@WebServlet("/bank")
public class GetBankServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(GetBankServlet.class);
private static final ErpHttpDestination destination =
DestinationAccessor.getDestination("Erp1809")
.asHttp().decorate(DefaultErpHttpDestination::new);
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
throws IOException {
logger.info("Start get method: " + request.getRequestURI());
try{
final List<Bank> banks =
new DefaultBankService()
.getAllBank()
.select(Bank.BANK_KEY, Bank.BANK_NAME)
.filter(Bank.BANK_COUNTRY.eq("JP"))
.top(5)
.execute(destination);
logger.info(new Gson().toJson(banks));
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8"); //日本語用
response.getWriter().write(new Gson().toJson(banks));
} catch (final ODataException e){
logger.error(e.getMessage(), e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.getWriter().write(e.getMessage());
}
}
}
set destinations=[{name: "Erp1809", url: "http://<host>:<port>", username: "xxx", password: "xxx", sap-language: "ja"}]
mvn clean package && mvn tomee:run
[{"BankInternalId":"0000000","BankName":"銀行 冨田"},{"BankInternalId":"0000001","BankName":"bank ale3 test"},{"BankInternalId":"0000777","BankName":"ダミー銀行"},{"BankInternalId":"0001001","BankName":"ミズホ"},{"BankInternalId":"0001026","BankName":"ミズホ"}]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
40 | |
25 | |
17 | |
13 | |
8 | |
7 | |
7 | |
7 | |
6 | |
6 |