Weblogic读取元数据文件

罗伯特3452

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

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

谁能指出我在文档中正确的位置。

罗伯特3452

我已经破解了自己想要的方式。为此,我必须:

  1. 获取WL Server的JNDI上下文
  2. 查找一个MBeanServer
  3. (注释掉)使用MBean界面列出MDS存储库和分区
  4. 获取MDSAppRuntime
  5. 调用startExport并保存streamID
  6. 调用doExport传入我想要的文件名
  7. 调用获取保存返回的字节数组
  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;
        }
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法读取Eclipse方面的项目元数据文件

来自分类Dev

使用Matlab可靠地读取列表数据文件

来自分类Dev

用Java快速读取大数据文件

来自分类Dev

读取大型矩阵数据文件的特定行

来自分类Dev

gnuplot从数据文件列读取线型

来自分类Dev

读取具有可变大小的行的数据文件

来自分类Dev

读取具有可变大小的行的数据文件

来自分类Dev

Android-SVN上的元数据文件夹

来自分类Dev

无法验证XSD SAML元数据文件

来自分类Dev

无法在TeamCity上的Android上读取Jacoco数据文件

来自分类Dev

读取数据文件作为链表中的节点的功能

来自分类Dev

如何使用GLPK中的坐标读取数据文件

来自分类Dev

c-读取数据文件中的特定列

来自分类Dev

在R读取的数据文件中分配列名

来自分类Dev

跳过从数据文件C ++读取字符

来自分类Dev

如何在Python的类中读取数据文件?

来自分类Dev

JSON元数据文件的流浪者URL

来自分类Dev

使用python将数据文件读取到数组

来自分类Dev

用Java快速读取大数据文件

来自分类Dev

元数据文件删除的不利影响

来自分类Dev

gnuplot从数据文件列读取线型

来自分类Dev

无法读取Eclipse方面的项目元数据文件

来自分类Dev

CentOS或RedHat-搜索rpm DB元数据文件

来自分类Dev

在C ++中读取“大”数据文件

来自分类Dev

从数据文件中读取数据点

来自分类Dev

VS2017 元数据文件“.dll”找不到

来自分类Dev

未找到参考的元数据文件

来自分类Dev

Weblogic 如何使用 WLST 发布元数据文件

来自分类Dev

读取 Avro 文件时不是数据文件错误