Example usage for javax.xml.ws.handler MessageContext SERVLET_REQUEST

List of usage examples for javax.xml.ws.handler MessageContext SERVLET_REQUEST

Introduction

In this page you can find the example usage for javax.xml.ws.handler MessageContext SERVLET_REQUEST.

Prototype

String SERVLET_REQUEST

To view the source code for javax.xml.ws.handler MessageContext SERVLET_REQUEST.

Click Source Link

Document

Standard property: servlet request object.

Usage

From source file:org.easyrec.soap.nodomain.impl.EasyRecSoap.java

@WebMethod
public ResponseItem view(@WebParam(name = "apikey") String apiKey, @WebParam(name = "tenantid") String tenantId,
        @WebParam(name = "userid") String userId, @WebParam(name = "sessionid") String sessionId,
        @WebParam(name = "itemid") String itemId, @WebParam(name = "itemdescription") String itemDescription,
        @WebParam(name = "itemurl") String itemUrl, @WebParam(name = "itemimageurl") String itemImageUrl,
        @WebParam(name = "actionTime") String actionTime, @WebParam(name = "itemtype") String itemType)
        throws EasyRecSoapException {

    // Collect a List of messages for the user to understand,
    // what went wrong (e.g. Wrong API key).
    List<Message> messages = new ArrayList<Message>();

    Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);

    checkParams(coreTenantId, itemId, itemDescription, itemUrl, sessionId, messages);

    Date actionDate = null;//from   w  w w  . j av  a2  s  .  c  om

    if (actionTime != null) {
        actionDate = MyUtils.dateFormatCheck(actionTime, dateFormatter);
        if (actionDate == null) {
            messages.add(MSG.DATE_PARSE);
        }
    }

    if (messages.size() > 0) {
        throw new EasyRecSoapException(messages, WS.ACTION_VIEW);
    }

    itemType = checkItemType(itemType, coreTenantId, tenantId, WS.ACTION_VIEW);
    Session session = new Session(sessionId,
            ((HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST))
                    .getRemoteAddr());

    Item item = shopRecommenderService.viewItem(remoteTenantDAO.get(coreTenantId), userId, itemId, itemType,
            itemDescription, itemUrl, itemImageUrl, actionDate, session);

    return new ResponseItem(tenantId, WS.ACTION_VIEW, userId, sessionId, null, item);

}

From source file:org.easyrec.soap.nodomain.impl.EasyRecSoap.java

public ResponseItem rate(@WebParam(name = "apikey") String apiKey, @WebParam(name = "tenantid") String tenantId,
        @WebParam(name = "userid") String userId, @WebParam(name = "sessionid") String sessionId,
        @WebParam(name = "itemid") String itemId, @WebParam(name = "ratingvalue") String ratingValue,
        @WebParam(name = "itemdescription") String itemDescription, @WebParam(name = "itemurl") String itemUrl,
        @WebParam(name = "itemimageurl") String itemImageUrl, @WebParam(name = "actionTime") String actionTime,
        @WebParam(name = "itemtype") String itemType) throws EasyRecSoapException {
    // Collect a List of messages for the user to understand,
    // what went wrong (e.g. Wrong API key).
    List<Message> messages = new ArrayList<Message>();

    Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);

    checkParams(coreTenantId, itemId, itemDescription, itemUrl, sessionId, messages);

    Date actionDate = null;// w  ww .  j  ava  2 s. c  om

    if (actionTime != null) {
        actionDate = MyUtils.dateFormatCheck(actionTime, dateFormatter);
        if (actionDate == null) {
            messages.add(MSG.DATE_PARSE);
        }
    }

    Integer rateValue = -1;
    try {
        rateValue = Integer.valueOf(ratingValue);

        if (rateValue < tenantService.getTenantById(coreTenantId).getRatingRangeMin()
                || rateValue > tenantService.getTenantById(coreTenantId).getRatingRangeMax()) {
            throw new Exception();
        }

    } catch (Exception e) {
        messages.add(MSG.ITEM_INVALID_RATING_VALUE);
    }

    if (messages.size() > 0) {

        throw new EasyRecSoapException(messages, WS.ACTION_RATE);
    }

    itemType = checkItemType(itemType, coreTenantId, tenantId, WS.ACTION_RATE);
    Session session = new Session(sessionId,
            ((HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST))
                    .getRemoteAddr());

    Item item = shopRecommenderService.rateItem(remoteTenantDAO.get(coreTenantId), userId, itemId, itemType,
            itemDescription, itemUrl, itemImageUrl, rateValue, actionDate, session);

    return new ResponseItem(tenantId, WS.ACTION_RATE, userId, sessionId, ratingValue, item);
}

From source file:org.easyrec.soap.nodomain.impl.EasyRecSoap.java

@WebMethod
public ResponseItem buy(@WebParam(name = "apikey") String apiKey, @WebParam(name = "tenantid") String tenantId,
        @WebParam(name = "userid") String userId, @WebParam(name = "sessionid") String sessionId,
        @WebParam(name = "itemid") String itemId, @WebParam(name = "itemdescription") String itemDescription,
        @WebParam(name = "itemurl") String itemUrl, @WebParam(name = "itemimageurl") String itemImageUrl,
        @WebParam(name = "actionTime") String actionTime, @WebParam(name = "itemtype") String itemType)
        throws EasyRecSoapException {
    // Collect a List of messages for the user to understand,
    // what went wrong (e.g. Wrong API key).
    List<Message> messages = new ArrayList<Message>();

    Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);

    checkParams(coreTenantId, itemId, itemDescription, itemUrl, sessionId, messages);

    Date actionDate = null;/*from w w  w. ja v  a 2 s  .c om*/

    if (actionTime != null) {
        actionDate = MyUtils.dateFormatCheck(actionTime, dateFormatter);
        if (actionDate == null) {
            messages.add(MSG.DATE_PARSE);
        }
    }

    if (messages.size() > 0) {

        throw new EasyRecSoapException(messages, WS.ACTION_BUY);
    }

    itemType = checkItemType(itemType, coreTenantId, tenantId, WS.ACTION_BUY);
    Session session = new Session(sessionId,
            ((HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST))
                    .getRemoteAddr());

    Item item = shopRecommenderService.purchaseItem(remoteTenantDAO.get(coreTenantId), userId, itemId, itemType,
            itemDescription, itemUrl, itemImageUrl, actionDate, session);

    return new ResponseItem(tenantId, WS.ACTION_BUY, userId, sessionId, null, item);
}

From source file:org.easyrec.soap.nodomain.impl.EasyRecSoap.java

@WebMethod
public ResponseItem sendAction(@WebParam(name = "apikey") String apiKey,
        @WebParam(name = "tenantid") String tenantId, @WebParam(name = "userid") String userId,
        @WebParam(name = "sessionid") String sessionId, @WebParam(name = "itemid") String itemId,
        @WebParam(name = "actiontype") String actionType, @WebParam(name = "actionvalue") String actionValue,
        @WebParam(name = "itemdescription") String itemDescription, @WebParam(name = "itemurl") String itemUrl,
        @WebParam(name = "itemimageurl") String itemImageUrl, @WebParam(name = "actionTime") String actionTime,
        @WebParam(name = "itemtype") String itemType) throws EasyRecSoapException {
    // Collect a List of messages for the user to understand,
    // what went wrong (e.g. Wrong API key).
    List<Message> messages = new ArrayList<Message>();

    Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);

    checkParams(coreTenantId, itemId, itemDescription, itemUrl, sessionId, messages);
    Integer actValue = -1;/* ww  w.j  av a  2s  .c om*/
    if (Strings.isNullOrEmpty(actionType)) {
        messages.add(MSG.MISSING_ACTIONTYPE);
    } else {
        Boolean hasValue = tenantService.hasActionValue(coreTenantId, actionType);
        if (hasValue == null) {
            messages.add(MSG.INVALID_ACTIONTYPE);
        } else {
            if (hasValue) {
                if (Strings.isNullOrEmpty(actionValue)) {
                    messages.add(MSG.MISSING_ACTION_VALUE);
                } else {
                    try {
                        actValue = Integer.valueOf(actionValue);
                    } catch (Exception e) {
                        messages.add(MSG.ITEM_INVALID_RATING_VALUE);
                    }
                }
            }
        }
    }
    Date actionDate = null;

    if (actionTime != null) {
        actionDate = MyUtils.dateFormatCheck(actionTime, dateFormatter);
        if (actionDate == null) {
            messages.add(MSG.DATE_PARSE);
        }
    }

    if (messages.size() > 0) {

        throw new EasyRecSoapException(messages, WS.ACTION_SENDACTION);
    }

    itemType = checkItemType(itemType, coreTenantId, tenantId, WS.ACTION_SENDACTION);
    Session session = new Session(sessionId,
            ((HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST))
                    .getRemoteAddr());

    Item item = shopRecommenderService.sendAction(remoteTenantDAO.get(coreTenantId), userId, itemId, itemType,
            itemDescription, itemUrl, itemImageUrl, actionType, actValue, actionDate, session);

    return new ResponseItem(tenantId, WS.ACTION_SENDACTION, userId, sessionId, null, item);
}

From source file:org.easyrec.soap.nodomain.impl.EasyRecSoap.java

@WebMethod
public Recommendation otherUsersAlsoViewed(@WebParam(name = "apikey") String apiKey,
        @WebParam(name = "tenantid") String tenantId, @WebParam(name = "userid") String userId,
        @WebParam(name = "sessionid") String sessionId, @WebParam(name = "itemid") String itemId,
        @WebParam(name = "numberOfResults") Integer numberOfResults,
        @WebParam(name = "itemtype") String itemType,
        @WebParam(name = "requesteditemtype") String requestedItemType) throws EasyRecSoapException {
    List<Message> messages = new ArrayList<Message>();
    Recommendation rec = null;//  w  w w  . j a v  a 2s. co  m

    Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);

    if (coreTenantId != null) {

        itemType = checkItemType(itemType, coreTenantId, tenantId, WS.ACTION_OTHER_USERS_ALSO_VIEWED);
        requestedItemType = checkItemType(requestedItemType, coreTenantId, tenantId,
                WS.ACTION_OTHER_USERS_ALSO_VIEWED, null);

        Session session = new Session(sessionId,
                ((HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST)));

        try {
            if ((numberOfResults == null) || (numberOfResults > WS.DEFAULT_NUMBER_OF_RESULTS)) {
                numberOfResults = WS.DEFAULT_NUMBER_OF_RESULTS;
            }

            rec = shopRecommenderService.alsoViewedItems(coreTenantId, userId, itemId, itemType,
                    requestedItemType, session, numberOfResults);
        } catch (EasyRecSoapException sre) {
            messages.add(MSG.ITEM_NOT_EXISTS);
        }

    } else {
        messages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
    }

    if (messages.size() > 0) {

        throw new EasyRecSoapException(messages, WS.ACTION_OTHER_USERS_ALSO_VIEWED);
    }

    return rec;
}

From source file:org.easyrec.soap.nodomain.impl.EasyRecSoap.java

@WebMethod
public Recommendation recommendationsForUser(@WebParam(name = "apikey") String apiKey,
        @WebParam(name = "tenantid") String tenantId, @WebParam(name = "userid") String userId,
        @WebParam(name = "numberOfResults") Integer numberOfResults,
        @WebParam(name = "requesteditemtype") String requestedItemType,
        @WebParam(name = "actiontype") String actiontype) throws EasyRecSoapException {

    Recommendation rec = null;//from  ww  w . ja va2s  . c o m
    List<Message> messages = new ArrayList<Message>();
    Session session = new Session(null,
            ((HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST)));

    Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);

    if (coreTenantId != null) {

        RemoteTenant r = remoteTenantDAO.get(coreTenantId);

        if (!Strings.isNullOrEmpty(userId)) {

            requestedItemType = checkItemType(requestedItemType, coreTenantId, tenantId,
                    WS.ACTION_RECOMMENDATIONS_FOR_USER, null);

            if (actiontype == null)
                actiontype = TypeMappingService.ACTION_TYPE_VIEW;
            if (typeMappingService.getIdOfActionType(coreTenantId, actiontype) != null) {
                try {
                    if ((numberOfResults == null) || (numberOfResults > WS.DEFAULT_NUMBER_OF_RESULTS))
                        numberOfResults = WS.DEFAULT_NUMBER_OF_RESULTS;

                    rec = shopRecommenderService.itemsBasedOnActionHistory(coreTenantId, userId, session,
                            actiontype, null, null, null, requestedItemType, numberOfResults);
                } catch (EasyRecSoapException sre) {
                    messages.add(MSG.ITEM_NOT_EXISTS);
                }
            } else {
                messages.add(MSG.OPERATION_FAILED
                        .append(String.format(" actionType %s not found for tenant %s", actiontype, tenantId)));
            }
        } else {
            messages.add(MSG.USER_NO_ID);
        }
    } else {
        messages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
    }

    if (messages.size() > 0) {

        throw new EasyRecSoapException(messages, WS.ACTION_RECOMMENDATIONS_FOR_USER);
    }

    return rec;
}

From source file:org.easyrec.soap.nodomain.impl.EasyRecSoap.java

@WebMethod
public Recommendation actionHistoryForUser(@WebParam(name = "apikey") String apiKey,
        @WebParam(name = "tenantid") String tenantId, @WebParam(name = "userid") String userId,
        @WebParam(name = "numberOfResults") Integer numberOfResults,
        @WebParam(name = "requesteditemtype") String requestedItemType,
        @WebParam(name = "actiontype") String actiontype) throws EasyRecSoapException {
    Recommendation rec = null;//from   w w  w  .  j  a v  a  2 s .c om
    List<Message> messages = new ArrayList<Message>();
    Session session = new Session(null,
            ((HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST)));

    Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);

    if (coreTenantId != null) {

        RemoteTenant r = remoteTenantDAO.get(coreTenantId);

        if (!Strings.isNullOrEmpty(userId)) {

            requestedItemType = checkItemType(requestedItemType, coreTenantId, tenantId,
                    WS.ACTION_RECOMMENDATIONS_FOR_USER, null);

            if (actiontype == null)
                actiontype = TypeMappingService.ACTION_TYPE_VIEW;
            if (typeMappingService.getIdOfActionType(coreTenantId, actiontype) != null) {
                try {
                    if ((numberOfResults == null) || (numberOfResults > WS.DEFAULT_NUMBER_OF_RESULTS))
                        numberOfResults = WS.DEFAULT_NUMBER_OF_RESULTS;

                    rec = rec = shopRecommenderService.actionHistory(coreTenantId, userId, session, actiontype,
                            requestedItemType, numberOfResults + 5, numberOfResults); // +5 to compensate for inactive items
                } catch (EasyRecSoapException sre) {
                    messages.add(MSG.OPERATION_FAILED.append("Error retrieving actionHistory for user!"));
                }
            } else {
                messages.add(MSG.OPERATION_FAILED
                        .append(String.format(" actionType %s not found for tenant %s", actiontype, tenantId)));
            }
        } else {
            messages.add(MSG.USER_NO_ID);
        }
    } else {
        messages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
    }

    if (messages.size() > 0) {

        throw new EasyRecSoapException(messages, WS.ACTION_RECOMMENDATIONS_FOR_USER);
    }

    return rec;

}

From source file:org.easyrec.soap.nodomain.impl.EasyRecSoap.java

@WebMethod
public Recommendation otherUsersAlsoBought(@WebParam(name = "apikey") String apiKey,
        @WebParam(name = "tenantid") String tenantId, @WebParam(name = "userid") String userId,
        @WebParam(name = "sessionid") String sessionId, @WebParam(name = "itemid") String itemId,
        @WebParam(name = "numberOfResults") Integer numberOfResults,
        @WebParam(name = "itemtype") String itemType,
        @WebParam(name = "requesteditemtype") String requestedItemType) throws EasyRecSoapException {
    List<Message> messages = new ArrayList<Message>();
    Recommendation rec = null;/*  ww w .  ja  v  a2  s. co m*/

    Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);

    if (coreTenantId != null) {

        itemType = checkItemType(itemType, coreTenantId, tenantId, WS.ACTION_OTHER_USERS_ALSO_VIEWED);
        requestedItemType = checkItemType(requestedItemType, coreTenantId, tenantId,
                WS.ACTION_OTHER_USERS_ALSO_VIEWED, null);

        Session session = new Session(sessionId,
                ((HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST)));

        try {
            if ((numberOfResults == null) || (numberOfResults > WS.DEFAULT_NUMBER_OF_RESULTS)) {
                numberOfResults = WS.DEFAULT_NUMBER_OF_RESULTS;
            }

            rec = shopRecommenderService.alsoBoughtItems(coreTenantId, userId, itemId, itemType,
                    requestedItemType, session, numberOfResults);
        } catch (EasyRecSoapException sre) {
            messages.add(MSG.ITEM_NOT_EXISTS);
        }

    } else {
        messages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
    }

    if (messages.size() > 0) {
        throw new EasyRecSoapException(messages, WS.ACTION_OTHER_USERS_ALSO_BOUGHT);
    }

    return rec;
}

From source file:org.easyrec.soap.nodomain.impl.EasyRecSoap.java

public Recommendation itemsRatedGoodByOtherUsers(@WebParam(name = "apikey") String apiKey,
        @WebParam(name = "tenantid") String tenantId, @WebParam(name = "userid") String userId,
        @WebParam(name = "sessionid") String sessionId, @WebParam(name = "itemid") String itemId,
        @WebParam(name = "numberOfResults") Integer numberOfResults,
        @WebParam(name = "itemtype") String itemType,
        @WebParam(name = "requesteditemtype") String requestedItemType) throws EasyRecSoapException {
    List<Message> messages = new ArrayList<Message>();
    Recommendation rec = null;/* w  w  w .j  a v a 2 s .co  m*/

    Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);

    if (coreTenantId != null) {

        itemType = checkItemType(itemType, coreTenantId, tenantId, WS.ACTION_OTHER_USERS_ALSO_VIEWED);
        requestedItemType = checkItemType(requestedItemType, coreTenantId, tenantId,
                WS.ACTION_OTHER_USERS_ALSO_VIEWED, null);

        Session session = new Session(sessionId,
                ((HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST)));

        try {
            if ((numberOfResults == null) || (numberOfResults > WS.DEFAULT_NUMBER_OF_RESULTS)) {
                numberOfResults = WS.DEFAULT_NUMBER_OF_RESULTS;
            }
            rec = shopRecommenderService.alsoGoodRatedItems(coreTenantId, userId, itemId, itemType,
                    requestedItemType, session, numberOfResults);
        } catch (EasyRecSoapException sre) {
            messages.add(MSG.ITEM_NOT_EXISTS);
        }

    } else {
        messages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
    }

    if (messages.size() > 0) {
        throw new EasyRecSoapException(messages, WS.ACTION_ITEMS_RATED_GOOD_BY_OTHER_USERS);
    }
    return rec;
}

From source file:org.easyrec.soap.nodomain.impl.EasyRecSoap.java

@WebMethod
public Recommendation mostBoughtItems(@WebParam(name = "apikey") String apiKey,
        @WebParam(name = "tenantid") String tenantId,
        @WebParam(name = "numberOfResults") Integer numberOfResults,
        @WebParam(name = "timeRange") String timeRange, @WebParam(name = "startDate") String startDate,
        @WebParam(name = "endDate") String endDate,
        @WebParam(name = "requesteditemtype") String requesteditemtype) throws EasyRecSoapException {
    List<Message> messages = new ArrayList<Message>();
    Recommendation rr = null;/*www  . j a v a  2 s .c  om*/

    Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);

    if (coreTenantId != null) {

        TimeConstraintVO tc = checkTimeConstraints(startDate, endDate, messages);
        requesteditemtype = checkItemType(requesteditemtype, coreTenantId, tenantId, WS.ACTION_MOST_BOUGHT,
                null);
        List<Item> items;

        if (tc != null) {

            Session session = new Session(null,
                    ((HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST)));

            items = shopRecommenderService.mostBoughtItems(coreTenantId, requesteditemtype, numberOfResults,
                    timeRange, tc, session);

            rr = new Recommendation(tenantId, WS.ACTION_MOST_BOUGHT, null, null, null, items);
        }

    } else {
        messages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
    }

    if (messages.size() > 0) {
        throw new EasyRecSoapException(messages, WS.ACTION_MOST_BOUGHT);
    }

    return rr;
}