Sunday, May 31, 2015

Understanding trace.syms 2>&1

Understanding trace.syms 2>&1

cmd 2>&1 > log
This redirects stderr to wherever stdout is currently being redirected, which is typically the console. Then stdout is redirected to log. Remember that stderr does not "follow" stdout, so it continues to redirect to the console.

End result: stdout is redirected to the log file and stderr is (still) sent to the console. This is almost certainly not what you want.

Here’s an example command:

wibble > /dev/null 2>&1
Output redirection
The greater-thans (>) in commands like these redirect the program’s output somewhere. In this case, something is being redirected into /dev/null, and something is being redirected into &1.

Standard in, out, and error
There are three standard sources of input and output for a program. Standard input usually comes from the keyboard if it’s an interactive program, or from another program if it’s processing the other program’s output. The program usually prints to standard output, and sometimes prints to standard error. These three file descriptors (you can think of them as “data pipes”) are often called STDIN, STDOUT, and STDERR.

Sometimes they’re not named, they’re numbered! The built-in numberings for them are 0, 1, and 2, in that order. By default, if you don’t name or number one explicitly, you’re talking about STDOUT.

Given that context, you can see the command above is redirecting standard output into /dev/null, which is a place you can dump anything you don’t want (often called the bit-bucket), then redirecting standard error into standard output (you have to put an & in front of the destination when you do this).


The short explanation, therefore, is “all output from this command should be shoved into a black hole.” That’s one good way to make a program be really quiet!

Friday, May 29, 2015

503 issue in ibm WCS

Problem

Creating, formatting, and reading packet traces is sometimes required to resolve problems with IBM WebSphere  Edge Server. However, the most appropriate tool varies, depending on operating system.
Resolving the problem

Available for multiple operating systems
Wireshark is useful and a freely available tool that can read files and capture packets on almost any operating system.
Solution :

1.     Run iptrace on AIX interface en1 to capture port 80 traffic from a single client IP to a server IP:

iptrace -a -i en1 -s clientip -b -d serverip -p 80 trace.out

This trace will capture both directions of the port 80 traffic on interface en1 between the clientip and serverip and send this to the raw file of trace.out.
2.     Reproduce the problem, then run the following:

ps -ef|grep iptrace
kill -15 <pid>

Trace tools like Wireshark can read trace.out files created by iptrace 

Using Wireshark







Thursday, May 7, 2015

Some useful methods in IBM WCS


/***** Getting DB connection and run direct SQL ******/

public class CommonJDBCHelperBean extends BaseJDBCHelper implements SessionBean {
private String fetchPhysicalStoresSQL = "select stloc_id, identifier, address1, address3, country from stloc where latitude = ? order by address1"
                  + READONLY_WITH_UR_CLAUSE;

                /**
                 * It fetches list of all active stores address details from STLOC table.
                 *
                 * @return Vector - list of StoreLocationObjectBean
                 * @throws NamingException
                 *             If failed to get SQL connection
                 * @throws SQLException
                 *             if failed to execute SQL query
                 */
                public Vector fetchPhysicalStores(String storeId) throws NamingException, SQLException {
                                final String methodName = "fetchPhysicalStores";
                                if (logger.isLoggable(TraceIdentifiers.METHOD_ENTRY_EXIT)) {
                                                logger.entering(CLASS_NAME, methodName);
                                }
                                Vector vPhysicalStore = new Vector();
                                PreparedStatement stmt = null;
                                ResultSet rs = null;
                                try {
                                                makeConnection();
                                                if (logger.isLoggable(TraceIdentifiers.DEBUG_OUTPUT)) {
                                                                logger.logp(TraceIdentifiers.DEBUG_OUTPUT, CLASS_NAME, methodName, "sql is[{0}]",
                                                                                                fetchPhysicalStoresSQL.toString());
                                                }
                                                stmt = getPreparedStatement(fetchPhysicalStoresSQL);
                                                stmt.setBigDecimal(1, new BigDecimal(storeId));
                                                rs = executeQuery(stmt, false);
                                                while (rs.next()) {
                                                                StoreLocationObjectBean storeLocationObjectBean = new StoreLocationObjectBean();
                                                                storeLocationObjectBean.setStloc_id(rs.getString(1));
                                                                storeLocationObjectBean.setIdentifier(rs.getString(2));
                                                                storeLocationObjectBean.setAddress1(rs.getString(3));
                                                                storeLocationObjectBean.setAddress3(rs.getString(4));
                                                                storeLocationObjectBean.setCountry(rs.getString(5));
                                                                vPhysicalStore.add(storeLocationObjectBean);
                                                }
                                } finally {
                                                closeConnection();
                                                if (null != rs) {
                                                                rs.close();
                                                }

                                                if (null != stmt) {
                                                                stmt.close();
                                                }
                                }
                                if (logger.isLoggable(TraceIdentifiers.METHOD_ENTRY_EXIT)) {
                                                logger.entering(CLASS_NAME, methodName);
                                }
                                return vPhysicalStore;

                }

/********* To send XML in QUEUE ***************/

To send OR02XML

Insert in msgtype:
insert into msgtypes values(10002,1,'OR02MIGRATION','OR02MIGRATION','Abster Send OR02 XML Message for completed Orders',null);


SendMsgCmd sendXMLCmd = (SendMsgCmd) CommandFactory
                                                                        .createCommand(SendMsgCmd.NAME, oaBean.getStoreEntityIdInEJBType());
                                                sendXMLCmd.setMsgType("OR02MIGRATION");
                                                sendXMLCmd.setStoreID(oaBean.getStoreEntityIdInEJBType());
// get clone of request to put additional values
                                                TypedProperty properties = (TypedProperty) getRequestProperties()
                                                                        .clone();
properties.put("ordersId", ordersId);
properties.put("OrderRefNumber", ordersId);
properties.put("LanguageId", -1);
sendXMLCmd.compose(OR02_VIEW,getCommandContext(), properties);
sendXMLCmd.sendTransacted();
sendXMLCmd.setCommandContext(getCommandContext());

sendXMLCmd.execute();



*****************Session *******************
<c:choose>
<c:when test="${userType == 'G' || fn:contains(userEmail,'@X.XX')|| user_id == '-1002'}">
<%
session.setAttribute("eMarketsubscriberBeanRequired","N");
session.setAttribute("subscriberBean",new com.xxxx.commerce.subscribers.commands.EmailServiceDataBean());
%>

</c:when>

<c:otherwise>

<wcbase:useBean id="bnRegister" classname="com.ibm.commerce.user.beans.UserRegistrationDataBean" >
<c:set value="${CommandContext.user.userRegistry.userId}" target="${bnRegister}" property="userId"/>
</wcbase:useBean>
<c:set var="service_Id"><fmt:message key="SUBSCRIPTION_DEFAULT_SERVICE_ID" bundle="${storeFrontText}"/></c:set>
<c:set var="qubituserEmail" value="${bnRegister.email1}" />
<c:if test="${!fn:contains(qubituserEmail,'@X.XX')|| user_id == '-1002'}">
<%
Object isAlreadyAvailable= session.getAttribute("eMarketsubscriberBeanRequired");                                            
              if(null != isAlreadyAvailable && isAlreadyAvailable.toString().equals("N")) {                                          

%>
<wcbase:useBean id="bean" classname="com.xxxxx.commerce.subscribers.commands.EmailServiceDataBean">
<c:set value="${service_Id}" target="${bean}" property="inputVal" />
<c:set value="${qubituserEmail}" target="${bean}" property="userEmail"/>
<c:set value="${userType}" target="${bean}" property="userType"/>
</wcbase:useBean>
<%
session.setAttribute("eMarketsubscriberBeanRequired","Y");
session.setAttribute("subscriberBean",bean);
}
%>    
</c:if>

</c:otherwise>
</c:choose>


Using it

<%@include file="QubitMarketing.jspf"%>
<%
com.xxxxxx.commerce.subscribers.commands.EmailServiceDataBean subscriberBean=(com.xxxxx.commerce.subscribers.commands.EmailServiceDataBean)session.getAttribute("subscriberBean"); 
if(subscriberBean!= null && subscriberBean.getSubscriberId() > 0 && subscriberBean.getSubscriptionId()>0 && subscriberBean.getSubscriptionStatus()>0){%>,
"subscriber_id": "<c:out value="${subscriberBean.subscriberId}" />",
"subscription_id": "<c:out value="${subscriberBean.subscriptionId}" />"<%} %>

Creating data bean
public class EmailServiceDataBean implements SmartDataBean {
private static final String CLASS_NAME = EmailServiceDataBean.class
.getName();
private static final Logger logger = Logger.getLogger(CLASS_NAME);
private Long subscriberId;
private String emailAddress;
private Integer brandId;
private String userEmail;
protected Integer Key_emailServiceId;
private String userType;
private Long subscriptionId;
private Short subscriptionStatus;
public CommandContext iCommandContext = null;
public TypedProperty requestProperties = null;

public String getUserType() {
return userType;
}

public void setUserType(String userType) {
this.userType = userType;
}

protected String inputVal;

public String getInputVal() {
return inputVal;
}

public void setInputVal(String inputVal) {
this.inputVal = inputVal;
}

public Integer getKey_emailServiceId() {
return Key_emailServiceId;
}

public void setKey_emailServiceId(Integer key_emailServiceId) {
Key_emailServiceId = getKey_emailServiceId();
}

public String getUserEmail() {
return userEmail;
}

public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}

public Long getSubscriberId() {
return subscriberId;
}

public void setSubscriberId(Long subscriberId) {
this.subscriberId = subscriberId;
}

public String getEmailAddress() {
return emailAddress;
}

public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}

public Integer getBrandId() {
return brandId;
}

public void setBrandId(Integer brandId) {
this.brandId = brandId;
}

@Override
public void populate() throws Exception {
final String METHOD_NAME = "populate";
if (logger.isLoggable(TraceIdentifiers.METHOD_ENTRY_EXIT)) {
logger.entering(CLASS_NAME, METHOD_NAME);
}
// EmailServiceAccessBean is initilize to get brand_id from
// EMAIL_SERVICE table
EmailServiceAccessBean emailServiceAccessBean = new EmailServiceAccessBean();
emailServiceAccessBean.setInitKey_emailServiceId(Integer
.valueOf(getInputVal()));
emailServiceAccessBean.refreshCopyHelper();
brandId = emailServiceAccessBean.getBrandId();
// Guest user check. If user is of type guest then emailId will not
// available
System.out.println("brandId"+brandId);
System.out.println("getInputVal()"+getInputVal());
try {
if (!getUserType().equals("G") && !getUserEmail().equals(null)) {
// subscriberId from SubscriberAccessBean
SubscriberAccessBean subscriberAccessBean = new SubscriberAccessBean();
subscriberAccessBean.findByBrandIdAndEmailAddress(brandId,
getUserEmail());
Enumeration subscriberIds = null;
subscriberIds = subscriberAccessBean
.findByBrandIdAndEmailAddress(brandId, getUserEmail());
if (subscriberIds != null) {
boolean count = true;
while (subscriberIds.hasMoreElements() && count == true) {
subscriberId = ((SubscriberAccessBean) (subscriberIds
.nextElement())).getSubscriberId();
count = false;
}
}
// subscriptionId from SubscriptionsAccessBean
System.out.println("subscriberId"+subscriberId);
Enumeration subscriptionIds = null;
Enumeration subscriptionStatuss = null;
SubscriptionsAccessBean subscriptionsAccessBean = new SubscriptionsAccessBean();
try {
if (subscriberId != null) {
subscriptionIds = subscriptionsAccessBean
.findBySubscriberIdAndEmailServiceId(
subscriberId, Integer
.valueOf(getInputVal()));
subscriptionStatuss = subscriptionsAccessBean
.findBySubscriberIdAndEmailServiceId(
subscriberId, Integer
.valueOf(getInputVal()));
if (subscriptionIds != null) {
boolean count1 = true;
while (subscriptionIds.hasMoreElements()) {
subscriptionId = ((SubscriptionsAccessBean) (subscriptionIds
.nextElement())).getSubscriptionId();
count1 = false;
}
}
if (subscriptionStatuss != null) {
boolean count1 = true;
while (subscriptionStatuss.hasMoreElements()) {
subscriptionStatus = ((SubscriptionsAccessBean) (subscriptionStatuss
.nextElement()))
.getSubscriptionStatus();
count1 = false;
}
}
}
} catch (NullPointerException e) {
System.out.println("subscriberId is null ..."
+ e.getMessage());
}
}
} catch (Exception e) {
System.out.println("No Record Found ...." + e.getMessage());
}

if (logger.isLoggable(TraceIdentifiers.METHOD_ENTRY_EXIT)) {
logger.exiting(CLASS_NAME, METHOD_NAME);
}
}

public Long getSubscriptionId() {
return subscriptionId;
}

public void setSubscriptionId(Long subscriptionId) {
this.subscriptionId = subscriptionId;
}

public Short getSubscriptionStatus() {
return subscriptionStatus;
}

public void setSubscriptionStatus(Short subscriptionStatus) {
this.subscriptionStatus = subscriptionStatus;
}

@Override
public void setCommandContext(CommandContext commandContext) {
iCommandContext = commandContext;
}

@Override
public void setRequestProperties(TypedProperty reqProp) throws Exception {
requestProperties = reqProp;
}

@Override
public CommandContext getCommandContext() {
return iCommandContext;
}

@Override
public TypedProperty getRequestProperties() {
return requestProperties;
}

}

Some useful methods in IBM WCS


/***** Getting DB connection and run direct SQL ******/

public class CommonJDBCHelperBean extends BaseJDBCHelper implements SessionBean {
private String fetchPhysicalStoresSQL = "select stloc_id, identifier, address1, address3, country from stloc where latitude = ? order by address1"
                  + READONLY_WITH_UR_CLAUSE;

                /**
                 * It fetches list of all active stores address details from STLOC table.
                 *
                 * @return Vector - list of StoreLocationObjectBean
                 * @throws NamingException
                 *             If failed to get SQL connection
                 * @throws SQLException
                 *             if failed to execute SQL query
                 */
                public Vector fetchPhysicalStores(String storeId) throws NamingException, SQLException {
                                final String methodName = "fetchPhysicalStores";
                                if (logger.isLoggable(TraceIdentifiers.METHOD_ENTRY_EXIT)) {
                                                logger.entering(CLASS_NAME, methodName);
                                }
                                Vector vPhysicalStore = new Vector();
                                PreparedStatement stmt = null;
                                ResultSet rs = null;
                                try {
                                                makeConnection();
                                                if (logger.isLoggable(TraceIdentifiers.DEBUG_OUTPUT)) {
                                                                logger.logp(TraceIdentifiers.DEBUG_OUTPUT, CLASS_NAME, methodName, "sql is[{0}]",
                                                                                                fetchPhysicalStoresSQL.toString());
                                                }
                                                stmt = getPreparedStatement(fetchPhysicalStoresSQL);
                                                stmt.setBigDecimal(1, new BigDecimal(storeId));
                                                rs = executeQuery(stmt, false);
                                                while (rs.next()) {
                                                                StoreLocationObjectBean storeLocationObjectBean = new StoreLocationObjectBean();
                                                                storeLocationObjectBean.setStloc_id(rs.getString(1));
                                                                storeLocationObjectBean.setIdentifier(rs.getString(2));
                                                                storeLocationObjectBean.setAddress1(rs.getString(3));
                                                                storeLocationObjectBean.setAddress3(rs.getString(4));
                                                                storeLocationObjectBean.setCountry(rs.getString(5));
                                                                vPhysicalStore.add(storeLocationObjectBean);
                                                }
                                } finally {
                                                closeConnection();
                                                if (null != rs) {
                                                                rs.close();
                                                }

                                                if (null != stmt) {
                                                                stmt.close();
                                                }
                                }
                                if (logger.isLoggable(TraceIdentifiers.METHOD_ENTRY_EXIT)) {
                                                logger.entering(CLASS_NAME, methodName);
                                }
                                return vPhysicalStore;

                }

/********* To send XML in QUEUE ***************/

To send OR02XML

Insert in msgtype:
insert into msgtypes values(10002,1,'OR02MIGRATION','OR02MIGRATION','Abster Send OR02 XML Message for completed Orders',null);


SendMsgCmd sendXMLCmd = (SendMsgCmd) CommandFactory
                                                                        .createCommand(SendMsgCmd.NAME, oaBean.getStoreEntityIdInEJBType());
                                                sendXMLCmd.setMsgType("OR02MIGRATION");
                                                sendXMLCmd.setStoreID(oaBean.getStoreEntityIdInEJBType());
// get clone of request to put additional values
                                                TypedProperty properties = (TypedProperty) getRequestProperties()
                                                                        .clone();
properties.put("ordersId", ordersId);
properties.put("OrderRefNumber", ordersId);
properties.put("LanguageId", -1);
sendXMLCmd.compose(OR02_VIEW,getCommandContext(), properties);
sendXMLCmd.sendTransacted();
sendXMLCmd.setCommandContext(getCommandContext());

sendXMLCmd.execute();



*****************Session *******************
<c:choose>
<c:when test="${userType == 'G' || fn:contains(userEmail,'@X.XX')|| user_id == '-1002'}">
<%
session.setAttribute("eMarketsubscriberBeanRequired","N");
session.setAttribute("subscriberBean",new com.xxxx.commerce.subscribers.commands.EmailServiceDataBean());
%>

</c:when>

<c:otherwise>

<wcbase:useBean id="bnRegister" classname="com.ibm.commerce.user.beans.UserRegistrationDataBean" >
<c:set value="${CommandContext.user.userRegistry.userId}" target="${bnRegister}" property="userId"/>
</wcbase:useBean>
<c:set var="service_Id"><fmt:message key="SUBSCRIPTION_DEFAULT_SERVICE_ID" bundle="${storeFrontText}"/></c:set>
<c:set var="qubituserEmail" value="${bnRegister.email1}" />
<c:if test="${!fn:contains(qubituserEmail,'@X.XX')|| user_id == '-1002'}">
<%
Object isAlreadyAvailable= session.getAttribute("eMarketsubscriberBeanRequired");                                            
              if(null != isAlreadyAvailable && isAlreadyAvailable.toString().equals("N")) {                                          

%>
<wcbase:useBean id="bean" classname="com.xxxxx.commerce.subscribers.commands.EmailServiceDataBean">
<c:set value="${service_Id}" target="${bean}" property="inputVal" />
<c:set value="${qubituserEmail}" target="${bean}" property="userEmail"/>
<c:set value="${userType}" target="${bean}" property="userType"/>
</wcbase:useBean>
<%
session.setAttribute("eMarketsubscriberBeanRequired","Y");
session.setAttribute("subscriberBean",bean);
}
%>    
</c:if>

</c:otherwise>
</c:choose>


Using it

<%@include file="QubitMarketing.jspf"%>
<%
com.xxxxxx.commerce.subscribers.commands.EmailServiceDataBean subscriberBean=(com.xxxxx.commerce.subscribers.commands.EmailServiceDataBean)session.getAttribute("subscriberBean"); 
if(subscriberBean!= null && subscriberBean.getSubscriberId() > 0 && subscriberBean.getSubscriptionId()>0 && subscriberBean.getSubscriptionStatus()>0){%>,
"subscriber_id": "<c:out value="${subscriberBean.subscriberId}" />",
"subscription_id": "<c:out value="${subscriberBean.subscriptionId}" />"<%} %>

Creating data bean
public class EmailServiceDataBean implements SmartDataBean {
private static final String CLASS_NAME = EmailServiceDataBean.class
.getName();
private static final Logger logger = Logger.getLogger(CLASS_NAME);
private Long subscriberId;
private String emailAddress;
private Integer brandId;
private String userEmail;
protected Integer Key_emailServiceId;
private String userType;
private Long subscriptionId;
private Short subscriptionStatus;
public CommandContext iCommandContext = null;
public TypedProperty requestProperties = null;

public String getUserType() {
return userType;
}

public void setUserType(String userType) {
this.userType = userType;
}

protected String inputVal;

public String getInputVal() {
return inputVal;
}

public void setInputVal(String inputVal) {
this.inputVal = inputVal;
}

public Integer getKey_emailServiceId() {
return Key_emailServiceId;
}

public void setKey_emailServiceId(Integer key_emailServiceId) {
Key_emailServiceId = getKey_emailServiceId();
}

public String getUserEmail() {
return userEmail;
}

public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}

public Long getSubscriberId() {
return subscriberId;
}

public void setSubscriberId(Long subscriberId) {
this.subscriberId = subscriberId;
}

public String getEmailAddress() {
return emailAddress;
}

public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}

public Integer getBrandId() {
return brandId;
}

public void setBrandId(Integer brandId) {
this.brandId = brandId;
}

@Override
public void populate() throws Exception {
final String METHOD_NAME = "populate";
if (logger.isLoggable(TraceIdentifiers.METHOD_ENTRY_EXIT)) {
logger.entering(CLASS_NAME, METHOD_NAME);
}
// EmailServiceAccessBean is initilize to get brand_id from
// EMAIL_SERVICE table
EmailServiceAccessBean emailServiceAccessBean = new EmailServiceAccessBean();
emailServiceAccessBean.setInitKey_emailServiceId(Integer
.valueOf(getInputVal()));
emailServiceAccessBean.refreshCopyHelper();
brandId = emailServiceAccessBean.getBrandId();
// Guest user check. If user is of type guest then emailId will not
// available
System.out.println("brandId"+brandId);
System.out.println("getInputVal()"+getInputVal());
try {
if (!getUserType().equals("G") && !getUserEmail().equals(null)) {
// subscriberId from SubscriberAccessBean
SubscriberAccessBean subscriberAccessBean = new SubscriberAccessBean();
subscriberAccessBean.findByBrandIdAndEmailAddress(brandId,
getUserEmail());
Enumeration subscriberIds = null;
subscriberIds = subscriberAccessBean
.findByBrandIdAndEmailAddress(brandId, getUserEmail());
if (subscriberIds != null) {
boolean count = true;
while (subscriberIds.hasMoreElements() && count == true) {
subscriberId = ((SubscriberAccessBean) (subscriberIds
.nextElement())).getSubscriberId();
count = false;
}
}
// subscriptionId from SubscriptionsAccessBean
System.out.println("subscriberId"+subscriberId);
Enumeration subscriptionIds = null;
Enumeration subscriptionStatuss = null;
SubscriptionsAccessBean subscriptionsAccessBean = new SubscriptionsAccessBean();
try {
if (subscriberId != null) {
subscriptionIds = subscriptionsAccessBean
.findBySubscriberIdAndEmailServiceId(
subscriberId, Integer
.valueOf(getInputVal()));
subscriptionStatuss = subscriptionsAccessBean
.findBySubscriberIdAndEmailServiceId(
subscriberId, Integer
.valueOf(getInputVal()));
if (subscriptionIds != null) {
boolean count1 = true;
while (subscriptionIds.hasMoreElements()) {
subscriptionId = ((SubscriptionsAccessBean) (subscriptionIds
.nextElement())).getSubscriptionId();
count1 = false;
}
}
if (subscriptionStatuss != null) {
boolean count1 = true;
while (subscriptionStatuss.hasMoreElements()) {
subscriptionStatus = ((SubscriptionsAccessBean) (subscriptionStatuss
.nextElement()))
.getSubscriptionStatus();
count1 = false;
}
}
}
} catch (NullPointerException e) {
System.out.println("subscriberId is null ..."
+ e.getMessage());
}
}
} catch (Exception e) {
System.out.println("No Record Found ...." + e.getMessage());
}

if (logger.isLoggable(TraceIdentifiers.METHOD_ENTRY_EXIT)) {
logger.exiting(CLASS_NAME, METHOD_NAME);
}
}

public Long getSubscriptionId() {
return subscriptionId;
}

public void setSubscriptionId(Long subscriptionId) {
this.subscriptionId = subscriptionId;
}

public Short getSubscriptionStatus() {
return subscriptionStatus;
}

public void setSubscriptionStatus(Short subscriptionStatus) {
this.subscriptionStatus = subscriptionStatus;
}

@Override
public void setCommandContext(CommandContext commandContext) {
iCommandContext = commandContext;
}

@Override
public void setRequestProperties(TypedProperty reqProp) throws Exception {
requestProperties = reqProp;
}

@Override
public CommandContext getCommandContext() {
return iCommandContext;
}

@Override
public TypedProperty getRequestProperties() {
return requestProperties;
}

}