日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

使用SAP云平台 + JNDI访问Internet Service

發(fā)布時(shí)間:2023/12/19 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用SAP云平台 + JNDI访问Internet Service 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

以Internet Service http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Walldorf&destinations=Berlin為例,

在瀏覽器里訪問這個(gè)url,得到輸出:從Walldorf到Berlin的距離。

如何讓一個(gè)部署到SAP云平臺(tái)的Java應(yīng)用也能訪問到該internet service呢?

首先在SAP云平臺(tái)里創(chuàng)建一個(gè)destination,維護(hù)service的end point:

在Java代碼里使用SAP云平臺(tái)里創(chuàng)建的destination:

然后使用JNDI service讀取destination里配置的url:

部署到SAP云平臺(tái)之后,在Eclipse里看到preview結(jié)果:

SAP云平臺(tái)Cockpit顯示如下:

瀏覽器訪問如下:

web.xml:

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID" version="2.5"><!-- Main sample servlet mapped to / so that the integration test harness can detect readiness (generic for all samples) --><servlet><servlet-name>ConnectivityServlet</servlet-name><servlet-class>com.sap.cloud.sample.connectivity.ConnectivityServlet</servlet-class></servlet><servlet-mapping><servlet-name>ConnectivityServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping><!-- Declare the JNDI lookup of destination --><resource-ref><res-ref-name>connectivityConfiguration</res-ref-name><res-type>com.sap.core.connectivity.api.configuration.ConnectivityConfiguration</res-type></resource-ref> </web-app> package com.sap.cloud.sample.connectivity;import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL;import javax.annotation.Resource; import javax.naming.Context; import javax.naming.InitialContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;import org.slf4j.Logger; import org.slf4j.LoggerFactory;import com.sap.cloud.account.TenantContext; import com.sap.core.connectivity.api.configuration.ConnectivityConfiguration; import com.sap.core.connectivity.api.configuration.DestinationConfiguration;public class ConnectivityServlet extends HttpServlet {@Resourceprivate TenantContext tenantContext;private static final long serialVersionUID = 1L;private static final int COPY_CONTENT_BUFFER_SIZE = 1024;private static final Logger LOGGER = LoggerFactory.getLogger(ConnectivityServlet.class);private static final String ON_PREMISE_PROXY = "OnPremise";@Overridepublic void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {HttpURLConnection urlConnection = null;String destinationName = request.getParameter("destname");if (destinationName == null) {destinationName = "google_map";}try {Context ctx = new InitialContext();ConnectivityConfiguration configuration = (ConnectivityConfiguration) ctx.lookup("java:comp/env/connectivityConfiguration");DestinationConfiguration destConfiguration = configuration.getConfiguration(destinationName);if (destConfiguration == null) {response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,String.format("Destination %s is not found. Hint:"+ " Make sure to have the destination configured.", destinationName));return;}String value = destConfiguration.getProperty("URL");URL url = new URL(value + "xml?origins=Walldorf&destinations=Paris");String proxyType = destConfiguration.getProperty("ProxyType");Proxy proxy = getProxy(proxyType);urlConnection = (HttpURLConnection) url.openConnection(proxy);injectHeader(urlConnection, proxyType);InputStream instream = urlConnection.getInputStream();OutputStream outstream = response.getOutputStream();copyStream(instream, outstream);} catch (Exception e) {String errorMessage = "Connectivity operation failed with reason: "+ e.getMessage()+ ". See "+ "logs for details. Hint: Make sure to have an HTTP proxy configured in your "+ "local environment in case your environment uses "+ "an HTTP proxy for the outbound Internet "+ "communication.";LOGGER.error("Connectivity operation failed", e);response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,errorMessage);}}private Proxy getProxy(String proxyType) {Proxy proxy = Proxy.NO_PROXY;String proxyHost = null;String proxyPort = null;if (ON_PREMISE_PROXY.equals(proxyType)) {// Get proxy for on-premise destinationsproxyHost = System.getenv("HC_OP_HTTP_PROXY_HOST");proxyPort = System.getenv("HC_OP_HTTP_PROXY_PORT");} else {// Get proxy for internet destinationsproxyHost = System.getProperty("https.proxyHost");proxyPort = System.getProperty("https.proxyPort");}if (proxyPort != null && proxyHost != null) {int proxyPortNumber = Integer.parseInt(proxyPort);proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPortNumber));}return proxy;}private void injectHeader(HttpURLConnection urlConnection, String proxyType) {if (ON_PREMISE_PROXY.equals(proxyType)) {// Insert header for on-premise connectivity with the consumer account nameurlConnection.setRequestProperty("SAP-Connectivity-ConsumerAccount",tenantContext.getTenant().getAccount().getId());}}private void copyStream(InputStream inStream, OutputStream outStream) throws IOException {byte[] buffer = new byte[COPY_CONTENT_BUFFER_SIZE];int len;while ((len = inStream.read(buffer)) != -1) {outStream.write(buffer, 0, len);}} }

要獲取更多Jerry的原創(chuàng)技術(shù)文章,請(qǐng)關(guān)注公眾號(hào)"汪子熙"或者掃描下面二維碼:

總結(jié)

以上是生活随笔為你收集整理的使用SAP云平台 + JNDI访问Internet Service的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 在线视频福利 | 婷婷视频网 | 朱竹清到爽高潮痉挛 | 三级黄色短视频 | 疯狂伦交 | 亚洲综合激情在线 | 在线观看二区 | 亚洲夜夜爱 | 日本不卡1 | 国产xx在线观看 | 尤物最新网址 | 久久久久亚洲av成人网人人网站 | 亚洲永久精品一区 | av综合在线观看 | 少妇h视频 | 国产精品欧美久久久久天天影视 | 女生被草| 日本韩国在线播放 | 国产中文字幕久久 | 伊人亚洲 | 亚洲成av人片一区二区 | 人人妻人人爽一区二区三区 | 一区影视| 国产视频一区二区三区在线观看 | 二区在线播放 | 国产91看片 | 麻豆成人免费视频 | 国产精品熟妇一区二区三区四区 | 日韩精品小视频 | 久久久久久日产精品 | 国产精品后入内射日本在线观看 | 视频网站在线观看18 | 超碰cc| 超碰不卡 | 免费一级毛片麻豆精品 | 色婷婷精品视频 | 伊人55 | 丰满人妻一区二区三区在线 | 亚洲欧美一二三 | 91网站免费观看 | 人妻与黑人一区二区三区 | 亚洲一区二区国产精品 | 国产精品免费视频一区二区三区 | 日本一二三区在线视频 | 影音先锋久久久久av综合网成人 | 琪琪久久 | 毛片毛片毛片毛片毛片毛片 | 欧美成人综合 | 老女人黄色片 | 色综合视频在线观看 | 国产一级一区 | 91美女高潮出水 | 日韩小视频在线观看 | xiuxiuavnet| 中文字幕日韩欧美在线 | 国产做爰全免费的视频软件 | 西西久久| 福利片在线观看 | av天堂一区二区三区 | 亚洲一区在线播放 | 国产精品高清在线观看 | 色激情网| 91激情视频在线观看 | 亚洲另类春色 | 成人久久国产 | 无码人妻精品一区二区三区蜜桃91 | 色av网| 久久久久久久色 | 99热| 在线视频一区二区 | 少妇一区二区三区 | www.88av| 999在线观看视频 | 色婷婷一区二区 | 久久sese| 免费无码毛片一区二三区 | 五月天av在线 | 欧美一级片在线视频 | 亚洲欧美日韩中文在线 | 狠狠干网址 | 麻豆一区产品精品蜜桃的特点 | 老司机在线免费视频 | 女女爱爱视频 | 欧美日韩在线免费播放 | 精品人妻人人做人人爽夜夜爽 | 超碰99在线 | 国产精品宾馆在线精品酒店 | 国产精品高清无码 | 亚洲一本二本 | 日本不卡视频在线 | 久久久精品人妻一区二区三区色秀 | 亚洲成人av在线播放 | 午夜看毛片 | 欧美高清视频一区二区 | 国产顶级毛片 | 国产精品福利一区 | 人人干狠狠干 | 天天操天天操天天射 | 超碰最新在线 |