Переписал процедуру на java. Теперь у меня java- агент вызывает методы сервиса. Ошибка 401 Authorization Required пропала и теперь вроде бы сервис вызывается, но возвращает другой стек ошибок:
WebServiceEngineFault
faultCode: Client
faultSubcode:
faultString: An exception has been raised as a result of client data.
faultActor:
faultNode:
faultDetail:
{http://www.ups.com/XMLSchema/XOLTWS/Error/v1.1}Errors: <err:ErrorDetail><err:Severity></err:Severity><err
rimaryErrorCode><err:Code></err:Code><err
escription></err
escription></err
rimaryErrorCode></err:ErrorDet<!--shcode--><pre><code class='<b></b>'>WebServiceEngineFault
faultCode: Client
faultSubcode:
faultString: An exception has been raised as a result of client data.
faultActor:
faultNode:
faultDetail:
{http://www.ups.com/XMLSchema/XOLTWS/Error/v1.1}Errors: <err:ErrorDetail><err:Severity></err:Severity><err
rimaryErrorCode><err:Code></err:Code><err
escription></err
escription></err
rimaryErrorCode></err:ErrorDetail>
An exception has been raised as a result of client data.
at java.lang.J9VMInternals.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1547)
at lotus.domino.axis.encoding.ser.BeanDeserializer.<init>(Unknown Source)
at lotus.domino.axis.encoding.ser.V3BeanDeserializerFactory.getGeneralPurpose(Unknown Source)
at lotus.domino.axis.encoding.ser.BaseDeserializerFactory.getDeserializerAs(Unknown Source)
at lotus.domino.axis.encoding.ser.BeanDeserializerFactory.getDeserializerAs(Unknown Source)
at lotus.domino.axis.encoding.DeserializationContextImpl.getDeserializer(Unknown Source)
at lotus.domino.axis.encoding.DeserializationContextImpl.getDeserializerForType(Unknown Source)
at lotus.domino.axis.message.SOAPFaultDetailsBuilder.onStartChild(Unknown Source)
at lotus.domino.axis.encoding.DeserializationContextImpl.startElement(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
at lotus.domino.axis.encoding.DeserializationContextImpl.parse(Unknown Source)
at lotus.domino.axis.SOAPPart.getAsSOAPEnvelope(Unknown Source)
at lotus.domino.axis.Message.getSOAPEnvelope(Unknown Source)
at lotus.domino.axis.client.Call.invokeEngine(Unknown Source)
at lotus.domino.axis.client.Call.invoke(Unknown Source)
at lotus.domino.axis.client.Call.invoke(Unknown Source)
at lotus.domino.axis.client.Call.invoke(Unknown Source)
at lotus.domino.axis.client.Call.invoke(Unknown Source)
at lotus.domino.websvc.client.Call.invoke(Unknown Source)
at com.ups.www.WSDL.XOLTWS.Rate.v1_1.RateBindingStub.processRate(Unknown Source)
at JavaAgent.NotesMain(Unknown Source)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)[/CODE]ail>
An exception has been raised as a result of client data.
at java.lang.J9VMInternals.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1547)
at lotus.domino.axis.encoding.ser.BeanDeserializer.<init>(Unknown Source)
at lotus.domino.axis.encoding.ser.V3BeanDeserializerFactory.getGeneralPurpose(Unkno
wn Source)
at lotus.domino.axis.encoding.ser.BaseDeserializerFactory.getDeserializerAs(Unknown Source)
at lotus.domino.axis.encoding.ser.BeanDeserializerFactory.getDeserializerAs(Unknown Source)
at lotus.domino.axis.encoding.DeserializationContextImpl.getDeserializer(Unknown Source)
at lotus.domino.axis.encoding.DeserializationContextImpl.getDeserializerForType(Unk
nown Source)
at lotus.domino.axis.message.SOAPFaultDetailsBuilder.onStartChild(Unknown Source)
at lotus.domino.axis.encoding.DeserializationContextImpl.startElement(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
at lotus.domino.axis.encoding.DeserializationContextImpl.parse(Unknown Source)
at lotus.domino.axis.SOAPPart.getAsSOAPEnvelope(Unknown Source)
at lotus.domino.axis.Message.getSOAPEnvelope(Unknown Source)
at lotus.domino.axis.client.Call.invokeEngine(Unknown Source)
at lotus.domino.axis.client.Call.invoke(Unknown Source)
at lotus.domino.axis.client.Call.invoke(Unknown Source)
at lotus.domino.axis.client.Call.invoke(Unknown Source)
at lotus.domino.axis.client.Call.invoke(Unknown Source)
at lotus.domino.websvc.client.Call.invoke(Unknown Source)
at com.ups.www.WSDL.XOLTWS.Rate.v1_1.RateBindingStub.processRate(Unknown Source)
at JavaAgent.NotesMain(Unknown Source)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
Вот сам код агента:
import com.ups.www.XMLSchema.XOLTWS.Rate.v1_1.*;
import com.ups.www.XMLSchema.XOLTWS.Common.v1_0.*;
import com.ups.www.XMLSchema.XOLTWS.Rate.v1_1.CodeDescriptionType;
import com.ups.www.WSDL.XOLTWS.Rate.v1_1.RateServiceLocator;
import com.ups.www.XMLSchema.XOLTWS.UPSS.v1_0.*;
import lotus.domino.*;
public class JavaAgent extends AgentBase {
Session session;
Database db ;
String wssearchkey ;
ShipmentType shipment;
_RateRequest raterequest;
_RateResponse rateresponse;
RequestType requestType ;
public void NotesMain() {
try {
Document setdoc ;
session = getSession();
db = session.getCurrentDatabase();
wssearchkey = "UPSWebServiceSetting".toLowerCase();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
Document demand = db.getDocumentByID(agentContext.getCurrentAgent().getParameterDocID());
if (demand== null) {
System.out.println("Не найден документ");
return;
};
// System.out.println("Нашли документ для обработки");
setdoc = this.getsettingdoc();
if (setdoc == null) return;
//******************************************************
// System.out.println("записываем параметры безопасности");
_UPSSecurity upssec = new _UPSSecurity ();
upssec = this.getupssecurityparams(setdoc);
if (upssec== null) return;
//******************************************************
//System.out.println("генерируем запрос");
raterequest = this.generaterequest(demand, setdoc);
if (raterequest == null){
System.out.println("raterequest == null");
return;
};
//System.out.println(raterequest.getRequest().getRequestOption(0).toString());
// System.out.println("запуск самого сервиса");
// запуск самого сервиса
System.out.println("getShipTo CountryCode: "+raterequest.getShipment().getShipTo().getAddress().getCountryCode());
System.out.println("getShipTo getPostalCode: "+raterequest.getShipment().getShipTo().getAddress().getPostalCode());
System.out.println("getShipTo getAddressLine: "+raterequest.getShipment().getShipTo().getAddress().getAddressLine(0));
System.out.println("Shipper CountryCode: "+raterequest.getShipment().getShipper().getAddress().getCountryCode());
System.out.println("Shipper getPostalCode: "+raterequest.getShipment().getShipper().getAddress().getPostalCode());
System.out.println("Shipper getAddressLine: "+raterequest.getShipment().getShipper().getAddress().getAddressLine(0));
System.out.println("getLength"+raterequest.getShipment().get_package(0).getDimensions().getLength());
RateServiceLocator rr = new RateServiceLocator ();
//com.ups.www.WSDL.XOLTWS.Rate.v1_1.RatePortType stub = rr.getRatePort();
// URL portaddr = new URL ("https://wwwcie.ups.com/webservices/Rate");
rr.getRatePort().setCredentials(setdoc.getItemValueString("USERNAME"), setdoc.getItemValueString("USERPASSWORD"));
if (upssec == null) {
System.out.println("upssec is nothing");
return;
};
// данные о параметрах безопасности
System.out.println("getAccessLicenseNumber "+upssec.getServiceAccessToken().getAccessLicenseNumber());
System.out.println("getUsernameToken UserName "+upssec.getUsernameToken().getUsername());
System.out.println("getUsernameToken Password "+upssec.getUsernameToken().getPassword());
if (raterequest== null) {
System.out.println("raterequest== null");
return;
};
rateresponse = rr.getRatePort().processRate(raterequest, upssec);
System.out.println ("Статус"+ rateresponse.getResponse().getResponseStatus().toString());
} catch(Exception e) {
System.out.println("Error in AgentBase: ");
e.printStackTrace();
}
};
//====================================================
private Document getsettingdoc () {
try {
// System.out.println("получение setview");
View setview = db.getView("(WSSETView)");
if (setview==null) {
System.out.println("setview is null");
return null;
};
// System.out.println("wssearchkey = "+wssearchkey);
Document setdoc = setview.getDocumentByKey(wssearchkey, true);
if (setdoc == null) return null;
return setdoc;
} catch (NotesException err) {
System.out.println("Error in function 'getsettingdoc': "+err.toString());
return null;
}
}
//====================================================
private _UPSSecurity getupssecurityparams (Document setdoc){
try {
_UPSSecurity usec = new _UPSSecurity ();
_UPSSecurity_UsernameToken upsusnametoken = new _UPSSecurity_UsernameToken ();
_UPSSecurity_ServiceAccessToken upsservaccesstoken = new _UPSSecurity_ServiceAccessToken ();
// прописываем логин и пароль
upsusnametoken.setUsername(setdoc.getItemValueString("USERNAME"));
upsusnametoken.setPassword(setdoc.getItemValueString("USERPASSWORD"));
// ключ договора
upsservaccesstoken.setAccessLicenseNumber(setdoc.getItemValueString("AccessLicenseNumber"));
usec.setServiceAccessToken(upsservaccesstoken);
usec.setUsernameToken(upsusnametoken);
return usec;
} catch (NotesException err) {
System.out.println("Error in function 'getupssecurityparams': "+err.toString());
return null;
}
}
//====================================================
private _RateRequest generaterequest(Document demanddoc , Document setdoc) {
try {
System.out.println("generaterequest start");
_RateRequest grequest = new _RateRequest ();
System.out.println("grequest");
requestType = new RequestType ();
// System.out.println("RequestType setdoc"+setdoc.getItemValueString("REQUESTOPTION"));
String str [] = {"Rate",""};
requestType.setRequestOption(str);
// System.out.println(grequest.getRequest().getRequestOption(0).toString());
// формирование параметров для отправки
shipment = this.generateshipmentparameters(demanddoc, setdoc);
if (shipment == null) return null;
grequest.setShipment(shipment);
// System.out.println("grequest getShipperNumber"+grequest.getShipment().getShipper().getShipperNumber().toLowerCase());
// System.out.println(grequest.getShipment().getService().getCode());
return grequest ;
} catch (Exception e) {
System.out.println("Error in 'generaterequest': "+e.toString());
return null ;
}
};
//====================================================
private ShipmentType generateshipmentparameters (Document demanddoc , Document setdoc) {
try {
// System.out.println ("generateshipmentparameters start");
ShipmentType shipment1 = new ShipmentType ();; // парметры отгрузки
ShipperType shipper = new ShipperType ();
ShipToType shipTo = new ShipToType ();
ShipFromType shipFrom = new ShipFromType ();
CodeDescriptionType service = new CodeDescriptionType ();
PackageType _package = new PackageType ();
AddressType adr = new AddressType ();
ShipToAddressType shiptoaddress = new ShipToAddressType ();
// данные об отправителе
// System.out.println ("данные об отправителе");
String fromloc = demanddoc.getItemValueString("FromLocation");
shipper.setName(fromloc);
// System.out.println ("Проставили наименование отправителя");
shipper.setShipperNumber(demanddoc.getItemValueString("ShipperNumber"));
// System.out.println ("Проставили ShipperNumber");
String cc [] = {demanddoc.getItemValueString("From_Address"),""};
adr.setAddressLine(cc);
adr.setCity(demanddoc.getItemValueString("FromTown")); // город откуда отправляем
// System.out.println ("город откуда");
adr.setCountryCode(setdoc.getItemValueString("CountryCode")); // код страны откуда отправляем
// System.out.println ("код страны откуда отправляем");
adr.setPostalCode(demanddoc.getItemValueString("FromZip"));
// System.out.println ("индекс города откуда отправляем");
shipper.setAddress(adr);
// System.out.println ("Проставили Адресные данные");
//-------------------------------------------//
// данные о получателе
// System.out.println ("данные о получателе");
String tolocation = demanddoc.getItemValueString("ToLocation");
shipTo.setName(tolocation);
String cc1 [] = {demanddoc.getItemValueString("To_Address"),""};
shiptoaddress.setAddressLine(cc1);
shiptoaddress.setCity(demanddoc.getItemValueString("ToTown")); // город куда отправляем
shiptoaddress.setCountryCode(setdoc.getItemValueString("CountryCode")); // код страны откуда отправляем
shiptoaddress.setPostalCode(demanddoc.getItemValueString("To_Index"));
shipTo.setAddress(shiptoaddress);
//-------------------------------------------//
// данные об отправителе
System.out.println ("данные от кого");
shipFrom.setName(fromloc);
adr.setAddressLine(cc);
adr.setCity(demanddoc.getItemValueString("FromTown")); // город откуда отправляем
adr.setCountryCode(setdoc.getItemValueString("CountryCode")); // код страны откуда отправляем
adr.setPostalCode(demanddoc.getItemValueString("From_Index"));
shipFrom.setAddress(adr);
//--------------------------------------------------------------
// код типа сервиса
// System.out.println ("код типа сервиса");
service.setCode(setdoc.getItemValueString("ServiceCode"));
//данные об отправляемом объекте
// System.out.println ("данные об отправляемом объекте");
CodeDescriptionType packagingType = new CodeDescriptionType ();
// System.out.println("Corresp_Type = "+demanddoc.getItemValueString("Corresp_Type"));
// if (demanddoc.getItemValueString("Corresp_Type") == "01") {
// packagingType.setCode("01"); // письмо
if (demanddoc.getItemValueString("Corresp_Type") == "02"){
// packagingType.setCode("02"); // коробка
com.ups.www.XMLSchema.XOLTWS.Rate.v1_1.DimensionsType dimensions = new com.ups.www.XMLSchema.XOLTWS.Rate.v1_1.DimensionsType ();
dimensions.setHeight(demanddoc.getItemValueString("Height"));
dimensions.setLength(demanddoc.getItemValueString("Length"));
dimensions.setWidth(demanddoc.getItemValueString("Width"));
CodeDescriptionType cdtype = new CodeDescriptionType ();
cdtype.setCode(setdoc.getItemValueString("unitOfMeasurementCode"));
dimensions.setUnitOfMeasurement(cdtype);
// вес коробки
PackageWeightType PackageWeight = new PackageWeightType();
cdtype.setCode(setdoc.getItemValueString("unitOfWeightCode"));
PackageWeight.setUnitOfMeasurement(cdtype); // размерность веса
PackageWeight.setWeight(demanddoc.getItemValueString("Weight"));
_package.setPackageWeight(PackageWeight);
_package.setDimensions(dimensions);
} else {
DimensionsType dimensions = new DimensionsType ();
dimensions.setHeight("0");
dimensions.setLength("0");
dimensions.setWidth("0");
CodeDescriptionType cdtype = new CodeDescriptionType ();
cdtype.setCode(setdoc.getItemValueString("unitOfMeasurementCode"));
dimensions.setUnitOfMeasurement(cdtype);
// вес коробки
PackageWeightType PackageWeight = new PackageWeightType();
cdtype.setCode(setdoc.getItemValueString("unitOfWeightCode"));
PackageWeight.setUnitOfMeasurement(cdtype); // размерность веса
PackageWeight.setWeight("0");
_package.setPackageWeight(PackageWeight);
_package.setDimensions(dimensions);
};
packagingType.setCode(demanddoc.getItemValueString("Corresp_Type"));
_package.setPackagingType(packagingType);
PackageType ptype [] = {_package};
// System.out.println ("запись параметров");
if (shipment1 == null) {
System.out.println ("shipment is null");
return null;
};
shipment1.setService(service);
System.out.println ("service");
shipment1.setShipper(shipper);
System.out.println ("shipper");
shipment1.setShipFrom(shipFrom);
System.out.println ("shipFrom");
shipment1.setShipTo(shipTo);
System.out.println ("shipTo");
shipment1.set_package(ptype);
System.out.println ("set_package");
// System.out.println ("generateshipmentparameters end");
return shipment1 ;
} catch (Exception err) {
System.out.println("Error in function 'generateshipmentparameters': "+err.toString());
return null;
}
}
}