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"));
}
use of org.apache.cxf.headers.Header in project cxf by apache.
the class RMSoapOutInterceptorTest method verifyHeaders.
private void verifyHeaders(SoapMessage message, String... names) {
List<Header> headers = new ArrayList<Header>(message.getHeaders());
for (String name : names) {
boolean found = false;
Iterator<Header> iter = headers.iterator();
while (iter.hasNext()) {
Header header = iter.next();
Object obj = header.getObject();
String namespace = header.getName().getNamespaceURI();
String localName = header.getName().getLocalPart();
if (obj instanceof Element) {
Element elem = (Element) obj;
namespace = elem.getNamespaceURI();
localName = elem.getLocalName();
}
if (RM10Constants.NAMESPACE_URI.equals(namespace) && localName.equals(name)) {
found = true;
iter.remove();
break;
} else if (Names.WSA_NAMESPACE_NAME.equals(namespace) && localName.equals(name)) {
found = true;
iter.remove();
break;
}
}
assertTrue("Could not find header element " + name, found);
}
// no other headers should be present
if (!headers.isEmpty()) {
assertTrue("Unexpected header element " + headers.get(0).getName(), false);
}
}
Aggregations