use of com.predic8.membrane.annot.model.doc.Doc in project service-proxy by membrane.
the class AbstractJavadocedInfo method getDoc.
public Doc getDoc(ProcessingEnvironment processingEnv) {
if (docGenerated)
return doc;
docGenerated = true;
String javadoc = processingEnv.getElementUtils().getDocComment(getDocedE());
if (javadoc == null)
return null;
return doc = new Doc(processingEnv, javadoc, getDocedE());
}
use of com.predic8.membrane.annot.model.doc.Doc in project service-proxy by membrane.
the class Schemas method assembleDocumentation.
private void assembleDocumentation(Writer w, AbstractJavadocedInfo aji) throws IOException {
Doc doc = aji.getDoc(processingEnv);
if (doc == null)
return;
w.append("<xsd:annotation>\r\n");
w.append("<xsd:documentation>");
for (Entry e : doc.getEntries()) {
w.append(xmlEscape("<h3><b>"));
w.append(xmlEscape(capitalize(e.getKey()) + ":"));
w.append(xmlEscape("</b></h3> "));
w.append(xmlEscape(e.getValueAsXMLSnippet(false)));
w.append(xmlEscape("<br/>"));
}
w.append("</xsd:documentation>\r\n");
w.append("</xsd:annotation>\r\n");
}
use of com.predic8.membrane.annot.model.doc.Doc in project service-proxy by membrane.
the class HelpLinkExistenceTest method doit.
@Test
public void doit() throws Exception {
Set<Class<?>> classes = getElementClasses();
Assert.assertNotEquals(0, classes.size());
HttpClient hc = new HttpClient();
for (Class<?> clazz : classes) {
if (Interceptor.class.isAssignableFrom(clazz)) {
Interceptor i = (Interceptor) clazz.newInstance();
String helpId = i.getHelpId();
String url = "http://membrane-soa.org/service-proxy-doc/" + getVersion() + "/configuration/reference/" + helpId + ".htm";
Response r = hc.call(new Request.Builder().get(url).buildExchange()).getResponse();
try {
Assert.assertEquals(200, r.getStatusCode());
} catch (Throwable e) {
throw new RuntimeException(url, e);
}
}
}
}
use of com.predic8.membrane.annot.model.doc.Doc in project service-proxy by membrane.
the class WSDLPublisherInterceptor method processDocuments.
private void processDocuments(Exchange exc) throws Exception {
// exc.response is set to garbage and should be discarded after this method
synchronized (paths) {
try {
while (true) {
String doc = documents_to_process.poll();
if (doc == null)
break;
log.debug("WSDLPublisherInterceptor: processing " + doc);
exc.setResponse(WebServerInterceptor.createResponse(router.getResolverMap(), doc));
WSDLInterceptor wi = new WSDLInterceptor();
wi.setRewriteEndpoint(false);
wi.setPathRewriter(new RelativePathRewriter(exc, doc));
wi.handleResponse(exc);
}
} catch (ResourceRetrievalException e) {
log.error("Could not recursively load all documents referenced by '" + wsdl + "'.", e);
}
}
}
use of com.predic8.membrane.annot.model.doc.Doc in project service-proxy by membrane.
the class XML2HTTP method unwrapMessageIfNecessary.
/**
* Checks, if the response contains an XML doc with NS {@link Constants#HTTP_NS}.
* If it does, the HTTP data (uri, method, status, headers, body) is extracted from the doc
* and set as the response.
*
* Reverse of {@link com.predic8.membrane.core.http.xml.Request#write(XMLStreamWriter)} and
* {@link com.predic8.membrane.core.http.xml.Response#write(XMLStreamWriter)}.
*/
public static void unwrapMessageIfNecessary(Message message) {
if (MimeType.TEXT_XML_UTF8.equals(message.getHeader().getContentType())) {
try {
if (message.getBody().getLength() == 0)
return;
XMLEventReader parser;
synchronized (xmlInputFactory) {
parser = xmlInputFactory.createXMLEventReader(message.getBodyAsStreamDecoded(), message.getCharset());
}
/* States:
* 0 = before root element,
* 1 = root element has HTTP_NS namespace
*/
int state = 0;
boolean keepSourceHeaders = false, foundHeaders = false, foundBody = false;
while (parser.hasNext()) {
XMLEvent event = parser.nextEvent();
switch(state) {
case 0:
if (event.isStartElement()) {
QName name = event.asStartElement().getName();
if (Constants.HTTP_NS.equals(name.getNamespaceURI())) {
state = 1;
if ("request".equals(name.getLocalPart())) {
Request req = (Request) message;
req.setMethod(requireAttribute(event.asStartElement(), "method"));
String httpVersion = getAttribute(event.asStartElement(), "http-version");
if (httpVersion == null)
httpVersion = "1.1";
req.setVersion(httpVersion);
}
} else {
return;
}
}
break;
case 1:
if (event.isStartElement()) {
String localName = event.asStartElement().getName().getLocalPart();
if ("status".equals(localName)) {
Response res = (Response) message;
res.setStatusCode(Integer.parseInt(requireAttribute(event.asStartElement(), "code")));
res.setStatusMessage(slurpCharacterData(parser, event.asStartElement()));
}
if ("uri".equals(localName)) {
Request req = (Request) message;
req.setUri(requireAttribute(event.asStartElement(), "value"));
// uri/... (port,host,path,query) structure is ignored, as value already contains everything
slurpXMLData(parser, event.asStartElement());
}
if ("headers".equals(localName)) {
foundHeaders = true;
keepSourceHeaders = "true".equals(getAttribute(event.asStartElement(), "keepSourceHeaders"));
}
if ("header".equals(localName)) {
String key = requireAttribute(event.asStartElement(), "name");
boolean remove = getAttribute(event.asStartElement(), "remove") != null;
if (remove && !keepSourceHeaders)
throw new XML2HTTPException("<headers keepSourceHeaders=\"false\"><header name=\"...\" remove=\"true\"> does not make sense.");
message.getHeader().removeFields(key);
if (!remove)
message.getHeader().add(key, slurpCharacterData(parser, event.asStartElement()));
}
if ("body".equals(localName)) {
foundBody = true;
String type = requireAttribute(event.asStartElement(), "type");
if ("plain".equals(type)) {
message.setBodyContent(slurpCharacterData(parser, event.asStartElement()).getBytes(Constants.UTF_8_CHARSET));
} else if ("xml".equals(type)) {
message.setBodyContent(slurpXMLData(parser, event.asStartElement()).getBytes(Constants.UTF_8_CHARSET));
} else {
throw new XML2HTTPException("XML-HTTP doc body type '" + type + "' is not supported (only 'plain' or 'xml').");
}
}
}
break;
}
}
if (!foundHeaders && !keepSourceHeaders)
message.getHeader().clear();
if (!foundBody)
message.setBodyContent(new byte[0]);
} catch (XMLStreamException e) {
log.error("", e);
} catch (XML2HTTPException e) {
log.error("", e);
} catch (IOException e) {
log.error("", e);
}
}
}
Aggregations