org.apache.cxf.binding.soap.SoapFault Java Examples

The following examples show how to use org.apache.cxf.binding.soap.SoapFault. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebFaultOutInterceptorTestCase.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSoapFaultException() {
    // create message that contains Fault that contains exception
    SOAPFaultException soapFaultException = new SOAPFaultException(new SOAPFaultStub());
    SoapFault soapFault = new SoapFault("message", soapFaultException, CODE);
    Message message = createMessage(soapFault);

    interceptor.handleMessage(message);




    Assert.assertNotNull(soapFault.getSubCodes());
    Assert.assertEquals(1, soapFault.getSubCodes().size());
    Assert.assertEquals(SUBCODE, soapFault.getSubCodes().get(0));
    Assert.assertEquals(CODE, soapFault.getFaultCode());
}
 
Example #2
Source File: SoapFaultSerializerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testCXF1864() throws Exception {

    SoapMessage m = new SoapMessage(new MessageImpl());
    m.setVersion(Soap12.getInstance());


    XMLStreamReader reader = StaxUtils.createXMLStreamReader(this.getClass()
                                                             .getResourceAsStream("cxf1864.xml"));
    m.setContent(XMLStreamReader.class, reader);

    reader.nextTag();

    Soap12FaultInInterceptor inInterceptor = new Soap12FaultInInterceptor();
    inInterceptor.handleMessage(m);

    SoapFault fault2 = (SoapFault)m.getContent(Exception.class);
    assertNotNull(fault2);
    assertEquals(Soap12.getInstance().getReceiver(), fault2.getFaultCode());
}
 
Example #3
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test(expected = SoapFault.class)
public void testResponderInboundInvalidMAPsNoMessageIdReqResp() throws Exception {
    SetupMessageArgs args = new SetupMessageArgs();
    args.requestor = false;
    args.outbound = false;
    args.oneway = false;
    args.usingAddressing = false;
    args.mapsInContext = false;
    args.decoupled = false;
    args.zeroLengthAction = true;
    args.fault = false;
    args.noMessageId = true;

    Message message = setUpMessage(args);
    aggregator.setAllowDuplicates(false);
    aggregator.mediate(message, true);
    control.verify();
    verifyMessage(message, false, false, false /*check*/);
}
 
Example #4
Source File: StartBodyInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc}*/
public void handleMessage(SoapMessage message) throws Fault {
    if (isGET(message)) {
        LOG.fine("StartBodyInterceptor skipped in HTTP GET method");
        return;
    }
    XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
    //advance to just outside the <soap:body> opening tag, but not
    //to the nextTag as that may skip over white space that is
    //important to keep for ws-security signature digests and stuff
    try {
        int i = xmlReader.next();
        while (i == XMLStreamConstants.NAMESPACE
            || i == XMLStreamConstants.ATTRIBUTE) {
            i = xmlReader.next();
        }
    } catch (XMLStreamException e) {
        throw new SoapFault(new Message("XML_STREAM_EXC", LOG, e.getMessage()), e,
                            message.getVersion().getSender());
    }

}
 
Example #5
Source File: SoapFaultFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void createSoap12Fault() {
    SoapBinding sb = control.createMock(SoapBinding.class);
    EasyMock.expect(sb.getSoapVersion()).andReturn(Soap12.getInstance());
    Identifier id = new Identifier();
    id.setValue("sid");
    setupSequenceFault(true, RM10Constants.UNKNOWN_SEQUENCE_FAULT_QNAME, id);
    control.replay();
    SoapFaultFactory factory = new SoapFaultFactory(sb);
    SoapFault fault = (SoapFault)factory.createFault(sf, createInboundMessage());
    assertEquals("reason", fault.getReason());
    assertEquals(Soap12.getInstance().getSender(), fault.getFaultCode());
    assertEquals(RM10Constants.UNKNOWN_SEQUENCE_FAULT_QNAME, fault.getSubCode());
    Element elem = fault.getDetail();
    assertEquals(RM10Constants.NAMESPACE_URI, elem.getNamespaceURI());
    assertEquals("Identifier", elem.getLocalName());
    assertNull(fault.getCause());
    control.verify();
}
 
Example #6
Source File: SoapFaultFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void createSoap12FaultWithIdentifierDetail() {
    SoapBinding sb = control.createMock(SoapBinding.class);
    EasyMock.expect(sb.getSoapVersion()).andReturn(Soap12.getInstance());
    Identifier id = new Identifier();
    id.setValue("sid");
    setupSequenceFault(true, RM10Constants.UNKNOWN_SEQUENCE_FAULT_QNAME, id);
    control.replay();
    SoapFaultFactory factory = new SoapFaultFactory(sb);
    SoapFault fault = (SoapFault)factory.createFault(sf, createInboundMessage());
    assertEquals("reason", fault.getReason());
    assertEquals(Soap12.getInstance().getSender(), fault.getFaultCode());
    assertEquals(RM10Constants.UNKNOWN_SEQUENCE_FAULT_QNAME, fault.getSubCode());
    Element elem = fault.getDetail();
    assertEquals(RM10Constants.NAMESPACE_URI, elem.getNamespaceURI());
    assertEquals("Identifier", elem.getLocalName());
    control.verify();
}
 
Example #7
Source File: SoapFaultFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void createSoap12FaultWithAcknowledgementDetail() {
    SoapBinding sb = control.createMock(SoapBinding.class);
    EasyMock.expect(sb.getSoapVersion()).andReturn(Soap12.getInstance());
    SequenceAcknowledgement ack = new SequenceAcknowledgement();
    Identifier id = new Identifier();
    id.setValue("sid");
    ack.setIdentifier(id);
    SequenceAcknowledgement.AcknowledgementRange range =
        new SequenceAcknowledgement.AcknowledgementRange();
    range.setLower(Long.valueOf(1));
    range.setUpper(Long.valueOf(10));
    ack.getAcknowledgementRange().add(range);
    setupSequenceFault(true, RM10Constants.INVALID_ACKNOWLEDGMENT_FAULT_QNAME, ack);
    control.replay();
    SoapFaultFactory factory = new SoapFaultFactory(sb);
    SoapFault fault = (SoapFault)factory.createFault(sf, createInboundMessage());
    assertEquals("reason", fault.getReason());
    assertEquals(Soap12.getInstance().getSender(), fault.getFaultCode());
    assertEquals(RM10Constants.INVALID_ACKNOWLEDGMENT_FAULT_QNAME, fault.getSubCode());
    Element elem = fault.getDetail();
    assertEquals(RM10Constants.NAMESPACE_URI, elem.getNamespaceURI());
    assertEquals("SequenceAcknowledgement", elem.getLocalName());
    control.verify();
}
 
Example #8
Source File: SoapFaultFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
Fault createSoap12Fault(SequenceFault sf, Message msg) {
    SoapFault fault = (SoapFault)createSoap11Fault(sf);
    fault.setSubCode(sf.getFaultCode());
    Object detail = sf.getDetail();
    if (null == detail) {
        return fault;
    }

    try {
        RMProperties rmps = RMContextUtils.retrieveRMProperties(msg, false);
        AddressingProperties maps = RMContextUtils.retrieveMAPs(msg, false, false);
        EncoderDecoder codec = ProtocolVariation.findVariant(rmps.getNamespaceURI(),
            maps.getNamespaceURI()).getCodec();
        setDetail(fault, detail, codec);
    } catch (Exception ex) {
        LogUtils.log(LOG, Level.SEVERE, "MARSHAL_FAULT_DETAIL_EXC", ex);
        ex.printStackTrace();
    }
    return fault;
}
 
Example #9
Source File: AbstractSoapInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
static String getFaultMessage(SoapMessage message, SoapFault fault) {
    if (message.get("forced.faultstring") != null) {
        return (String) message.get("forced.faultstring");
    }
    boolean config = MessageUtils.getContextualBoolean(message, Message.EXCEPTION_MESSAGE_CAUSE_ENABLED, false);
    if (fault.getMessage() != null) {
        if (config && fault.getCause() != null
            && fault.getCause().getMessage() != null && !fault.getMessage().equals(fault.getCause().getMessage())) {
            return fault.getMessage() + " Caused by: " + fault.getCause().getMessage();
        }
        return fault.getMessage();
    } else if (config && fault.getCause() != null) {
        if (fault.getCause().getMessage() != null) {
            return fault.getCause().getMessage();
        }
        return fault.getCause().toString();
    } else {
        return "Fault occurred while processing.";
    }
}
 
Example #10
Source File: MAPAggregatorImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void checkAddressingResponses(EndpointReferenceType replyTo, EndpointReferenceType faultTo) {
    if (this.addressingResponses == WSAddressingFeature.AddressingResponses.ALL) {
        return;
    }
    boolean passed = false;
    boolean anonReply = ContextUtils.isGenericAddress(replyTo);
    boolean anonFault = ContextUtils.isGenericAddress(faultTo);
    boolean isAnonymous = anonReply && anonFault;
    if (WSAddressingFeature.AddressingResponses.ANONYMOUS == addressingResponses
        && isAnonymous) {
        passed = true;
    } else if (WSAddressingFeature.AddressingResponses.NON_ANONYMOUS == addressingResponses
               && (!anonReply && (!anonFault && faultTo.getAddress() != null)
                   || !anonReply && faultTo == null)) {
        passed = true;
    }
    if (!passed) {
        String reason = BUNDLE.getString("INVALID_ADDRESSING_PROPERTY_MESSAGE");
        QName detail = WSAddressingFeature.AddressingResponses.ANONYMOUS == addressingResponses
            ? Names.ONLY_ANONYMOUS_ADDRESS_SUPPORTED_QNAME
            : Names.ONLY_NONANONYMOUS_ADDRESS_SUPPORTED_QNAME;
        throw new SoapFault(reason, detail);
    }
}
 
Example #11
Source File: SoapCxfProxyComponent.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Override
protected Endpoint createDelegateEndpoint(ComponentDefinition definition, String scheme,
                                          Map<String, String> options) {

    final Endpoint delegateEndpoint = super.createDelegateEndpoint(definition, scheme, options);

    // wrap the delegate in a proxy that decorates the CXF producer
    final boolean isSoap11 = Soap11.getInstance().equals(soapVersion);
    return new ComponentProxyEndpoint(delegateEndpoint.getEndpointUri(), this, delegateEndpoint) {

        @Override
        public Producer createProducer() throws Exception {
            final CamelContext context = getCamelContext();

            // replace with a try-catch pipeline to handle SOAP faults
            return new ComponentProxyProducer(this, Pipeline.newInstance(context,
                new TryProcessor(context, super.createProducer(),
                    Collections.singletonList(new CatchProcessor(Collections.singletonList(SoapFault.class),
                        (isSoap11 ? new Soap11FaultSoapPayloadConverter(exceptionMessageCauseEnabled) :
                            new Soap12FaultSoapPayloadConverter(exceptionMessageCauseEnabled)), null, null)), null)));
        }
    };
}
 
Example #12
Source File: AbstractFaultSoapPayloadConverter.java    From syndesis with Apache License 2.0 6 votes vote down vote up
protected String getFaultMessage(SoapFault fault) {
    if (fault.getMessage() != null) {
        if (exceptionMessageCauseEnabled && fault.getCause() != null
            && fault.getCause().getMessage() != null && !fault.getMessage().equals(fault.getCause().getMessage())) {
            return fault.getMessage() + " Caused by: " + fault.getCause().getMessage();
        }
        return fault.getMessage();
    } else if (exceptionMessageCauseEnabled && fault.getCause() != null) {
        if (fault.getCause().getMessage() != null) {
            return fault.getCause().getMessage();
        }
        return fault.getCause().toString();
    } else {
        return "Fault occurred while processing.";
    }
}
 
Example #13
Source File: WSS4JPrincipalInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void handleMessage(SoapMessage message) throws Fault {
    SecurityContext context = message.get(SecurityContext.class);
    if (context == null) {
        throw new SoapFault("No Security Context", Fault.FAULT_CODE_SERVER);
    }

    Principal principal = context.getUserPrincipal();
    if (principal == null) {
        throw new SoapFault("No Security Principal", Fault.FAULT_CODE_SERVER);
    }

    if (principalName != null && !principalName.equals(principal.getName())) {
        throw new SoapFault("Security Principal does not match", Fault.FAULT_CODE_SERVER);
    }
}
 
Example #14
Source File: ProtocolVariationsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidWSRMMustUnderstandOnReceive() throws Exception {
    init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", false);

    // WS-RM 1.0 using the WS-A 1.0 namespace
    Client client = ClientProxy.getClient(greeter);
    client.getRequestContext().put(RMManager.WSRM_VERSION_PROPERTY, RM10Constants.NAMESPACE_URI);
    client.getRequestContext().put(RMManager.WSRM_WSA_VERSION_PROPERTY, Names200408.WSA_NAMESPACE_NAME);

    // rewrite the outgoing message's WS-RM namespace to an invalid one
    TransformOutInterceptor trans = new TransformOutInterceptor();
    Map<String, String> outElements = new HashMap<>();
    outElements.put("{" + RM10Constants.NAMESPACE_URI + "}*", "{http://cxf.apache.org/invalid}*");
    trans.setOutTransformElements(outElements);

    client.getOutInterceptors().add(trans);
    try {
        greeter.greetMe("one");
        fail("invalid wsrm header");
    } catch (Exception e) {
        assertTrue(e.getCause() instanceof SoapFault);
        final String text = "WS-ReliableMessaging is required";
        assertTrue(e.getCause().getMessage(), e.getCause().getMessage() != null
            && e.getCause().getMessage().indexOf(text) >= 0);
    }
}
 
Example #15
Source File: WSS4JStaxInInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc}*/
public void handleMessage(SoapMessage message) throws Fault {
    if (isGET(message)) {
        LOG.fine("StartBodyInterceptor skipped in HTTP GET method");
        return;
    }
    XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
    try {
        int i = xmlReader.getEventType();
        while (i == XMLStreamConstants.NAMESPACE
            || i == XMLStreamConstants.ATTRIBUTE
            || i == XMLStreamConstants.CHARACTERS) {
            i = xmlReader.next();
        }
    } catch (XMLStreamException e) {
        throw new SoapFault(new Message("XML_STREAM_EXC", LOG, e.getMessage()), e,
                            message.getVersion().getSender());
    }

}
 
Example #16
Source File: MemoryResourceManager.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public Representation get(ReferenceParametersType ref) {
    String uuid = getUUID(ref);
    if (!storage.containsKey(uuid)) {
        throw new UnknownResource();
    }
    String resource = storage.get(uuid);
    if (resource.isEmpty()) {
        return new Representation();
    }
    Document doc = null;
    try {
        doc = StaxUtils.read(new StringReader(storage.get(uuid)));
    } catch (XMLStreamException e) {
        LOG.severe(e.getLocalizedMessage());
        throw new SoapFault("Internal Error", getSoapVersion().getReceiver());
    }
    Representation representation = new Representation();
    representation.setAny(doc.getDocumentElement());
    return representation;
}
 
Example #17
Source File: JAXWSClientMetricsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void usingClientProxyStopIsCalledWhenServerReturnsFault() throws Exception {
    final JaxWsClientFactoryBean factory = new JaxWsClientFactoryBean();
    factory.setAddress("local://services/Book");
    factory.setServiceClass(IBookWebService.class);
    factory.setFeatures(Arrays.asList(new MetricsFeature(provider)));
    
    try {
        final Client client = factory.create();
        expectedException.expect(SoapFault.class);
        client.invoke("getBook", 11);
    } finally {
        Mockito.verify(operationContext, times(1)).start(any(Exchange.class));
        Mockito.verify(operationContext, times(1)).stop(anyLong(), anyLong(), anyLong(), any(Exchange.class));
        Mockito.verify(endpointContext, times(1)).start(any(Exchange.class));
        Mockito.verify(endpointContext, times(1)).stop(anyLong(), anyLong(), anyLong(), any(Exchange.class));
        Mockito.verifyNoInteractions(resourceContext);
    }
}
 
Example #18
Source File: SoapOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleMessage(SoapMessage message) throws Fault {
    try {
        XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
        if (xtw != null) {
            // Write body end
            xtw.writeEndElement();
            // Write Envelope end element
            xtw.writeEndElement();
            xtw.writeEndDocument();

            xtw.flush();
        }
    } catch (XMLStreamException e) {
        if (e.getCause() instanceof EOFException) {
            //Nothing we can do about this, some clients will close the connection early if
            //they fully parse everything they need
        } else {
            SoapVersion soapVersion = message.getVersion();
            throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e,
                                soapVersion.getSender());
        }
    }
}
 
Example #19
Source File: Soap12Test.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Test the endpoint address sent to the STS as part of AppliesTo. If the STS does not
 * recognise the endpoint address it does not issue a token.
 */
@org.junit.Test
public void testFaultCode() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = Soap12Test.class.getResource("cxf-client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    try {
        String badAddress =
            "https://localhost:" + PORT + "/doubleit/services/baddoubleittransportsaml1";
        requestSecurityToken(SAML1_TOKEN_TYPE, BEARER_KEYTYPE, bus, badAddress);
        fail("Failure expected on a bad endpoint address");
    } catch (SoapFault ex) {
        // expected
    }

    bus.shutdown(true);
}
 
Example #20
Source File: AbstractJAXWSMethodInvoker.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
protected Fault createFault(Throwable ex, Method m, List<Object> params, boolean checked) {
    //map the JAX-WS faults
    SOAPFaultException sfe = findSoapFaultException(ex);
    if (sfe != null) {
        SoapFault fault = new SoapFault(sfe.getFault().getFaultString(),
                                        ex,
                                        sfe.getFault().getFaultCodeAsQName());
        fault.setRole(sfe.getFault().getFaultActor());
        if (sfe.getFault().hasDetail()) {
            fault.setDetail(sfe.getFault().getDetail());
        }

        return fault;
    }
    return super.createFault(ex, m, params, checked);
}
 
Example #21
Source File: MessageModeOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void validateFault(SoapMessage message, SOAPFault fault, BindingOperationInfo bop) {
    if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)) {
        Schema schema = EndpointReferenceUtils.getSchema(message.getExchange().getService()
                                                         .getServiceInfos().get(0),
                                                     message.getExchange().getBus());
        Detail d = fault.getDetail();
        try {
            validateFaultDetail(d, schema, bop);
        } catch (Exception e) {
            throw new SoapFault(e.getMessage(), e, message.getVersion().getReceiver());
        }

        //We validated what we can from a fault standpoint
        message.put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE);
    }
}
 
Example #22
Source File: MustUnderstandInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleMessage(SoapMessage soapMessage) throws Fault {
    SoapVersion soapVersion = soapMessage.getVersion();
    Set<QName> notFound = new HashSet<>();
    List<Header> heads = soapMessage.getHeaders();

    for (Header header : heads) {
        if (header instanceof SoapHeader
            && ((SoapHeader)header).isMustUnderstand()
            && header.getDirection() == Header.Direction.DIRECTION_IN
            && !knownHeaders.contains(header.getName())
            && (StringUtils.isEmpty(((SoapHeader)header).getActor())
                || soapVersion.getUltimateReceiverRole()
                    .equals(((SoapHeader)header).getActor()))) {

            notFound.add(header.getName());
        }
    }


    if (!notFound.isEmpty()) {
        soapMessage.remove(UNKNOWNS);
        throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notFound),
                        soapVersion.getMustUnderstand());
    }
}
 
Example #23
Source File: FragmentDialect.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public JAXBElement<ValueType> processGet(Get body, Representation representation) {
    for (Object o : body.getAny()) {
        if (o instanceof JAXBElement<?> && ((JAXBElement<?>)o).getDeclaredType() == ExpressionType.class) {
            ExpressionType expression = (ExpressionType) ((JAXBElement<?>)o).getValue();
            String languageIRI = expression.getLanguage();
            languageIRI = languageIRI == null ? FragmentDialectConstants.XPATH10_LANGUAGE_IRI : languageIRI;
            if (languages.containsKey(languageIRI)) {
                FragmentDialectLanguage language = languages.get(languageIRI);
                return generateGetResponse(language.getResourceFragment(representation, expression));
            }
            throw new UnsupportedLanguage();
        }
    }
    throw new SoapFault("wsf:Expression is not present.", getSoapVersion().getSender());
}
 
Example #24
Source File: SAAJInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(SoapMessage message) throws Fault {
    if (isGET(message)) {
        return;
    }
    if (isRequestor(message) && message.getExchange().getInMessage() == null) {
        //already processed
        return;
    }
    try {
        XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
        if (xmlReader == null) {
            return;
        }
        if (xmlReader.nextTag() == XMLStreamConstants.START_ELEMENT) {
            ReadHeadersInterceptor.readVersion(xmlReader, message);
        }
        MessageFactory factory = getFactory(message);
        SOAPMessage soapMessage = factory.createMessage();
        message.setContent(SOAPMessage.class, soapMessage);

        SOAPPart part = soapMessage.getSOAPPart();
        message.setContent(Node.class, part);
        message.put(W3CDOMStreamWriter.class, new SAAJStreamWriter(part));
        message.put(BODY_FILLED_IN, Boolean.FALSE);

    } catch (RuntimeException ex) {
        throw ex;
    } catch (Exception e) {
        throw new SoapFault("XML_STREAM_EXC", BUNDLE, e, message.getVersion().getSender());
    }
}
 
Example #25
Source File: SoapFaultFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void createSoap12FaultWithoutDetail() {
    SoapBinding sb = control.createMock(SoapBinding.class);
    EasyMock.expect(sb.getSoapVersion()).andReturn(Soap12.getInstance());
    setupSequenceFault(true, RM10Constants.CREATE_SEQUENCE_REFUSED_FAULT_QNAME, null);
    control.replay();
    SoapFaultFactory factory = new SoapFaultFactory(sb);
    SoapFault fault = (SoapFault)factory.createFault(sf, createInboundMessage());
    assertEquals("reason", fault.getReason());
    assertEquals(Soap12.getInstance().getSender(), fault.getFaultCode());
    assertEquals(RM10Constants.CREATE_SEQUENCE_REFUSED_FAULT_QNAME, fault.getSubCode());
    assertNull(fault.getDetail());

    control.verify();
}
 
Example #26
Source File: MAPAggregatorImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Check for NONE ReplyTo value in request-response MEP
 * @param message the current message
 * @param maps the incoming MAPs
 */
private void checkReplyTo(Message message, AddressingProperties maps) {
    // if ReplyTo address is none then 202 response status is expected
    // However returning a fault is more appropriate for request-response MEP
    if (!message.getExchange().isOneWay()
        && !MessageUtils.isPartialResponse(message)
        && ContextUtils.isNoneAddress(maps.getReplyTo())) {
        String reason = MessageFormat.format(BUNDLE.getString("REPLYTO_NOT_SUPPORTED_MSG"),
                                             maps.getReplyTo().getAddress().getValue());
        throw new SoapFault(reason,
                            new QName(Names.WSA_NAMESPACE_NAME,
                                      Names.WSA_NONE_ADDRESS));
    }
}
 
Example #27
Source File: WebFaultOutInterceptorTestCase.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSoapFaultCause() {
    SOAPFaultException cause = new SOAPFaultException(new SOAPFaultStub());
    Exception exception = new Exception(cause);
    SoapFault soapFault = new SoapFault("message", exception, CODE);
    Message message = createMessage(soapFault);

    interceptor.handleMessage(message);

    Assert.assertNotNull(soapFault.getSubCodes());
    Assert.assertEquals(1, soapFault.getSubCodes().size());
    Assert.assertEquals(SUBCODE, soapFault.getSubCodes().get(0));
    Assert.assertEquals(CODE, soapFault.getFaultCode());
}
 
Example #28
Source File: SoapFaultFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
public String toString(Fault f) {
    SoapFault sf = (SoapFault)f;
    org.apache.cxf.common.i18n.Message msg
        = new org.apache.cxf.common.i18n.Message("SEQ_FAULT_MSG", LOG,
            new Object[] {sf.getReason(), sf.getFaultCode(), sf.getSubCode()});
    return msg.toString();
}
 
Example #29
Source File: SoapFaultFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
void setDetail(SoapFault fault, Object detail, EncoderDecoder codec) throws Exception {
    String name = fault.getSubCode().getLocalPart();
    Element element = null;
    if (RMConstants.INVALID_ACKNOWLEDGMENT_FAULT_CODE.equals(name)) {
        element = codec.encodeSequenceAcknowledgement((SequenceAcknowledgement)detail);
    } else if (!RMConstants.CREATE_SEQUENCE_REFUSED_FAULT_CODE.equals(name)
        && !RMConstants.WSRM_REQUIRED_FAULT_CODE.equals(name)) {
        element = codec.encodeIdentifier((Identifier)detail);
    }
    fault.setDetail(element);
}
 
Example #30
Source File: WebFaultOutInterceptorTestCase.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSoapFaultCauseCause() {
    SOAPFaultException cause = new SOAPFaultException(new SOAPFaultStub());
    Exception innerException = new Exception(cause);
    Exception outerException = new Exception(innerException);
    SoapFault soapFault = new SoapFault("message", outerException, CODE);
    Message message = createMessage(soapFault);

    interceptor.handleMessage(message);

    Assert.assertTrue("SoapFault.subCodes are expected to be empty.",
            soapFault.getSubCodes() == null || soapFault.getSubCodes().isEmpty());
    Assert.assertEquals(CODE, soapFault.getFaultCode());
}