title: How to send username password for web service authentication from client side
body: <p>I have searched this forum and and searched the net but i am not able to find the solution to my problem.</p>
  
  <p>I was given a WSDL file, using which i generated stubs with the help of axis1.4 . I have also created the XML response which is exactly the same as which the service requires, but when i try to access the service it says "Authorization failed".</p>
  
  <p>Then i came to know the web service is protected with username password.</p>
  
  <p>How should i send username password in my XML request.</p>
  
  <p>Below is my code how i generate a request.</p>
  
  <pre><code>public class SearcUserFriendlyIsMain {
  
  /**
   * @param args
   */
  Tews6SoapBindingStub stub = null;
  public void init(){
      if(null == stub) {
          try {
  
              URL url = null;
              String endPoint = "http://localhost:1111";
  
              try {
                  url = new URL(endPoint);
              } catch (MalformedURLException e) {                 
                  e.printStackTrace();
              }
  
              stub = new Tews6SoapBindingStub(url, null);
              stub.setMaintainSession(true);
  
          } catch (AxisFault e) {
  
  
  
              StringBuffer sb = new StringBuffer();
              for (StackTraceElement t : e.getStackTrace()) {
                  sb.append("\n").append(t.toString());
              }
              System.out.println("DEBUG"+ sb.toString());
  
          }
      }
  }
  public static void main(String[] args) {
      SearcUserFriendlyIsMain tds = new SearcUserFriendlyIsMain();
      tds.init();
      NYCBSearchUserByFriendlyIdQuery query = new NYCBSearchUserByFriendlyIdQuery();
      NYCBSearchUserByFriendlyIdSearch search = new NYCBSearchUserByFriendlyIdSearch();
      NYCBSearchUserByFriendlyIdQueryResult res = null;
      NYCBSearchUserByFriendlyIdSearchFilter filter = new NYCBSearchUserByFriendlyIdSearchFilter();
      NYCBSearchUserByFriendlyIdSearchFilter[] filters = {filter};
      filter.setOp(OperatorType.EQUALS);
      filter.setIndex(new  BigInteger("1"));
      filter.setField("USERID");
      filter.setValue("junaidaj01");
      search.setFilter(filters);
      NYCBSearchUserByFriendlyIdQueryTaskContext context = new NYCBSearchUserByFriendlyIdQueryTaskContext();
      context.setAdmin_id("uid=00000001-0001-0001-0001-0000000ja202,ou=serviceaccounts,dc=test,dc=com");
      query.setNYCBSearchUserByFriendlyIdSearch(search);
      try {
          res = tds.stub.NYCBSearchUserByFriendlyIdQuery(context,query);
          System.out.println(res.getImsStatus());
      } catch (ImsException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (RemoteException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  
  }
  </code></pre>