我需要从.NET ASHX处理程序中重复地提取图像,该处理程序遵循http://domain.com/handler.ashx?id=013505形式,其中ID标识处理程序应该服务的图像的人。我必须在PeopleSoft应用程序中执行此操作,因此我仅限于在PeopleCode中提供的内容,但是也可以使用大量的Java(尽管从语法上讲,它对于一个人来说不是很有意义。纯Java开发人员)。到目前为止我能做的事情
如果有人觉得它有用,我会很乐意发布我正在使用的代码,但正如我所说,这是对这些Java类的“PeopleCode-ized”使用,所以对许多人来说可能没有意义。我真的只是在Java中寻找一些其他可能出错的一般建议;我可以从那里翻译它以在PeopleCode中尝试。
答案 0 :(得分:2)
只是为了繁荣,因为这将永远存在于“teh interwebs”这里是我问题的最终解决方案:
首先,我之所以回到我所引用的“HTML模糊”的原因是因为我指向的URL正在重定向到另一台服务器。
一旦我弄清楚并指出“真正的”服务器,我开始收到SSL证书信任错误。在这种情况下,服务器具有内部自签名证书。我尝试在PeopleSoft Web服务器和PeopleSoft的数字证书库中安装该证书,但无济于事。然后我继续计划B:强迫我的PeopleCode / Java混合使用证书本身。
在大多数情况下,this post帮助我弄清楚我需要做什么。一般来说,这些是我采取的步骤:
希望将来有人会觉得这很有帮助。这是完整的PeopleCode供参考(注意,这只是测试代码,我将一个按钮绑定到一个页面的FieldChange事件):
Local JavaObject &joCertString, &joUrl, &joUrlConnection, &joInputStream, &joImageIO, &joBufferedImage, &joFile;
Local JavaObject &joCertificateFactoryClass, &joCertificateFactory, &joCertInputStream, &joCertificate;
Local JavaObject &joKeystoreClass, &joKeystore, &joTrustManagerFactoryClass, &joTrustManagerFactory;
Local JavaObject &joSSLContextClass, &joSSLContext, &joSSLFactory, &joCastObjectClass;
Local any &anyFileData;
Local Record &recTest;
Local string &sPhotosCert;
Local number &nPutResult;
/*Setup CertificateFactory*/
&sPhotosCert = GetHTMLText(HTML.PHOTOS_CERT);
&joCertString = CreateJavaObject("java.lang.String", &sPhotosCert);
&joCertificateFactoryClass = GetJavaClass("java.security.cert.CertificateFactory");
&joCertificateFactory = &joCertificateFactoryClass.getInstance("X.509");
&joCertInputStream = CreateJavaObject("java.io.ByteArrayInputStream", &joCertString.getBytes("UTF-8"));
&joCertificate = &joCertificateFactory.generateCertificate(&joCertInputStream);
/*Create Keystore*/
&joKeystoreClass = GetJavaClass("java.security.KeyStore");
&joKeystore = &joKeystoreClass.getInstance("JKS");
&joKeystore.load( Null, Null);
&joKeystore.setCertificateEntry("photos", &joCertificate);
/*Create TrustManagerFactory*/
&joTrustManagerFactoryClass = GetJavaClass("javax.net.ssl.TrustManagerFactory");
&joTrustManagerFactory = &joTrustManagerFactoryClass.getInstance(&joTrustManagerFactoryClass.getDefaultAlgorithm());
&joTrustManagerFactory.init(&joKeystore);
/*Create SSLContext and get SSLSocketFactory*/
&joSSLContextClass = GetJavaClass("javax.net.ssl.SSLContext");
&joSSLContext = &joSSLContextClass.getInstance("TLS");
&joSSLContext.init( Null, &joTrustManagerFactory.getTrustManagers(), Null);
&joSSLFactory = &joSSLContext.getSocketFactory();
/*Create URL*/
&joUrl = CreateJavaObject("java.net.URL", "https://domain.com/handler.ashx?id=123456");
/*Get URLConnection*/
&joUrlConnection = &joUrl.openConnection();
/*Cast to HttpsURLConnection*/
&joCastObjectClass = GetJavaClass("com.domain.CastObject");
&joUrlConnection = &joCastObjectClass.objectToHttpsURLConnection(&joUrlConnection);
/*Set connection properties*/
&joUrlConnection.setSSLSocketFactory(&joSSLFactory);
&joUrlConnection.setRequestMethod("GET");
/*Get InputStream*/
&joInputStream = GetJavaClass("java.io.InputStream");
&joInputStream = &joUrlConnection.getInputStream();
/*Get Image From Stream*/
&joImageIO = GetJavaClass("javax.imageio.ImageIO");
&joBufferedImage = CreateJavaObject("java.awt.image.BufferedImage", 1, 1, 1);
&joBufferedImage = &joImageIO.read(&joInputStream);
/*Write Image to File*/
&joFile = CreateJavaObject("java.io.File", "/temp/URLImage2.jpg");
&joImageIO.write(&joBufferedImage, "jpg", &joFile);
/*Put the File into a PS record so we can get a BLOB of it*/
&nPutResult = PutAttachment("record://PSFILE_ATTDET", "013505.jpg", "/temp/URLImage2.jpg");
/*Grab that BLOB*/
SQLExec("SELECT FILE_DATA FROM PSFILE_ATTDET WHERE ATTACHSYSFILENAME = :1 AND VERSION = 1", "013505.jpg", &anyFileData);
/*Clean up the temp row we inserted*/
SQLExec("DELETE FROM PSFILE_ATTDET WHERE ATTACHSYSFILENAME = :1 AND VERSION = 1", "013505.jpg");
/*Setup an employee photo record*/
&recTest = CreateRecord(Record.EMPL_PHOTO);
&recTest.EMPLID.Value = "013505";
&recTest.PSIMAGEVER.Value = (Days365(Date3(1999, 12, 31), %Date) * 86400) + (%Time - Time3(0, 0, 0));
&recTest.EMPLOYEE_PHOTO.Value = &anyFileData;
/*Insert/Update the employee photo record*/
&recTest.Insert();
&recTest.Update();