Post HTTP 调用适用于邮递员,但不适用于 Java 中的本地
我正在调用一个 api,其目的是验证客户的数据,该数据在邮递员中工作正常,但在我本地进行 http 调用时,它给出了不同的响应,甚至没有通过第一行。请求和响应采用 XML 形式。
Postman 请求和响应如下:
curl --location --request POST 'https://ckyc.olacabs-dev.in:54322/crmapi/TrackwizzWebApi/A63/CreateUpdateCustomer/V1' \
--header 'Content-Type: text/plain' \
--data-raw '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CustomerRelatedPartyCreateUpdateRequest>
<ParentCompany>NFPL</ParentCompany>
<ApiToken>ecef5041-a08a-43c9-9599-fc2d0c8da616</ApiToken>
<RecordRequestDetails>
<RecordRequestDetail>
<SourceSystemName>HomeLoan</SourceSystemName>
<SourceSystemCustomerCode>321875112</SourceSystemCustomerCode>
<IsSmallCustomer>0</IsSmallCustomer>
<EkycOTPBased>0</EkycOTPBased>
<CustomerStatus>
<StatusDetail>
<Status>Active</Status>
<EffectiveDate>1970-01-01T05:29:57.991+05:30</EffectiveDate>
</StatusDetail>
</CustomerStatus>
<CustomerType>1</CustomerType>
<Prefix>MISS</Prefix>
<FirstName>dolly</FirstName>
<LastName>vaishnav</LastName>
<FatherPrefix>MR</FatherPrefix>
<fatherFirstName>Prakash</fatherFirstName>
<Gender>female</Gender>
<formSixty>0</formSixty>
<KYCAttestationType>1</KYCAttestationType>
<CountryOfResidence>IN</CountryOfResidence>
<DateofBirth>1970-01-01T05:29:57.991+05:30</DateofBirth>
<KYCDateOfDeclaration>1970-01-01T05:29:57.991+05:30</KYCDateOfDeclaration>
<KYCPlaceOfDeclaration>Mumbai</KYCPlaceOfDeclaration>
<KYCVerificationDate>1970-01-01T05:29:57.991+05:30</KYCVerificationDate>
<KYCEmployeeName>Vikash</KYCEmployeeName>
<KYCEmployeeDesignation>manager</KYCEmployeeDesignation>
<KYCVerificationBranch>mumbai</KYCVerificationBranch>
<KYCEmployeeCode>1234</KYCEmployeeCode>
<AddressDetails>
<AddressDetail>
<AddressType>permanent</AddressType>
<AddressLine1>xyz</AddressLine1>
<PinCode>491001</PinCode>
<City>bhilai</City>
<AddressLine2>kormangala</AddressLine2>
<AddressLine3>5th block</AddressLine3>
<State>CG</State>
<Country>IN</Country>
<District>durg</District>
</AddressDetail>
</AddressDetails>
<PermanentAddressProof>passport</PermanentAddressProof>
<CorrespondenceAddressProof>dl</CorrespondenceAddressProof>
<IdentificationDetails>
<IdentificationDetail>
<IdType>passport</IdType>
<IdNumber>AVPBV4738</IdNumber>
</IdentificationDetail>
</IdentificationDetails>
<Minor>0</Minor>
<ModuleApplicable>
<ModuleDetail>
<Module>ckyc</Module>
</ModuleDetail>
</ModuleApplicable>
</RecordRequestDetail>
</RecordRequestDetails>
</CustomerRelatedPartyCreateUpdateRequest>
'
响应:
<?xml version="1.0" encoding="utf-16"?>
<A63CustomerResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ApiToken>ecef5041-a08a-43c9-9599-fc2d0c8da616</ApiToken>
<RequestId>82718d83-9206-4ab1-819a-a79e63e832a4</RequestId>
<RequestStatus>AcceptedbyTW</RequestStatus>
<ParentCompany>NFPL</ParentCompany>
<CustomerResponseDetails>
<A63CustomerResponseDetail>
<TransactionId xsi:nil="true" />
<SourceSystemName>HomeLoan</SourceSystemName>
<SourceSystemCustomerCode>321875112</SourceSystemCustomerCode>
<CustomerIntegrationStatusCode>AcceptedbyTW</CustomerIntegrationStatusCode>
<TrackWizzUpdatedOn>22-02-2022</TrackWizzUpdatedOn>
</A63CustomerResponseDetail>
</CustomerResponseDetails>
</A63CustomerResponse>
示例 java 代码:
public Map<String, String> updateCustomerData(String userId, CkycCustomerDetailsUpdateRequest request) throws CkycException {
String addressType = request.getAddressType();
String addressLine1 = request.getAddressLine1();
String addressLine2 = request.getAddressLine2();
String addressLine3 = request.getAddressLine3();
int pincode = request.getPincode();
String city = request.getCity();
String state = request.getState();
String country = request.getCountry();
String district = request.getDistrict();
AddressDetail addressDetail = formPayloadForAddressDetail(addressType, addressLine1, addressLine2, addressLine3, pincode, city, state, country, district);
List<AddressDetail> addressDetailList = new ArrayList<>();
addressDetailList.add(addressDetail);
AddressDetails addressDetails = new AddressDetails();
addressDetails.setAddressDetail(addressDetailList);
String idType = request.getIdType();
String idNumber = request.getIdNumber();
IdentificationDetail identificationDetail = formPayloadForIdentificationDetail(idType, idNumber);
IdentificationDetails identificationDetails = new IdentificationDetails();
identificationDetails.setIdentificationDetail(identificationDetail);
String module = request.getModule();
ModuleDetail moduleDetail = new ModuleDetail();
moduleDetail.setModule(module);
ModuleApplicable moduleApplicable = new ModuleApplicable();
moduleApplicable.setModuleDetail(moduleDetail);
String status = request.getStatus();
Date effectiveDate = request.getEffectiveDate();
CustomerStatus customerStatus = formPayloadForCustomerStatus(status, effectiveDate);
String prefix = request.getPrefix();
String firstName = request.getFirstName();
String lastName = request.getLastName();
String fatherPrefix = request.getFatherPrefix();
String fatherFirstName = request.getFatherFirstName();
String gender = request.getGender();
String sourceSystemName = request.getSourceSystemName();
String sourceSystemCustomerCode = request.getSourceSystemCustomerCode();
int isSmallCustomer = request.getIsSmallCustomer();
int ekycOTPBased = request.getEkycOTPBased();
String customerType = request.getCustomerType();
int formSixty = request.getFormSixty();
int kycAttestationType = request.getKYCAttestationType();
String countryOfResidence = request.getCountryOfResidence();
Date dob = request.getDob();
Date kycDateOfDeclaration = request.getKycDateOfDeclaration();
String kycPlaceOfDeclaration = request.getKycPlaceOfDeclaration();
Date kycVerificationDate = request.getKycVerificationDate();
String kycEmployeeName = request.getKycEmployeeName();
String kycEmployeeDesignation = request.getKycEmployeeDesignation();
String kycVerificationBranch = request.getKycVerificationBranch();
String kycEmployeeCode = request.getKycEmployeeCode();
String permanentAddressProof = request.getPermanentAddressProof();
String correspondenceAddressProof = request.getCorrespondenceAddressProof();
int minor = request.getMinor();
RecordRequestDetails recordRequestDetails = formPayloadForRecordRequestDetails(prefix, firstName, lastName, fatherFirstName, fatherPrefix, gender, sourceSystemCustomerCode, sourceSystemName,
isSmallCustomer, ekycOTPBased, customerType, formSixty, countryOfResidence, dob, kycAttestationType, kycDateOfDeclaration, kycPlaceOfDeclaration,
kycVerificationBranch, kycVerificationDate, kycEmployeeName, kycEmployeeDesignation, kycEmployeeCode, permanentAddressProof, correspondenceAddressProof, minor,
customerStatus, identificationDetails, moduleApplicable, addressDetails);
String parentCompany = request.getParentCompany();
String apiToken = request.getApiToken();
A63CustomerDetailsUpdateRequest a63CustomerDetailsUpdateRequest = formPayloadForCustomerDetailsUpdateReqest(parentCompany, apiToken, recordRequestDetails);
String payloadCustomerUpdateDetailsXml = XMLUtil.toXML(a63CustomerDetailsUpdateRequest);
String response = null;
response = doPostCkycReverseUpload(userId, payloadCustomerUpdateDetailsXml, trackwizzConfig.getImageIntegrationEndPoint(), 0, CKYC_UPLOAD, CUSTOMER_VALIDATION_API);
JSONObject jsonObject = XML.toJSONObject(response, true);
String jsonString = jsonObject.toString();
try {
return mapper.readValue(jsonString, Map.class);
} catch (IOException e) {
throw new CkycException(ErrorCode.internal_parsing_error, "Unable to parse the response");
}
}
private A63CustomerDetailsUpdateRequest formPayloadForCustomerDetailsUpdateReqest(String parentCompany, String apiToken, RecordRequestDetails recordRequestDetails) {
A63CustomerDetailsUpdateRequest a63CustomerDetailsUpdateRequest = new A63CustomerDetailsUpdateRequest();
a63CustomerDetailsUpdateRequest.setParentCompany(parentCompany);
a63CustomerDetailsUpdateRequest.setApiToken(apiToken);
a63CustomerDetailsUpdateRequest.setRecordRequestDetails(recordRequestDetails);
return a63CustomerDetailsUpdateRequest;
}
private RecordRequestDetails formPayloadForRecordRequestDetails(String prefix, String firstName, String lastName, String fatherFirstName, String fatherPrefix, String gender, String sourceSystemCustomerCode, String sourceSystemName, int isSmallCustomer, int ekycOTPBased, String customerType, int formSixty, String countryOfResidence, Date dob, int kycAttestationType, Date kycDateOfDeclaration, String kycPlaceOfDeclaration, String kycVerificationBranch, Date kycVerificationDate, String kycEmployeeName, String kycEmployeeDesignation, String kycEmployeeCode, String permanentAddressProof, String correspondenceAddressProof, int minor, CustomerStatus customerStatus, IdentificationDetails identificationDetails, ModuleApplicable moduleApplicable, AddressDetails addressDetails) {
RecordRequestDetail recordRequestDetail = new RecordRequestDetail();
recordRequestDetail.setPrefix(prefix);
recordRequestDetail.setFirstName(firstName);
recordRequestDetail.setLastName(lastName);
recordRequestDetail.setFatherPrefix(fatherPrefix);
recordRequestDetail.setFatherFirstName(fatherFirstName);
recordRequestDetail.setGender(gender);
recordRequestDetail.setSourceSystemName(sourceSystemName);
recordRequestDetail.setSourceSystemCustomerCode(sourceSystemCustomerCode);
recordRequestDetail.setIsSmallCustomer(isSmallCustomer);
recordRequestDetail.setEkycOTPBased(ekycOTPBased);
recordRequestDetail.setCustomerType(customerType);
recordRequestDetail.setCustomerStatus(customerStatus);
recordRequestDetail.setFormSixty(formSixty);
recordRequestDetail.setDob(dob);
recordRequestDetail.setMinor(minor);
recordRequestDetail.setCountryOfResidence(countryOfResidence);
recordRequestDetail.setKycAttestationType(kycAttestationType);
recordRequestDetail.setKycDateOfDeclaration(kycDateOfDeclaration);
recordRequestDetail.setKycEmployeeCode(kycEmployeeCode);
recordRequestDetail.setKycEmployeeName(kycEmployeeName);
recordRequestDetail.setKycPlaceOfDeclaration(kycPlaceOfDeclaration);
recordRequestDetail.setKycVerificationBranch(kycVerificationBranch);
recordRequestDetail.setKycVerificationDate(kycVerificationDate);
recordRequestDetail.setKycEmployeeDesignation(kycEmployeeDesignation);
recordRequestDetail.setPermanentAddressProof(permanentAddressProof);
recordRequestDetail.setCorrespondenceAddressProof(correspondenceAddressProof);
recordRequestDetail.setIdentificationDetails(identificationDetails);
recordRequestDetail.setModuleApplicable(moduleApplicable);
recordRequestDetail.setAddressDetails(addressDetails);
RecordRequestDetails recordRequestDetails = new RecordRequestDetails();
recordRequestDetails.setRecordRequestDetail(recordRequestDetail);
return recordRequestDetails;
}
private CustomerStatus formPayloadForCustomerStatus(String status, Date effectiveDate) {
StatusDetail statusDetail = new StatusDetail();
statusDetail.setStatus(status);
statusDetail.setEffectiveDate(effectiveDate);
CustomerStatus customerStatus = new CustomerStatus();
customerStatus.setStatusDetail(statusDetail);
return customerStatus;
}
private IdentificationDetail formPayloadForIdentificationDetail(String idType, String idNumber) {
IdentificationDetail identificationDetail = new IdentificationDetail();
identificationDetail.setIdNumber(idNumber);
identificationDetail.setIdType(idType);
return identificationDetail;
}
private AddressDetail formPayloadForAddressDetail(String addressType, String addressLine1, String addressLine2, String addressLine3, int pincode, String city, String state, String country, String district) {
AddressDetail addressDetail = new AddressDetail();
addressDetail.setAddressType(addressType);
addressDetail.setAddressLine1(addressLine1);
addressDetail.setAddressLine2(addressLine2);
addressDetail.setAddressLine3(addressLine3);
addressDetail.setPinCode(pincode);
addressDetail.setCity(city);
addressDetail.setState(state);
addressDetail.setCountry(country);
addressDetail.setDistrict(district);
return addressDetail;
}
private void setHeadersAsXml(AbstractHttpMessage entity) {
entity.setHeader(CONTENT_TYPE, APPLICATION_XML);
}
@Trace(dispatcher = true)
private String doPostCkycReverseUpload(String userId, String request, String endPoint, int retryCount, String context, String tssApi) throws CkycException {
HttpPost post = new HttpPost(trackwizzConfig.getBaseUrl() + endPoint);
setEntity(post, request);
setHeaders(post);
post.setConfig(requestConfig);
long startTime = System.currentTimeMillis();
long endTime = 0;
try (CloseableHttpResponse response = httpClient.execute(post)){
endTime = System.currentTimeMillis();
log.info("[TSS] Response from trackwizz : {} with status : {}", response, response.getStatusLine().getStatusCode());
int status = response.getStatusLine().getStatusCode();
NewRelic.addCustomParameter(tssApi+HYPHEN+STATUS, String.valueOf(status));
NewRelic.addCustomParameter(tssApi+LATENCY, (endTime - startTime)/1000);
if(status == 200){
log.info("[TSS] Successfully received response from trackwizz service for integration of the " + tssApi);
return EntityUtils.toString(response.getEntity());
} else{
log.info("Exception occured while integrating the " + tssApi);
throw new Exception();
}
} catch (SocketTimeoutException | ConnectTimeoutException ex) {
endTime = System.currentTimeMillis();
NewRelic.addCustomParameter(tssApi+HYPHEN+STATUS, "408");
NewRelic.addCustomParameter(tssApi+LATENCY, (endTime - startTime)/1000);
if(retryCount < trackwizzConfig.getMaxRetryCount()){
log.info("[TSS]Error while receiving response from trackwizz service. Failed by timeout exception, retryCount : {}", retryCount);
return doPostCkycReverseUpload(userId, request, endPoint, retryCount+1, context, tssApi);
}
log.info("[TSS]Error while receiving response from trackwizz service. Failed by timeout exception, retryCount : {}", retryCount);
throw new CkycException(ErrorCode.unknown_error, "Error while receiving response from trackwizz service. Failed by timeout exception, retry count:" + retryCount);
} catch (Exception e) {
NewRelic.addCustomParameter(tssApi+HYPHEN+STATUS, "NA");
log.error("[TSS]Exception : {} for request : {}", e.getMessage(), request);
throw new CkycException(ErrorCode.unknown_error, e.getMessage());
}
}
}
我正在执行解组的 XMLUtil 类:
package com.olacabs.money.utils;
import lombok.extern.slf4j.Slf4j;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
@Slf4j
public class XMLUtil {
public static String toXML(Object data) {
String xml = "";
try {
log.info("Generating xml for: " + data.getClass());
JAXBContext jaxbContext = JAXBContext.newInstance(data.getClass());
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(data, sw);
xml = sw.toString();
} catch (JAXBException e) {
log.error("Exception {} while converting data to xml", e.getMessage(), e);
}
return xml;
}
}
我从类中得到的响应:
<?xml version="1.0" encoding="utf-16"?>
<A63CustomerResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ApiToken>ecef5041-a08a-43c9-9599-fc2d0c8da616</ApiToken>
<RequestId>b9393295-cf97-49c4-8c0f-978e68b1dd2e</RequestId>
<RequestStatus>RejectedByTW</RequestStatus>
<RequestRejectionCode>RC184</RequestRejectionCode>
<RequestRejectionDescription>Invalid API Token, API token does not exist in TrackWizz.</RequestRejectionDescription>
<ParentCompany>NFPL</ParentCompany>
<CustomerResponseDetails />
</A63CustomerResponse>
我在两种情况下传递的 api 令牌只是相同的。
添加了 Maven 依赖项:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.8</version>
</dependency>
不发布示例请求正文,因为它很大。
I am calling an api the purpose of which to validate customer's data which is working fine in postman but in my local while doing http call it's giving a different response and not passing even the first line. The request and response are in the form of XML.
Postman request and response are as follows:
curl --location --request POST 'https://ckyc.olacabs-dev.in:54322/crmapi/TrackwizzWebApi/A63/CreateUpdateCustomer/V1' \
--header 'Content-Type: text/plain' \
--data-raw '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CustomerRelatedPartyCreateUpdateRequest>
<ParentCompany>NFPL</ParentCompany>
<ApiToken>ecef5041-a08a-43c9-9599-fc2d0c8da616</ApiToken>
<RecordRequestDetails>
<RecordRequestDetail>
<SourceSystemName>HomeLoan</SourceSystemName>
<SourceSystemCustomerCode>321875112</SourceSystemCustomerCode>
<IsSmallCustomer>0</IsSmallCustomer>
<EkycOTPBased>0</EkycOTPBased>
<CustomerStatus>
<StatusDetail>
<Status>Active</Status>
<EffectiveDate>1970-01-01T05:29:57.991+05:30</EffectiveDate>
</StatusDetail>
</CustomerStatus>
<CustomerType>1</CustomerType>
<Prefix>MISS</Prefix>
<FirstName>dolly</FirstName>
<LastName>vaishnav</LastName>
<FatherPrefix>MR</FatherPrefix>
<fatherFirstName>Prakash</fatherFirstName>
<Gender>female</Gender>
<formSixty>0</formSixty>
<KYCAttestationType>1</KYCAttestationType>
<CountryOfResidence>IN</CountryOfResidence>
<DateofBirth>1970-01-01T05:29:57.991+05:30</DateofBirth>
<KYCDateOfDeclaration>1970-01-01T05:29:57.991+05:30</KYCDateOfDeclaration>
<KYCPlaceOfDeclaration>Mumbai</KYCPlaceOfDeclaration>
<KYCVerificationDate>1970-01-01T05:29:57.991+05:30</KYCVerificationDate>
<KYCEmployeeName>Vikash</KYCEmployeeName>
<KYCEmployeeDesignation>manager</KYCEmployeeDesignation>
<KYCVerificationBranch>mumbai</KYCVerificationBranch>
<KYCEmployeeCode>1234</KYCEmployeeCode>
<AddressDetails>
<AddressDetail>
<AddressType>permanent</AddressType>
<AddressLine1>xyz</AddressLine1>
<PinCode>491001</PinCode>
<City>bhilai</City>
<AddressLine2>kormangala</AddressLine2>
<AddressLine3>5th block</AddressLine3>
<State>CG</State>
<Country>IN</Country>
<District>durg</District>
</AddressDetail>
</AddressDetails>
<PermanentAddressProof>passport</PermanentAddressProof>
<CorrespondenceAddressProof>dl</CorrespondenceAddressProof>
<IdentificationDetails>
<IdentificationDetail>
<IdType>passport</IdType>
<IdNumber>AVPBV4738</IdNumber>
</IdentificationDetail>
</IdentificationDetails>
<Minor>0</Minor>
<ModuleApplicable>
<ModuleDetail>
<Module>ckyc</Module>
</ModuleDetail>
</ModuleApplicable>
</RecordRequestDetail>
</RecordRequestDetails>
</CustomerRelatedPartyCreateUpdateRequest>
'
Response:
<?xml version="1.0" encoding="utf-16"?>
<A63CustomerResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ApiToken>ecef5041-a08a-43c9-9599-fc2d0c8da616</ApiToken>
<RequestId>82718d83-9206-4ab1-819a-a79e63e832a4</RequestId>
<RequestStatus>AcceptedbyTW</RequestStatus>
<ParentCompany>NFPL</ParentCompany>
<CustomerResponseDetails>
<A63CustomerResponseDetail>
<TransactionId xsi:nil="true" />
<SourceSystemName>HomeLoan</SourceSystemName>
<SourceSystemCustomerCode>321875112</SourceSystemCustomerCode>
<CustomerIntegrationStatusCode>AcceptedbyTW</CustomerIntegrationStatusCode>
<TrackWizzUpdatedOn>22-02-2022</TrackWizzUpdatedOn>
</A63CustomerResponseDetail>
</CustomerResponseDetails>
</A63CustomerResponse>
Sample java code:
public Map<String, String> updateCustomerData(String userId, CkycCustomerDetailsUpdateRequest request) throws CkycException {
String addressType = request.getAddressType();
String addressLine1 = request.getAddressLine1();
String addressLine2 = request.getAddressLine2();
String addressLine3 = request.getAddressLine3();
int pincode = request.getPincode();
String city = request.getCity();
String state = request.getState();
String country = request.getCountry();
String district = request.getDistrict();
AddressDetail addressDetail = formPayloadForAddressDetail(addressType, addressLine1, addressLine2, addressLine3, pincode, city, state, country, district);
List<AddressDetail> addressDetailList = new ArrayList<>();
addressDetailList.add(addressDetail);
AddressDetails addressDetails = new AddressDetails();
addressDetails.setAddressDetail(addressDetailList);
String idType = request.getIdType();
String idNumber = request.getIdNumber();
IdentificationDetail identificationDetail = formPayloadForIdentificationDetail(idType, idNumber);
IdentificationDetails identificationDetails = new IdentificationDetails();
identificationDetails.setIdentificationDetail(identificationDetail);
String module = request.getModule();
ModuleDetail moduleDetail = new ModuleDetail();
moduleDetail.setModule(module);
ModuleApplicable moduleApplicable = new ModuleApplicable();
moduleApplicable.setModuleDetail(moduleDetail);
String status = request.getStatus();
Date effectiveDate = request.getEffectiveDate();
CustomerStatus customerStatus = formPayloadForCustomerStatus(status, effectiveDate);
String prefix = request.getPrefix();
String firstName = request.getFirstName();
String lastName = request.getLastName();
String fatherPrefix = request.getFatherPrefix();
String fatherFirstName = request.getFatherFirstName();
String gender = request.getGender();
String sourceSystemName = request.getSourceSystemName();
String sourceSystemCustomerCode = request.getSourceSystemCustomerCode();
int isSmallCustomer = request.getIsSmallCustomer();
int ekycOTPBased = request.getEkycOTPBased();
String customerType = request.getCustomerType();
int formSixty = request.getFormSixty();
int kycAttestationType = request.getKYCAttestationType();
String countryOfResidence = request.getCountryOfResidence();
Date dob = request.getDob();
Date kycDateOfDeclaration = request.getKycDateOfDeclaration();
String kycPlaceOfDeclaration = request.getKycPlaceOfDeclaration();
Date kycVerificationDate = request.getKycVerificationDate();
String kycEmployeeName = request.getKycEmployeeName();
String kycEmployeeDesignation = request.getKycEmployeeDesignation();
String kycVerificationBranch = request.getKycVerificationBranch();
String kycEmployeeCode = request.getKycEmployeeCode();
String permanentAddressProof = request.getPermanentAddressProof();
String correspondenceAddressProof = request.getCorrespondenceAddressProof();
int minor = request.getMinor();
RecordRequestDetails recordRequestDetails = formPayloadForRecordRequestDetails(prefix, firstName, lastName, fatherFirstName, fatherPrefix, gender, sourceSystemCustomerCode, sourceSystemName,
isSmallCustomer, ekycOTPBased, customerType, formSixty, countryOfResidence, dob, kycAttestationType, kycDateOfDeclaration, kycPlaceOfDeclaration,
kycVerificationBranch, kycVerificationDate, kycEmployeeName, kycEmployeeDesignation, kycEmployeeCode, permanentAddressProof, correspondenceAddressProof, minor,
customerStatus, identificationDetails, moduleApplicable, addressDetails);
String parentCompany = request.getParentCompany();
String apiToken = request.getApiToken();
A63CustomerDetailsUpdateRequest a63CustomerDetailsUpdateRequest = formPayloadForCustomerDetailsUpdateReqest(parentCompany, apiToken, recordRequestDetails);
String payloadCustomerUpdateDetailsXml = XMLUtil.toXML(a63CustomerDetailsUpdateRequest);
String response = null;
response = doPostCkycReverseUpload(userId, payloadCustomerUpdateDetailsXml, trackwizzConfig.getImageIntegrationEndPoint(), 0, CKYC_UPLOAD, CUSTOMER_VALIDATION_API);
JSONObject jsonObject = XML.toJSONObject(response, true);
String jsonString = jsonObject.toString();
try {
return mapper.readValue(jsonString, Map.class);
} catch (IOException e) {
throw new CkycException(ErrorCode.internal_parsing_error, "Unable to parse the response");
}
}
private A63CustomerDetailsUpdateRequest formPayloadForCustomerDetailsUpdateReqest(String parentCompany, String apiToken, RecordRequestDetails recordRequestDetails) {
A63CustomerDetailsUpdateRequest a63CustomerDetailsUpdateRequest = new A63CustomerDetailsUpdateRequest();
a63CustomerDetailsUpdateRequest.setParentCompany(parentCompany);
a63CustomerDetailsUpdateRequest.setApiToken(apiToken);
a63CustomerDetailsUpdateRequest.setRecordRequestDetails(recordRequestDetails);
return a63CustomerDetailsUpdateRequest;
}
private RecordRequestDetails formPayloadForRecordRequestDetails(String prefix, String firstName, String lastName, String fatherFirstName, String fatherPrefix, String gender, String sourceSystemCustomerCode, String sourceSystemName, int isSmallCustomer, int ekycOTPBased, String customerType, int formSixty, String countryOfResidence, Date dob, int kycAttestationType, Date kycDateOfDeclaration, String kycPlaceOfDeclaration, String kycVerificationBranch, Date kycVerificationDate, String kycEmployeeName, String kycEmployeeDesignation, String kycEmployeeCode, String permanentAddressProof, String correspondenceAddressProof, int minor, CustomerStatus customerStatus, IdentificationDetails identificationDetails, ModuleApplicable moduleApplicable, AddressDetails addressDetails) {
RecordRequestDetail recordRequestDetail = new RecordRequestDetail();
recordRequestDetail.setPrefix(prefix);
recordRequestDetail.setFirstName(firstName);
recordRequestDetail.setLastName(lastName);
recordRequestDetail.setFatherPrefix(fatherPrefix);
recordRequestDetail.setFatherFirstName(fatherFirstName);
recordRequestDetail.setGender(gender);
recordRequestDetail.setSourceSystemName(sourceSystemName);
recordRequestDetail.setSourceSystemCustomerCode(sourceSystemCustomerCode);
recordRequestDetail.setIsSmallCustomer(isSmallCustomer);
recordRequestDetail.setEkycOTPBased(ekycOTPBased);
recordRequestDetail.setCustomerType(customerType);
recordRequestDetail.setCustomerStatus(customerStatus);
recordRequestDetail.setFormSixty(formSixty);
recordRequestDetail.setDob(dob);
recordRequestDetail.setMinor(minor);
recordRequestDetail.setCountryOfResidence(countryOfResidence);
recordRequestDetail.setKycAttestationType(kycAttestationType);
recordRequestDetail.setKycDateOfDeclaration(kycDateOfDeclaration);
recordRequestDetail.setKycEmployeeCode(kycEmployeeCode);
recordRequestDetail.setKycEmployeeName(kycEmployeeName);
recordRequestDetail.setKycPlaceOfDeclaration(kycPlaceOfDeclaration);
recordRequestDetail.setKycVerificationBranch(kycVerificationBranch);
recordRequestDetail.setKycVerificationDate(kycVerificationDate);
recordRequestDetail.setKycEmployeeDesignation(kycEmployeeDesignation);
recordRequestDetail.setPermanentAddressProof(permanentAddressProof);
recordRequestDetail.setCorrespondenceAddressProof(correspondenceAddressProof);
recordRequestDetail.setIdentificationDetails(identificationDetails);
recordRequestDetail.setModuleApplicable(moduleApplicable);
recordRequestDetail.setAddressDetails(addressDetails);
RecordRequestDetails recordRequestDetails = new RecordRequestDetails();
recordRequestDetails.setRecordRequestDetail(recordRequestDetail);
return recordRequestDetails;
}
private CustomerStatus formPayloadForCustomerStatus(String status, Date effectiveDate) {
StatusDetail statusDetail = new StatusDetail();
statusDetail.setStatus(status);
statusDetail.setEffectiveDate(effectiveDate);
CustomerStatus customerStatus = new CustomerStatus();
customerStatus.setStatusDetail(statusDetail);
return customerStatus;
}
private IdentificationDetail formPayloadForIdentificationDetail(String idType, String idNumber) {
IdentificationDetail identificationDetail = new IdentificationDetail();
identificationDetail.setIdNumber(idNumber);
identificationDetail.setIdType(idType);
return identificationDetail;
}
private AddressDetail formPayloadForAddressDetail(String addressType, String addressLine1, String addressLine2, String addressLine3, int pincode, String city, String state, String country, String district) {
AddressDetail addressDetail = new AddressDetail();
addressDetail.setAddressType(addressType);
addressDetail.setAddressLine1(addressLine1);
addressDetail.setAddressLine2(addressLine2);
addressDetail.setAddressLine3(addressLine3);
addressDetail.setPinCode(pincode);
addressDetail.setCity(city);
addressDetail.setState(state);
addressDetail.setCountry(country);
addressDetail.setDistrict(district);
return addressDetail;
}
private void setHeadersAsXml(AbstractHttpMessage entity) {
entity.setHeader(CONTENT_TYPE, APPLICATION_XML);
}
@Trace(dispatcher = true)
private String doPostCkycReverseUpload(String userId, String request, String endPoint, int retryCount, String context, String tssApi) throws CkycException {
HttpPost post = new HttpPost(trackwizzConfig.getBaseUrl() + endPoint);
setEntity(post, request);
setHeaders(post);
post.setConfig(requestConfig);
long startTime = System.currentTimeMillis();
long endTime = 0;
try (CloseableHttpResponse response = httpClient.execute(post)){
endTime = System.currentTimeMillis();
log.info("[TSS] Response from trackwizz : {} with status : {}", response, response.getStatusLine().getStatusCode());
int status = response.getStatusLine().getStatusCode();
NewRelic.addCustomParameter(tssApi+HYPHEN+STATUS, String.valueOf(status));
NewRelic.addCustomParameter(tssApi+LATENCY, (endTime - startTime)/1000);
if(status == 200){
log.info("[TSS] Successfully received response from trackwizz service for integration of the " + tssApi);
return EntityUtils.toString(response.getEntity());
} else{
log.info("Exception occured while integrating the " + tssApi);
throw new Exception();
}
} catch (SocketTimeoutException | ConnectTimeoutException ex) {
endTime = System.currentTimeMillis();
NewRelic.addCustomParameter(tssApi+HYPHEN+STATUS, "408");
NewRelic.addCustomParameter(tssApi+LATENCY, (endTime - startTime)/1000);
if(retryCount < trackwizzConfig.getMaxRetryCount()){
log.info("[TSS]Error while receiving response from trackwizz service. Failed by timeout exception, retryCount : {}", retryCount);
return doPostCkycReverseUpload(userId, request, endPoint, retryCount+1, context, tssApi);
}
log.info("[TSS]Error while receiving response from trackwizz service. Failed by timeout exception, retryCount : {}", retryCount);
throw new CkycException(ErrorCode.unknown_error, "Error while receiving response from trackwizz service. Failed by timeout exception, retry count:" + retryCount);
} catch (Exception e) {
NewRelic.addCustomParameter(tssApi+HYPHEN+STATUS, "NA");
log.error("[TSS]Exception : {} for request : {}", e.getMessage(), request);
throw new CkycException(ErrorCode.unknown_error, e.getMessage());
}
}
}
XMLUtil class where I am performing unmarshalling:
package com.olacabs.money.utils;
import lombok.extern.slf4j.Slf4j;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
@Slf4j
public class XMLUtil {
public static String toXML(Object data) {
String xml = "";
try {
log.info("Generating xml for: " + data.getClass());
JAXBContext jaxbContext = JAXBContext.newInstance(data.getClass());
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(data, sw);
xml = sw.toString();
} catch (JAXBException e) {
log.error("Exception {} while converting data to xml", e.getMessage(), e);
}
return xml;
}
}
Response I am getting from the class:
<?xml version="1.0" encoding="utf-16"?>
<A63CustomerResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ApiToken>ecef5041-a08a-43c9-9599-fc2d0c8da616</ApiToken>
<RequestId>b9393295-cf97-49c4-8c0f-978e68b1dd2e</RequestId>
<RequestStatus>RejectedByTW</RequestStatus>
<RequestRejectionCode>RC184</RequestRejectionCode>
<RequestRejectionDescription>Invalid API Token, API token does not exist in TrackWizz.</RequestRejectionDescription>
<ParentCompany>NFPL</ParentCompany>
<CustomerResponseDetails />
</A63CustomerResponse>
The api token which I am passing in both the cases are same only.
Maven dependency added:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.8</version>
</dependency>
Not posting the sample request body as it's huge.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论