Repository: juddi Updated Branches: refs/heads/master c0354a44f -> e06b6c55f
JUDDI-923 changing the way errors are handled from the admin console. adding ui bits for failed replication updates Project: http://git-wip-us.apache.org/repos/asf/juddi/repo Commit: http://git-wip-us.apache.org/repos/asf/juddi/commit/e06b6c55 Tree: http://git-wip-us.apache.org/repos/asf/juddi/tree/e06b6c55 Diff: http://git-wip-us.apache.org/repos/asf/juddi/diff/e06b6c55 Branch: refs/heads/master Commit: e06b6c55fea323bb99d80f763cbad667f24604d4 Parents: c0354a4 Author: Alex <[email protected]> Authored: Thu Jan 29 14:15:27 2015 -0500 Committer: Alex <[email protected]> Committed: Thu Jan 29 14:15:27 2015 -0500 ---------------------------------------------------------------------- .../juddi/adminconsole/hub/UddiAdminHub.java | 231 ++++++++++++------- juddiv3-war/src/main/webapp/admin/admin.jsp | 36 ++- juddiv3-war/src/main/webapp/admin/ajax/go.jsp | 2 - 3 files changed, 183 insertions(+), 86 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/juddi/blob/e06b6c55/juddiv3-war/src/main/java/org/apache/juddi/adminconsole/hub/UddiAdminHub.java ---------------------------------------------------------------------- diff --git a/juddiv3-war/src/main/java/org/apache/juddi/adminconsole/hub/UddiAdminHub.java b/juddiv3-war/src/main/java/org/apache/juddi/adminconsole/hub/UddiAdminHub.java index 9a472fd..01e3503 100644 --- a/juddiv3-war/src/main/java/org/apache/juddi/adminconsole/hub/UddiAdminHub.java +++ b/juddiv3-war/src/main/java/org/apache/juddi/adminconsole/hub/UddiAdminHub.java @@ -88,6 +88,8 @@ import org.apache.juddi.api_v3.DeleteClerk; import org.apache.juddi.api_v3.DeleteNode; import org.apache.juddi.api_v3.GetEntityHistoryMessageRequest; import org.apache.juddi.api_v3.GetEntityHistoryMessageResponse; +import org.apache.juddi.api_v3.GetFailedReplicationChangeRecordsMessageRequest; +import org.apache.juddi.api_v3.GetFailedReplicationChangeRecordsMessageResponse; import org.apache.juddi.api_v3.NodeList; import org.apache.juddi.api_v3.SubscriptionWrapper; import org.apache.juddi.config.AppConfig; @@ -310,7 +312,7 @@ public class UddiAdminHub { DispositionReportFaultMessage f = (DispositionReportFaultMessage) ex; log.error(ex.getMessage() + (f.detail != null && f.detail.getMessage() != null ? StringEscapeUtils.escapeHtml(f.detail.getMessage()) : "")); log.debug(ex.getMessage(), ex); - return ResourceLoader.GetResource(session, "errors.uddi") + " " + StringEscapeUtils.escapeHtml(ex.getMessage()) + " " + (f.detail != null && f.detail.getMessage() != null ? StringEscapeUtils.escapeHtml(f.detail.getMessage()) : ""); + return ResourceLoader.GetResource(session, "errors.generic") + " " + StringEscapeUtils.escapeHtml(ex.getMessage()) + " " + (f.detail != null && f.detail.getMessage() != null ? StringEscapeUtils.escapeHtml(f.detail.getMessage()) : ""); } else if (ex instanceof RemoteException) { RemoteException f = (RemoteException) ex; log.error("RemoteException " + ex.getMessage()); @@ -410,6 +412,8 @@ public class UddiAdminHub { return change_NodeID(parameters); } else if (action.equalsIgnoreCase("changeRecord")) { return getChangeRecord(parameters); + } else if (action.equalsIgnoreCase("getFailedReplicationChangeRecords")) { + return getFailedReplicationChangeRecords(parameters); } } catch (Exception ex) { @@ -542,9 +546,12 @@ public class UddiAdminHub { return HandleException(ex); } } - StringWriter sw = new StringWriter(); - JAXB.marshal(allNodes, sw); - return StringEscapeUtils.escapeHtml(sw.toString()); + try { + return PrettyPrintJaxbObject(allNodes); + } catch (Exception ex) { + return HandleException(ex); + } + } private String getAllClerks(HttpServletRequest parameters) { @@ -565,9 +572,11 @@ public class UddiAdminHub { return HandleException(ex); } } - StringWriter sw = new StringWriter(); - JAXB.marshal(allNodes, sw); - return StringEscapeUtils.escapeHtml(sw.toString()); + try { + return PrettyPrintJaxbObject(allNodes); + } catch (Exception ex) { + return HandleException(ex); + } } private String getAllClientSubscriptionInfo(HttpServletRequest parameters) { @@ -588,9 +597,11 @@ public class UddiAdminHub { return HandleException(ex); } } - StringWriter sw = new StringWriter(); - JAXB.marshal(allClientSubscriptionInfo, sw); - return StringEscapeUtils.escapeHtml(sw.toString()); + try { + return PrettyPrintJaxbObject(allClientSubscriptionInfo); + } catch (Exception ex) { + return HandleException(ex); + } } private String getReplicationNodes(HttpServletRequest parameters) { @@ -611,9 +622,11 @@ public class UddiAdminHub { return HandleException(ex); } } - StringWriter sw = new StringWriter(); - JAXB.marshal(cfg, sw); - return StringEscapeUtils.escapeHtml(sw.toString()); + try { + return PrettyPrintJaxbObject(cfg); + } catch (Exception ex) { + return HandleException(ex); + } } private String deleteNode(HttpServletRequest parameters) { @@ -708,9 +721,11 @@ public class UddiAdminHub { return HandleException(ex); } } - StringWriter sw = new StringWriter(); - JAXB.marshal(setReplicationNodes, sw); - return StringEscapeUtils.escapeHtml(sw.toString()); + try { + return PrettyPrintJaxbObject(setReplicationNodes); + } catch (Exception ex) { + return HandleException(ex); + } } private String adminSaveBusiness(HttpServletRequest parameters) { @@ -733,9 +748,11 @@ public class UddiAdminHub { return HandleException(ex); } } - StringWriter sw = new StringWriter(); - JAXB.marshal(setReplicationNodes, sw); - return StringEscapeUtils.escapeHtml(sw.toString()); + try { + return PrettyPrintJaxbObject(setReplicationNodes); + } catch (Exception ex) { + return HandleException(ex); + } } private String adminSaveTmodel(HttpServletRequest parameters) { @@ -759,9 +776,11 @@ public class UddiAdminHub { return HandleException(ex); } } - StringWriter sw = new StringWriter(); - JAXB.marshal(setReplicationNodes, sw); - return StringEscapeUtils.escapeHtml(sw.toString()); + try { + return PrettyPrintJaxbObject(setReplicationNodes); + } catch (Exception ex) { + return HandleException(ex); + } } private String adminSaveSubscription(HttpServletRequest parameters) { @@ -787,9 +806,11 @@ public class UddiAdminHub { } AdminSaveSubscriptionResponse res = new AdminSaveSubscriptionResponse(); res.getSubscriptions().addAll(holder.value); - StringWriter sw = new StringWriter(); - JAXB.marshal(res, sw); - return StringEscapeUtils.escapeHtml(sw.toString()); + try { + return PrettyPrintJaxbObject(res); + } catch (Exception ex) { + return HandleException(ex); + } } private String getEntityHistory(HttpServletRequest parameters) { @@ -818,9 +839,12 @@ public class UddiAdminHub { if (entityHistory == null) { return "Something went wrong!"; } - StringWriter sw = new StringWriter(); - JAXB.marshal(entityHistory, sw); - return StringEscapeUtils.escapeHtml(sw.toString()); + try { + return PrettyPrintJaxbObject(entityHistory); + } catch (Exception ex) { + return HandleException(ex); + } + } private String change_NodeID(HttpServletRequest parameters) { @@ -933,25 +957,66 @@ public class UddiAdminHub { new ChangeRecordIDType(parameters.getParameter("nodeid"), Long.parseLong(parameters.getParameter("recordid")))); ChangeRecords changeRecords = new UDDIReplicationImpl().getChangeRecords(req); + return PrettyPrintJaxbObject(changeRecords); + + } catch (Exception ex) { + return HandleException(ex); + } + } - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - StringWriter sw = new StringWriter(); - JAXB.marshal(changeRecords, sw); - InputSource is = new InputSource(new StringReader(sw.toString())); + /** + * returns html/xml escaped, pretty printed pre formated xml string + * + * @param jaxb + * @return + * @throws Exception + */ + private String PrettyPrintJaxbObject(Object jaxb) throws Exception { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + StringWriter sw = new StringWriter(); + JAXB.marshal(jaxb, sw); + InputSource is = new InputSource(new StringReader(sw.toString())); + + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + //initialize StreamResult with File object to save to file + StreamResult result = new StreamResult(new StringWriter()); + Document document = db.parse(is); + DOMSource source = new DOMSource(document); + transformer.transform(source, result); + String xmlString = result.getWriter().toString(); + + return "<pre>" + StringEscapeUtils.escapeXml(xmlString) + "</pre>"; + } - Transformer transformer = TransformerFactory.newInstance().newTransformer(); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - //initialize StreamResult with File object to save to file - StreamResult result = new StreamResult(new StringWriter()); - Document document = db.parse(is); - DOMSource source = new DOMSource(document); - transformer.transform(source, result); - String xmlString = result.getWriter().toString(); - //System.out.println(xmlString); + private String getFailedReplicationChangeRecords(HttpServletRequest parameters) { + try { + + GetFailedReplicationChangeRecordsMessageRequest req = new GetFailedReplicationChangeRecordsMessageRequest(); + req.setAuthInfo(GetToken()); + req.setMaxRecords(Integer.parseInt(parameters.getParameter("getFailedReplicationChangeRecordsMaxCount"))); + req.setOffset(0); + req.setOffset(Integer.parseInt(parameters.getParameter("getFailedReplicationChangeRecordsOffset"))); + GetFailedReplicationChangeRecordsMessageResponse failedReplicationChangeRecords = null; + try { + failedReplicationChangeRecords = juddi.getFailedReplicationChangeRecords(req); + } catch (Exception ex) { + if (isExceptionExpiration(ex)) { + token = null; + req.setAuthInfo(GetToken()); + try { + failedReplicationChangeRecords = juddi.getFailedReplicationChangeRecords(req); + } catch (Exception ex1) { + return "Error!" + HandleException(ex1); + } + + } else { + return "Error!" + HandleException(ex); + } + } - // JAXB.marshal(changeRecords, sw); - return "<pre>"+StringEscapeUtils.escapeXml(xmlString) + "</pre>"; + return PrettyPrintJaxbObject(failedReplicationChangeRecords); } catch (Exception ex) { return HandleException(ex); } @@ -1153,11 +1218,12 @@ public class UddiAdminHub { } } if (d != null) { - ret.append("<pre>"); - StringWriter sw = new StringWriter(); - JAXB.marshal(d, sw); - sw.append(PrettyPrintXML(sw.toString())); - ret.append("</pre>"); + try { + ret.append(PrettyPrintJaxbObject(d)); + } catch (Exception ex) { + return HandleException(ex); + } + } else { ret.append("No data returned"); } @@ -1179,7 +1245,7 @@ public class UddiAdminHub { return null; } - public static String getSampleSave_ClientSubscriptionInfo() { + public String getSampleSave_ClientSubscriptionInfo() { SaveClientSubscriptionInfo x = new SaveClientSubscriptionInfo(); x.setAuthInfo(""); x.getClientSubscriptionInfo().add(new ClientSubscriptionInfo()); @@ -1252,11 +1318,12 @@ public class UddiAdminHub { } } if (d != null) { - ret.append("<pre>"); - StringWriter sw = new StringWriter(); - JAXB.marshal(d, sw); - sw.append(PrettyPrintXML(sw.toString())); - ret.append("</pre>"); + try { + ret.append(PrettyPrintJaxbObject(d)); + } catch (Exception ex) { + return HandleException(ex); + } + } else { ret.append("No data returned"); } @@ -1491,22 +1558,23 @@ public class UddiAdminHub { public String SendAdvanced(Object request, String method) { StringWriter sw = new StringWriter(); + Object result=null; try { if (method.equalsIgnoreCase("save_ClientSubscriptionInfo")) { SaveClientSubscriptionInfo x = (SaveClientSubscriptionInfo) request; x.setAuthInfo(GetToken()); ClientSubscriptionInfoDetail saveClientSubscriptionInfo = null; try { - saveClientSubscriptionInfo = juddi.saveClientSubscriptionInfo(x); + result = juddi.saveClientSubscriptionInfo(x); sw.append("Success:<br>"); - JAXB.marshal(saveClientSubscriptionInfo, sw); + //JAXB.marshal(saveClientSubscriptionInfo, sw); } catch (Exception ex) { if (isExceptionExpiration(ex)) { token = null; x.setAuthInfo(GetToken()); - saveClientSubscriptionInfo = juddi.saveClientSubscriptionInfo(x); + result = juddi.saveClientSubscriptionInfo(x); sw.append("Success:<br>"); - JAXB.marshal(saveClientSubscriptionInfo, sw); + //JAXB.marshal(saveClientSubscriptionInfo, sw); } else { throw ex; @@ -1519,16 +1587,16 @@ public class UddiAdminHub { x.setAuthInfo(GetToken()); SyncSubscriptionDetail invokeSyncSubscription = null; try { - invokeSyncSubscription = juddi.invokeSyncSubscription(x); + result = juddi.invokeSyncSubscription(x); sw.append("Success:<br>"); - JAXB.marshal(invokeSyncSubscription, sw); + //JAXB.marshal(invokeSyncSubscription, sw); } catch (Exception ex) { if (isExceptionExpiration(ex)) { token = null; x.setAuthInfo(GetToken()); - invokeSyncSubscription = juddi.invokeSyncSubscription(x); + result = juddi.invokeSyncSubscription(x); sw.append("Success:<br>"); - JAXB.marshal(invokeSyncSubscription, sw); + //JAXB.marshal(invokeSyncSubscription, sw); } else { throw ex; @@ -1542,17 +1610,17 @@ public class UddiAdminHub { DispositionReport adminSaveBusiness = null; try { - adminSaveBusiness = juddi.adminSaveBusiness(GetToken(), x.getValues()); + result = juddi.adminSaveBusiness(GetToken(), x.getValues()); sw.append("Success:<br>"); - JAXB.marshal(adminSaveBusiness, sw); + //JAXB.marshal(adminSaveBusiness, sw); } catch (Exception ex) { if (isExceptionExpiration(ex)) { token = null; x.setAuthInfo(GetToken()); - adminSaveBusiness = juddi.adminSaveBusiness(GetToken(), x.getValues()); + result = juddi.adminSaveBusiness(GetToken(), x.getValues()); sw.append("Success:<br>"); - JAXB.marshal(adminSaveBusiness, sw); + // JAXB.marshal(adminSaveBusiness, sw); } else { throw ex; @@ -1564,17 +1632,17 @@ public class UddiAdminHub { DispositionReport adminSaveTModel = null; try { - adminSaveTModel = juddi.adminSaveTModel(GetToken(), x.getValues()); + result = juddi.adminSaveTModel(GetToken(), x.getValues()); sw.append("Success:<br>"); - JAXB.marshal(adminSaveTModel, sw); + //JAXB.marshal(adminSaveTModel, sw); } catch (Exception ex) { if (isExceptionExpiration(ex)) { token = null; x.setAuthInfo(GetToken()); - adminSaveTModel = juddi.adminSaveTModel(GetToken(), x.getValues()); + result = juddi.adminSaveTModel(GetToken(), x.getValues()); sw.append("Success:<br>"); - JAXB.marshal(adminSaveTModel, sw); + //JAXB.marshal(adminSaveTModel, sw); } else { throw ex; @@ -1589,14 +1657,14 @@ public class UddiAdminHub { try { juddi.adminSaveSubscription(GetToken(), x.getPublisherOrUsername(), holder); sw.append("Success:<br>"); - JAXB.marshal(holder, sw); + result=holder; } catch (Exception ex) { if (isExceptionExpiration(ex)) { token = null; juddi.adminSaveSubscription(GetToken(), x.getPublisherOrUsername(), holder); sw.append("Success:<br>"); - JAXB.marshal(holder, sw); + result=holder; } else { throw ex; @@ -1607,16 +1675,16 @@ public class UddiAdminHub { ReplicationConfiguration x = (ReplicationConfiguration) request; // Holder<List<Subscription>> holder = new Holder<List<Subscription>>(x.getSubscriptions()); try { - DispositionReport setReplicationNodes = juddi.setReplicationNodes(GetToken(), x); + result = juddi.setReplicationNodes(GetToken(), x); sw.append("Success:<br>"); - JAXB.marshal(setReplicationNodes, sw); + // JAXB.marshal(setReplicationNodes, sw); } catch (Exception ex) { if (isExceptionExpiration(ex)) { token = null; - DispositionReport setReplicationNodes = juddi.setReplicationNodes(GetToken(), x); + result = juddi.setReplicationNodes(GetToken(), x); sw.append("Success:<br>"); - JAXB.marshal(setReplicationNodes, sw); + //JAXB.marshal(setReplicationNodes, sw); } else { throw ex; @@ -1627,7 +1695,14 @@ public class UddiAdminHub { } catch (Exception ex) { return HandleException(ex); } - return null; + if (result!=null){ + try { + return sw.toString() + "<br>" + PrettyPrintJaxbObject(result); + } catch (Exception ex) { + return HandleException(ex); + } + } + return "Error! no work was done?"; } http://git-wip-us.apache.org/repos/asf/juddi/blob/e06b6c55/juddiv3-war/src/main/webapp/admin/admin.jsp ---------------------------------------------------------------------- diff --git a/juddiv3-war/src/main/webapp/admin/admin.jsp b/juddiv3-war/src/main/webapp/admin/admin.jsp index d810025..bbc4bd5 100644 --- a/juddiv3-war/src/main/webapp/admin/admin.jsp +++ b/juddiv3-war/src/main/webapp/admin/admin.jsp @@ -87,6 +87,7 @@ <option>get_ReplicationNodes</option> <option>get_EntityHistory</option> <option>change_NodeID</option> + <option>getFailedReplicationChangeRecords</option> <option>------ Backup/Restore Management -----</option> <option>admin_SaveBusiness</option> @@ -120,7 +121,7 @@ </div> <div id="save_ClientSubscriptionInfo" style="display:none"> <%=ResourceLoader.GetResource(session, "items.noauthtoken")%><br> - <textarea rows="4" cols="80" id="ClientSubscriptionInfoDetailXML" class="forminput" placeholder="Enter subscription XML"><%=StringEscapeUtils.escapeHtml(UddiAdminHub.getSampleSave_ClientSubscriptionInfo())%></textarea> + <textarea rows="4" cols="80" id="ClientSubscriptionInfoDetailXML" class="forminput" placeholder="Enter subscription XML"><%=StringEscapeUtils.escapeHtml(x.getSampleSave_ClientSubscriptionInfo())%></textarea> </div> <div id="save_publisher" style="display:none"> <%=ResourceLoader.GetResource(session, "items.name")%> <input type="text" id="savePublisherNAME" class="forminput" placeholder="Enter name"><br> @@ -239,11 +240,16 @@ Note: Depending on how jUDDI was deployed, you may have to manually edit the juddiv3.xml config file, then restart jUDDI after this process is complete.<br><br> New Node ID <input type="text" id="change_NodeIDKey" class="forminput" placeholder="Node ID" value="<%=StringEscapeUtils.escapeHtml( AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID))%>"><br> </div> + <div id="getFailedReplicationChangeRecords" style="display:none"> + Records to fetch <input type="text" id="getFailedReplicationChangeRecordsMaxCount" class="forminput" value="5"><br> + Offset <input type="text" id="getFailedReplicationChangeRecordsOffset" class="forminput" value="0"><br> + </div> </div> + <script type="text/javascript"> function toggledivs() { @@ -275,6 +281,7 @@ $("#admin_SaveSubscription").hide(); $("#get_EntityHistory").hide(); $("#change_NodeID").hide(); + $("#getFailedReplicationChangeRecords").hide(); $("#" + x).show(); @@ -314,7 +321,7 @@ data: postbackdata }); - + $("#resultsDiv").html(""); request.done(function(msg) { window.console && console.log('postback done ' + url); //trim it @@ -330,6 +337,7 @@ } toggledivs();//run when the page loads function submitform() { + $("#resultsDiv").val("Please wait..."); var url = 'ajax/go.jsp'; var postbackdata = new Array(); @@ -380,8 +388,15 @@ request.done(function(msg) { window.console && console.log('postback done ' + url); - $("#adminresults").html(msg); - $('#adminresultsmodal').modal(); + if (StringStartsWith(msg.trim(),"Error")){ + $("#adminresults").html(msg); + $('#adminresultsmodal').modal(); + } + else + { + $("#resultsDiv").html(msg); + location.hash = "#resultsAnchor"; + } }); request.fail(function(jqXHR, textStatus) { @@ -391,13 +406,22 @@ }); } + + function StringStartsWith(source, str){ + + return source.slice(0, str.length) == str; + + } </script> <br> <%=ResourceLoader.GetResource(session, "pages.admin.notes")%> <br> - <a href="javascript:submitform();" class="btn btn-primary"><%=ResourceLoader.GetResource(session, "actions.go")%></a><br><br> - <br> + <a href="javascript:submitform();" class="btn btn-primary"><%=ResourceLoader.GetResource(session, "actions.go")%></a><br> + + <hr> + <br><a name="resultsAnchor"></a> + <div id="resultsDiv"></div> </div> </div> http://git-wip-us.apache.org/repos/asf/juddi/blob/e06b6c55/juddiv3-war/src/main/webapp/admin/ajax/go.jsp ---------------------------------------------------------------------- diff --git a/juddiv3-war/src/main/webapp/admin/ajax/go.jsp b/juddiv3-war/src/main/webapp/admin/ajax/go.jsp index ba5ee27..f03c6d3 100644 --- a/juddiv3-war/src/main/webapp/admin/ajax/go.jsp +++ b/juddiv3-war/src/main/webapp/admin/ajax/go.jsp @@ -19,13 +19,11 @@ * */ --%> - <%@page import="org.apache.juddi.adminconsole.resources.ResourceLoader"%> <%@page import="org.apache.juddi.adminconsole.hub.UddiAdminHub"%> <%@page import="org.apache.commons.lang.StringEscapeUtils"%> <%@page import="java.util.Enumeration"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> -<!DOCTYPE html> <%@include file="../csrf.jsp" %> <% if (request.getMethod().equalsIgnoreCase("POST")) { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
