且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Eclipse的Java Web Service客户端身份验证

更新时间:2023-12-04 07:53:52

由于您的错误,我认为您使用的是 Axis ,因此 Authenticator 不能在其中使用.如果要对 Axis 服务执行客户端的基本身份验证,则需要执行以下操作:

From your error I assume you are using Axis so the Authenticator won't work on it. If you want to perform the client's basic authentication to Axis service, you need to do something like this:

private static final Logger LOGGER = LoggerFactory.getLogger(YourClass.class);

private ShipmentService_PortType proxy;

public void init()
        throws Exception {
    ShipmentService_ServiceLocator locator = new ShipmentService_ServiceLocator();
    try {
        LOGGER.debug("Initializing shipment service...");
        proxy = locator.getShipmentServicePort(new URL("yourServiceEndpointURL"));
        ((ShipmentServicePortBindingStub) proxy).setUsername("yourUsername");
        ((ShipmentServicePortBindingStub) proxy).setPassword("yourPassword");
        ((ShipmentServicePortBindingStub) proxy).setTimeout(10000);
        LOGGER.debug("Shipment service successfully initialized.");
    } catch (ServiceException e) {
        LOGGER.error("Error in shipment client initialization", e);
        throw new Exception("Error in shipment client initialization.");
    } catch (MalformedURLException e) {
        LOGGER.error("Error in shipment client initialization", e);
        throw new Exception("Error in shipment client initialization.");
    }
}

并且只有当此 init()方法被调用时,您才可以通过以下方法调用客户端的方法:

And only when this init() method will be called you will be able to call your client's methods through this:

proxy.getCloseDesc("35557");