on 03-09-2009 2:04 PM
Hi Frndz..
My requirment is to give a logging report for portal using users, So for this i used a plain java class file with WD API like
package com.sap;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.sap.security.api.IUser;
import com.sap.tc.webdynpro.services.sal.adapter.api.WDProtocolAdapter;
import com.sap.tc.webdynpro.services.sal.um.api.IWDClientUser;
import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser;
public class Log_ESPB {
public void getLogInfo(){
try{
IWDClientUser wdJUser = WDClientUser.getCurrentUser();
IUser Juser_get = wdJUser.getSAPUser();
String JUser = Juser_get.getUniqueName();
String JipAddress = WDProtocolAdapter.getProtocolAdapter().getRequestObject().getClientHostAddress();
Date dt = new Date(System.currentTimeMillis());
SimpleDateFormat Dateformatter = new SimpleDateFormat("dd-MM-yyyy");
SimpleDateFormat Timeformatter = new SimpleDateFormat("HH:mm:ss");
String formattedDate = Dateformatter.format(dt);
String formattedTime = Timeformatter.format(dt);
String filepath="/usr/sap/ED3/DVEBMGS00/j2ee/cliuster/server0/";
String filename = "JRLog.txt";
String ExFile = filepath+filename;
File EFile = new File("/usr/sap/ED3/DVEBMGS00/j2ee/cluster/server0/JRLog.txt");
String Data = JUser + " || " +JipAddress " || "formattedDate" || "formattedTime;
if(EFile.exists()){
FileWriter fstream = new FileWriter(EFile,true);
BufferedWriter fbw = new BufferedWriter(fstream);
fbw.write(Data);
fbw.newLine();
fbw.close();
}
else{ }
}
}catch(Exception X){
System.out.println("login exception "+X);
}
}
}
This is working very fiine as an WDJ app , but as per my requirment i need to place this class to portal Logon page but there the code related to WD is not working ..
IWDClientUser wdJUser = WDClientUser.getCurrentUser();
IUser Juser_get = wdJUser.getSAPUser();
String JUser = Juser_get.getUniqueName();
String JipAddress = WDProtocolAdapter.getProtocolAdapter().getRequestObject().getClientHostAddress();
n am trying to get UserID with UME API like
String str= "XXX" IUser usr = UMFactory.getUserFactory().getUser(str);
can any one suggest me how we can with UME API
Regards
Rajesh
Hi
To get current logged in user u can use
String logonID = "";
try
{
IWDClientUser wdUser = null;
try
{
wdUser = WDClientUser.getCurrentUser();
}
catch (WDUMException e1)
{
e1.printStackTrace();
}
IUser user = wdUser.getSAPUser();
logonID = user.getUniqueID();
wdComponentAPI.getMessageManager().reportSuccess(logonID);
}
catch (Exception e)
{
wdComponentAPI.getMessageManager().reportException("Error: " + e.getMessage());
e.printStackTrace();
}
and as u already maintained code for lient host address and name
WDProtocolAdapter.getProtocolAdapter().getRequestObject().getClientHostAddress();
WDProtocolAdapter.getProtocolAdapter().getRequestObject().getClientHostName();
Best Regards
Satish Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Satish,
My requirment is not to get the User ID n client IP address usiing WDJ, beacaz i need to place this code into Par files , par files does;t allow WDJ API .
So i need to get User ID n client IP address using UME API in PAR files.
User ID am gettiing using UME API
public void GetWelcomeID(IPortalComponentRequest request, String welcomeClause)
{
IUserContext userContext = request.getUser();
String usr =userContext.getLogonUid();
}
But am unable to get the Client IP
Thanks in Advance
Regards
Rajesh
Ok
For u can access CLIENT IP from simple java code also
InetAddress thisIp;
try
{
thisIp = InetAddress.getLocalHost();
System.out.println("IP:+" + thisIp.getHostAddress());
System.out.println("Name:+" + thisIp.getHostName());
System.out.println("Name / Ip:+" + thisIp.getLocalHost());
}
catch (UnknownHostException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Best Regards
'Satish Kumar
Hi Rajeshkelam,
Are you running the above code in the portal logon page? Is it on the same page where the users enter the login information or is it on a page after the logon process?
The code you have mentioned is correct and will fetch you the user name and the ipaddress. This code will work properly in the portal. But if you are using this in the portal logon page then the login information is not available to your application unless the user logs in. So when the code executes the user has not logged in to the portal.
You can try moving the code to a page after the login page.
Regards,
Sanyev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.