use of com.predic8.membrane.core.util.EndOfStreamException in project service-proxy by membrane.
the class Request method parseStartLine.
@Override
public void parseStartLine(InputStream in) throws IOException, EndOfStreamException {
try {
String firstLine = HttpUtil.readLine(in);
Matcher matcher = pattern.matcher(firstLine);
if (matcher.find()) {
method = matcher.group(1);
uri = matcher.group(2);
version = matcher.group(3);
} else if (stompPattern.matcher(firstLine).find()) {
method = firstLine;
uri = "";
version = "STOMP";
} else {
throw new EOFWhileReadingFirstLineException(firstLine);
}
} catch (EOFWhileReadingLineException e) {
if (e.getLineSoFar().length() == 0)
// happens regularly at the end of a keep-alive connection
throw new NoMoreRequestsException();
throw new EOFWhileReadingFirstLineException(e.getLineSoFar());
}
}
use of com.predic8.membrane.core.util.EndOfStreamException in project service-proxy by membrane.
the class Response method parseStartLine.
@Override
public void parseStartLine(InputStream in) throws IOException, EndOfStreamException {
String line;
try {
line = HttpUtil.readLine(in);
} catch (EOFWhileReadingLineException e) {
if (e.getLineSoFar().length() == 0)
throw new NoResponseException(e);
throw new EOFWhileReadingFirstLineException(e.getLineSoFar());
}
Matcher matcher = pattern.matcher(line);
boolean find = matcher.find();
if (!find) {
throw new RuntimeException("Invalid server response: " + line);
}
version = matcher.group(1);
statusCode = Integer.parseInt(matcher.group(2));
statusMessage = matcher.group(4);
}
use of com.predic8.membrane.core.util.EndOfStreamException in project service-proxy by membrane.
the class WebSocketStompReassembler method convertToExchange.
private Exchange convertToExchange(WebSocketFrame wsStompFrame) throws IOException, EndOfStreamException {
byte[] realPayload = new byte[(int) wsStompFrame.getPayloadLength()];
System.arraycopy(wsStompFrame.getPayload(), 0, realPayload, 0, (int) wsStompFrame.getPayloadLength());
if (wsStompFrame.getPayloadLength() == 0)
throw new IOException("Empty STOMP frame.");
ByteArrayInputStream bais = new ByteArrayInputStream(wsStompFrame.getPayload(), 0, (int) wsStompFrame.getPayloadLength() - 1);
Request request = new Request();
if (isHeartBeat(wsStompFrame)) {
request.setMethod("");
request.setBody(new Body(bais));
} else {
if (wsStompFrame.getPayload()[(int) wsStompFrame.getPayloadLength() - 1] != 0)
throw new IOException("STOMP frame is not terminated by \\0.");
request.read(bais, true);
}
Exchange result = new Exchange(null);
result.setRequest(request);
if (wsStompFrame.getOriginalExchange() != null)
result.setProperty(Exchange.WS_ORIGINAL_EXCHANGE, wsStompFrame.getOriginalExchange());
return result;
}
use of com.predic8.membrane.core.util.EndOfStreamException in project service-proxy by membrane.
the class XMLContentFilter method removeMatchingElements.
/**
* Removes parts of an XML document based on an XPath expression.
*
* If the message is not valid XML, it is left unchanged.
*/
public void removeMatchingElements(Message message) {
try {
Message xop = null;
try {
xop = xopReconstitutor.getReconstitutedMessage(message);
} catch (ParseException e) {
} catch (EndOfStreamException e) {
} catch (FactoryConfigurationError e) {
}
if (elementFinder != null && !elementFinder.matches(xop != null ? xop.getBodyAsStream() : message.getBodyAsStream())) {
return;
}
DocumentBuilder db = createDocumentBuilder();
Document d;
try {
d = db.parse(xop != null ? xop.getBodyAsStream() : message.getBodyAsStream());
} finally {
db.reset();
}
removeElementsIfNecessary(message, xop, d);
} catch (SAXException e) {
return;
} catch (IOException e) {
throw new RuntimeException(e);
} catch (XMLStreamException e) {
return;
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (XPathExpressionException e) {
throw new RuntimeException(e);
} catch (TransformerConfigurationException e) {
throw new RuntimeException(e);
} catch (TransformerException e) {
throw new RuntimeException(e);
} catch (TransformerFactoryConfigurationError e) {
throw new RuntimeException(e);
}
}
use of com.predic8.membrane.core.util.EndOfStreamException 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;
}
Aggregations