Java-Web-Service-client-Authentifizierung mithilfe von eclipse

Habe ich verwendet Standard-eclipse-Assistent zum erstellen einer web-service-client (Datei>Neu - >Sonstige, und wählen Sie einen Assistenten für die web-service-client). Die Klassen generiert wurden, und ich war in der Lage, zur Nutzung von service-Methoden mit code wie diesem:

import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.olsn.ws.ShipmentService_PortType;
import com.olsn.ws.ShipmentService_ServiceLocator;

public class wsClient {
 public static void main(String[] args) throws ServiceException, RemoteException {

             //To load the web service and to create the client
             ShipmentService_ServiceLocator WS = new ShipmentService_ServiceLocator();              
             ShipmentService_PortType client = WS.getShipmentServicePort();

             //To get Close status for Issue
             System.out.println(client.getCloseDesc("35557"));

             //To get the list of NetP projects
             for (int i=1; i<client.getProjects().length;i++)
                 {System.out.println(client.getProjects()[i].toString());}

           }

     }

Das problem ist jetzt, dass der Benutzername und das Passwort wurden eingeführt, und ich weiß nicht, wie zu ändern mein code, um den Zugriff auf den server, ich habe versucht, hinzufügen authenticator:

import java.net.Authenticator;
import java.net.PasswordAuthentication;

Authenticator myAuth = new Authenticator() 
{
    @Override
    protected PasswordAuthentication getPasswordAuthentication()
    {
        return new PasswordAuthentication("user", "password".toCharArray());
    }
};

Authenticator.setDefault(myAuth);

ändern oder _initShipmentServiceProxy () - Methode der generierten proxy-Klasse

  private void _initShipmentServiceProxy() {
    try {
      shipmentService_PortType = (new com.olsn.ws.ShipmentService_ServiceLocator()).getShipmentServicePort();
      if (shipmentService_PortType != null) {
        if (_endpoint != null)
        {
          ((javax.xml.rpc.Stub)shipmentService_PortType)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
          **((javax.xml.rpc.Stub)shipmentService_PortType)._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, "user");
          ((javax.xml.rpc.Stub)shipmentService_PortType)._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, "password");**
        }  
        else
          _endpoint = (String)((javax.xml.rpc.Stub)shipmentService_PortType)._getProperty("javax.xml.rpc.service.endpoint.address");
      }

    }
    catch (javax.xml.rpc.ServiceException serviceException) {}
  }

Aber ich auch weiterhin immer diesen Fehler:

org.apache.axis.utils.JavaUtils isAttachmentSupported
WARNING: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
Exception in thread "main" AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client.Authentication
 faultSubcode: 
 faultString: Access denied to operation getCloseDesc

Bitte beraten, was sollte ich ändern?

  • wie zur Authentifizierung im server...Bitte teilen Sie die Informationen
InformationsquelleAutor lenchevsky | 2012-09-20
Schreibe einen Kommentar