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());
}
}
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;
}
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);
}
}
Aggregations