Monday, August 26, 2024

disable access control policy in HCL WCS


AccessControlUnitTest="true" : Disable Access Control Policy

In wc-server.xml make below change to disable access control policy.

The updated configuration will look as follows/

    <Instance
      AccessControlUnitTest="true"
      ChannelOrgDN="ou=Channel Organization,o=Manufacturer Organization,o=Root Organization"
      ConfigFilePath="C:\IBM\WCDE_V9/conf"

Tuesday, February 21, 2023

HCL Commerce ACP policy

MERGE

INTO

  ACRESCGRY acresgry

USING

  (

    SELECT ACRESCGRY_ID, RESCLASSNAME FROM (

  SELECT (SELECT MAX(ACRESCGRY_ID)+1 FROM acrescgry) ACRESCGRY_ID, 'com.XYX.commerce.usermanagement.commands.XYZProfileTypeCmd' RESCLASSNAME FROM SYSIBM.SYSDUMMY1 

  )

  ) t

ON

  (

    acresgry.RESCLASSNAME = t.RESCLASSNAME

  )

WHEN MATCHED THEN

  UPDATE SET

  acresgry.RESCLASSNAME = t.RESCLASSNAME

WHEN NOT MATCHED THEN

  INSERT (acresgry.ACRESCGRY_ID, acresgry.RESCLASSNAME)

  VALUES (t.ACRESCGRY_ID, t.RESCLASSNAME)

;



MERGE

INTO

  ACRESACT acresact

USING

  (

    SELECT ACRESCGRY_ID, ACACTION_ID FROM (

  SELECT (SELECT ACRESCGRY_ID FROM acrescgry where RESCLASSNAME like 'com.XYX.commerce.usermanagement.commands.XYZProfileTypeCmd') ACRESCGRY_ID, (SELECT ACACTION_ID FROM acaction where action = 'Execute') ACACTION_ID FROM SYSIBM.SYSDUMMY1 

  )

  ) t

ON

  (

    acresact.ACRESCGRY_ID = t.ACRESCGRY_ID and acresact.ACACTION_ID = t.ACACTION_ID 

  )

WHEN NOT MATCHED THEN

  INSERT (acresact.ACRESCGRY_ID, acresact.ACACTION_ID)

  VALUES (t.ACRESCGRY_ID, t.ACACTION_ID)

;



MERGE

INTO

  ACRESGPRES acresgpres

USING

  (

    SELECT ACRESGRP_ID, ACRESCGRY_ID FROM (

  SELECT (SELECT ACRESGRP_ID FROM ACRESGRP where GRPNAME = 'RegisteredUserCmdResourceGroup') ACRESGRP_ID , (SELECT ACRESCGRY_ID FROM acrescgry where RESCLASSNAME like 'com.XYX.commerce.usermanagement.commands.XYZProfileTypeCmd') ACRESCGRY_ID  FROM SYSIBM.SYSDUMMY1 

  )

  ) t

ON

  (

    acresgpres.ACRESGRP_ID = t.ACRESGRP_ID and acresgpres.ACRESCGRY_ID = t.ACRESCGRY_ID 

  )

WHEN NOT MATCHED THEN

  INSERT (acresgpres.ACRESGRP_ID , acresgpres.ACRESCGRY_ID)

  VALUES (t.ACRESGRP_ID,  t.ACRESCGRY_ID )

;

Wednesday, December 28, 2022

java was started but returned exit code=-805306369

 Issue : java was started but returned exit code = -805306369 C:\Windows\System32\javaw.exe -jar C:\Program Files\Java\eclipse-jee-helios-SR2-win32-x86_64\eclipse\plugins\org.eclipse.equinox.launcher_1.11.1.R36x_v20101122_1400.jar


Resolution : Update eclipe.ini file located in C:\IBM\SDP. Update below 2 highlighted value



-Dorg.eclipse.swt.browser.IEVersion=11001

-Xquickstart

-Xms1024m

-Xmx1536m

-Xmnx64m

-XX:MaxPermSize=1024M


Monday, July 5, 2021

SonarQube Setup Guide

 

                                    SonarQube Setup Guide

Download the SonarQube Community Edition

Note : SonarQube requires disk space of around 100 GB.



2. Unzip it, let's say in C:\sonarqube or /etc/sonarqube.

3. Install java 11 and set the path.

4. Edit the wrapper.conf file from the sonar and set the path location of java.



5. Start the SonarQube Server.



6. Log in to http://localhost:9000 with System Administrator credentials (admin/admin)

7. Download sonar scanner from the given link. SonarScanner | SonarQube Docs



8. Create sonar-project.properties file in the project folder which is to be scanned and configure the project properties.



9. Set user variable for the sonar scanner.

10. Run sonar-scanner.bat command on command prompt from the project folder.

11. Log in to http://localhost:9000 with System Administrator credentials (admin/admin) to check the scan results.

REFERENCES:

https://github.com/SonarSource/sonar-.net-documentation/blob/master/doc/installation-and-configuration.md#:~:text=In%20the%20extracted%

20folder%20navigate,the%20currently%20in%20use%20ports.

Wednesday, June 9, 2021

Adding trace in ts-app container in HCL commerce

 


Adding new trace from ts-app container : Execute you container then from there run :


run set-dynamic-trace-specification com.ibm.commerce.*=all

To Revert:

run set-dynamic-trace-specification *=severe

Wednesday, January 27, 2021

Installing NetBeans12.2

 

Download NetBeans : https://www.apache.org/dyn/closer.cgi/netbeans/netbeans/12.2/Apache-NetBeans-12.2-bin-windows-x64.exe



open NetBeans installer location in command prompt and type: netbeans*****.exe --javahome "C:\Program Files\Java\jdk"


e.g. C:\Users\Documents\>Apache-NetBeans-12.2-bin-windows-x64.exe --javahome "C:\Program Files (x86)\Java\jdk1.8.0_281"

Tuesday, December 15, 2020

Input validation of number in JSP

 As per one security flaw in security scan Input Validation : We have to validate input is number or not .

Use below code for same


<jsp:forward page="AccessError.jsp">

<jsp:param name="storeId" value="${WCParam.storeId}" />

<jsp:param name="langId" value="${WCParam.langId}" />

<jsp:param name="catalogId" value="${WCParam.catalogId}" />

</jsp:forward>


Solution used was: 

<c:set var="storeId">
		<c:if test="${WCParam.storeId.matches('[0-9]+')}">
<c:out value="${WCParam.storeId}"/>
</c:if></c:set>

Thursday, August 20, 2020

RestTemplate to POST with UTF-8 encoding

Sometime we see extra character in rest response like Â, â. To overcome this issue We need to add StringHttpMessageConverter to rest template's message converter with charset UTF-8. Like below


RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters()
        .add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));


Refer : UTF encoding from rest response

Saturday, July 18, 2020

msgtypes related tables in WCS

select * from msgtypes
select * from profile
select * from iseditatt
select * from cseditatt 

Friday, May 1, 2020

WCS Useful loggers



Struts
com.ibm.websphere.commerce.WC_SERVER=all: org.apache.struts.*=all

REST


com.ibm.commerce.foundation.rest.providers.*=all:com.ibm.commerce.store.taglibs.RESTTag=all:com.ibm.commerce.foundation.internal.client.taglib.HeaderTag=all:com.ibm.commerce.component.internal.client.util.RESTInvoker=all:com.ibm.commerce.component.internal.client.util.RESTHandler=all

Search in WAS


com.ibm.commerce.catalog.*=all:com.ibm.commerce.foundation.*=all:com.ibm.commerce.search.*=all

Search in solr:


com.ibm.commerce.foundation.*=all: com.ibm.commerce.rest.*=all: org.apache.solr.*=all: org.apache.wink.*=all: com.ibm.commerce.solr.*=all

Price index:


com.ibm.commerce.foundation.dataimport.priceindex.*=finest
com.ibm.commerce.price.*=finest
com.ibm.websphere.commerce.WC_ORDER

JPA

*=info:JPA=all:openjpa.*=finer:openjpa.kernel=finest

SQL


com.ibm.ws.rsadapter.jdbc.WSJdbcCallableStatement=finer:
com.ibm.ws.rsadapter.jdbc.WSJdbcStatement=finer:
com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement=finer:
com.ibm.ws.rsadapter.jdbc.WSJccCallableStatement=finer:
com.ibm.ws.rsadapter.jdbc.WSJccStatement=finer:
com.ibm.ws.rsadapter.jdbc.WSJccPreparedStatement=finer

ACPOLICY

com.ibm.websphere.commerce.WC_SERVER=all:com.ibm.websphere.commerce.WC_USER=all:com.ibm.websphere.commerce.WC_ACCESSCONTROL=all:

com.ibm.commerce.component.helper.*=all:com.ibm.commerce.component.registry.*=all:com.ibm.commerce.foundation.logging.*=all

To Get xml in log:  
com.ibm.commerce.foundation.server.command.bod.BusinessObjectDocumentProcessor

In ts-app enable log :
 
 
 run set-dynamic-trace-specification "*=info:com.ibm.websphere.commerce.WC_ORDER=all:com.ibm.commerce.foundation.logging.*=all:com.ibm.commerce.order.facade.server.commands.ComposeOrderDetailsCmdImpl=all:com.ibm.commerce.order.*=all:com.ibm.commerce.foundation.server.command.bod.*=all:com.ibm.commerce.order.event.*=all"

crs-app
run set-trace-specification "*=warning:org.apache.commons.httpclient.*=all:java.net.*=all"


xc-app
run set-trace-specification "*=warning:com.ibm.commerce.order.ue.rest.*=all"





Thursday, April 9, 2020

Decrypt AES encrypted Password in WCS

                   How to Decrypt AES encrypted Password in WCS 

package com.xyz.commerce.me.datatype;

import com.ibm.commerce.ejb.helpers.nc_crypt;
import com.ibm.commerce.util.wrapper.AES128Cryptx;

public class test {
        public static void main(String[] args) throws Exception {

                System.out.println("merchantKey         ");
               
                String key = "PxrEn69MEqvE4rGLFnQoxZl6VAbbxVvQp2bPrDKxAYX=";
                System.out.println("str length         " + key.length());

//TO decrypt merchent key in CustomKeys.xml

                String keyFileValue = "HuRIPYJ92f5mf1iMUDqTLivbros95jcCNTWSjcgDh/dCbdAn9LR+JEEn7X3PsHkhUk+zl6XhSU2rH0RtwKBgwg=="; //value present in keyFile file.
                String KeyEncryptionFileValue= "1234567890abcdef1234567890abcdef"; //Value present in keyEncryptionFile file.


                String decryptedMerchantKey = AES128Cryptx.decrypt(keyFileValue,KeyEncryptionFileValue, false) ;

//Printing decrypted merchant Key
                System.out.println("Decrypted Merchant Key : " +  decryptedMerchantKey);
                String stringToDecrypt = "PxrEn69MEqvE4rGLFnQoxZl6VAbbxVvQp2bPrDKxANM=";//String to decrypt

//printing decrypted password using merchant key

                System.out.println("Decrypted String : " + AES128Cryptx.decrypt(stringToDecrypt,decryptedMerchantKey,false));

        }
}

Wednesday, April 8, 2020

ADMA5014E - The installation of application WC failed



Sometime while doing server clean we are getting below exception :

[4/6/20 13:22:32:576 EDT] 00000099 UninstallSche I   ADMA5017I: Uninstallation of WC started.
[4/6/20 13:23:04:849 EDT] 00000099 UninstallSche I   ADMA5106I: Application WC uninstalled successfully.
[4/6/20 13:25:06:174 EDT] 000000ac InstallSchedu I   ADMA5016I: Installation of WC started.
[4/6/20 13:26:03:189 EDT] 000000ac FfdcProvider  W com.ibm.ws.ffdc.impl.FfdcProvider logIncident FFDC1003I: FFDC Incident emitted on C:\IBM\WCDE_V9\wasprofile\logs\ffdc\server1_a33aa440_20.04.06_13.26.02.9397908970630759559988.txt com.ibm.ws.management.application.task.ConfigureTask.performTask 481
[4/6/20 13:26:03:283 EDT] 000000ac FfdcProvider  W com.ibm.ws.ffdc.impl.FfdcProvider logIncident FFDC1003I: FFDC Incident emitted on C:\IBM\WCDE_V9\wasprofile\logs\ffdc\server1_a33aa440_20.04.06_13.26.03.2214555710547160290204.txt com.ibm.ws.management.application.task.ConfigureTask.performTask 494
[4/6/20 13:26:03:408 EDT] 000000ac InstallSchedu I   ADMA5014E: The installation of application WC failed.
[4/6/20 13:26:03:299 EDT] 000000ac SystemErr     R org.eclipse.jst.j2ee.commonarchivecore.internal.exception.ArchiveWrappedException
Stack trace of nested exception:
org.eclipse.jst.j2ee.commonarchivecore.internal.exception.NoModuleFileException: A file does not exist for module element having uri: Stores.war
at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.checkType(ModuleRefImpl.java:591)
at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.initModuleFileFromEAR(ModuleRefImpl.java:167)
at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.getModuleFile(ModuleRefImpl.java:120)
at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.EARFileImpl.getModuleFile(EARFileImpl.java:175)
at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.EARFileImpl.getDeploymentDescriptor(EARFileImpl.java:851)
at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.getDeploymentDescriptor(ModuleRefImpl.java:230)
at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.getDeploymentDescriptor(ModuleRefImpl.java:223)
at com.ibm.ws.management.application.task.ConfigureTask.getModuleNameFromModuleRef(ConfigureTask.java:2056)
at com.ibm.ws.management.application.task.ConfigureTask.createMDsForModuleRefs(ConfigureTask.java:1258)
at com.ibm.ws.management.application.task.ConfigureTask.createMDsIfNeeded(ConfigureTask.java:1095)
at com.ibm.ws.management.application.task.ConfigureTask.reconcileModuleDeployment(ConfigureTask.java:994)
at com.ibm.ws.management.application.task.ConfigureTask.performTask(ConfigureTask.java:375)
at com.ibm.ws.management.application.SchedulerImpl.run(SchedulerImpl.java:315)
at java.lang.Thread.run(Thread.java:812)

[4/6/20 13:26:03:299 EDT] 000000ac SystemErr     R Stack trace of nested exception:
[4/6/20 13:26:03:299 EDT] 000000ac SystemErr     R org.eclipse.jst.j2ee.commonarchivecore.internal.exception.NoModuleFileException: A file does not exist for module element having uri: Stores.war
[4/6/20 13:26:03:299 EDT] 000000ac SystemErr     R at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.checkType(ModuleRefImpl.java:591)
[4/6/20 13:26:03:299 EDT] 000000ac SystemErr     R at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.initModuleFileFromEAR(ModuleRefImpl.java:167)
[4/6/20 13:26:03:299 EDT] 000000ac SystemErr     R at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.getModuleFile(ModuleRefImpl.java:120)
[4/6/20 13:26:03:299 EDT] 000000ac SystemErr     R at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.EARFileImpl.getModuleFile(EARFileImpl.java:175)
[4/6/20 13:26:03:314 EDT] 000000ac SystemErr     R at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.EARFileImpl.getDeploymentDescriptor(EARFileImpl.java:851)
[4/6/20 13:26:03:314 EDT] 000000ac SystemErr     R at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.getDeploymentDescriptor(ModuleRefImpl.java:230)
[4/6/20 13:26:03:314 EDT] 000000ac SystemErr     R at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.getDeploymentDescriptor(ModuleRefImpl.java:223)
[4/6/20 13:26:03:314 EDT] 000000ac SystemErr     R at com.ibm.ws.management.application.task.ConfigureTask.getModuleNameFromModuleRef(ConfigureTask.java:2056)
[4/6/20 13:26:03:314 EDT] 000000ac SystemErr     R at com.ibm.ws.management.application.task.ConfigureTask.createMDsForModuleRefs(ConfigureTask.java:1258)
[4/6/20 13:26:03:314 EDT] 000000ac SystemErr     R at com.ibm.ws.management.application.task.ConfigureTask.createMDsIfNeeded(ConfigureTask.java:1095)
[4/6/20 13:26:03:314 EDT] 000000ac SystemErr     R at com.ibm.ws.management.application.task.ConfigureTask.reconcileModuleDeployment(ConfigureTask.java:994)
[4/6/20 13:26:03:314 EDT] 000000ac SystemErr     R at com.ibm.ws.management.application.task.ConfigureTask.performTask(ConfigureTask.java:375)
[4/6/20 13:26:03:314 EDT] 000000ac SystemErr     R at com.ibm.ws.management.application.SchedulerImpl.run(SchedulerImpl.java:315)
[4/6/20 13:26:03:314 EDT] 000000ac SystemErr     R at java.lang.Thread.run(Thread.java:812)
[4/6/20 13:26:37:750 EDT] 00000089 AppBinaryProc I   ADMA7021I: Distribution of application WC completed successfully.

Solution :
1. Right click on WC project and select properties --> Select Deployment Assembly

2. You may see Store is not there or may be there in both case remove Stores and re-add that
3.Select project

 4. select stores in project and finish.



Decrypt IBM WCS encrypted key

Decrypt IBM WCS encrypted key


package com.xyz.commerce.tools.devtools.flexflow.taglibs;

import com.ibm.commerce.ejb.helpers.nc_crypt;

public class TEST {
public static void main(String[] args) {

String merchantKey = nc_crypt.decrypt(
"ldbrNlajddp8od+xZpJDiK/DbuVqOEE+", null);

System.out.println("merchantKey         " + merchantKey);

String keyToDecrypt = "gpJMgIorXCz/1yTeFHiEcDPWJYv7NmRQ";
System.out.println("Decrypted String : "
+ nc_crypt.decrypt(keyToDecrypt , merchantKey ));

}
}

Wednesday, March 11, 2020

DB2 connection problem in WebSphere

DB2 connection problem in WebSphere

I am getting below issue while server startup.

DSConfigHelpe W   DSRA8200W: DataSource Configuration: DSRA8020E: Warning: The property 'connectionAttribute' does not exist on the DataSource class com.ibm.db2.jcc.DB2ConnectionPoolDataSource.

com.ibm.commerce.wc.appmanagement.exception.WCAppManagementException: com.ibm.websphere.ce.cm.StaleConnectionException: [jcc][t4][10380][11951][4.19.66] Required property "mydbhost.com" is unknown host. ERRORCODE=-4222, SQLSTATE=08001 DSRA0010E: SQL State = 08001, Error Code = -4,222



Solution : Please check hostname used in resources.xml and wc-server.xml files are correct. 
WCDE_V9\workspace\WC\META-INF\ibmconfig\cells\defaultCell\applications\defaultApp\deployments\defaultApp\resources.xml

<resourceProperties description="The name of the server, used with thin driver setup" name="serverName" required="false" type="java.lang.String" value="mydbhost.com" xmi:id="J2EEResourceProperty_1123801797694"/>

After updating value, Please restart server.

Tuesday, October 16, 2018

Promotion Related DB queries

Promotion Related DB queries.
OrderItem cacode relation -->ORDICALCD
Calcode with px_promotion -->CLCDPROMO

--This table contains all the Promotion that is created and it can be identified by the name Under the column "NAME"
select * from PX_PROMOTION where PX_Promotion_id=10001;

-- This table contains all the promotions that are created and the promotion name is present under "CODE" column
select * from calcode;

-- This table contains all the promotion codes available for the particular store.
select * from px_cdpool;

-- This table contains all the promotion code information for relationships with a promotion.
select * from PX_CDPROMO;

-- This table contains all the promotion code usage information.
select * from PX_CDUSAGE;

-- This table contains all of the coupons issued to individual customers.
select * from PX_COUPON;

-- This table contains promotion description information.
select * from PX_DESCRIPTION ;

-- This table Contains the promotion group information (i.e. under the grpname we can classify the type of promotion it belongs to).
select * from PX_GROUP;

-- This table contains promotion policies (based on the storeent_id we can classify the promotions and also we can get the status of the promotion).
select * from PX_POLICY;

-- This table contains details about how promotions are applied to an order.
select * from PX_PROMOARG;

-- This table contains statistics about promotion usage.
select * from PX_USAGE;

Monday, September 3, 2018

manually generate heapdumps in Websphere


To manually generate heapdumps, set a JVM parameter. Then send the JVM process an interrupt (signal 3), a javacore and a heapdump will be generated.

In the Administrative Console:
Servers > Application Servers > serverName:
In the Server Infrastructure section open Java and Process Management, then select Process Definition:
In the Additional Properties select Java™ Virtual Machine:

Add the following string to the Generic JVM arguments field:
-Xdump:heap:events=user

Press OK, and save the configuration.

Note: The Application Server will need to be recycled for the setting to take effect.


To generate the heapdump, send the Application Server an interrupt. Use the "kill" command:
kill -3 <java process ID>

To get process id
ps -aux | grep java   (Look for server1)

Monday, July 9, 2018

SRVE0216E: post body contains less bytes than specified by content-length

i was writing service handle HTTP POST request and come accross below exception




00000070 SRTServletReq E com.ibm.ws.webcontainer.srt.SRTServletRequest parseParameters SRVE0133E: An error occurred while parsing parameters. {0}
                                 java.io.IOException: SRVE0216E: post body contains less bytes than specified by content-length
    at com.ibm.ws.webcontainer.servlet.RequestUtils.parsePostData(RequestUtils.java:311)



Using data : JSON.stringify(json) , in the AJAX call resolved issue

Sunday, July 8, 2018

REST POST CALL with JSON BODY in Websphere commerce

REST POST CALL with JSON BODY in Websphere commerce. The code below is an example of a POST request that requests and receives a JSON string response. The Apache Wink framework also supports GET and other applicable request types, but for the purposes of this example a POST request will be leveraged.
Apache Wink REST Client Creation Tutorial for WebSphere Commerce
Step 1. Create a ClientConfig object. This object will be used to configure and construct a RestClient.
By default, the client uses the java.net.HttpURLConnection for issuing requests and responses; but the Apache HttpClient can also be used. In my experience with WebSphere Commerce v7.0, I recommend using the ApacheHttpClientConfig object as shown below to construct your ClientConfig object.
Configure and set appropriate properties on the ClientConfig object, such as the readTimeout and connectTimeout properties.
NOTE: After a ClientConfig object is used to construct a RestClient object, the ClientConfig object can no longer be modified and will result in a ClientConfigException error.

// import org.apache.wink.client.ApacheHttpClientConfig;
// import org.apache.wink.client.ClientConfig;
ClientConfig clientConfig = newApacheHttpClientConfig();
clientConfig.readTimeout(readTimeout);
clientConfig.connectTimeout(connectionTimeout);

Step 2. Create a RestClient with the ClientConfig object created and configured previously.

// import org.apache.wink.client.RestClient;
RestClient restClient = newRestClient(clientConfig);

Step 3. Create a Resource object with your REST service URI from the REST client object. Configure and set appropriate properties on the Resource object, and add any required headers to the request. Ensure you set the appropriate MediaType you expect to receive in response to your REST service call.

// import org.apache.wink.client.Resource;
// import javax.ws.rs.core.MediaType;
Resource restResource = restClient.resource("http://www.example.com/some/rest/service");
restResource.accept(MediaType.APPLICATION_JSON);
resource.header(ECConstants.EC_CONTENT_TYPE, MediaType.APPLICATION_JSON);
resource.header("Authorization","<Basic cmFjaGVsLmZvb0BmYWly>");
restResource.header("HeaderField", "HeaderValue");

Step 4. Creating JSON object to send in body for POST call

String json=null;
Map detailsMap = new LinkedHashMap<String, String>();
    detailsMap.put("ticket",detailsMap);
                    ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
                    try {
                    json = ow.writeValueAsString(detailsMap);
System.out.println("request proprs :::: "+json);
            } catch (JsonProcessingException e) {
            e.printStackTrace();
}

Step 5. Execute a GET or POST call, and process the response by using the status code, response headers, or the response message body as needed.

// import org.apache.wink.client.ClientResponse;
ClientResponse clientResponse = restResource. .contentType(MediaType.APPLICATION_JSON).post(json.toString());
int statusCode = clientResponse.getStatusCode();
String responseEntity = clientRepsonse.getEntity(String.class);
            }


NOTE: Instead of calling the response.getEntity(String.class) to retrieve a String response, you can use any other class that has a valid javax.ws.rs.ext.MessageBodyReader object.
And there you go, you’ve implemented an Apache Wink REST service client, and can now process the response as your application requires.

Tuesday, May 29, 2018

Using LIKE wildcard in prepared statement

Using “like” wildcard in prepared statement

Query : SELECT COUNT(o.orders_id) AS orders,ROUND(SUM(o.totalproduct),0) AS ordersum,ROUND(AVG(o.totalproduct),0) AS orderavg FROM orders o, users usr WHERE o.member_id=usr.users_id and  o.timeplaced like  ? and usr.field1='IU' and o.status='M'

In Java:
String mmSearch = "%";
            Set<String> keys = previousOrdersDateMap.keySet();
            for(String key: keys){
               if(null != key){
                               key = mmSearch+key+mmSearch;
                PreparedStatement preparedStatement = conn.prepareStatement(detQryType);

                preparedStatement.setString(1,key);

Friday, May 25, 2018

Writing REST handler in ibm wcs

Writing REST handler: If you are writing a custom handle in WCS follow below steps:

1.       Make entry of your custome handler in resources-ext.properties at below path
Rest\WebContent\WEB-INF\config\resources-ext.properties

e.g com.mycomp.commerce.rest.handlers.ExMyHandler

Now lets try to get value passed in header for GET request

package com.mycomp.commerce.rest.handlers.ExMyHandler;

import java.util.Set;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;

@Path("store/{storeId}/http-header/")
public class HttpHeaderService extends AbstractClassicResourceHandler {
               
                @GET
    @Produces( { "application/atom+xml", "application/json", "application/xml" })
    @Path("/queryheader")
    public Response findHeader(@PathParam("storeId") String storeId, @QueryParam("responseFormat") String responseFormat, , @Context HttpHeaders httpHeaders) {
                String METHODNAME = " findHeader()";
                LOGGER.entering(CLASSNAME,METHODNAME);
        Response result = null;
        String cacheControl = httpHeaders.getRequestHeader("Cache-Control").get(0);
        System.out.println("Cache-Control: "+cacheControl);
        /** get list of all header parameters from request **/
        Set<String> headerKeys = httpHeaders.getRequestHeaders().keySet();
        for(String header:headerKeys){
            System.out.println(header+":"+httpHeaders.getRequestHeader(header).get(0));
        }

        LOGGER.exiting(CLASSNAME,METHODNAME);
System.out.println("----------"+result);
        return result;
    }


Now use below URL in POSTMAN to get header query results:



Results in console : All parameter passed in header will come in system out

[5/25/18 12:40:56:611 IST] 000001ad SystemOut     O Cache-Control: no-cache
[5/25/18 12:40:56:611 IST] 000001ad SystemOut     O Accept:*/*
[5/25/18 12:40:56:611 IST] 000001ad SystemOut     O Accept-Encoding:gzip, deflate
[5/25/18 12:40:56:612 IST] 000001ad SystemOut     O Cache-Control:no-cache
[5/25/18 12:40:56:612 IST] 000001ad SystemOut     O Connection:keep-alive
[5/25/18 12:40:56:612 IST] 000001ad SystemOut     O Content-Type:application/json
[5/25/18 12:40:56:612 IST] 000001ad SystemOut     O Cookie:JSESSIONID=0000XFHI_0g_W1W40QAO34yPPQ8:-1
[5/25/18 12:40:56:613 IST] 000001ad SystemOut     O emailId:pawan@gmail.com
[5/25/18 12:40:56:613 IST] 000001ad SystemOut     O Host:localhost
[5/25/18 12:40:56:613 IST] 000001ad SystemOut     O Postman-Token:d299a6ae-91a6-4710-8a73-223c1b5d63f0
[5/25/18 12:40:56:614 IST] 000001ad SystemOut     O User-Agent:PostmanRuntime/7.1.1
[5/25/18 12:40:56:614 IST] 000001ad SystemOut     O WCToken:125002%2CrbkigQ6NXpcvA2fu2rhe%2BasrZVIbdxvJavsmYi4OFe%2BglUf9Mbq%2F9lz37NMjdk0PvgsSZf5quQghTNL7TTFAbSa03WFEAqmO4tZ5zlRXlCgdQTYfJwH4jY%2B%2FnuRHTaqRjLghrBE%2ByI8jsBbmU80TZQVslYSsLJsSxDIS8hRhaZp9RUjh16nc2iROD7xdj7Q81bPln7rsgYXt6XuttxhQ%2F1uS1jLHY5dM3b07d9pffKj3kT4K6FmA7W%2FRvxLm%2B%2Foh

[5/25/18 12:40:56:614 IST] 000001ad SystemOut     O WCTrustedToken:125002%2CWb5DERrSx6keRM7Ql1yJjh5pYbYy2URYgvSGu0J3cMk%3D