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 Recommendation mostViewedItems(@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;/*from  w  w  w.jav a  2s  .c  o  m*/

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

    if (coreTenantId != null) {

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

        if (tc != null) {

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

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

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

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

    if (messages.size() > 0) {

        throw new EasyRecSoapException(messages, WS.ACTION_MOST_VIEWED);
    }
    return rr;
}

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

@WebMethod
public Recommendation mostRatedItems(@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;/*  w  w w . ja va2s . c o  m*/

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

    if (coreTenantId != null) {

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

        if (tc != null) {

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

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

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

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

    if (messages.size() > 0) {

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

    return rr;
}

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

@WebMethod
public Recommendation bestRatedItems(@WebParam(name = "apikey") String apiKey,
        @WebParam(name = "tenantid") String tenantId, @WebParam(name = "userid") String userId,
        @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;//from w w w .  jav a2  s  . c  o m

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

    if (coreTenantId != null) {

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

        if (tc != null) {

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

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

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

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

    if (messages.size() > 0) {

        throw new EasyRecSoapException(messages, WS.ACTION_BEST_RATED);
    }
    return rr;
}

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

@WebMethod
public Recommendation worstRatedItems(@WebParam(name = "apikey") String apiKey,
        @WebParam(name = "tenantid") String tenantId, @WebParam(name = "userid") String userId,
        @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;//  w w  w.  j  a v  a 2s. c o m

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

    if (coreTenantId != null) {

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

        if (tc != null) {

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

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

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

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

    if (messages.size() > 0) {

        throw new EasyRecSoapException(messages, WS.ACTION_WORST_RATED);
    }
    return rr;
}

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

@WebMethod
public Recommendation relatedItems(@WebParam(name = "apikey") String apiKey,
        @WebParam(name = "tenantid") String tenantId, @WebParam(name = "assoctype") String assocType,
        @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 rr = null;/*from w ww.j av a2  s .  co  m*/

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

    if (coreTenantId != null) {

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

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

        RemoteTenant r = remoteTenantDAO.get(coreTenantId);
        if (!r.getPluginsEnabled()) {
            messages.add(MSG.PLUGIN_NOT_INSTALLED);
        }

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

                rr = shopRecommenderService.relatedItems(coreTenantId, assocType, null, //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_RELATED_ITEMS);
    }

    return rr;

}

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

@WebMethod
public Recommendation getItemsOfCluster(@WebParam(name = "apikey") String apiKey,
        @WebParam(name = "tenantid") String tenantId, @WebParam(name = "clusterid") String clusterId,
        @WebParam(name = "numberOfResults") Integer numberOfResults,
        @WebParam(name = "strategy") String strategy, @WebParam(name = "usefallback") Boolean useFallback,
        @WebParam(name = "requesteditemtype") String requestedItemType) throws EasyRecSoapException {

    List<Message> messages = new ArrayList<Message>();
    Recommendation recommendation = null;
    Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);

    if (coreTenantId != null) {

        RemoteTenant remoteTenant = remoteTenantDAO.get(coreTenantId);

        if (clusterId != null) {

            requestedItemType = checkItemType(requestedItemType, coreTenantId, tenantId,
                    WS.ACTION_ITEMS_OF_CLUSTER, null);
            Session session = new Session(null,
                    ((HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST)));
            List<Item> items;
            try {
                Integer coreItemType = typeMappingService.getIdOfItemType(coreTenantId, requestedItemType);
                if (useFallback == null)
                    useFallback = false;
                items = shopRecommenderService.itemsOfCluster(coreTenantId, clusterId,
                        numberOfResults != null ? numberOfResults : WS.DEFAULT_NUMBER_OF_RESULTS, strategy,
                        useFallback, coreItemType, session);

                recommendation = new Recommendation(tenantId, WS.ACTION_ITEMS_OF_CLUSTER, null, null, null,
                        items);// ww  w. j  a va  2 s .  c o  m
            } catch (EasyRecSoapException sre) {
                messages.add(sre.getMessageObject());
            }
            return recommendation;
        } else {
            messages.add(MSG.CLUSTER_NO_ID);
        }
    } else {
        messages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
    }

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

    return recommendation;
}

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

private Integer authenticate(String tenant) throws EasyRecSoapException {
    try {//from w ww  .  j  a  va2 s.com
        MessageContext mc = wsContext.getMessageContext();
        HttpServletRequest req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST);
        //logger.info("Request from: " + getRequestIP() + "/" + getRequestHost());
        Integer tenantId = authenticationDispatcher.authenticateTenant(tenant, serviceName, req);
        if (tenantId == null) {
            throw new EasyRecSoapException("Unauthorized access!");
        }
        return tenantId;
    } catch (Exception e) {
        throw new EasyRecSoapException(e.getMessage());
    }
}

From source file:org.ejbca.core.protocol.ws.EjbcaWS.java

private void logAdminName(final AuthenticationToken admin, final IPatternLogger logger) {
    // Log certificate info
    final X509Certificate cert = ((X509CertificateAuthenticationToken) admin).getCertificate();
    logger.paramPut(TransactionTags.ADMIN_DN.toString(), cert.getSubjectDN().toString());
    logger.paramPut(TransactionTags.ADMIN_ISSUER_DN.toString(), cert.getIssuerDN().toString());

    // Log IP address
    MessageContext msgctx = wsContext.getMessageContext();
    HttpServletRequest request = (HttpServletRequest) msgctx.get(MessageContext.SERVLET_REQUEST);
    logger.paramPut(TransactionTags.ADMIN_REMOTE_IP.toString(), request.getRemoteAddr());
    String addr = request.getHeader("X-Forwarded-For");
    if (addr != null)
        addr = addr.replaceAll("[^a-zA-Z0-9.:-_]", "?");
    logger.paramPut(TransactionTags.ADMIN_FORWARDED_IP.toString(), addr);
}

From source file:org.idempiere.webservices.AbstractService.java

/**
 * Get HttpServletRequest object/*www .jav a2  s  .c o  m*/
 * @return HttpServletRequest
 */
private HttpServletRequest getHttpServletRequest() {
    HttpServletRequest req;
    if (jaxrsContext != null) {
        req = (HttpServletRequest) jaxrsContext.getHttpServletRequest();
    } else
        req = (HttpServletRequest) jaxwsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST);
    return req;
}

From source file:org.nuxeo.ecm.core.opencmis.bindings.NuxeoCmisAuthHandler.java

@Override
public boolean handleMessage(SOAPMessageContext context) {
    boolean res = super.handleMessage(context);

    HttpServletRequest request = (HttpServletRequest) context.get(MessageContext.SERVLET_REQUEST);
    request.setAttribute(CmisWebServicesServlet.CMIS_VERSION, CmisVersion.CMIS_1_1);

    @SuppressWarnings("unchecked")
    Map<String, String> callContextMap = (Map<String, String>) context.get(AbstractService.CALL_CONTEXT_MAP);
    if (callContextMap != null) {
        // login to Nuxeo
        String username = callContextMap.get(CallContext.USERNAME);
        String password = callContextMap.get(CallContext.PASSWORD);
        try {//w ww  .j a  v  a2s. c o  m
            LoginContext loginContext = getLoginProvider().login(username, password);
            // store in message context, for later logout
            context.put(NUXEO_LOGIN_CONTEXT, loginContext);
            context.setScope(NUXEO_LOGIN_CONTEXT, Scope.APPLICATION);
        } catch (LoginException e) {
            throw new RuntimeException("Login failed for user '" + username + "'", e);
        }
    }
    return res;
}