Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6836603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:22:30+00:00 2026-05-26T23:22:30+00:00

I have web-service created and configured via Spring and CXF . See beans below:

  • 0

I have web-service created and configured via Spring and CXF. See beans below:

<?xml version="1.0" encoding="UTF-8"?>
<beans <!-- ommited -->>
    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

    <bean id="internalActService" class="package.InternalActServiceImpl" />

    <jaxws:endpoint implementor="#internalActService" address="/InternalActService">
        <jaxws:properties>
            <entry key="schema-validation-enabled" value="true" />
        </jaxws:properties>

        <jaxws:outFaultInterceptors>
            <bean class="package.InternalActServiceFaultOutInterceptor" />
        </jaxws:outFaultInterceptors>
    </jaxws:endpoint>
</beans>

As can you see I added schema validation to my web service. But CXF throws SoapFault when request is not corresponding with schema.
I want to send to the client SoapMessage instead of SoapFault, that’s why I added outFaultInterceptors.

My question is how to transform SoapFault to SoapMessage? I’ve made few tries but I don’t know how to implement outFaultInterceptor.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:22:31+00:00Added an answer on May 26, 2026 at 11:22 pm

    Probably you forgot to setup interceptor phase and its order in the interceptor chain.

    Try something like this:

    package org.foo.bar;
    
    import org.apache.cxf.binding.soap.SoapMessage;
    import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
    import org.apache.cxf.interceptor.AttachmentOutInterceptor;
    import org.apache.cxf.interceptor.Fault;
    import org.apache.cxf.interceptor.StaxOutInterceptor;
    import org.apache.cxf.message.Message;
    import org.apache.cxf.message.MessageContentsList;
    import org.apache.cxf.phase.AbstractPhaseInterceptor;
    import org.apache.cxf.phase.Phase;
    
    import java.util.Arrays;
    import java.util.List;
    
    public class InternalActServiceFaultOutInterceptor extends AbstractSoapInterceptor {
    
        public InternalActServiceFaultOutInterceptor() {
            super(Phase.PRE_STREAM);
            addBefore(Arrays.asList(StaxOutInterceptor.class.getName(), AttachmentOutInterceptor.class.getName()));
        }
    
        @Override
        public void handleMessage(SoapMessage message) throws Fault {
            Exception exception = message.getContent(Exception.class);
            if(exception != null) {
                message.getExchange().put(Exception.class, null);
    
                for(Class<?> contentFormat : message.getContentFormats()) {
                    message.setContent(contentFormat, null);
                }
    
                message.setContent(List.class, new MessageContentsList(createSoapMessage(RegisterDocumentResponse.class)));
            }
        }
    
        protected <T> T createSoapMessage(Class<T> messageType) {
            // create your message
            return null;
        }
    
    }
    

    -EDIT-

    Here is a unit test that works for me. It’s a little bit tricky to be able to send POJOs to the output. I suppose it can be much more simpler if constructing DOM by yourself.

    Interceptor

    package foo.bar;
    
    import java.util.Arrays;
    import java.util.List;
    
    import org.apache.cxf.binding.soap.SoapMessage;
    import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
    import org.apache.cxf.endpoint.Endpoint;
    import org.apache.cxf.interceptor.Fault;
    import org.apache.cxf.interceptor.Interceptor;
    import org.apache.cxf.interceptor.InterceptorChain;
    import org.apache.cxf.interceptor.OutgoingChainInterceptor;
    import org.apache.cxf.message.Exchange;
    import org.apache.cxf.message.Message;
    import org.apache.cxf.message.MessageContentsList;
    import org.apache.cxf.phase.Phase;
    import org.apache.cxf.service.model.BindingMessageInfo;
    import org.apache.cxf.service.model.BindingOperationInfo;
    import org.apache.cxf.service.model.MessageInfo;
    import org.apache.cxf.service.model.OperationInfo;
    import org.apache.cxf.service.model.ServiceModelUtil;
    import org.apache.cxf.ws.policy.PolicyOutInterceptor;
    
    public class InternalActServiceFaultOutInterceptor extends AbstractSoapInterceptor {
    
        public InternalActServiceFaultOutInterceptor() {
            super(Phase.SETUP);
            addBefore(Arrays.asList(PolicyOutInterceptor.class.getName()));
        }
    
        @Override
        public void handleMessage(SoapMessage message) throws Fault {
            Exchange exchange = message.getExchange();
    
            resetOrigInterceptorChain(message);
            resetFault(exchange);
    
            Message outMessage = createOutMessage(exchange);
    
            InterceptorChain chain = prepareNewInterceptorChain(exchange);
            chain.doIntercept(outMessage);
        }
    
        private InterceptorChain prepareNewInterceptorChain(Exchange exchange) {
            Message message = exchange.getOutMessage();
            bind(message);
    
            InterceptorChain chain = OutgoingChainInterceptor.getOutInterceptorChain(exchange);
            message.setInterceptorChain(chain);
    
            return chain;
        }
    
        private Message createOutMessage(Exchange exchange) {
            Endpoint ep = exchange.get(Endpoint.class);
    
            Message outMessage = ep.getBinding().createMessage();
            outMessage.setExchange(exchange);
            outMessage.setContent(List.class, new MessageContentsList(createSoapMessage()));
    
            exchange.setOutMessage(outMessage);
            return outMessage;
        }
    
        private void resetFault(Exchange exchange) {
            exchange.put(Exception.class, null);
        }
    
        private void resetOrigInterceptorChain(SoapMessage message) {
            InterceptorChain chain = message.getInterceptorChain();
            for(Interceptor<?> interceptor : chain) {
                chain.remove(interceptor);
            }
            chain.reset();
        }
    
        private void bind(Message message) {
            Exchange exchange = message.getExchange();
            BindingOperationInfo bop = unwrap(message.getExchange().getBindingOperationInfo());
    
            message.put(MessageInfo.class, bop.getOperationInfo().getOutput());
            message.put(BindingMessageInfo.class, bop.getOutput());
    
            bop = unwrap(ServiceModelUtil.getOperationForWrapperElement(exchange, bop.getName(), false));
    
            exchange.put(BindingOperationInfo.class, bop);
            if (bop != null) {
                exchange.put(BindingOperationInfo.class, bop);
                exchange.put(OperationInfo.class, bop.getOperationInfo());
            }
        }
    
        private BindingOperationInfo unwrap(BindingOperationInfo bop) {
            while(bop.getUnwrappedOperation() != null) {
                bop = bop.getUnwrappedOperation();
                return bop;
            }
            return bop;
        }
    
        protected Echo createSoapMessage() {
            Echo e = new Echo();
            e.setValue("Bye World!");
            return e;
        }
    
    }
    

    Request/Response POJO

    package foo.bar;
    
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlType;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "EchoType")
    public class Echo {
        private String value;
        public String getValue() {
            return value;
        }
        public void setValue(String value) {
            this.value = value;
        }
    }
    

    WebService

    package foo.bar;
    
    import javax.jws.WebService;
    
    @WebService
    public class InternalActServiceImpl {
        public Echo echo(Echo val) {
            return val;
        }
    }
    

    Spring Context: CxfInterceptorTest-context.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
    ">
    
        <import resource="classpath:META-INF/cxf/cxf.xml" />
        <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
        <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
        <import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml" />
    
        <bean id="internalActService" class="foo.bar.InternalActServiceImpl" />
    
        <jaxws:endpoint implementor="#internalActService" address="http://localhost:9080/InternalActService">
            <jaxws:properties>
                <entry key="schema-validation-enabled" value="true" />
            </jaxws:properties>
            <jaxws:outFaultInterceptors>
                <bean class="foo.bar.InternalActServiceFaultOutInterceptor" />
            </jaxws:outFaultInterceptors>
        </jaxws:endpoint>
    

    Unit Test

    package foo.bar;
    
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    import org.junit.Assert;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration
    public class CxfInterceptorTest {
    
        private static final String REQ =
                "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:bar=\"http://bar.foo/\">\r\n" +
                "   <soapenv:Header/>\r\n" +
                "   <soapenv:Body>\r\n" +
                "      <bar:echo>\r\n" +
                "         <arg0>\r\n" +
                "            <value1>Hello World</value1>\r\n" +
                "         </arg0>\r\n" +
                "      </bar:echo>\r\n" +
                "   </soapenv:Body>\r\n" +
                "</soapenv:Envelope>";
    
        @Test
        public void validate() throws Exception {
            String s = call();
            Assert.assertTrue(s.contains("Bye World!"));
        }
    
        private String call() throws Exception {
            URL url = new URL("http://localhost:9080/InternalActService");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    
            conn.setDoOutput(true);
            conn.setInstanceFollowRedirects(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
            conn.setRequestProperty("SOAPAction", "");
    
            OutputStream os = conn.getOutputStream();
            os.write(REQ.getBytes());
            os.flush();
            os.close();
    
            final int buffSize = 1024;
            byte[] buff = new byte[1024];
            InputStream is = conn.getInputStream();
    
            StringBuilder builder = new StringBuilder(buffSize);
            for(int readBytes = -1; (readBytes = is.read(buff, 0, buffSize)) != -1; ) {
                builder.append(new String(buff, 0, readBytes));
            }
    
            is.close();
    
            return builder.toString();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a web service via WCF. Then I exposed it as a
I have two applications Web Socket and Web Service created in .Net/Web Form and
I have created Web-Service in asp.net with c# . Now i want to pass
I have a web service in which I created an enum.. i have a
I have created a web service which is saving some data into to db.
I have created a web service which takes a username and password as parameters
I have created a web service which returns some data and am trying to
I have created a REST web service and successfully used it with a client.
I have created the simple web service. Code: [ServiceContract] public interface ITsdxService { [OperationContract]
I have created a Java web service and I am trying to access this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.