public void afterSubmit(Submit submit, SubmitContext context) { if (submit.getResponse() == null) return; HttpResponse httpResponse = (HttpResponse) submit.getResponse(); String content = httpResponse.getContentAsXml(); if (content == null || content.equals("<xml/>")) return; XmlObject xml; try { URL url = httpResponse.getURL(); String defaultNamespace = url.getProtocol() + "://" + url.getHost(); XmlOptions options = new XmlOptions() .setLoadSubstituteNamespaces(Collections.singletonMap("", defaultNamespace)); xml = XmlObject.Factory.parse(content, options); } catch (XmlException e) { e.printStackTrace(); return; } if (!submit.getStatus().equals(Status.CANCELED) && !InferredSchemaManager.getInferredSchema(service).validate(xml)) { setTitle("Schema (conflicts)"); if (thread != null && thread.isAlive()) { handler.kill(); try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } handler = new Handler(tabs, xml); thread = new Thread(handler); thread.start(); } }
public String createXmlRepresentation(HttpResponse response) { try { String content = response.getContentAsString().trim(); if (!StringUtils.hasContent(content)) return null; // remove nulls - workaround for bug in xmlserializer!? content = content.replaceAll("\\\\u0000", ""); JSON json = JSONSerializer.toJSON(content); JsonXmlSerializer serializer = new JsonXmlSerializer(); serializer.setTypeHintsEnabled(false); serializer.setRootName( HttpUtils.isErrorStatus(response.getStatusCode()) ? "Fault" : "Response"); URL url = response.getURL(); serializer.setNamespace("", url.getProtocol() + "://" + url.getHost() + url.getPath()); content = serializer.write(json); content = XmlUtils.prettyPrintXml(content); return content; } catch (Throwable e) { if (!(e instanceof JSONException)) e.printStackTrace(); } return "<xml/>"; }