Sunday, September 17, 2017

Lambda Expressions in Java 8

What is Lambda Expression?
Lambda Expression is a feature to implement functional logic without method name, class name in a object oriented programming. It simplifies the way functional logic implemented in object oriented programming.

Where Lambda Expressions can be used?
In Object Oriented Programming, A complex method would be broken into multiple methods by grouping logic statements to reduce complexity for better reading and maintenance. But those new methods would not be reused for any other purposes. Here, Lambda expression can be used to implement the functional logic in elegant way rather than creating multiple methods or anonymous classes.

Syntax:

= (parameters as comma separated) -> {     };

.(parameters>);

Here, (parameters as comma separated) are not mandatory, it can be empty parenthesis if no parameter required.  

Simple Example:

public class LambdaCalculate {    
   
   public static void main(String[] args){
       
       int var1 = 6;
       int var2 = 5;
       
       Calculate addition = (int a, int b) -> { return a+b; };
       
       int result1 = addition.calculate(var1, var2);
       System.out.println("lambda.LambdaCalculate.main() :: " + result1);
       
       Calculate subtraction = (int a, int b) -> { return a-b; };
       
       int result2 = subtraction.calculate(var1, var2);
       System.out.println("lambda.LambdaCalculate.main() :: " + result2);
       
   }
}
   
public interface Calculate{        
       public int calculate(int a, int b);    

}

Thursday, May 25, 2017

MongoDB Introduction and Basics


Big Data
Big Data is a concept to define data as a key value pair structure which provides high scalability and performance for persistence, retrieval, and maintenance. As name stands, it handles large volume data and complex structure easily.
Mongo Database
MongoDB is open source big data type database. Record in MongoDB is a document defined using key value pair. MongoDB is NoSQL database, User need to use MongoDB Shell and MongoDB syntax to create database, insert document, and query the data.
MongoDB document would be
{
 "fieldName1": "value1",
 "fieldName2": "value2",
 "fieldName3": "value3"
}
There are some rules for field names:
  • “id” is reserved for Primary Key field.
  • Field name has to be unique in a document.
  • Field name should not start with null, $.
  • Field name should be alphanumeric.    
Basics
MongoDB comprises databases > collections > records as listed order in BSON format. Collection will have 1 or more number of records, Database will have 1 or more Collections, and there can be 1 or more databases.  
Structure would be:         

Commands:
To create new database Use  

To insert new record in a collection: db..insert(<{structure}>})
To insert one record in a collection: db..insertOne(<{structure}>})
To insert many record in a collection: db..insertMany(,
     

To find record in a collection: db..find()
To find one record in a collection: db..findOne()

When we insert a record into collection, MongoDB will create database and collection if it doesn’t exist.   

User has to connect to MongoDB Shell, and insert record.

Tuesday, January 31, 2017

Useful commands



To identify the locked table name and session id:


SELECT B.Owner, B.Object_Name, A.Oracle_Username, A.OS_User_Name, A.SESSION_ID
FROM V$Locked_Object A, All_Objects B
WHERE A.Object_ID = B.Object_ID;



To Identify user domain information from windows: 

net user 183378 /domain

Friday, January 8, 2016

Accessing Secured SOAP WEBSERVICE in Java


When Endpoint Service is protected that SOAP request XML Header should have SSL Certificate agreed (between client and provider) and User Name/Password, then below approach can help to achieve in accessing highly secured service.

How to add Security tag and Digital Signature to SOAP request header:

JAX-WS (JAVA API for XML Webservice) provides the API to handle the SOAP request XML and add security tag with digital signature to SOAP request XML before sending it over in http to endpoint.

javax.xml.ws.Binding class has API to set custom Handler, and Binding object can be fetched from javax.xml.ws.BindinigProvider class object.


 BindingProvider bindingProvider = (BindingProvider)servicePort;
 List handlerChain = bindingProvider.getBinding().getHandlerChain();  
 handlerChain.add(new SOAPSecurityHandler();  
 bindingProvider.getBinding().setHandlerChain(handlerChain);  

SOAPSecurity handler class will be extending SOAPHandler interface and implementing the functionality for method handleMessage() method to intercept the SOAP message before sending it to Webservice provider.  

Example:

public class SOAPSecurityHandler implements javax.xml.ws.handler.soap.SOAPHandler {

public Set getHeaders() {
return Collections.emptySet();
}

public boolean handleMessage(SOAPMessageContext context) {
try {

if (Boolean.TRUE.equals(context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) {
// Add User Name Token to Security Context
addSecurityHeader(context);

// Add Digital Signature from Keystore.
addSignatureToMessageHeader(context);
}
} catch (Exception e) {
LOGGER.error("Error in SOAPSecurity Handler Handle Message", e);
}
return true;
}

public boolean handleFault(SOAPMessageContext context) {
return false;
}

public void close(MessageContext context) {
}



private void addSecurityHeader(SOAPMessageContext messageContext) throws SOAPException {
SOAPFactory sf = SOAPFactory.newInstance();
SOAPHeader header = messageContext.getMessage().getSOAPPart().getEnvelope().getHeader();
if (header == null) {
header = messageContext.getMessage().getSOAPPart().getEnvelope().addHeader();
}
Name securityName = sf.createName(WSSE_SECURITY_LNAME, WSSE_NS_PREFIX, WSSE_NS);
SOAPHeaderElement securityElem = header.addHeaderElement(securityName);
securityElem.setMustUnderstand(mustUnderstand);
Name usernameTokenName = sf.createName("UsernameToken", WSSE_NS_PREFIX, WSSE_NS);
SOAPElement usernameTokenMsgElem = sf.createElement(usernameTokenName);
Name usernameName = sf.createName("Username", WSSE_NS_PREFIX, WSSE_NS);
SOAPElement usernameMsgElem = sf.createElement(usernameName);
usernameMsgElem.addTextNode(username);
usernameTokenMsgElem.addChildElement(usernameMsgElem);
Name passwordName = sf.createName("Type", WSSE_NS_PREFIX, WSSE_NS);
SOAPElement passwordMsgElem = sf.createElement("Password", WSSE_NS_PREFIX, WSSE_NS);
passwordMsgElem.addAttribute(passwordName, PASSWORD_TEXT_TYPE);
passwordMsgElem.addTextNode(password);
usernameTokenMsgElem.addChildElement(passwordMsgElem);
securityElem.addChildElement(usernameTokenMsgElem);
}

/**
* Method to add Digital Signature to SOAPP Header

* @param messageContext
* @throws SOAPException
* @throws NoSuchAlgorithmException
* @throws InvalidAlgorithmParameterException
* @throws KeyStoreException
* @throws IOException
* @throws CertificateException
* @throws UnrecoverableEntryException
* @throws MarshalException
* @throws XMLSignatureException
*/
private void addSignatureToMessageHeader(SOAPMessageContext messageContext)
throws SOAPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, KeyStoreException,
IOException, CertificateException, UnrecoverableEntryException, MarshalException, XMLSignatureException {
/// Add Signature
Source source = new DOMSource(messageContext.getMessage().getSOAPHeader());
Node root = null;
root = ((DOMSource) source).getNode();
XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
Reference ref = fac.newReference("", fac.newDigestMethod(DigestMethod.SHA256, null),
Collections.singletonList(fac.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null)), null,
null);
SignedInfo signedInfo = fac.newSignedInfo(
fac.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null),
fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null), Collections.singletonList(ref));
// Load the KeyStore and get the signing key and certificate.
KeyStore ks = KeyStore.getInstance(KEYSTORE_INSTANCE);
ks.load(new FileInputStream(KEYSTORE_FILE), KEYSTORE_PWD.toCharArray());
KeyStore.PrivateKeyEntry keyEntry = (KeyStore.PrivateKeyEntry) ks.getEntry(KEYSTORE_ALIAS,
new KeyStore.PasswordProtection(KEYSTORE_PWD.toCharArray()));
X509Certificate cert = (X509Certificate) keyEntry.getCertificate();
// Create the KeyInfo containing the X509Data.
KeyInfoFactory kif2 = fac.getKeyInfoFactory();
List x509Content = new ArrayList();
x509Content.add(cert.getSubjectX500Principal().getName());
x509Content.add(cert);
X509Data xd = kif2.newX509Data(x509Content);
KeyInfo keyInfo = kif2.newKeyInfo(Collections.singletonList(xd));
Element header = DOMUtils.getFirstChildElement(root);
DOMSignContext dsc = new DOMSignContext(keyEntry.getPrivateKey(), (Node) header);
XMLSignature signature = fac.newXMLSignature(signedInfo, keyInfo);
signature.sign(dsc);
}
}

Monday, January 13, 2014

How to check WEBCENTER Framework Version from Installation



In many cases, we would need to know the version of WEBCENTER Framework from Installation. 

In that case, we need to use opatch command tool to list the exact version number. 

Below is the step: 

  • Navigate through the Oracle Middleware Path
  • Then navigate through the Oracle_WC1 installation directory /Oracle_WC1
  • then, navigate through the OPatch folder inside Oracle_WC1.
  • Then, execute below command to know the status
./opatch lsinventory -invPtrLoc /oraInst.loc -details


Then it will list down all installation with exact version number including patch.



Wednesday, August 28, 2013

SOLARIS Command Tools for System Configuration Data


SOLARIS Command Tools for System Configuration Data




System Resource
Command Name
Path
Description
Number of CPU
uname -X

Will describe Number of CPUs allocated in zone level
CPU Pool Name
pooladm
/usr/sbin/
CPU Pool Name and CPU System ID will be listed
RAM Size
prtconf
/usr/sbin
RAM Size will be printed in output

Tuesday, August 6, 2013

JDEVELOPER 11.1.1.7/11.1.1.6 with WEBLOGIC 10.3.6 Server





By default, Oracle JDEVELOPER 11.1.1.7 installation comes with WEBLOGIC 10.3.5. But AROR Portal needs to be configured in WEBLOGIC 10.3.6.
Below flow diagram explains the steps to configure JDEVELOPER 11.1.1.7 with Oracle 10.3.6 domain server.