title: How to throw a custom fault code and fault string in a webservice created using IBM Webexperience factory?
body: <p>I've created a service provider model in wef 8.0.0.2 and generated the wsdl using the service definition builder. It had a service operation which will authenticate a user, the input is username and password. If the username is invalid i wanted to show the error as a soap fault. So an exception is thrown in the java class which will validate the user name. The soap fault thrown is given below</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;soapenv:Body&gt;
          &lt;soapenv:Fault&gt;
              &lt;faultcode&gt;soapenv:Server.userException&lt;/faultcode&gt;
              &lt;faultstring&gt;java.rmi.RemoteException: Error in method authenticate.  Error in method authenticateExecute.  Error in method authenticate_al.  Error in method authenticateUser_ljo.authorizeUser.  ||01013||Authentication Failed, Try again !&lt;/faultstring&gt;
              &lt;detail&gt;
                  &lt;ns1:hostname xmlns:ns1="http://xml.apache.org/axis/"&gt;254&lt;/ns1:hostname&gt;
              &lt;/detail&gt;
          &lt;/soapenv:Fault&gt;
      &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>You can see the fault string is showing the trace where the exception is thrown. I only wanted to show the || separated text in the fault string -- <strong>||01013||Authentication Failed, Try again !</strong><br>
  The ljo class to throw the error is also shown</p>
  
  <pre><code>public class AuthenticateUser{
  public void authorizeUser(WebAppAccess webAppAccess) throws Exception {
          try {
              String username = webAppAccess.getVariables().getString("userNameVar");
              String password = webAppAccess.getVariables().getString("passwordVar");
              if (username.trim().length() == 0 || password.trim().length() == 0) {
                  throw new Exception();
              } else {
                  System.out.println("Success");
              }
          } catch (Exception e) {
              throw new Exception("||01013||Authentication Failed, Try again !");
          }
      }
  }
  </code></pre>
  
  <p>How can we set a custom fault code and fault string while throwing an exception.??</p>