Integrating Oracle BI Publisher with Java Application (using Web Service)
Pre-Requisites:
1) Oracle BI Publisher Installation, that is publishing a Web Service
2) Eclipse IDE (with WTP updates)
3) Axis 2 Run Time(library Files i.e. jaxrpc.jar, axis.jar etc.)
Configuring Eclipse IDE :
This tutorial need a Axis2 runtime. You can download the latest axis2 binary distribution from here. - Download the latest Axis2 runtime from the above link and extract it.
- Now we point Eclipse WTP to downloaded Axis2 Runtime. Open Window -> Preferences -> Web Services -> Axis2 Preferences
Select the Axis2 Runtime tab and point to the correct Axis2 runtime location. Alternatively at the Axis2 Preference tab, you can set the default setting that will come up on the Web Services Creation wizards. For the moment we will accept the default settings.
Axis 2 Runtime Settings in Eclipse
- Click OK.
- Next we need to create a project with the support of Axis2 features. Open File -> New -> Other... -> Web -> Dynamic Web Project
Dynamic Web project in the New Project tab
Click next
- Select the name Axis2WSTest as the Dynamic Web project name (you can specify any name you prefer), and select the configured Tomcat runtime as the target runtime.
Select Apache Tomcat as Target Runtime
Click next.
Note : If you don’t find Apache Tomcat v6.0, listed in the Target Runtime, it means you haven’t configured Tomcat in Eclipse. Just click on the New button and follow the prompts. You will end up at a screen where you have to tell Eclipse where your Tomcat Installation Directory Path.
- Select the Axis2 Web service facet
Click Finish.
- This will create a dynamic Web project in the workbench
Make sure you have the following JARs in your Java Build Path,
1. Include the following jar files in your classpath (these files can be obtained from the Web):
1. activation.jar
2. mail-1.4.jar
2. Include xmlpserver.jar file (installed with Oracle BI Publisher) in your classpath. This is to ensure that you have all the required request and response objects. This way you will not need to generate response and request stub objects.
8. Next we need to create a Web Service Client. To do this, go to File-> New -> Other … -> Web Services -> Web service Client
Web Service Client
Click Next
9. Here we have to specify the Service Definition for the desired Web Service. Since we would be using the Web Service published by Oracle BI Publisher, we would enter the specific url, leading to the WSDL.
After you have installed or deployed Oracle BI Publisher, there is a unique URL associated with this installation:
http://:/xmlpserver/services/PublicReportService?wsdl
Enter this URL in your browser, substituting in the correct host and port number, to display the full Web Service Description Language definition for the publicly supported BI Publisher Web service.
In eclipse, click on the browse button, and enter the above URL. The OK button will get activated, once eclipse gets the WSDL definition using the entered URL.
Click OK , the entered URL would appear in the Service Definition text box
Web Service Definition
Click Next
And finally click on Finish.
10. Now check your Workspace. Inside the Java resources : src tree, you will find a new package by the name com.oracle.xmlns.oxp.service.PublicReportService. This package contains several java files, which we would be importing and using in our code.
This finishes the eclipse configuration that is required to test our code / Web Service Method Invocation.Code Samples :
Import the generated Stub Classes (the classes inside the com.oracle.xmlns …… package) and the other required Apache Axis and Java classes
import com.oracle.xmlns.oxp.service.PublicReportService.ItemData;
import com.oracle.xmlns.oxp.service.PublicReportService.ReportRequest;
import com.oracle.xmlns.oxp.service.PublicReportService.ReportResponse;
import com.oracle.xmlns.oxp.service.PublicReportService.ParamNameValue;
import com.oracle.xmlns.oxp.service.PublicReportService.ReportDefinition;
import com.oracle.xmlns.oxp.service.PublicReportService.ScheduleRequest;
import com.oracle.xmlns.oxp.service.PublicReportService.DeliveryRequest;
import com.oracle.xmlns.oxp.service.PublicReportService.LocalDeliveryOption;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Calendar;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import java.net.URL;Create global variables
final static String bipEndpoint = "http://:/xmlpserver/services/PublicReportService?wsdl";
final static String bipNamespace = "http://xmlns.oracle.com/oxp/service/PublicReportService";
static String userID = “Administrator”, password; = “Administrator”;
Use validateLogin to validate that a UserID and Password have the privilege to access the Oracle BI Publisher report server.
input message = validateLoginRequest
output message = validateLoginResponse
public static boolean validateLogin() throws Exception {
final String reportPath = "/NSDL/BO_DATA_TEMPLATE/BO_DATA_TEMPLATE.xdo";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(bipEndpoint));
System.out.println("TESTING login Service BEGIN");
call.setOperationName(new QName(bipNamespace, "validateLogin"));
call.addParameter("userID", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_BOOLEAN);
// issue the request
Boolean valid = (Boolean) call.invoke(
new Object[] {userID, password});
if (valid) { System.out.println("user valid");return(true); }
else { System.out.println("user invalid"); return(false); }
}
Use hasReportAccess to validate that a UserID and Password have the privilege to access a specific report.
input message = hasReportAccessRequest
output message =hasReportAccessResponse
public static boolean hasReportAccess(String reportPath) throws Exception {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(bipEndpoint));
System.out.println("TESTING hasReportAccess BEGIN");
call.setOperationName(new QName(bipNamespace, "hasReportAccess"));
call.addParameter("reportAbsolutePath", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("userID", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_BOOLEAN);
// issue the request
Boolean valid = (Boolean) call.invoke(
new Object[] {reportPath,userID, password});
if (valid==true) { System.out.println("User has access.");return(true); }
else { System.out.println("User does not have access"); return(false); }
getReportParameters
Use getReportParameters to get an array of report parameters and their default values. Once you have the list of parameters you can set parameter values before running or scheduling a report.
input message = getReportParametersRequest
output message = getReportParametersResponse
type="impl:ArrayOfParamNameValue"/>
Sample Code for getReportParameters
public static String[] getParameters(String xdofile) throws Exception {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(bipEndpoint));
System.out.println("BEGIN TESTING: getParameters Service");
// register the ReportRequest class
QName reportReq = new QName(bipNamespace, "ReportRequest");
call.registerTypeMapping(ReportRequest.class, reportReq,
BeanSerializerFactory.class, BeanDeserializerFactory.class);
// register the ParamNameValue class
QName nmvals = new QName(bipNamespace, "ParamNameValue");
call.registerTypeMapping(ParamNameValue.class, nmvals, BeanSerializerFactory.class, BeanDeserializerFactory.class);
// Define parameters
ParamNameValue[] paramNmVals = new ParamNameValue[1];
paramNmVals[0] = new ParamNameValue(false,“” ,null);
//ReportRequest req = new ReportRequest("pdf", "en-US", "Simple", paramNmVals, xdofile);
ReportRequest report = new ReportRequest();
report.setAttributeFormat("pdf");
report.setAttributeLocale("en-US");
report.setParameterNameValues(paramNmVals);
report.setReportAbsolutePath(xdofile);
report.setReportDataFileName("template.rtf");
report.setFlattenXML(false);
call.setOperationName(new QName(bipNamespace, "getReportParameters"));
call.addParameter( "ReportRequest", reportReq, ParameterMode.IN );
call.addParameter("userID", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnClass(ParamNameValue [].class);
// issue the request
ParamNameValue params [] = (ParamNameValue []) call.invoke(
new Object[] { report, "Administrator", "Administrator"});
String[] par = new String[params.length];
if (params != null) {
for (int i = 0; i <>
System.out.print("Parameter " + params[i].getName() + ":");
if (params[i].getValues() != null) {
for (int j = 0; j < style=""> {
System.out.print(" " + params[i].getValues()[j]);
par[i]=params[i].getValues()[j];
}
} else
System.out.print(" null");
System.out.println(" - multiple values? " + params[i].isMultiValuesAllowed());
}
}
System.out.println("END TESTING: getParameters");
return par;
}scheduleReport
Use scheduleReport to schedule a report for execution and delivery to either printer, fax, email, WebDAV, ftp or simply save in the report repository. Jobs can be scheduled to run immediately, once, or on a recurring pattern and can have an end date to stop the recurrence. This operation returns JobID upon successfully scheduling the report job.
inputmessage = scheduleReportRequest
outputmessage = scheduleReportResponse
public static void scheduleReport(String[] requestId,String xdofile) throws Exception {
// set up the call object
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(bipEndpoint));
// TEST Run Report
System.out.println("TESTING scheduleReport Service BEGIN");
// register the ReportRequest class
QName reportReq = new QName(bipNamespace, "ReportRequest");
call.registerTypeMapping(ReportRequest.class, reportReq,
BeanSerializerFactory.class, BeanDeserializerFactory.class);
// register the ParamNameValue class
QName nmvals = new QName(bipNamespace, "ParamNameValue");
call.registerTypeMapping(ParamNameValue.class, nmvals, BeanSerializerFactory.class, BeanDeserializerFactory.class);
// register the BIPReportResponse class (part of Schedule Request)
QName reportRespqn = new QName(bipNamespace, "ReportResponse");
call.registerTypeMapping(ReportResponse.class, reportRespqn, BeanSerializerFactory.class, BeanDeserializerFactory.class);
// register the Schedule Request class
QName scheduleReq = new QName(bipNamespace, "ScheduleRequest");
call.registerTypeMapping(ReportRequest.class, reportReq,
BeanSerializerFactory.class, BeanDeserializerFactory.class);
// Default return type based on what we expect
call.setOperationName( new QName(bipNamespace, "scheduleReport" ));
call.addParameter( "ScheduleRequest", scheduleReq, ParameterMode.IN );
call.addParameter("userID", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
// Define Report Request Object
ParamNameValue[] paramNmVals = new ParamNameValue[1];
paramNmVals[0] = new ParamNameValue(false, " ",requestId);
ReportRequest report = new ReportRequest();
report.setParameterNameValues(paramNmVals);
report.setReportAbsolutePath(xdofile);
//Define Local Delivery Options
LocalDeliveryOption local = new LocalDeliveryOption("C:");
DeliveryRequest delivery = new DeliveryRequest();
delivery.setLocalOption(local);
ScheduleRequest req = new ScheduleRequest();
req.setDeliveryRequest(delivery);
req.setScheduleBurstringOption(true);
req.setReportRequest(report);
req.setUserJobName("WEB SERVICE SCHEDULED JOB");
// issue the request
String result = (String) call.invoke(
new Object[] {req,userID,password} );
System.out.println("JOB ID is "+ result);
System.out.println("Success for Schedule Report");
}
3 comments:
Hi.. Thanks for your blog.
Can I get the full code? my email id is ziaul.14@gmail.com
would it be possible to get the full code? Thanks... my email is lifepeart@yahoo.com
titanium alloy nier | TitaniumArts
Titanium-Arts 메이피로출장마사지 - remmington titanium Classic T-Shirts; babyliss nano titanium T-Shirts; fallout 76 black titanium T-Shirts. These, Classic T-Shirts are sugarboo extra long digital titanium styler inspired by the finest T-Shirts in
Post a Comment