use of com.predic8.wsdl.Part in project service-proxy by membrane.
the class XOPReconstitutor method getReconstitutedMessage.
/**
* @return reassembled SOAP message or null if message is not SOAP or not multipart
*/
public Message getReconstitutedMessage(Message message) throws ParseException, MalformedStreamException, IOException, EndOfStreamException, XMLStreamException, FactoryConfigurationError {
ContentType contentType = message.getHeader().getContentTypeObject();
if (contentType == null || contentType.getPrimaryType() == null)
return null;
if (!contentType.getPrimaryType().equals("multipart") || !contentType.getSubType().equals("related"))
return null;
String type = contentType.getParameter("type");
if (!"application/xop+xml".equals(type))
return null;
String start = contentType.getParameter("start");
if (start == null)
return null;
String boundary = contentType.getParameter("boundary");
if (boundary == null)
return null;
HashMap<String, Part> parts = split(message, boundary);
Part startPart = parts.get(start);
if (startPart == null)
return null;
ContentType innerContentType = new ContentType(startPart.getHeader().getContentType());
if (!innerContentType.getPrimaryType().equals("application") || !innerContentType.getSubType().equals("xop+xml"))
return null;
byte[] body = fillInXOPParts(startPart.getInputStream(), parts);
Message m = new Message() {
@Override
protected void parseStartLine(InputStream in) throws IOException, EndOfStreamException {
throw new RuntimeException("not implemented.");
}
@Override
public String getStartLine() {
throw new RuntimeException("not implemented.");
}
@Override
public <T extends Message> T createSnapshot() {
throw new RuntimeException("not implemented.");
}
};
m.setBodyContent(body);
String reconstitutedContentType = innerContentType.getParameter("type");
if (reconstitutedContentType != null)
m.getHeader().add(Header.CONTENT_TYPE, reconstitutedContentType);
return m;
}
use of com.predic8.wsdl.Part in project service-proxy by membrane.
the class XOPReconstitutor method split.
@SuppressWarnings("deprecation")
private HashMap<String, Part> split(Message message, String boundary) throws IOException, EndOfStreamException, MalformedStreamException {
HashMap<String, Part> parts = new HashMap<String, Part>();
MultipartStream multipartStream = new MultipartStream(MessageUtil.getContentAsStream(message), boundary.getBytes(Constants.UTF_8_CHARSET));
boolean nextPart = multipartStream.skipPreamble();
while (nextPart) {
Header header = new Header(multipartStream.readHeaders());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
multipartStream.readBodyData(baos);
// see http://www.iana.org/assignments/transfer-encodings/transfer-encodings.xml
String cte = header.getFirstValue("Content-Transfer-Encoding");
if (cte != null && !cte.equals("binary") && !cte.equals("8bit") && !cte.equals("7bit"))
throw new RuntimeException("Content-Transfer-Encoding '" + cte + "' not implemented.");
Part part = new Part(header, baos.toByteArray());
String id = part.getContentID();
if (id != null) {
parts.put(id, part);
}
nextPart = multipartStream.readBoundary();
}
return parts;
}
use of com.predic8.wsdl.Part in project service-proxy by membrane.
the class WebServiceExplorerInterceptor method createSOAPUIResponse.
@Mapping("(?!.*operation)([^?]*)")
public Response createSOAPUIResponse(QueryParameter params, final String relativeRootPath, final Exchange exc) throws Exception {
try {
final String myPath = router.getUriFactory().create(exc.getRequestURI()).getPath();
final Definitions w = getParsedWSDL();
final Service service = getService(w);
final Port port = SOAPProxy.selectPort(service.getPorts(), portName);
final List<Port> ports = getPortsByLocation(service, port);
StringWriter sw = new StringWriter();
new StandardPage(sw, service.getName()) {
@Override
protected void createContent() {
h1().text("Service Proxy: " + service.getName()).end();
p();
text("Target Namespace: " + w.getTargetNamespace());
br().end();
String wsdlLink = getClientURL(exc) + "?wsdl";
text("WSDL: ").a().href(wsdlLink).text(wsdlLink).end();
end();
for (PortType pt : w.getPortTypes()) {
h2().text("Port Type: " + pt.getName()).end();
Documentation d = pt.getDocumentation();
if (d != null) {
p().text("Documentation: " + d.toString()).end();
}
}
Binding binding = port.getBinding();
PortType portType = binding.getPortType();
List<Operation> bindingOperations = getOperationsByBinding(w, binding);
if (bindingOperations.isEmpty())
p().text("There are no operations defined.").end();
else
createOperationsTable(w, bindingOperations, binding, portType);
h2().text("Virtual Endpoint").end();
p().a().href(getClientURL(exc)).text(getClientURL(exc)).end().end();
h2().text("Target Endpoints").end();
if (service.getPorts().isEmpty())
p().text("There are no endpoints defined.").end();
else
createEndpointTable(service.getPorts(), ports);
}
private void createOperationsTable(Definitions w, List<Operation> bindingOperations, Binding binding, PortType portType) {
table().cellspacing("0").cellpadding("0").border("" + 1);
tr();
th().text("Operation").end();
th().text("Input").end();
th().text("Output").end();
end();
for (Operation o : bindingOperations) {
tr();
td();
if ("HTTP".equals(getProtocolVersion(binding))) {
text(o.getName());
} else {
String link = myPath + "/operation/" + binding.getName() + "/" + portType.getName() + "/" + o.getName();
a().href(link).text(o.getName()).end();
}
end();
td();
for (Part p : o.getInput().getMessage().getParts()) text(p.getElement().getName());
end();
td();
for (Part p : o.getOutput().getMessage().getParts()) text(p.getElement().getName());
end();
end();
}
end();
}
private void createEndpointTable(List<Port> ports, List<Port> matchingPorts) {
table().cellspacing("0").cellpadding("0").border("" + 1);
tr();
th().text("Port Name").end();
th().text("Protocol").end();
th().text("URL").end();
end();
for (Port p : ports) {
tr();
td().text(p.getName()).end();
td().text(getProtocolVersion(p.getBinding())).end();
td().text(p.getAddress().getLocation()).end();
td();
if (matchingPorts.contains(p))
text("*");
end();
end();
}
end();
p().small().text("* available through this proxy").end().end();
}
};
return Response.ok(sw.toString()).build();
} catch (IllegalArgumentException e) {
log.error("", e);
return Response.internalServerError().build();
}
}
use of com.predic8.wsdl.Part in project service-proxy by membrane.
the class SimpleXPathAnalyzer method splitUnionExprIntoIntersectExceptExprs.
private List<ContainerNode> splitUnionExprIntoIntersectExceptExprs(ContainerNode node) {
List<ContainerNode> res = new ArrayList<ContainerNode>();
List<Node> intersectExceptExprParts = new ArrayList<Node>();
for (Node n : node.nodes) if (n instanceof UnparsedStringNode) {
List<String> parts = new ArrayList<String>();
for (String part : splitOnOperand(((UnparsedStringNode) n).s, "|")) for (String part2 : splitOnOperand(part, "union")) parts.add(part2);
for (int i = 0; i < parts.size(); i++) {
if (i >= 1) {
// next IntersectExceptExpr
res.add(new ContainerNode(intersectExceptExprParts.toArray(new Node[0])));
intersectExceptExprParts = new ArrayList<Node>();
}
intersectExceptExprParts.add(new UnparsedStringNode(parts.get(i)));
}
} else {
intersectExceptExprParts.add(n);
}
if (intersectExceptExprParts.size() > 0)
res.add(new ContainerNode(intersectExceptExprParts.toArray(new Node[0])));
return res;
}
use of com.predic8.wsdl.Part in project service-proxy by membrane.
the class AdminPageBuilder method getVersion.
/**
* @return The major and minor part of the version, e.g. "3.4"; or "current" if the version could not be parsed.
*/
private String getVersion() {
String v = Constants.VERSION;
int p = v.indexOf('.');
if (p == -1)
return "current";
p = v.indexOf('.', p + 1);
if (p == -1)
return "current";
return v.substring(0, p);
}
Aggregations