Saturday, May 19, 2012

Cascade type - EJB 3.0


Cascade type - EJB 3.0:

The cascade type specifies the set of operations that can be cascaded to a related entity. CascadeType can have different values: PERSIST, MERGE, REMOVE, REFRESH, and ALL.
PERSIST is similar to an insert command. Specifying a CascadeType of PERSIST implies that a persist operation will be cascaded from a parent entity to its child entity.

MERGE is similar to an update command. Specifying a CascadeType of MERGE implies that a merge operation will be cascaded from a parent entity to its child entity.

REMOVE is similar to a delete command. Specifying a CascadeType of REMOVE implies that a remove operation will be cascaded from a parent entity to its child entity.

REFRESH reloads the related entity from the database when the referring entity is refreshed.

If you do not specify a cascade type, no operations are cascaded.

Fetch Type - Lazy vs. Eager Loading in EJB 3.0

Fetch Type - Lazy vs. Eager Loading in EJB 3.0:

The fetch type is used to specify the data-fetching strategy that a persistence provider uses to fetch data from the database. FetchType is used on the @Basicannotation, @LOB annotation, and relationship annotations such as OneToMany, ManyToMany, ManyToOne, and OneToOne. The default for fetchTypeis EAGER, except for a ManyToMany and a OneToMany relationship, for which the default is LAZY. A fetchType of EAGER means that a persistence provider will load the attribute of an entity along with the entity, whereas a fetchType of LAZY is a hint to the provider that the attribute need not be fetched along with the entity, or we can say that In eager loading we will fetch all the values from the Persistent storage and cache it. It will make serious performance issues. There we use lazy loading to avoid that.

Keep in mind that a FetchType of EAGER is a requirement on the persistence provider, whereas a fetchType of LAZY is only a hint. So even though you may specify the fetchType to be LAZY, the persistence provider may choose to load the attribute eagerly.
A FetchType of lazy benefits Large Objects and Relationships in which the attributes are not accessed immediately when the entity is loaded.The attributes are loaded whenever required.

Example:

@Entity
public class Order {
@OneToMany(fetchType=FetchType.EAGER, ...)
public Collection<OrderLineItem> getLineItems(){
return lineItems;
}
}

@Entity
public class Order {
@OneToMany(fetchType=FetchType.LAZY, ...)
public Collection<OrderLineItem> getLineItems(){
return lineItems;
}
}

Advantages of EJB 3.0

Advantages of EJB 3.0:

The below are the some of the advantages of using EJB 3.0


  1. More work is done by container,less by developer
  2. Everything is a POJO(Plain old java object)
  3. Simplify programming model
  4. Hibernate like ORM(Object Relational Mapping)
  5. Dependency injection
  6. Annotations(Requires Java 5)
  7. Bean specifies what it needs through metadata
  8. No longer written to unneeded container interfaces
  9. Deployment descriptor no longer required

FTP Upload/Download with Java

The below java code will help us to Download/Upload files from/To FTP server.

import java.io.*;
import java.net.*;

public class FTPClient {
    public final String host;
    public final String user;
    protected final String password;
    protected URLConnection ftpurl;

    public FTPClient(String host, String user, String password) {
        this.host = host;
        this.user = user;
        this.password = password;
        this.ftpurl = null;
    }

    private URL createURL(String destfile) throws MalformedURLException {
        if (user == null)
            return new URL("ftp://" + host + "/" + destfile + ";type=i");
        else
            return new URL("ftp://" + user + ":" + password + "@" + host +"/" + destfile + ";type=i");
    }

    protected InputStream openDownloadStream(String destfile) throws Exception {
        URL url = createURL(destfile);
        ftpurl = url.openConnection();
        InputStream is = ftpurl.getInputStream();
        return is;
    }

    protected OutputStream openUploadStream(String targetfile) throws Exception {
        URL url = createURL(targetfile);
        ftpurl = url.openConnection();
        OutputStream os = ftpurl.getOutputStream();
        return os;
    }

    protected void close() {
        ftpurl = null;
    }

    public void Upload(String sourcefile, String destfile) {
        try {
            OutputStream os = openUploadStream(destfile);
            FileInputStream is = new FileInputStream(sourcefile);
            byte[] buf = new byte[33554432];
            int c;
            while (true) {
                c = is.read(buf);
                if (c <= 0)
                    break;
                os.write(buf, 0, c);
            }
            os.close();
            is.close();
            close();
        } catch (Exception e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    }

    public void Download(String sourcefile, String destfile) {
        try {
            InputStream is = openDownloadStream(destfile);
            FileOutputStream os = new FileOutputStream(sourcefile);
            byte[] buf = new byte[41943040];//Buffer size set to 40 MB ,change based on the file size
            int c;
            while (true) {
                c = is.read(buf);
                if (c <= 0)
                    break;
                os.write(buf, 0, c);
            }
            is.close();
            os.close();
            close();
        } catch (Exception e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    }
}

Thursday, May 17, 2012

Setting the Composite Instance Name (Title) in Oracle Mediator - Oracle SOA Suite

Setting the Composite Instance Name (Title) in Oracle Mediator - Oracle SOA Suite:

 The composite instance name (Title) will help us to track the composite instances at runtime, the below two approaches can be used to set the instance Name (Title) for the composite with the Mediator instances.

Oracle SOA Suite 11g:

Assign Activity:

1.       Click on the Assign Values in the Routing Rule section and create new Assign value


 
2.       Select the Type as expression in the From (Left) side and insert the Mediator Extension Function setCompositeInstanceTitle and pass the input based on which variable the title should be set.
 
 

Recovering the Oracle BPEL instances from the Recovery Queue – Oracle SOA Suite

 Recovering the Oracle BPEL instances from the Recovery Queue – Oracle SOA:

Sometimes the BPEL instances may go to the recovery queue, the instances in the recovery queue can be recovered manually to continue the processing.
Below are the some of the reasons the instances to go to manual recovery.
  1. There are not enough threads or memory to process the message.
  2. The server shuts down or crash before it finishes processing the BPEL message
  3. The engine could not finish processing the message before reaching the time-out as dictated by the transaction-timeout configuration

Recovering the BPEL instances:

Oracle SOA Suite 11g:

  1. Login  to EM console
  2. Right click on soa-infra  ,Click on Service Engine - BPEL
  3. Click on Recovery tab
  4. Change the Type accordingly(Invoke,Activity,Callback) and the Message state to “Undelivered”  and click on search
  5. All the recoverable messages that match the criteria will be displayed.
  6. Select the required messages and click on Recovery button.
 

Oracle SOA Suite 12c:

  1. Login  to EM console
  2. Click on Target Navigation
  3. Click on soa-infra
  4. Click on SOA Infrastructure - Service Engines - BPEL
  5. Click on Recovery tab
  6. Change the Type accordingly(Invoke,Activity,Callback) and the Message state to “Undelivered”  and click on search
  7. All the recoverable messages that match the criteria will be displayed.
  8. Select the required messages and click on Recovery button.
em_console_target_navigation


em_console_service_engines


em_console_recovery_messages


Tuesday, May 8, 2012

Proxy Configuration in Oracle SOA Suite 11g


Proxy Configuration in Oracle SOA Suite 11g:

If we are invoking any web services and it needs to be passed through Proxy then the proxy server details should be configured on soa11g server. In SOA11g we have two ways of configuring the proxy. The first way is to configure the Server Level and the second level is Composite level.
Configuration can be done using Enterprise manager/JDeveloper

Server Level from EM console:

 Login to the em console
Navigate to SOA Infrastructure->SOA Administration->Common Properties -> More SOA Infra Advanced Configuration Properties...
Enter the HttpProxyHost, HttpProxyPort, HttpProxyUsername and HttpProxyPassword
Click on Apply and then restart Server


 

Composite service Level from EM console:

If we want to configure the configure proxy only to a particular composite the can be configured in composite Level.
Navigate to the Process in EM and in the dashboard click on the Service (Adapter used to invoke the web service to which the proxy is required) under the Services and References section.
Click on the properties tab and you can find the different properties as shown below where you can fill the Proxyhost, ProxyPort.

Monday, May 7, 2012

Java code to Decrypt the weblogic server passwords

The below Java code will help us to decrypt the weblogic server password

import weblogic.security.internal.SerializedSystemIni;
    import weblogic.security.internal.encryption.ClearOrEncryptedService;
    import weblogic.security.internal.encryption.EncryptionService;
   
    public class Decrypt {
        public static void main(String[] args) {
            String string = args[0];
            EncryptionService encryptionService = SerializedSystemIni.getEncryptionService();
            ClearOrEncryptedService clearOrEncryptedService = new ClearOrEncryptedService(encryptionService);
            System.out.println("Clear text password: " + clearOrEncryptedService.decrypt(string));
        }
    }

weblogic.transaction.internal.TimedOutException:Transaction timed out after 301 seconds – Oracle SOA Suite


weblogic.transaction.internal.TimedOutException:Transaction timed out after 301 seconds – Oracle SOA Suite:

Frequently the Oracle  BPEL instances are getting rolled back with the following exception.
 The root cause of the issue is, JTA transaction getting timeout before completing the execution of the BPEL instance; the JTA transaction should be active to complete the execution successfully.

[2012-04-26T05:15:45.139+00:00] [SOA1] [ERROR] [] [oracle.soa.bpel.engine] [tid: orabpel.invoke.pool-4.thread-23] [userId: <anonymous>] [ecid: 0000JRh3heOAxGoqwSuXMG1F_qb^000aP5,0:1:100080683] [APP: soa-infra] [composite_name: AM_Invoker] [component_name: AM_Invoker] [component_instance_id: 5977508] The reason was The execution of this instance "5977508" for process "AM_Invoker" is supposed to be in an active jta transaction, the current transaction status is "MARKED_ROLLBACK" . Root cause: null

 [APP: soa-infra] Error while invoking bean "cube delivery": JTA transaction is not in active state.[[
The transaction became inactive when executing activity "5977508-BpInv1-BpSeq9.78-2" for instance "5,977,508", bpel engine cannot proceed further without an active transaction. please debug the invoked subsystem on why the transaction is not in active status. the transaction status is "MARKED_ROLLBACK".

Message handle error.error while attempting to process the message "com.collaxa.cube.engine.dispatch.message.invoke.InvokeInstanceMessage"; the reported exception is: Transaction Rolledback.: weblogic.transaction.internal.TimedOutException: Transaction timed out after 301 seconds
BEA1-2980B7B48F411EE46991

Solution:

Increase the JTA time out and the BPEL EJB transaction timeout.

Change the JTA transaction timeout:

  1. Log in to Oracle WebLogic Server Administration Console.
  2. In the Domain Structure, select Services > JTA
  3. Increase the JTA transaction timeout value to some higher value like 3600

Change the BPEL EJB transaction timeout settings:

  1. Log in to Oracle WebLogic Server Administration Console.
  2. In the Domain Structure, click Deployments.
  3. Expand soa-infra > EJBs.
  4. Update the following EJBs transaction Timeout value to some higher value like 1200:
 BPELActivityManagerBean
 BPELEngineBean
 BPELInstanceManagerBean
 BPELProcessManagerBean
 BPELServerManagerBean
  1. Click Save.
  2. Restart Oracle WebLogic Server.
There is no standard value for transaction timeout property. We need to trail out and set the value.
If the component still fails with the transaction timeout error then revisit the component design and tune the same.

Sunday, May 6, 2012

Java code to Marshal/Unmarshal XML using JAXB

Java code to Marshal/Unmarshal XML using JAXB:

Unmarshalling:

JAXBContext jc =JAXBContext.newInstance("com.java.test");//add multiple packages seperated by ":" eg.com.java.test1:com.java.test2
Unmarshaller u = jc.createUnmarshaller();
JAXBElement obj =(JAXBElement)u.unmarshal(new File(inputXMLPath)); // ok

Marshalling

Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,Boolean.TRUE);
String outXML = "Response.xml";
marshaller.marshal(obj,new FileOutputStream(outXML));

Thursday, May 3, 2012

java.lang.ArrayIndexOutOfBoundsException in DB Adapter – Oracle SOA Suite 11g


java.lang.ArrayIndexOutOfBoundsException in DB Adapter – Oracle SOA Suite 11g:

The DB Adapter insert were intermittently failing with the following exception in our Oracle SOA Suite environments. 

Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'update' failed due to: DBWriteInteractionSpec Execute Failed Exception. update failed. Descriptor name: [Update_Interfacebuffer.InterfaceBuffer].
Caused by java.lang.ArrayIndexOutOfBoundsException. Please see the logs for the full DBAdapter logging output prior to this exception. This exception is considered not retriable, likely due to a modelling mistake.

It is caused by using a non-synchronized class instead of a synchronized class. Read the Metalink Note 1332114.1 for more details about this.

Oracle suggested us to apply the below patch to resolve the issue.

Patch 11866793: DBADAPTER INSERT OPERATION IS FAILING INTERMITTENTLY WITH NPE

The issue is observed in the following versions 11.1.1.3.0, 11.1.1.4.0 and 11.1.1.5.0 and Fixed in the version 11.1.1.6.0.

The issue got resolved after applying the patch.