0
A
回答
1
扩展标识一的回答是:
提供远程图像URL作为参数传递给适配器:
适配器JS:
function getImage() {
WL.Logger.info("################### getImage ######################");
var val = com.company.ProjectName.ImageEncoder.getImage("http://Some-Domain/../.../id.gif");
WL.Logger.info("################### IMAGE IS ######################");
WL.Logger.info(val);
WL.Logger.info("#####################################################");
var imageData = {"data":val};
WL.Logger.info(JSON.stringify(imageData));
return imageData;
}
适配器XML:
添加程序到适配器:
<procedure name="getImage"/>
将自定义Java代码添加到您的服务器:
Java代码:
package com.company.ProjectName;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.MalformedInputException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class ImageEncoder {
public static String getImage(String imageUrl)
throws MalformedURLException, IOException {
String imageDataString = "";
URL url = null;
int i;
try {
url = new URL(imageUrl);
System.out.println(imageUrl);
HttpURLConnection connection = null;
String protocol = url.getProtocol();
System.out.println(protocol);
// this is to trust any certificates from the target server
if("https".equalsIgnoreCase(protocol)){
// Create a trust manager that does not validate certificate chains
System.out.println("inside If");
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
}
};
// Install the all-trusting trust manager
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
connection = (HttpsURLConnection)url.openConnection();
System.out.println("connection"+connection.getContentLength());
}else{
connection=(HttpURLConnection) url.openConnection();
}
InputStream input = connection.getInputStream();
byte[] bytes = org.apache.commons.io.IOUtils.toByteArray(input);
input.close();
imageDataString = encodeImage(bytes);
return imageDataString;
} catch (MalformedInputException malformedInputException) {
malformedInputException.printStackTrace();
imageDataString = malformedInputException.toString();
return ("exception while reading the imag <" + imageDataString + ">");
} catch (IOException ioException) {
ioException.printStackTrace();
imageDataString = ioException.toString();
return ("exception while reading the imag <" + imageDataString + ">");
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
imageDataString = e.toString();
return ("exception while reading the imag <" + imageDataString + ">");
} catch (KeyManagementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
imageDataString = e.toString();
return ("exception while reading the imag <" + imageDataString + ">");
}
public static String encodeImage(byte[] imageData) {
// TODO Auto-generated method stub
org.apache.commons.codec.binary.Base64 base = new org.apache.commons.codec.binary.Base64(
false);
return base.encodeToString(imageData);
}
}
Java代码目录:
注:DON“T TRUST所有证书。你需要添加你自己的信任经理。这仅用于测试
0
您可以按照提供的说明in this blog post。
的步骤如下:
- 作为参数提供远程图像URL到适配器
- 的Base64编码使用Java效用
- 返回的base64编码串在服务器上返回的图像到应用
- Base64的解码串并显示图像
相关问题
- 1. IBM Worklight Http适配器
- 2. ibm mobilefirst - 从Java适配器调用javascript适配器
- 3. IBM MobileFirst适配器安全角色
- 4. IBM Mobilefirst Java适配器会话超时
- 5. IBM MobileFirst 7.0 - 适配器调用
- 6. IBM Mobilefirst Java适配器连接Couchbase
- 7. “适配器”或“适配器”?
- 8. 错误配置IBM WAS在Eclipse开普勒7服务器适配器
- 9. IBM Db2 Visual Studio 2010表适配器问题
- 10. 调用在IBM使用适配器调用服务工作灯
- 11. IBM Mobilefirst 7.0 -Java适配器调用客户端
- 12. IBM与SQL适配器的mobilefirst混合应用程序
- 13. 适配器在IBM MobileFirst Platform v8.0中未被调用
- 14. 如何从IBM Mobilefirst的Java适配器调用Https Rest服务
- 15. SSL错误而在IBM MobileFirst适配器使用内部CA
- 16. 在IBM Worklight中运行HTTP适配器时出错
- 17. IBM worklight - “找不到适配器,程序调用错误”
- 18. 无法构建IBM MobileFirst Platform 7.0 Java适配器
- 19. 适配器模式:类适配器与对象适配器
- 20. IBM服务器配置
- 21. 适用于Ruby on Rails的DB2适配器与ActiveRecord JDBC适配器
- 22. Worklight HTTP适配器不适用于Kerberos
- 23. Postgres适配器
- 24. intent.putExtra适配器
- 25. NEGATOR适配器
- 26. BizTalk MQSeries适配器
- 27. 适配器ListView中
- 28. JMX Html适配器
- 29. 的ListView适配器
- 30. 适配器和Listactivity
jpg路径应该在json输出中返回的响应中,然后您可以抓取该文件。 –
@Hussam Eddin如何抓取文件呢? –
伊丹的答案解释了如何抓住它。我遵循相同的步骤将其放入我的项目中。 –