Thursday, April 2, 2015

Server fails to redirect to the view URL.

Issue : checkRedirectAllowed(String url, String servletContextName, String requestStoreId) CMN1245E: Server fails to redirect to the view URL.

Solution: Mostly it happens because you application is not having proper entries in allowed domains. We need to put proper entry in wc-server.xml
For example  I am accessing my store via http://xyz.com/webapp/wcs/stores/servlet/StoreView?storeId=10151
Here xyz.com is domain and we need to make sure wc-server.xml have entry below entries in store modules.
               <Module contextPath="/webapp/wcs/stores"
                    fileServletEnabled="false" name="Stores"
                    urlMappingPath="/servlet" webAlias="/wcsstore">
                    <InitParameters SSLAcceleratorOption="Enabled"
                        adapters="XML/HTTP, BrowserAdapter"
                        contextSetName="Store" handleDoubleClick="true"
                        inNonSSLPort="80" inSSLPort="80"
                        outNonSSLPort="80" outSSLPort="443"/>
                    <URLRedirectFilter enable="true">
<AllowedDomain name="xyz.com"/> <!-- We can put more domains here-->  
                     </URLRedirectFilter>

                </Module>

Same goes for other modules.

Friday, August 23, 2013

Pass URL Params to Controller Command Cont...

In last post We left the part "How to get the particular  function which gets called before the final ControllerCmd"
We take the example of last command only from previous post XYZOrderPrepareCmdImpl extends OrderPrepareCmdImpl. There we already discussed prepareOrder(Map parameters) function in XYZOrderFacadeClient. How did we get it???

Steps:
1) Put your server in debug mode.
2) Override performExecute in XYZOrderPrepareCmdImpl.
3) Put a debug marker on entry pint of above function.
4) Call this flow. Below is the image which I got from my system.


You can search *OrderFacadeClient in debug with Map argument. This function we need to override and write our code to pass the value userData field.

Pass URL Params to Controller Command

Hi ,

Many times we might  have faced this issue, We are passing few parameters from URL in either way post and get but we are not getting the parameters in the controller command under requestProperties.
For example:

Common Command framework.

Now problem comes when in struts config we get something like member.registerPerson or order.prepareOrder, where we had expected a interfaceName or className. Even if try to extend the OrderPrepareCmdImpl with our own defined class, we don't get the passed value from URL.

Solution:
Above is the service based flow in WCS.
We have multiple option to pass the URL parameter to the ControllerCMD, this one I found the simpler way to do it. Here we will take advantage of UserData field.
We need to modify flow at two places as numbered.
A) Extend OrderFacadeClient, lets name XYZOrderFacadeClient.
B) Update "order" with with xyzOrder in step 1.
C) update value="order" with value=" xyzOrder" and clientFacadeClassName with yourpackage.XYZOrderFacadeClient in step 2
D) Every clientFacade class have few set of function which gets called before the the final controllerCommand call. These function's have a map argument which will have the value we have passed from URL. I will discuss how to get this function later. For now in our example we need to override 

public Map prepareOrder(Map parameters) throws OrderException {
OrderIdentifierType orderIdent = this.buildOrderIdentifier(parameters,"prepareOrder");
OrderType order = getOrderFactory().createOrderType();
if (parameters.containsKey("myURLParam")) {
String[] poNumber = (String[])parameters.get("myURLParam");
if (myURLParam != null && myURLParam.length > 0) {
UserDataType userData = this.getCommerceFoundationFactory()
.createUserDataType();
userData.getUserDataField().put("myURLParam", myURLParam[0]);
order.setUserData(userData);
}
}
order.setOrderIdentifier(orderIdent);
AcknowledgeOrderDataAreaType orderData = this.prepareOrder(order);
this.populateResponse(response, "prepareOrder", orderData);
return response;
}

above one is too complicated lets have another example buildDynamicKit 

    @Override
    protected OrderItemType[] buildDynamicKitOrderItem(Map parameters, String actionName) throws OrderException {
        OrderItemType[]  orderItemType= super.buildDynamicKitOrderItem(parameters, actionName);
        if (parameters != null && parameters.keySet() != null) {
            if(parameters.get("myURLParam")!=null){
                UserDataType userDataType=orderItemType[0].getUserData();
                if (userDataType == null) {
                    userDataType = CommerceFoundationFactory.eINSTANCE
                    .createUserDataType();
                }

                orderItemType[0].setUserData(userDataType);
                Map dataFieldType = userDataType.getUserDataField();
                String myURLParam= ((String[])parameters.get("myURLParam"))[0];
                dataFieldType.put("myURLParam", myURLParam);
            }
        }
        return orderItemType;
    }

Now you will get your value in XYZOrderPrepareCmdImpl under getRequestProperties.

Please comment if you like the post or if any queries.