use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class XSLTInterceptorTest method testRequest.
@Test
public void testRequest() throws Exception {
exc = new Exchange(null);
exc.setResponse(Response.ok().body(getClass().getResourceAsStream("/customer.xml"), true).build());
XSLTInterceptor i = new XSLTInterceptor();
i.setXslt("classpath:/customer2person.xsl");
i.init(new HttpRouter());
i.handleResponse(exc);
// printBodyContent();
assertXPath("/person/name/first", "Rick");
assertXPath("/person/name/last", "Cort\u00e9s Ribotta");
assertXPath("/person/address/street", "Calle P\u00fablica \"B\" 5240 Casa 121");
assertXPath("/person/address/city", "Omaha");
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class SOAPFaultTest method getExchangeCP.
private Exchange getExchangeCP(String path) throws IOException {
Exchange exc = new Exchange(null);
exc.setResponse(Response.ok().contentType("text/xml").body(getClass().getClassLoader().getResourceAsStream(path), true).build());
return exc;
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class ResolverTestTriggerTest method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) {
try {
Class<?> clazz = Class.forName("com.predic8.membrane.core.resolver.ResolverTest");
clazz.getField("deployment").set(null, "J2EE");
Object value = router.getResolverMap().getFileSchemaResolver();
Object resolverMap = clazz.getField("resolverMap").get(null);
resolverMap.getClass().getMethod("addSchemaResolver", SchemaResolver.class).invoke(resolverMap, value);
Parameterized p = new Parameterized(clazz);
JUnitCore c = new JUnitCore();
Result run = c.run(Request.runner(p));
StringBuilder sb = new StringBuilder();
sb.append(MAGIC);
for (Failure f : run.getFailures()) {
sb.append(f.toString());
StringWriter stringWriter = new StringWriter();
f.getException().printStackTrace(new PrintWriter(stringWriter));
sb.append(stringWriter.toString());
sb.append("\n");
sb.append("\n");
}
exc.setResponse(Response.ok().header(Header.CONTENT_TYPE, MimeType.TEXT_PLAIN_UTF8).body(sb.toString()).build());
} catch (Throwable t) {
LOG.error(t.getMessage(), t);
}
return Outcome.RETURN;
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class AttributeInfo method analyze.
private void analyze(Types typeUtils) {
if (// already analyzed?
xsdType != null)
return;
if (getE().getParameters().size() != 1)
throw new ProcessingException("Setter is supposed to have 1 parameter.", getE());
VariableElement ve = getE().getParameters().get(0);
switch(ve.asType().getKind()) {
case INT:
xsdType = "spel_number";
return;
case LONG:
xsdType = "spel_number";
return;
case BOOLEAN:
xsdType = "spel_boolean";
return;
case DECLARED:
TypeElement e = (TypeElement) typeUtils.asElement(ve.asType());
if (e.getQualifiedName().toString().equals("java.lang.String")) {
xsdType = "xsd:string";
return;
}
if (e.getSuperclass().getKind() == TypeKind.DECLARED) {
TypeElement superClass = ((TypeElement) typeUtils.asElement(e.getSuperclass()));
if (superClass.getQualifiedName().toString().equals("java.lang.Enum")) {
isEnum = true;
// TODO: restriction, but be carefull about Spring EL usage, for example "#{config.XXX}"
xsdType = "xsd:string";
/*
* <xsd:attribute name=\"target\" use=\"optional\" default=\"body\">\r\n" +
* <xsd:simpleType>\r\n" +
* <xsd:restriction base=\"xsd:string\">\r\n" +
* <xsd:enumeration value=\"body\" />\r\n" +
* <xsd:enumeration value=\"header\" />\r\n" +
* </xsd:restriction>\r\n" +
* </xsd:simpleType>\r\n" +
* </xsd:attribute>\r\n"
*/
return;
}
}
isBeanReference = true;
xsdType = "xsd:string";
return;
default:
throw new ProcessingException("Not implemented: XSD type for " + ve.asType().getKind().toString(), this.getE());
}
}
use of com.predic8.membrane.core.http.Body in project service-proxy by membrane.
the class DynamicAbstractExchangeSnapshot method addObservers.
public static void addObservers(AbstractExchange exc, AbstractExchangeSnapshot excCopy, Consumer<AbstractExchangeSnapshot> callback) {
MessageObserver obs = new MessageObserver() {
@Override
public void bodyRequested(AbstractBody body) {
}
@Override
public void bodyComplete(AbstractBody body) {
update(callback, excCopy, exc);
}
};
exc.addExchangeViewerListener(new AbstractExchangeViewerListener() {
@Override
public void addResponse(Response response) {
response.addObserver(obs);
}
@Override
public void setExchangeFinished() {
update(callback, excCopy, exc);
}
});
Stream.of(exc.getRequest(), exc.getResponse()).forEach(msg -> {
if (msg == null)
return;
if (msg.containsObserver(obs))
return;
msg.addObserver(obs);
});
update(callback, excCopy, exc);
}
Aggregations