Advertisement
Guest User

Untitled

a guest
Jun 5th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. package linwebservicetest;
  2.  
  3. import java.net.Authenticator;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         String userName = "cramo";
  9.         String password = "INSERTPASSHERE";
  10.  
  11.         Authenticator.setDefault(new BasicHTTPAuthenticator(userName, password));
  12.  
  13.         try { // Call Web Service Operation
  14.             https.invoice_lindorff_com.webservices.LinaxInvoiceWebService service = new https.invoice_lindorff_com.webservices.LinaxInvoiceWebService();
  15.             https.invoice_lindorff_com.webservices.ILindorffInvoiceWebService port = service.getWS2007HttpBindingILindorffInvoiceWebService();
  16.  
  17.  
  18.             // TODO initialize WS operation arguments here
  19.             java.lang.String customerNumber = "1";
  20.             // TODO process result here
  21.             org.datacontract.schemas._2004._07.lindorff_invoice_web_service_interfaces.Customer result = port.getCustomer(customerNumber);
  22.             System.out.println("Result = "+result);
  23.         } catch (Exception ex) {
  24.             ex.printStackTrace();
  25.         }
  26.  
  27.     }
  28. }
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. package linwebservicetest;
  36.  
  37. import java.net.Authenticator;
  38. import java.net.PasswordAuthentication;
  39. import java.util.logging.Logger;
  40.  
  41. /**
  42.  *
  43.  * @author developer
  44.  */
  45. public class BasicHTTPAuthenticator extends Authenticator {
  46.  
  47.     private String userName;
  48.     private String password;
  49.     Logger log = Logger.getLogger(BasicHTTPAuthenticator.class.getName());
  50.  
  51.     public BasicHTTPAuthenticator(String userName, String password) {
  52.         this.userName = userName;
  53.         this.password = password;
  54.     }
  55.  
  56.     @Override
  57.     protected PasswordAuthentication getPasswordAuthentication() {
  58.         log.fine("getPasswordAuthenticator, protocol is " + this.getRequestingProtocol()
  59.                 + " userName is " + userName);
  60.         // only return username / password if using https
  61.         // because we don't want to show them in clear text
  62.         if (this.getRequestingProtocol().equalsIgnoreCase("https")) {
  63.             return new PasswordAuthentication(userName,
  64.                     password.toCharArray());
  65.         } else {
  66.             return null;
  67.         }
  68.     }
  69.  
  70.     public String getUserName() {
  71.         return userName;
  72.     }
  73.  
  74.     public void setUserName(String userName) {
  75.         this.userName = userName;
  76.     }
  77.  
  78.     public String getPassword() {
  79.         return password;
  80.     }
  81.  
  82.     public void setPassword(String password) {
  83.         this.password = password;
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement