use of org.apache.cxf.outofband.header.OutofBandHeader in project camel by apache.
the class CxfMessageHeadersRelayTest method validateReturnedOutOfBandHeaderWithInsertion.
protected static void validateReturnedOutOfBandHeaderWithInsertion(Map<String, Object> responseContext, boolean expect) {
List<OutofBandHeader> hdrToTest = new ArrayList<OutofBandHeader>();
List<Header> oobHdr = CastUtils.cast((List<?>) responseContext.get(Header.HEADER_LIST));
if (!expect) {
if (oobHdr == null || (oobHdr != null && oobHdr.size() == 0)) {
return;
}
fail("Should have got *no* out-of-band headers, but some were found");
}
if (oobHdr == null) {
fail("Should have got List of out-of-band headers");
}
assertTrue("HeaderHolder list expected to conain 2 object received " + oobHdr.size(), oobHdr.size() == 2);
for (Header hdr1 : oobHdr) {
if (hdr1.getObject() instanceof Node) {
try {
JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
hdrToTest.add((OutofBandHeader) job.getValue());
} catch (JAXBException ex) {
ex.printStackTrace();
}
}
}
assertTrue("out-of-band header should not be null", hdrToTest.size() > 0);
assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :" + hdrToTest.get(0).getName(), "testOobReturnHeaderName".equals(hdrToTest.get(0).getName()));
assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :" + hdrToTest.get(0).getValue(), "testOobReturnHeaderValue".equals(hdrToTest.get(0).getValue()));
assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :" + hdrToTest.get(0).getHdrAttribute(), "testReturnHdrAttribute".equals(hdrToTest.get(0).getHdrAttribute()));
assertTrue("Expected out-of-band Header name New_testOobHeader recevied :" + hdrToTest.get(1).getName(), "New_testOobHeader".equals(hdrToTest.get(1).getName()));
assertTrue("Expected out-of-band Header value New_testOobHeaderValue recevied :" + hdrToTest.get(1).getValue(), "New_testOobHeaderValue".equals(hdrToTest.get(1).getValue()));
assertTrue("Expected out-of-band Header attribute testHdrAttribute recevied :" + hdrToTest.get(1).getHdrAttribute(), "testHdrAttribute".equals(hdrToTest.get(1).getHdrAttribute()));
}
use of org.apache.cxf.outofband.header.OutofBandHeader in project camel by apache.
the class HeaderTesterImpl method addReplyOutOfBandHeader.
private void addReplyOutOfBandHeader() {
if (context != null) {
MessageContext ctx = context.getMessageContext();
if (ctx != null) {
try {
OutofBandHeader ob = new OutofBandHeader();
ob.setName("testOobReturnHeaderName");
ob.setValue("testOobReturnHeaderValue");
ob.setHdrAttribute("testReturnHdrAttribute");
JAXBElement<OutofBandHeader> job = new JAXBElement<OutofBandHeader>(new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_RESPONSE_ELEM), OutofBandHeader.class, null, ob);
Header hdr = new Header(new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_RESPONSE_ELEM), job, new JAXBDataBinding(ob.getClass()));
List<Header> hdrList = CastUtils.cast((List<?>) ctx.get(Header.HEADER_LIST));
hdrList.add(hdr);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
use of org.apache.cxf.outofband.header.OutofBandHeader in project camel by apache.
the class HeaderTesterWithInsertionImpl method verifyHeader.
private void verifyHeader(Object hdr, String headerName, String headerValue) {
if (hdr instanceof Header && ((Header) hdr).getObject() instanceof Node) {
Header hdr1 = (Header) hdr;
try {
JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
OutofBandHeader ob = (OutofBandHeader) job.getValue();
if (!headerName.equals(ob.getName())) {
throw new RuntimeException("test failed expected name ' + headerName + ' but found '" + ob.getName() + "'");
}
if (!headerValue.equals(ob.getValue())) {
throw new RuntimeException("test failed expected name ' + headerValue + ' but found '" + ob.getValue() + "'");
}
} catch (JAXBException ex) {
throw new RuntimeException("test failed", ex);
}
} else {
throw new RuntimeException("test failed. Unexpected type " + hdr.getClass());
}
}
use of org.apache.cxf.outofband.header.OutofBandHeader in project camel by apache.
the class CxfMessageHeadersRelayTest method validateReturnedOutOfBandHeader.
protected static void validateReturnedOutOfBandHeader(Map<String, Object> responseContext, boolean expect) {
OutofBandHeader hdrToTest = null;
List<Header> oobHdr = CastUtils.cast((List<?>) responseContext.get(Header.HEADER_LIST));
if (!expect) {
if (oobHdr == null || (oobHdr != null && oobHdr.size() == 0)) {
return;
}
fail("Should have got *no* out-of-band headers, but some were found");
}
if (oobHdr == null) {
fail("Should have got List of out-of-band headers");
}
assertTrue("HeaderHolder list expected to conain 1 object received " + oobHdr.size(), oobHdr.size() == 1);
for (Header hdr1 : oobHdr) {
if (hdr1.getObject() instanceof Node) {
try {
JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
hdrToTest = (OutofBandHeader) job.getValue();
} catch (JAXBException ex) {
ex.printStackTrace();
}
}
}
assertNotNull("out-of-band header should not be null", hdrToTest);
assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :" + hdrToTest.getName(), "testOobReturnHeaderName".equals(hdrToTest.getName()));
assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :" + hdrToTest.getValue(), "testOobReturnHeaderValue".equals(hdrToTest.getValue()));
assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :" + hdrToTest.getHdrAttribute(), "testReturnHdrAttribute".equals(hdrToTest.getHdrAttribute()));
}
use of org.apache.cxf.outofband.header.OutofBandHeader in project camel by apache.
the class CxfMessageHeadersRelayTest method buildOutOfBandHeaderList.
protected static List<Header> buildOutOfBandHeaderList(boolean invalid) throws JAXBException {
OutofBandHeader ob = new OutofBandHeader();
ob.setName("testOobHeader");
ob.setValue("testOobHeaderValue");
ob.setHdrAttribute(invalid ? "dontProcess" : "testHdrAttribute");
SoapHeader hdr = new SoapHeader(new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_REQUEST_ELEM), ob, new JAXBDataBinding(ob.getClass()));
hdr.setMustUnderstand(invalid);
List<Header> headers = new ArrayList<Header>();
headers.add(hdr);
return headers;
}
Aggregations