HTTP-Client的官方实例如下:
ODI官方文档中推荐HTTP URL方式调用Scenario
部分描述:
With the Metadata Navigator module, it is possible to launch a scenario from a web page or an
HTTP URL.
Note: To execute a scenario this way, you must first Install Metadata Navigator.
Principles
Metadata Navigator provides a StartScen servlet that responds to HTTP POST requests. This
servlet provides the same features as the OdiStartScen tool.
The StartScen servlet is called by using an HTTP POST request on the /snpsrepexp/startscen.do resource of your Metadata Navigator Server. Appropriate
HTTP parameters should be passed with the request.
The servlet returns an HTTP response in XML, HTML or plain text format.
The scenario execution returns a SOAP response as shown below:
<odi:invokeScenarioResponse xmlns:odi="xmlns.oracle.com/odi/OdiInvoke">
<odi:CommandResultType>
<odi:Ok>true</odi:Ok>
<odi:SessionNumber>1148001</odi:SessionNumber>
</odi:CommandResultType>
</odi:invokeScenarioResponse>
1、安装Metadata Navigator(参考Metadata Navigator安装及应用)
2、配置ODI Agent(参考ODI Scenario Scheduler Agent执行中的Agent配置文件设置->odiparams.bat设置)非必须
3、在ODI项目中创建Scenario(参考Running Scenario Using Variable)
4、创建JAVA应用
注:若oracledimn.war部署在远程服务器上,则
LOGON_SIT 与 LOGON_PORT需要改成对应的 IP 与 端口号
NameValuePair agentName = new NameValuePair("agent_name", "127.0.0.1");需要改成Agent所在机器的IP<如10.243.40.72>
创建ODIHttpWebService.java
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.cookie.CookieSpec;
import org.apache.commons.httpclient.methods.*;
public class ODIHttpWebservice {
static final String LOGON_SITE = "localhost";
static final int LOGON_PORT = 9090;
public ODIHttpWebservice() {
super();
}
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
PostMethod authpost = new PostMethod("/oracledimn/startscen.do");
// Prepare execute parameters(参数设置参照Oracle Data Integrator User's Guide/86)
NameValuePair agentName = new NameValuePair("agent_name", "127.0.0.1");
NameValuePair agentPort = new NameValuePair("agent_port", "20910");
NameValuePair masterDriver = new NameValuePair("master_driver","oracle.jdbc.driver.OracleDriver");
NameValuePair masterUrl = new NameValuePair("master_url", "jdbc:oracle:thin:@10.244.155.16:1521:ora10g");
NameValuePair masterUser = new NameValuePair("master_user", "EXTFWK");
NameValuePair masterPsw = new NameValuePair("master_psw", "cByXdik4DDOzPIqHygsc5Wp");
NameValuePair workRepository = new NameValuePair("work_repository", "EASAS WORK01");
NameValuePair snpsUser = new NameValuePair("snps_user", "SUPERVISOR");
NameValuePair snpsPsw = new NameValuePair("snps_psw", "fDyXwp0FX38Lh7SljxUs");
NameValuePair scenName = new NameValuePair("scen_name", "LOAD_ROLE_FUNCTIONS");
NameValuePair scenVersion = new NameValuePair("scen_version", "001");
NameValuePair contextCode = new NameValuePair("context_code", "GLOBAL");
NameValuePair logLevel = new NameValuePair("log_level", "2");
NameValuePair httpReply = new NameValuePair("http_reply", "XML");
//Add Project's Variable by using project code
NameValuePair projectParam1 = new NameValuePair("EASAS_PROJECT.roleCode", "'USER_MANAGE'");
authpost.setRequestBody(
new NameValuePair[] { agentName, agentPort, masterDriver, masterUrl,
masterUser, masterPsw, workRepository, snpsUser, snpsPsw, scenName,
scenVersion, contextCode, logLevel, httpReply, projectParam1});
client.executeMethod(authpost);
System.out.println("Project Param1: "+projectParam1.getValue()+" \nLogin form post: " + authpost.getResponseBodyAsString().toString());
// release any connection resources used by the method
authpost.releaseConnection();
}
}
5、启动Tomcat,确认Metadata Navigator应用正常
6、调用ODIAgent,确认Agent正常使用
7、运行JAVA应用,执行正常将在控制台得到输出信息,输出信息类似以下结构:
<odi:invokeScenarioResponse xmlns:odi="xmlns.oracle.com/odi/OdiInvoke">
<odi:CommandResultType>
<odi:Ok>true</odi:Ok>
<odi:SessionNumber>1148001</odi:SessionNumber>
</odi:CommandResultType>
</odi:invokeScenarioResponse>
8、到ODI中检查会话是否正常执行,检查参数传递是否生效