use of org.apache.cxf.headers.Header in project cxf by apache.
the class SAAJOutInterceptorTest method testHandleHeader.
@Test
public void testHandleHeader() throws Exception {
soapMessage = TestUtil.createEmptySoapMessage(Soap11.getInstance(), chain);
soapMessage.setContent(OutputStream.class, new ByteArrayOutputStream());
SOAPMessage m = SAAJFactoryResolver.createMessageFactory(soapMessage.getVersion()).createMessage();
InputStream ins = getClass().getResourceAsStream("../test-soap-header.xml");
m.getSOAPPart().setContent(new StreamSource(ins));
Element el = DOMUtils.getFirstElement(m.getSOAPPart().getEnvelope().getHeader());
List<Header> h = soapMessage.getHeaders();
while (el != null) {
h.add(new SoapHeader(DOMUtils.getElementQName(el), el));
el = DOMUtils.getNextElement(el);
}
soapMessage.setContent(SOAPMessage.class, m);
W3CDOMStreamWriter writer = new SAAJStreamWriter(m.getSOAPPart());
soapMessage.setContent(XMLStreamWriter.class, writer);
soi.handleMessage(soapMessage);
}
use of org.apache.cxf.headers.Header in project BIMserver by opensourceBIM.
the class SoapChannel method newToken.
@Override
public void newToken(String token) {
if (useSoapHeaderSessions) {
for (PublicInterface p : getServiceInterfaces().values()) {
List<Header> headers = new ArrayList<Header>();
try {
Token tokenObject = new Token(token);
Header sessionHeader = new Header(new QName("uri:org.bimserver.shared", "token"), tokenObject, new JAXBDataBinding(Token.class));
headers.add(sessionHeader);
} catch (JAXBException e) {
LOGGER.error("", e);
}
((BindingProvider) p).getRequestContext().put(Header.HEADER_LIST, headers);
}
}
}
use of org.apache.cxf.headers.Header in project BIMserver by opensourceBIM.
the class CustomInvoker method getServiceObject.
@Override
public Object getServiceObject(Exchange exchange) {
Message inMessage = exchange.getInMessage();
if (inMessage instanceof SoapMessage) {
SoapMessage soapMessage = (SoapMessage) inMessage;
Header header = soapMessage.getHeader(new QName("uri:org.bimserver.shared", "token"));
String token = null;
if (header != null) {
token = ((Token) (header.getObject())).getToken();
}
if (token == null) {
token = (String) exchange.getSession().get("token");
}
if (token != null) {
try {
return serviceFactory.get(token, AccessMethod.SOAP).get(interfaceClass);
} catch (UserException e) {
LOGGER.error("", e);
return null;
}
} else {
try {
PublicInterface newService = serviceFactory.get(AccessMethod.SOAP).get(interfaceClass);
exchange.getSession().put("token", token);
return newService;
} catch (UserException e) {
LOGGER.error("", e);
}
}
} else {
try {
return serviceFactory.get(AccessMethod.SOAP).get(interfaceClass);
} catch (UserException e) {
LOGGER.error("", e);
}
}
return null;
}
use of org.apache.cxf.headers.Header in project camel by apache.
the class HeaderTesterImpl method validateOutOfBandHander.
protected boolean validateOutOfBandHander() {
MessageContext ctx = context == null ? null : context.getMessageContext();
if (!relayHeaders) {
if (ctx != null && !ctx.containsKey(Header.HEADER_LIST) || (ctx.containsKey(Header.HEADER_LIST) && ((List<?>) ctx.get(Header.HEADER_LIST)).size() == 0)) {
return true;
}
return false;
}
boolean success = false;
if (ctx != null && ctx.containsKey(Header.HEADER_LIST)) {
List<?> oobHdr = (List<?>) ctx.get(Header.HEADER_LIST);
Iterator<?> iter = oobHdr.iterator();
while (iter.hasNext()) {
Object hdr = iter.next();
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 ("testOobHeader".equals(ob.getName()) && "testOobHeaderValue".equals(ob.getValue())) {
if ("testHdrAttribute".equals(ob.getHdrAttribute())) {
success = true;
//mark it processed
iter.remove();
} else if ("dontProcess".equals(ob.getHdrAttribute())) {
//we won't remove it so we won't let the runtime know
//it's processed. It SHOULD throw an exception
//saying the mustunderstand wasn't processed
success = true;
}
} else {
throw new RuntimeException("test failed");
}
} catch (JAXBException ex) {
ex.printStackTrace();
}
}
}
} else {
throw new RuntimeException("MessageContext is null or doesnot contain OOBHeaders");
}
return success;
}
use of org.apache.cxf.headers.Header in project cxf by apache.
the class OOBHdrServiceImpl method sendReturnOOBHeader.
private void sendReturnOOBHeader() {
if (context != null) {
MessageContext ctx = context.getMessageContext();
if (ctx != null) {
try {
// Create out-of-band header object.
OutofBandHeader ob = new OutofBandHeader();
ob.setName("testOobReturnHeaderName");
ob.setValue("testOobReturnHeaderValue");
ob.setHdrAttribute("testReturnHdrAttribute");
// Add Out-of-band header object to HeaderHolder.
JAXBElement<OutofBandHeader> job = new JAXBElement<OutofBandHeader>(new QName(OOBHeaderTest.TEST_HDR_NS, OOBHeaderTest.TEST_HDR_RESPONSE_ELEM), OutofBandHeader.class, null, ob);
Header hdr = new Header(new QName(OOBHeaderTest.TEST_HDR_NS, OOBHeaderTest.TEST_HDR_RESPONSE_ELEM), job, new JAXBDataBinding(ob.getClass()));
List<Header> hdrList = CastUtils.cast((List<?>) ctx.get(Header.HEADER_LIST));
hdrList.add(hdr);
// Add headerHolder to requestContext.
// ctx.put(Header.HEADER_LIST, hdrList);
// System.out.println("Completed adding list to context");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
Aggregations