Fetching server name and port number for ADF application

Requirement – How to get server name and server port.
Solutions- You can get this information in by writing below code in java

FacesContext fctx = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) fctx.getExternalContext ().GetRequest ();
String serverName = request.getServerName();
int serverPort =request.getServerPort();

System.out.println ("Server Name:" + serverName);
System.out.println ("Server Port no:" + server port);

Happy coding with Vinay Kumar in Techartifact.

Useful Expression language (el)in Webcenter Spaces Application

Small webenter tip- If we want to check whther a user if member of any group or space.Or role of the user. and etc etc

following are el which i found today and usefull too.thats why i am sharing with you.

WebCenterSecurityContextSupport -this interface Provides EL support for WebCenter Security.

#{WCSecurityContext.userInScopedRole[‘Moderator’]} – Checks if current user is in group space role. Role membership is checked against the current Group Space Identifier.

#{WCSecurityContext.userInGroup[‘Administrators’]} – Checks if the current user is a member of the specified enterprise group.

#{WCSecurityContext.userInAppRole[‘SiteResourceAdmin’]} – Checks if current user is in application role.

#{WCSecurityContext.currentUser[‘weblogic’]} – Checks if current user name matches the one specified.

you can try this el as well for checking the current user have specified role in spaces application – #{WCSecurityContext.userInScopedRole[‘ReadOnly or custom role’]}”

Happy coding with Vinay Kumar in Techartifact . 🙂

Using Log4j in Oracle ADF application

As i talked about more of ADF logger in my previous Adf logger post.Now what if you want log4j in ADF application.

1) Add the log4j JAR file to the project library JAR file .

2) Then you need to create log4j.properties file in your application src directory.

Content of properties file-

#####################################################

# Set root logger level to INFO and its only appender to ConsoleOut.
log4j.rootLogger=INFO,ConsoleOut,F

# ConsoleOut is set to be a ConsoleAppender.
log4j.appender.ConsoleOut=org.apache.log4j.ConsoleAppender

# ConsoleOut uses PatternLayout.
log4j.appender.ConsoleOut.layout=org.apache.log4j.PatternLayout
log4j.appender.ConsoleOut.layout.ConversionPattern=%-5p: [%d] %c{1} – %m%n

#####################################################

now you can use log4j as below –

package com.techartifact.log4jSample;

import org.apache.log4j.Logger;
import org.apache.log4j.Category;
import org.apache.log4j.PropertyConfigurator;
import javax.servlet.*;
import javax.servlet.http.*;



public class Log4JSample
extends HttpServlet
{
Logger log = Logger.getLogger(this.getClass().getSimpleName());
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

public void init(ServletConfig config)
 throws ServletException
{
 super.init(config);
 log.info("inside init() method of Log4JSample");
}

public void doGet(HttpServletRequest request,
                 HttpServletResponse response)
 throws ServletException, IOException
{
 log.info("inside doGet method of Log4JSample");
}
}

Happing logging in Techartifact with Vinay Kumar. 🙂