gpt4 book ai didi

java - Weblogic读取元数据文件

转载 作者:太空宇宙 更新时间:2023-11-04 13:21:13 26 4
gpt4 key购买 nike

我有一个在 Weblogic 服务器上运行的 Java 应用程序。weblogic服务器有许多元数据存储库我感兴趣的存储库有许多分区。我想找到一些可以调用的 API:

  1. 列出服务器上的所有元数据存储库
  2. 列出特定存储库中的所有分区
  3. 读取分区中特定文件的内容

任何人都可以指出我在文档中的正确位置。

最佳答案

我已经通过黑客手段获得了我想要的东西。为了实现这一目标,我必须:

  1. 获取 WL 服务器的 JNDI 上下文
  2. 查找 MBeanServer
  3. (已注释)使用 MBean 接口(interface)列出 MDS 存储库和分区
  4. 获取 MDSAppRuntime
  5. 调用startExport并保存streamID
  6. 调用 doExport 并传入我想要的文件名
  7. 调用 get 保存返回的字节数组
  8. 调用 endExport
  9. 字节数组实际上是一个zip文件,所以我需要提取我想要的文件的内容

读取文件似乎很麻烦,但这是我发现有效的唯一方法。

我的代码如下,注意步骤 3 已被注释掉,因为您不需要 weblogic 密码即可读取 MDS 文件。

希望这可以在将来节省某人的时间

package ic.ac.uk.icdev.rjmtest.wladminserversensor.wsdlgen;

import ic.ac.uk.icdev.rjmtest.wladminserversensor.wsdlgentypes.RequestSOAEndpointsMessageType;
import ic.ac.uk.icdev.rjmtest.wladminserversensor.wsdlgentypes.ResponseSOAEndpointsMessageType;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import java.util.Hashtable;

import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import javax.jms.Destination;

import javax.jws.WebService;

import javax.management.MBeanServer;

import javax.management.ObjectName;

import javax.management.RuntimeMBeanException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding;


@WebService(serviceName = "mainService", targetNamespace = "urn:WLAdminServerSensor", portName = "mainPort", endpointInterface = "ic.ac.uk.icdev.rjmtest.wladminserversensor.wsdlgen.Main_pt", wsdlLocation = "/WEB-INF/wsdl/service.wsdl")
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
public class Main_ptImpl {
public Main_ptImpl() {
}

private byte[] exportMetadataFile(MBeanServer p_server) throws Exception {
//Reading from SOA1
ObjectName mdsSOA1Bean = new ObjectName("oracle.mds.lcm:Location=WLS_SOA1,name=MDSAppRuntime,type=MDSAppRuntime,Application=soa-infra");


//String streamID = UUID.randomUUID().toString();
String streamID = (String) p_server.invoke(mdsSOA1Bean, "startExport",null,null);

String[] docs = new String[1];
docs[0] = "/apps/AIAMetaData/dvm/XXIC_DVM_SOAEndpoints.dvm";


Object[] x = new Object[9];
String[] y = new String[9];
int c=0;
x[c] = streamID; y[c] = String.class.getName(); c++;
x[c] = docs; y[c] = String[].class.getName(); c++;
x[c] = new String[0]; y[c] = String[].class.getName(); c++; //restrict custs to
x[c] = false; y[c] = boolean.class.getName(); c++;
x[c] = false; y[c] = boolean.class.getName(); c++;
x[c] = false; y[c] = boolean.class.getName(); c++;
x[c] = false; y[c] = boolean.class.getName(); c++;
x[c] = ""; y[c] = String.class.getName(); c++;
x[c] = ""; y[c] = String.class.getName(); c++;
javax.management.openmbean.TabularData ret = (javax.management.openmbean.TabularData) p_server.invoke(mdsSOA1Bean, "doExport",x,y);

Object[] x0 = new Object[2];
String[] y0 = new String[2];
c=0;
x0[c] = streamID; y0[c] = String.class.getName(); c++;
x0[c] = 4096; y0[c] = int.class.getName(); c++;
byte[] fil = (byte[]) p_server.invoke(mdsSOA1Bean, "get",x0,y0);



Object[] x2 = new Object[1];
x2[0] = streamID;
String[] y2 = new String[1];
y2[0] = String.class.getName();
p_server.invoke(mdsSOA1Bean, "endExport",x2,y2);

//We get a zip file with the MDS file contained inside it. We must extract it out
ZipInputStream zin = new ZipInputStream(new ByteArrayInputStream(fil));
ZipEntry ze = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream(fil.length);
while ((ze = zin.getNextEntry()) != null) {
if (true) {
byte[] buffer = new byte[8192];
int len;
while ((len = zin.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
break;
}
}
return bos.toByteArray();

}

private ResponseSOAEndpointsMessageType run(RequestSOAEndpointsMessageType requestSOAEndpointsInputPart) throws Exception {

Hashtable env = new Hashtable();
//Username and password only required for enurmrating parittipons
//env.put(Context.SECURITY_PRINCIPAL, "weblogic");
//env.put(Context.SECURITY_CREDENTIALS, "password");
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");

Context jndiContext = null;

try {
jndiContext = new InitialContext(env);
} catch (NamingException e) {
throw new Exception("Creating initial context NamingException:" + e.toString());
}

Destination passedDest = null;

//MBeanServer server = (MBeanServer)jndiContext.lookup("java:comp/env/jmx/runtime");
MBeanServer server = (MBeanServer)jndiContext.lookup("java:comp/env/jmx/domainRuntime");

/*
* Code to enurmrate MDS repos and partitions - not needed to read actual file
ObjectName service = new ObjectName(
"com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean"
);


ObjectName mdsBean = new ObjectName("oracle.mds.lcm:name=MDSDomainRuntime,type=MDSDomainRuntime");

String[] repositories = (String[]) server.invoke(mdsBean, "listRepositories",null,null);

ObjectName rep = null;
for (int c=0;c<repositories.length;c++) {
ObjectName cur = new ObjectName(repositories[c]);
if (cur.getKeyProperty("Name").equals("mds-owsm")) {
rep = new ObjectName(repositories[c]);
};
}
if (rep==null) throw new Exception("No mds-owsm repository found");

Object[] x = new Object[1];
x[0] = new String(rep.getKeyProperty("Name"));
String[] y = new String[1];
y[0] = String.class.getName();
String[] partitions = (String[]) server.invoke(mdsBean, "listPartitions",x,y);

String part = null;
for (int c=0;c<partitions.length;c++) {
if (partitions[c].equals("soa-infra")) {
part = partitions[c];
};
}
if (part==null) throw new Exception("Could not find partition soa-infra in mds");
*/

byte[] fil = exportMetadataFile(server);
String s = new String(fil,"UTF-8");

ResponseSOAEndpointsMessageType ret = new ResponseSOAEndpointsMessageType();
ret.setOutput(s);
return ret;

}

public ResponseSOAEndpointsMessageType querySOAEndpoints(RequestSOAEndpointsMessageType requestSOAEndpointsInputPart) {
ResponseSOAEndpointsMessageType ret = new ResponseSOAEndpointsMessageType();
try {
return run(requestSOAEndpointsInputPart);
} catch (RuntimeMBeanException e) {
String st = "";
for (int c=0;c<e.getStackTrace().length;c++) {
st += "\n" + e.getStackTrace()[c].toString();
}

if (e.getTargetException()==null) {
st += "\n\nTARG EXCEPTION IS NULL";
} else {
st += "\n\nTARG EXCEPTION: " + e.getTargetException().getMessage();
for (int c=0;c<e.getTargetException().getStackTrace().length;c++) {
st += "\n" + e.getTargetException().getStackTrace()[c].toString();
}
}

ret.setOutput("RuntimeMBeanException: " + e.getMessage() + "\n" + e.getLocalizedMessage() + "\n" + st);
return ret;
} catch (Exception e) {
String st = "";
for (int c=0;c<e.getStackTrace().length;c++) {
st += "\n" + e.getStackTrace()[c].toString();
}

ret.setOutput("Exception: " + e.getMessage() + "\n" + e.getLocalizedMessage() + "\n" + st);
return ret;
}
}
}

关于java - Weblogic读取元数据文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33041586/

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