« WS asynchrony models (BPEL Vs JAX-WS) | Main | End2End WS-Security with Oracle ESB (OESB) »

Customizing faults in WSM custom steps

Usually, WSM custom steps reflecting your own policy can lead to faults (as per the request not being compliant with the implemented policy). In those cases a custom SOAP fault will make sense in order to provide the invoker with details of the reason for the failure. The following code shows up how to generate such custom SOAP faults when creating WSM custom steps.


package ....;

import com.cfluent.pipelineengine.container.MessageContext;
import com.cfluent.policysteps.sdk.*;
import javax.xml.soap.*

public class CustomStep1 extends AbstractStep {

  private static final String CUSTOM_FAULT_NS = "http://my.custom.fault/ns";
  private static final String CUSTOM_DETAIL_NS = "http://my.custom.detail/ns";
  private static final String CUSTOM_DETAIL_PREFIX = "cd";

  //setters and getters
  .....
  public IResult execute(IMessageContext msgContext) throws Fault {
    IResult result = new Result();
    MessageContext msgCtxt = (MessageContext) msgContext;

    //evaluate error condition (true for testing)
    boolean myFaultCondicionA = true;

    if (myFaultCondicionA) {
      throw createCustomFaultA(msgCtxt, "detailValue1", "detailValue2");
    }

    return result;
  }

  private Fault createCustomFaultA(MessageContext msgCtxt, String value1, String value2) {
    return createFault(msgCtxt, "customCodeA", "error A description", new String[][] {{"CustomDetailA1", value1}, {"CustomDetailA2", value2}});
  }

  private Fault createFault(MessageContext msgCtxt, String faultCodeQualifier, String faultString, String[][] values) {
    try {
      SOAPFactory factory = SOAPFactoryImpl.newInstance();
      SOAPFault sf = msgCtxt.getRequest().getAxisMessage().getSOAPPart().getEnvelope().getBody().addFault();
      Detail detail = sf.addDetail();
      for (int i = 0; i < values.length; i++) {
        DetailEntry de = detail.addDetailEntry(factory.createName(values[i][0] , CUSTOM_DETAIL_PREFIX, CUSTOM_DETAIL_NS));
        de.addTextNode(values[i][1]);
      }
      return new Fault(CUSTOM_FAULT_NS, faultCodeQualifier, faultString, null, detail);
    } catch (SOAPException soape) {
      return new Fault(soape);
    }
  }
}







The result obtained because of the execution of the former code looks like this:


<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
    <SOAP-ENV:Fault>
      <faultcode xmlns:p="http://my.custom.fault/ns">p:Client.customCodeA</faultcode>
      <faultstring>error A description</faultstring>
      <detail>
        <cd:CustomDetailA1 xmlns:cd="http://my.custom.detail/ns">detailValue1</cd:CustomDetailA1>
        <cd:CustomDetailA2 xmlns:cd="http://my.custom.detail/ns">detailValue2</cd:CustomDetailA2>
      </detail>
    </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

TrackBack

TrackBack URL for this entry:
http://blogs.oracle.com/mte1521/mt-tb.cgi/8613

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on November 24, 2008 1:50 PM.

The previous post in this blog was WS asynchrony models (BPEL Vs JAX-WS).

The next post in this blog is End2End WS-Security with Oracle ESB (OESB).

Many more can be found on the main index page or by looking through the archives.

Top Tags

Powered by
Movable Type and Oracle