use of org.apache.cxf.headers.Header in project cxf by apache.
the class OOBHeaderTest method checkReturnedOOBHeader.
private void checkReturnedOOBHeader(PutLastTradedPricePortType portType) {
InvocationHandler handler = Proxy.getInvocationHandler(portType);
BindingProvider bp = null;
if (handler instanceof BindingProvider) {
bp = (BindingProvider) handler;
Map<String, Object> responseContext = bp.getResponseContext();
OutofBandHeader hdrToTest = null;
List<?> oobHdr = (List<?>) responseContext.get(Header.HEADER_LIST);
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);
if (oobHdr != null) {
Iterator<?> iter = oobHdr.iterator();
while (iter.hasNext()) {
Object hdr = iter.next();
if (hdr instanceof Header) {
Header hdr1 = (Header) hdr;
if (hdr1.getObject() instanceof Node) {
// System.out.println("Node conains : " + hdr1.getObject().toString());
try {
JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
hdrToTest = (OutofBandHeader) job.getValue();
// System.out.println("oob-hdr contains : \nname = "
// + hdrToTest.getName()
// + " \nvalue = " + hdrToTest.getValue()
// + " \natribute = " + hdrToTest.getHdrAttribute());
} 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.headers.Header in project cxf by apache.
the class X509TokenTest method testKeyIdentifier2.
@org.junit.Test
public void testKeyIdentifier2() throws Exception {
if (test.isStreaming()) {
return;
}
SpringBusFactory bf = new SpringBusFactory();
URL busFile = X509TokenTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = X509TokenTest.class.getResource("DoubleItOperations.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItKeyIdentifierPort2");
DoubleItPortType2 x509Port = service.getPort(portQName, DoubleItPortType2.class);
updateAddressPort(x509Port, PORT);
List<Header> headers = new ArrayList<>();
Header dummyHeader = new Header(new QName("uri:org.apache.cxf", "dummy"), "dummy-header", new JAXBDataBinding(String.class));
headers.add(dummyHeader);
((BindingProvider) x509Port).getRequestContext().put(Header.HEADER_LIST, headers);
int response = x509Port.doubleIt(25);
assertEquals(50, response);
int response2 = x509Port.doubleIt2(15);
assertEquals(30, response2);
((java.io.Closeable) x509Port).close();
bus.shutdown(true);
}
use of org.apache.cxf.headers.Header in project cxf by apache.
the class SimpleDocLitWrappedImpl method echoWithHeader.
public String echoWithHeader(String what) {
List<Header> headers = new ArrayList<>();
Header dummyHeader;
try {
dummyHeader = new Header(new QName("uri:org.apache.cxf", "dummy"), "decapitated", new JAXBDataBinding(String.class));
} catch (JAXBException e) {
throw new RuntimeException(e);
}
headers.add(dummyHeader);
context.getMessageContext().put(Header.HEADER_LIST, headers);
return what;
}
use of org.apache.cxf.headers.Header in project cxf by apache.
the class JAXWSMethodInvokerTest method prepareInMessage.
private Message prepareInMessage(Exchange ex, boolean copyHeadersByFault) throws ParserConfigurationException, SAXException, IOException {
Message inMessage = new MessageImpl();
inMessage.setExchange(ex);
inMessage.put(JAXWSMethodInvoker.COPY_SOAP_HEADERS_BY_FAULT, Boolean.valueOf(copyHeadersByFault));
List<Header> headers = new ArrayList<>();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document headerDoc = builder.parse(new ByteArrayInputStream("<test:testValue xmlns:test=\"test\"/>".getBytes()));
Header testHeader = new Header(TEST_HEADER_NAME, headerDoc.getDocumentElement());
headers.add(testHeader);
inMessage.put(Header.HEADER_LIST, headers);
ex.setInMessage(inMessage);
return inMessage;
}
use of org.apache.cxf.headers.Header in project cxf by apache.
the class SOAPHandlerInterceptorTest method testChangeSOAPHeaderInBound.
@Test
public void testChangeSOAPHeaderInBound() throws Exception {
@SuppressWarnings("rawtypes") List<Handler> list = new ArrayList<>();
list.add(new SOAPHandler<SOAPMessageContext>() {
public boolean handleMessage(SOAPMessageContext smc) {
try {
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outboundProperty.booleanValue()) {
// change mustUnderstand to false
SOAPMessage message = smc.getMessage();
SOAPHeader soapHeader = message.getSOAPHeader();
Element headerElementNew = (Element) soapHeader.getFirstChild();
SoapVersion soapVersion = Soap11.getInstance();
Attr attr = headerElementNew.getOwnerDocument().createAttributeNS(soapVersion.getNamespace(), "SOAP-ENV:mustUnderstand");
attr.setValue("false");
headerElementNew.setAttributeNodeNS(attr);
}
} catch (Exception e) {
throw new Fault(e);
}
return true;
}
public boolean handleFault(SOAPMessageContext smc) {
return true;
}
public Set<QName> getHeaders() {
return null;
}
public void close(MessageContext messageContext) {
}
});
HandlerChainInvoker invoker = new HandlerChainInvoker(list);
IMocksControl control = createNiceControl();
Binding binding = control.createMock(Binding.class);
expect(binding.getHandlerChain()).andReturn(list).anyTimes();
Exchange exchange = control.createMock(Exchange.class);
expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
// This is to set direction to inbound
expect(exchange.getOutMessage()).andReturn(null);
SoapMessage message = new SoapMessage(new MessageImpl());
message.setExchange(exchange);
XMLStreamReader reader = preparemXMLStreamReader("resources/greetMeRpcLitReq.xml");
message.setContent(XMLStreamReader.class, reader);
Object[] headerInfo = prepareSOAPHeader();
message.setContent(Node.class, headerInfo[0]);
Node node = ((Element) headerInfo[1]).getFirstChild();
message.getHeaders().add(new Header(new QName(node.getNamespaceURI(), node.getLocalName()), node));
control.replay();
SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
li.handleMessage(message);
control.verify();
// Verify SOAPMessage header
SOAPMessage soapMessageNew = message.getContent(SOAPMessage.class);
Element headerElementNew = DOMUtils.getFirstElement(soapMessageNew.getSOAPHeader());
SoapVersion soapVersion = Soap11.getInstance();
assertEquals("false", headerElementNew.getAttributeNS(soapVersion.getNamespace(), "mustUnderstand"));
// Verify XMLStreamReader
XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
QName qn = xmlReader.getName();
assertEquals("sendReceiveData", qn.getLocalPart());
// Verify Header Element
Iterator<Header> iter = message.getHeaders().iterator();
Element requiredHeader = null;
while (iter.hasNext()) {
Header localHdr = iter.next();
if (localHdr.getObject() instanceof Element) {
Element elem = (Element) localHdr.getObject();
if (elem.getNamespaceURI().equals("http://apache.org/hello_world_rpclit/types") && elem.getLocalName().equals("header1")) {
requiredHeader = (Element) localHdr.getObject();
break;
}
}
}
assertNotNull("Should have found header1", requiredHeader);
assertEquals("false", requiredHeader.getAttributeNS(soapVersion.getNamespace(), "mustUnderstand"));
}
Aggregations