gpt4 book ai didi

java - Java存储过程中的getOutputStream抛出错误

转载 作者:行者123 更新时间:2023-12-02 10:28:58 24 4
gpt4 key购买 nike

我正在尝试从 Java 存储过程使用 SOAP Web 服务,并且我使用 getOutputStream() 命令将有效负载写入连接,该连接抛出访问错误,如下所示。

Java 调用因未捕获的 Java 异常而终止:

java.security.AccessControlException:
the Permission (java.net.SocketPermission <Server-Name>:<Port> connect,resolve)
has not been granted to INFOIFACE.
The PL/SQL to grant this is dbms_java.grant_permission
( 'INFOIFACE', 'SYS:java.net.SocketPermission', <Server-Name>:<Port>, 'connect,resolve' )

但是 Oracle DB 中为架构提供了相同的访问权限,但仍然显示错误。

public class remoteConnection {
public static String connectToFPH(String destUrl, String pacFile, String cred, String payLoad) throws Exception {

System.out.println("Inside function");
BrowserProxyInfo bInfo = new BrowserProxyInfo();
bInfo.setType(ProxyType.AUTO);
bInfo.setAutoConfigURL(pacFile);
DummyAutoProxyHandler handler = new DummyAutoProxyHandler();
try {
handler.init(bInfo);
} catch (ProxyConfigException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}

String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(cred.getBytes());
URL url = new URL(destUrl);

String proxyUrl = "";
ProxyInfo[] ps = handler.getProxyInfo(url);
for(ProxyInfo p : ps){
proxyUrl = p.toString();
}

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyUrl.split(":")[0], Integer.valueOf(proxyUrl.split(":")[1])));

HttpsURLConnection conn = (HttpsURLConnection)url.openConnection(proxy);
conn.setRequestMethod("POST");
conn.setRequestProperty ("Authorization", basicAuth);
conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);

OutputStream out = conn.getOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
writer.write(payLoad);
writer.close();
out.close();

String inputLine;
StringBuffer buf = new StringBuffer();
if(conn.getResponseCode() == 200)
{
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

while ((inputLine = in.readLine()) != null)
{
buf.append(inputLine);
}
in.close();
}
else
{
//throw new Exception("Unable to connect to FPH. Please contact Administrator");
return "unable to connect";
}

conn.disconnect();

return buf.toString();
}

}

我请求这方面的帮助。 Oracle DB 中是否需要提供其他访问权限?

最佳答案

您似乎遇到了 Oracle 安全管理器。这基本上是一个由数据库表控制的经典 Java SecurityManager:

"As with Java2 security, Oracle Database supports the security classes. Normally, you set the permissions for the code base either using a tool or by editing the security policy file. In Oracle Database, you set the permissions dynamically using DBMS_JAVA procedures, which modify a policy table in the database."

有关详细信息,请参阅:

请注意,上面的示例 10-1 显示了如何使用 DBMS_Java 授予 Java 权限。 (该示例显示了 FilePermission 授权。您将需要具有相关属性的 SocketPermission 授权。)

关于java - Java存储过程中的getOutputStream抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53718413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com