Search in sources :

Example 1 with InquiryElement

use of com.sun.identity.liberty.ws.interaction.jaxb.InquiryElement in project OpenAM by OpenRock.

the class WSPRedirectHandlerServlet method sendInteractionRequestPage.

/*
     * Constructs an HTML/WML page from InteractionQuery using 
     * an XSL stylesheet and sends the page to browser.
     */
private void sendInteractionRequestPage(String messageID, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException {
    InquiryElement inquiryElement = InteractionManager.getInstance().getInquiryElement(messageID);
    // generate html page, with action url pointing back to this servlet
    // set query parameters transID and responseID
    String wspRedirectHandler = InteractionConfig.getInstance().getWSPRedirectHandler();
    String lbWspRedirectHandler = InteractionConfig.getInstance().getLbWSPRedirectHandler();
    String action = null;
    if (lbWspRedirectHandler == null) {
        action = httpRequest.getRequestURL().toString() + "?" + InteractionManager.TRANS_ID + "=" + messageID;
    } else {
        String localServerId = InteractionConfig.getInstance().getLocalServerId();
        action = lbWspRedirectHandler + "?" + InteractionManager.TRANS_ID + "=" + messageID + "&" + InteractionConfig.HANDLER_HOST_ID + "=" + localServerId;
    }
    if (debug.messageEnabled()) {
        debug.message("WSPRedirectHandlerServlet.sendInteractionRequestPage():" + "action=" + action);
    }
    DOMSource styleSource = null;
    boolean wmlClient = isWMLClient(httpRequest);
    PrintWriter out = null;
    if (!wmlClient) {
        //not a wmlClient, assume html client
        if (debug.messageEnabled()) {
            debug.message("WSPRedirectHandlerServlet." + "sendInteractionRequestPage():" + "clientType=html");
        }
        styleSource = htmlStyleSource;
        httpResponse.setContentType("text/html");
        out = httpResponse.getWriter();
    } else {
        //a wml client
        if (debug.messageEnabled()) {
            debug.message("WSPRedirectHandlerServlet." + "sendInteractionRequestPage():" + "clientType=wml");
        }
        styleSource = wmlStyleSource;
        httpResponse.setContentType("text/vnd.wap.wml");
        out = httpResponse.getWriter();
        out.println("<?xml version=\"1.0\"?>");
        out.println("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"");
        out.println("    \"http://www.wapforum.org/DTD/wml_1.1.xml\">");
    }
    try {
        //style inquiryElement and send it to browser
        JAXBContext jaxbContext = JAXBContext.newInstance("com.sun.identity.liberty.ws.interaction.jaxb");
        Marshaller marshaller = jaxbContext.createMarshaller();
        DocumentBuilder db = XMLUtils.getSafeDocumentBuilder(false);
        Document doc = db.newDocument();
        marshaller.marshal(inquiryElement, doc);
        doc.getDocumentElement().setAttribute("action", action);
        String trueLabel = DEFAULT_TRUE_LABEL;
        String falseLabel = DEFAULT_FALSE_LABEL;
        String helpLabel = DEFAULT_HELP_LABEL;
        String hintLabel = DEFAULT_HINT_LABEL;
        String linkLabel = DEFAULT_LINK_LABEL;
        String moreLinkLabel = DEFAULT_MORE_LINK_LABEL;
        String language = InteractionManager.getInstance().getLanguage(messageID);
        if (language == null) {
            trueLabel = i18n.getString(TRUE_LABEL);
            falseLabel = i18n.getString(FALSE_LABEL);
            helpLabel = i18n.getString(HELP_LABEL);
            hintLabel = i18n.getString(HINT_LABEL);
            linkLabel = i18n.getString(LINK_LABEL);
            moreLinkLabel = i18n.getString(MORE_LINK_LABEL);
        } else {
            Locale locale = new Locale(language);
            ResourceBundle bundle = ResourceBundle.getBundle("libInteraction", locale);
            trueLabel = bundle.getString(TRUE_LABEL);
            falseLabel = bundle.getString(FALSE_LABEL);
            helpLabel = bundle.getString(HELP_LABEL);
            hintLabel = bundle.getString(HINT_LABEL);
            linkLabel = bundle.getString(LINK_LABEL);
            moreLinkLabel = bundle.getString(MORE_LINK_LABEL);
        }
        Element documentElement = doc.getDocumentElement();
        documentElement.setAttribute(TRUE_LABEL, trueLabel);
        documentElement.setAttribute(FALSE_LABEL, falseLabel);
        documentElement.setAttribute(HELP_LABEL, helpLabel);
        documentElement.setAttribute(HINT_LABEL, hintLabel);
        documentElement.setAttribute(LINK_LABEL, linkLabel);
        documentElement.setAttribute(MORE_LINK_LABEL, moreLinkLabel);
        TransformerFactory transformerFactory = XMLUtils.getTransformerFactory();
        DOMSource domSource = new DOMSource(doc);
        StreamResult streamResult = new StreamResult(out);
        Transformer transformer = transformerFactory.newTransformer(styleSource);
        transformer.transform(domSource, streamResult);
        if (LogUtil.isLogEnabled()) {
            String[] objs = new String[1];
            objs[0] = messageID;
            LogUtil.access(Level.INFO, LogUtil.IS_PRESENTED_QUERY_TO_USER_AGENT, objs);
        }
    } catch (JAXBException je) {
        debug.error("WSPRedirectHandlerServlet.sendInteractionRequestPage():" + "catching JAXBException =", je);
        showErrorPage(httpRequest, httpResponse, "Error creating JAXBObject:" + je.getMessage());
    } catch (ParserConfigurationException pce) {
        debug.error("WSPRedirectHandlerServlet.sendInteractionRequestPage():" + "catching ParserConfigurationException =", pce);
        showErrorPage(httpRequest, httpResponse, "Error creating interaction request page:" + pce.getMessage());
    } catch (TransformerException tce) {
        debug.error("WSPRedirectHandlerServlet.sendInteractionRequestPage():" + "catching TransformerException =", tce);
        showErrorPage(httpRequest, httpResponse, "Error creating interaction request page:" + tce.getMessage());
    }
}
Also used : Locale(java.util.Locale) DOMSource(javax.xml.transform.dom.DOMSource) Marshaller(javax.xml.bind.Marshaller) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) InquiryElement(com.sun.identity.liberty.ws.interaction.jaxb.InquiryElement) Element(org.w3c.dom.Element) InteractionResponseElement(com.sun.identity.liberty.ws.interaction.jaxb.InteractionResponseElement) JAXBException(javax.xml.bind.JAXBException) InquiryElement(com.sun.identity.liberty.ws.interaction.jaxb.InquiryElement) JAXBContext(javax.xml.bind.JAXBContext) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ResourceBundle(java.util.ResourceBundle) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerException(javax.xml.transform.TransformerException) PrintWriter(java.io.PrintWriter)

Example 2 with InquiryElement

use of com.sun.identity.liberty.ws.interaction.jaxb.InquiryElement in project OpenAM by OpenRock.

the class InteractionManager method getInquiryElement.

InquiryElement getInquiryElement(String messageID) {
    InquiryElement inquiryElement = null;
    CacheEntry cacheEntry = cache.getCacheEntry(messageID);
    if (cacheEntry != null) {
        inquiryElement = cacheEntry.getInquiryElement();
    }
    return inquiryElement;
}
Also used : InquiryElement(com.sun.identity.liberty.ws.interaction.jaxb.InquiryElement)

Example 3 with InquiryElement

use of com.sun.identity.liberty.ws.interaction.jaxb.InquiryElement in project OpenAM by OpenRock.

the class PPRequestHandler method initInteraction.

/**
     * Initialize interaction for the queries that require interaction
     * @param isQuery true if this is a <code>PP</code> query request, 
     *                false if this is a <code>PP</code> modify request.
     * @param interactResourceMap map of resources that need an interaction
     *                            This map will have key as the resource
     *                            and the value as interaction type. 
     * @param msg SOAP request message
     * @exception SOAPFaultException for interaction redirection
     * @exception IDPPException for any other failure.
     */
private void initInteraction(boolean isQuery, Map interactResourceMap, Message msg) throws SOAPFaultException, IDPPException {
    IDPPUtils.debug.message("PPRequestHandler.initInteraction:Init");
    if (msg == null || interactResourceMap == null || interactResourceMap.isEmpty()) {
        IDPPUtils.debug.error("PPRequestHandler.initInteraction:Null" + "Input parameters");
        throw new IDPPException(IDPPUtils.bundle.getString("nullInputParams"));
    }
    try {
        //Create Interaction inquiry element
        InquiryElement inquiry = JAXBObjectFactory.getObjectFactory().createInquiryElement();
        inquiry.setTitle(IDPPUtils.bundle.getString(IDPPConstants.INTERACTION_TITLE));
        List selectElements = inquiry.getSelectOrConfirmOrText();
        Set inquirySelects = interactResourceMap.keySet();
        Iterator iter = inquirySelects.iterator();
        while (iter.hasNext()) {
            String resource = (String) iter.next();
            String interactionType = (String) interactResourceMap.get(resource);
            if (interactionType.equals(IDPPConstants.INTERACT_FOR_CONSENT)) {
                selectElements.add(getInteractConfirmElement(isQuery, resource, msg));
            } else if (interactionType.equals(IDPPConstants.INTERACT_FOR_VALUE)) {
                selectElements.addAll(getInteractTextElements(isQuery, resource, msg));
            }
        }
        String lang = getLanguage(msg);
        if (LogUtil.isLogEnabled()) {
            String[] data = { logMsg };
            LogUtil.access(Level.INFO, LogUtil.PP_INTERACTION_SUCCESS, data);
        }
        InteractionManager.getInstance().handleInteraction(msg, inquiry, lang);
    } catch (InteractionSOAPFaultException ise) {
        if (IDPPUtils.debug.messageEnabled()) {
            IDPPUtils.debug.message("PPRequestHandler.initInteraction:" + "Interact redirection happened");
        }
        throw ise.getSOAPFaultException();
    } catch (Exception ex) {
        IDPPUtils.debug.error("PPRequestHandler.initInteraction:Failed");
        throw new IDPPException(ex);
    }
}
Also used : Set(java.util.Set) InquiryElement(com.sun.identity.liberty.ws.interaction.jaxb.InquiryElement) Iterator(java.util.Iterator) InteractionSOAPFaultException(com.sun.identity.liberty.ws.interaction.InteractionSOAPFaultException) ArrayList(java.util.ArrayList) List(java.util.List) SOAPFaultException(com.sun.identity.liberty.ws.soapbinding.SOAPFaultException) SOAPBindingException(com.sun.identity.liberty.ws.soapbinding.SOAPBindingException) JAXBException(javax.xml.bind.JAXBException) DSTException(com.sun.identity.liberty.ws.dst.DSTException) InteractionSOAPFaultException(com.sun.identity.liberty.ws.interaction.InteractionSOAPFaultException)

Aggregations

InquiryElement (com.sun.identity.liberty.ws.interaction.jaxb.InquiryElement)3 JAXBException (javax.xml.bind.JAXBException)2 DSTException (com.sun.identity.liberty.ws.dst.DSTException)1 InteractionSOAPFaultException (com.sun.identity.liberty.ws.interaction.InteractionSOAPFaultException)1 InteractionResponseElement (com.sun.identity.liberty.ws.interaction.jaxb.InteractionResponseElement)1 SOAPBindingException (com.sun.identity.liberty.ws.soapbinding.SOAPBindingException)1 SOAPFaultException (com.sun.identity.liberty.ws.soapbinding.SOAPFaultException)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Locale (java.util.Locale)1 ResourceBundle (java.util.ResourceBundle)1 Set (java.util.Set)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Transformer (javax.xml.transform.Transformer)1 TransformerException (javax.xml.transform.TransformerException)1