Search in sources :

Example 31 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project cxf by apache.

the class SoapFaultSerializerTest method testCXF4181.

@Test
public void testCXF4181() throws Exception {
    // Try WITH SAAJ
    SoapMessage m = new SoapMessage(new MessageImpl());
    m.put(Message.HTTP_REQUEST_METHOD, "POST");
    m.setVersion(Soap12.getInstance());
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(this.getClass().getResourceAsStream("cxf4181.xml"));
    m.setContent(XMLStreamReader.class, reader);
    new SAAJPreInInterceptor().handleMessage(m);
    new ReadHeadersInterceptor(null).handleMessage(m);
    new StartBodyInterceptor().handleMessage(m);
    new SAAJInInterceptor().handleMessage(m);
    new Soap12FaultInInterceptor().handleMessage(m);
    Node nd = m.getContent(Node.class);
    SOAPPart part = (SOAPPart) nd;
    assertEquals("S", part.getEnvelope().getPrefix());
    assertEquals("S2", part.getEnvelope().getHeader().getPrefix());
    assertEquals("S3", part.getEnvelope().getBody().getPrefix());
    SOAPFault fault = part.getEnvelope().getBody().getFault();
    assertEquals("S", fault.getPrefix());
    assertEquals("Authentication Failure", fault.getFaultString());
    SoapFault fault2 = (SoapFault) m.getContent(Exception.class);
    assertNotNull(fault2);
    assertEquals(Soap12.getInstance().getSender(), fault2.getFaultCode());
    assertEquals(new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "FailedAuthentication"), fault2.getSubCode());
    Element el = part.getEnvelope().getBody();
    nd = el.getFirstChild();
    int count = 0;
    while (nd != null) {
        if (nd instanceof Element) {
            count++;
        }
        nd = nd.getNextSibling();
    }
    assertEquals(1, count);
    // Try WITHOUT SAAJ
    m = new SoapMessage(new MessageImpl());
    m.setVersion(Soap12.getInstance());
    reader = StaxUtils.createXMLStreamReader(this.getClass().getResourceAsStream("cxf4181.xml"));
    m.setContent(XMLStreamReader.class, reader);
    m.put(Message.HTTP_REQUEST_METHOD, "POST");
    new ReadHeadersInterceptor(null).handleMessage(m);
    new StartBodyInterceptor().handleMessage(m);
    new Soap12FaultInInterceptor().handleMessage(m);
    // nd = m.getContent(Node.class);
    fault2 = (SoapFault) m.getContent(Exception.class);
    assertNotNull(fault2);
    assertEquals(Soap12.getInstance().getSender(), fault2.getFaultCode());
    assertEquals(new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "FailedAuthentication"), fault2.getSubCode());
}
Also used : SAAJPreInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor.SAAJPreInInterceptor) SoapFault(org.apache.cxf.binding.soap.SoapFault) XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) SOAPPart(javax.xml.soap.SOAPPart) SOAPFault(javax.xml.soap.SOAPFault) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 32 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project cxf by apache.

the class SoapFaultSerializerTest method testCXF5493.

@Test
public void testCXF5493() throws Exception {
    SoapMessage m = new SoapMessage(new MessageImpl());
    m.setVersion(Soap11.getInstance());
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(this.getClass().getResourceAsStream("cxf5493.xml"));
    m.setContent(XMLStreamReader.class, reader);
    // env
    reader.nextTag();
    // body
    reader.nextTag();
    // fault
    reader.nextTag();
    Soap11FaultInInterceptor inInterceptor = new Soap11FaultInInterceptor();
    inInterceptor.handleMessage(m);
    SoapFault fault2 = (SoapFault) m.getContent(Exception.class);
    assertNotNull(fault2);
    assertEquals(Soap11.getInstance().getReceiver(), fault2.getFaultCode());
    assertEquals("some text containing a xml tag <xml-tag>", fault2.getMessage());
    m = new SoapMessage(new MessageImpl());
    m.put(Message.HTTP_REQUEST_METHOD, "POST");
    m.setVersion(Soap11.getInstance());
    reader = StaxUtils.createXMLStreamReader(this.getClass().getResourceAsStream("cxf5493.xml"));
    m.setContent(XMLStreamReader.class, reader);
    new SAAJPreInInterceptor().handleMessage(m);
    new ReadHeadersInterceptor(null).handleMessage(m);
    new StartBodyInterceptor().handleMessage(m);
    new SAAJInInterceptor().handleMessage(m);
    new Soap11FaultInInterceptor().handleMessage(m);
    fault2 = (SoapFault) m.getContent(Exception.class);
    assertNotNull(fault2);
    assertEquals(Soap11.getInstance().getReceiver(), fault2.getFaultCode());
    assertEquals("some text containing a xml tag <xml-tag>", fault2.getMessage());
}
Also used : SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) SAAJPreInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor.SAAJPreInInterceptor) SoapFault(org.apache.cxf.binding.soap.SoapFault) XMLStreamReader(javax.xml.stream.XMLStreamReader) MessageImpl(org.apache.cxf.message.MessageImpl) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Test(org.junit.Test)

Example 33 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project cxf by apache.

the class TestUtil method createEmptySoapMessage.

public static SoapMessage createEmptySoapMessage(SoapVersion soapVersion, InterceptorChain chain) {
    Exchange exchange = new ExchangeImpl();
    MessageImpl messageImpl = new MessageImpl();
    messageImpl.setInterceptorChain(chain);
    messageImpl.setExchange(exchange);
    SoapMessage soapMessage = new SoapMessage(messageImpl);
    soapMessage.setVersion(soapVersion);
    soapMessage.put(Message.HTTP_REQUEST_METHOD, "POST");
    return soapMessage;
}
Also used : Exchange(org.apache.cxf.message.Exchange) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 34 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project cxf by apache.

the class SoapPreProtocolOutInterceptorTest method setUpMessage.

private SoapMessage setUpMessage() throws Exception {
    SoapMessage message = new SoapMessage(new MessageImpl());
    Exchange exchange = new ExchangeImpl();
    BindingOperationInfo bop = setUpBindingOperationInfo("http://foo/bar", "opReq", "opResp", SEI.class.getMethod("op", new Class[0]));
    SoapOperationInfo sop = new SoapOperationInfo();
    sop.setAction("http://foo/bar/SEI/opReq");
    bop.addExtensor(sop);
    exchange.put(BindingOperationInfo.class, bop);
    message.setExchange(exchange);
    message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
    control.replay();
    return message;
}
Also used : Exchange(org.apache.cxf.message.Exchange) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 35 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project cxf by apache.

the class BareInInterceptorTest method setUpUsingDocLit.

private void setUpUsingDocLit() throws Exception {
    String ns = "http://apache.org/hello_world_doc_lit_bare";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource("/wsdl/jaxb/doc_lit_bare.wsdl").toString(), new QName(ns, "SOAPService"));
    service = factory.create();
    endpointInfo = service.getServiceInfos().get(0).getEndpoint(new QName(ns, "SoapPort"));
    endpoint = new EndpointImpl(bus, service, endpointInfo);
    JAXBDataBinding db = new JAXBDataBinding();
    db.setContext(JAXBContext.newInstance(new Class[] { TradePriceData.class }));
    service.setDataBinding(db);
    operation = endpointInfo.getBinding().getOperation(new QName(ns, "SayHi"));
    operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(TradePriceData.class);
    operation.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(TradePriceData.class);
    message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, endpoint.getBinding());
}
Also used : Exchange(org.apache.cxf.message.Exchange) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) TradePriceData(org.apache.hello_world_doc_lit_bare.types.TradePriceData) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Aggregations

MessageImpl (org.apache.cxf.message.MessageImpl)610 Message (org.apache.cxf.message.Message)291 Test (org.junit.Test)290 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)193 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)152 Exchange (org.apache.cxf.message.Exchange)148 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)137 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)115 Crypto (org.apache.wss4j.common.crypto.Crypto)113 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)107 JAXBElement (javax.xml.bind.JAXBElement)100 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)93 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)86 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)83 Element (org.w3c.dom.Element)74 ArrayList (java.util.ArrayList)62 ServiceMBean (org.apache.cxf.sts.service.ServiceMBean)61 StaticService (org.apache.cxf.sts.service.StaticService)61 Principal (java.security.Principal)59 Endpoint (org.apache.cxf.endpoint.Endpoint)58