/** * Converts a string based request to a RequestCtx obejct. * * @param request * the string request * @return the RequestCtx object * @throws MelcoeXacmlException */ public RequestCtx makeRequestCtx(String request) throws MelcoeXacmlException { RequestCtx reqCtx = null; try { ByteArrayInputStream is = new ByteArrayInputStream(request.getBytes()); reqCtx = BasicRequestCtx.getInstance(is); } catch (ParsingException pe) { throw new MelcoeXacmlException("Error parsing response.", pe); } return reqCtx; }
/** * Creates a new <code>RequestCtx</code> by parsing XML from an * input stream. Note that this a convenience method, and it will * not do schema validation by default. You should be parsing the data * yourself, and then providing the root node to the other * <code>getInstance</code> method. If you use this convenience * method, you probably want to turn on validation by setting the * context schema file (see the programmer guide for more information * on this). * * @param input a stream providing the XML data * * @return a new <code>RequestCtx</code> * * @throws ParsingException if there is an error parsing the input */ public static RequestCtx getInstance(InputStream input) throws ParsingException { return getInstance(InputParser.parseInput(input, "Request")); }
/** * Creates a new <code>RequestCtx</code> by parsing XML from an * input stream. Note that this a convenience method, and it will * not do schema validation by default. You should be parsing the data * yourself, and then providing the root node to the other * <code>getInstance</code> method. If you use this convenience * method, you probably want to turn on validation by setting the * context schema file (see the programmer guide for more information * on this). * * @param input a stream providing the XML data * * @return a new <code>RequestCtx</code> * * @throws ParsingException if there is an error parsing the input */ public static RequestCtx getInstance(InputStream input) throws ParsingException { return getInstance(InputParser.parseInput(input, "Request")); }
@Override public String evaluate(String request) throws EvaluationException { logger.debug("evaluating request: {}", request); RequestCtx req = null; ByteArrayInputStream is = new ByteArrayInputStream(request.getBytes()); try { req = BasicRequestCtx.getInstance(is); } catch (ParsingException pe) { logger.error("Error parsing request:\n" + request, pe); throw new EvaluationException("Error parsing request:\n" + request); } ResponseCtx res = evaluate(req); ByteArrayOutputStream os = new ByteArrayOutputStream(); res.encode(os, new Indenter()); if (logger.isDebugEnabled()) { logger.debug("response is: {}", os.toString()); } return os.toString(); }
@Override public String evaluateBatch(String[] requests) throws EvaluationException { logger.debug("evaluating string request batch"); RequestCtx[] requestCtxs = new RequestCtx[requests.length]; for (int i=0; i< requests.length; i++) { String request = requests[i]; ByteArrayInputStream is = new ByteArrayInputStream(request.getBytes()); try { requestCtxs[i] = BasicRequestCtx.getInstance(is); } catch (ParsingException pe) { logger.error("Error parsing request:\n" + request, pe); throw new EvaluationException("Error parsing request:\n" + request); } } ResponseCtx combinedResponse = evaluateBatch(requestCtxs); ByteArrayOutputStream os = new ByteArrayOutputStream(); combinedResponse.encode(os, new Indenter()); return os.toString(); }
@Test public void testRoundtrip() throws ParsingException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); test.encode(buf); ByteArrayInputStream encoded = new ByteArrayInputStream(buf.toByteArray()); RequestCtx actual = BasicRequestCtx.getInstance(encoded); assertEquals(toString(test), toString(actual)); assertTrue(test.equals(actual)); }