title: javax.xml.ws.Service fails in constructor because site has username/password
body: <p>I want to access a web service and this is what the code looks like:</p>
  
  <pre><code>URL url = new URL("http://localhost:8080/sample?ver_=1.0");
  
  QName qname = new QName("http://webservices.sample.com/sample", "sample");
  
  javax.xml.ws.Service service = javax.xml.ws.Service.create(url, qname);
  </code></pre>
  
  <p>The line that initializes 'service' throws a 401 Unauthorized exception.</p>
  
  <p>If I visit the </p>
  
  <pre><code>http://localhost:8080/sample?ver_=1.0 
  </code></pre>
  
  <p>using a browser, a window asking for a username and password pops up.</p>
  
  <p>I tried capturing the packets using Wireshark and noticed that the constructor for service sends an HTTP Get to the IP Address but without the credentials.</p>
  
  <p>How do I make sure that the call to HTTP Get by the Service constructor include the username/password?</p>
  
  <p>I already tried putting this before the call but it didn't help</p>
  
  <pre><code>Authenticator.setDefault(new Authenticator() {
  protected PasswordAuthentication getPasswordAuthentication() {
  return new PasswordAuthentication(
  "username",
  "password".toCharArray());
  }
  });
  </code></pre>
  
  <p>Thanks!</p>