use of org.kuali.kfs.module.purap.exception.B2BConnectionException in project cu-kfs by CU-CommunityApps.
the class CuB2BDaoImpl method sendPunchOutRequest.
/**
* @see org.kuali.kfs.module.purap.dataaccess.impl.B2BDaoImpl#sendPunchOutRequest(java.lang.String, java.lang.String)
*/
public String sendPunchOutRequest(String request, String punchoutUrl) {
LOG.debug("sendPunchOutRequest() started");
try {
URL url = new URL(punchoutUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
String charSet = "UTF-8";
if (request.contains("MIME_BOUNDARY_FOR_ATTACHMENTS")) {
// KFSPTS-794 : for attachments
conn.setRequestProperty("Content-type", "multipart/related; boundary=" + CUPurapConstants.MIME_BOUNDARY_FOR_ATTACHMENTS);
charSet = "ISO-8859-1";
LOG.info("content-type is multipart/related; boundary=" + CUPurapConstants.MIME_BOUNDARY_FOR_ATTACHMENTS);
} else {
conn.setRequestProperty("Content-type", "text/xml");
LOG.info("content-type is text/xml");
}
OutputStream out = conn.getOutputStream();
OutputStreamWriter outw = new OutputStreamWriter(out, charSet);
outw.write(request);
outw.flush();
outw.close();
out.flush();
out.close();
InputStream inp = conn.getInputStream();
StringBuffer response = new StringBuffer();
int i = inp.read();
while (i >= 0) {
if (i >= 0) {
response.append((char) i);
}
i = inp.read();
}
return response.toString();
} catch (MalformedURLException e) {
LOG.error("postPunchOutSetupRequestMessage() Error posting setup", e);
throw new B2BConnectionException("Unable to connect to remote site for punchout.", e);
} catch (ProtocolException e) {
LOG.error("postPunchOutSetupRequestMessage() Error posting setup", e);
throw new B2BConnectionException("Unable to connect to remote site for punchout.", e);
} catch (UnsupportedEncodingException e) {
LOG.error("postPunchOutSetupRequestMessage() Error posting setup", e);
throw new B2BConnectionException("Unable to connect to remote site for punchout.", e);
} catch (IOException e) {
LOG.error("postPunchOutSetupRequestMessage() Error posting setup", e);
throw new B2BConnectionException("Unable to connect to remote site for punchout.", e);
}
}
use of org.kuali.kfs.module.purap.exception.B2BConnectionException in project cu-kfs by CU-CommunityApps.
the class CuB2BPurchaseOrderSciquestServiceImpl method sendPurchaseOrder.
// end KFSUPGRADE-583
public String sendPurchaseOrder(PurchaseOrderDocument purchaseOrder) {
/*
* IMPORTANT DESIGN NOTE: We need the contract manager's name, phone number, and e-mail address. B2B orders that don't
* qualify to become APO's will have contract managers on the PO, and the ones that DO become APO's will not. We decided to
* always get the contract manager from the B2B contract associated with the order, and for B2B orders to ignore the
* contract manager field on the PO. We pull the name and phone number from the contract manager table and get the e-mail
* address from the user data.
*/
// CU change for contract manager
// non-catalog POs might not have a vendor contract, so we need to get the contract manager from the PO which will always be there
ContractManager contractManager = null;
if (!PurapConstants.RequisitionSources.B2B.equals(purchaseOrder.getRequisitionSourceCode())) {
contractManager = purchaseOrder.getContractManager();
} else {
contractManager = purchaseOrder.getVendorContract().getContractManager();
}
String contractManagerEmail = getContractManagerEmail(contractManager);
String vendorDuns = purchaseOrder.getVendorDetail().getVendorDunsNumber();
RequisitionDocument r = requisitionService.getRequisitionById(purchaseOrder.getRequisitionIdentifier());
WorkflowDocument reqWorkflowDoc = r.getDocumentHeader().getWorkflowDocument();
String requisitionInitiatorPrincipalId = getRequisitionInitiatorPrincipal(reqWorkflowDoc.getInitiatorPrincipalId());
if (LOG.isDebugEnabled()) {
LOG.debug("sendPurchaseOrder(): b2bPurchaseOrderURL is " + getB2bPurchaseOrderURL());
}
if (!PurapConstants.RequisitionSources.B2B.equals(purchaseOrder.getRequisitionSourceCode())) {
prepareNonB2BPurchaseOrderForTransmission(purchaseOrder);
}
String validateErrors = verifyCxmlPOData(purchaseOrder, requisitionInitiatorPrincipalId, getB2bPurchaseOrderPassword(), contractManager, contractManagerEmail, vendorDuns);
if (!StringUtils.isEmpty(validateErrors)) {
return validateErrors;
}
StringBuffer transmitErrors = new StringBuffer();
try {
LOG.debug("sendPurchaseOrder() Generating cxml");
String cxml = getCxml(purchaseOrder, requisitionInitiatorPrincipalId, getB2bPurchaseOrderPassword(), contractManager, contractManagerEmail, vendorDuns, true);
LOG.debug("sendPurchaseOrder() Sending cxml\n" + cxml);
LOG.debug("sendPurchaseOrder() Sending cxml\n" + cxml);
String responseCxml = b2bDao.sendPunchOutRequest(cxml, getB2bPurchaseOrderURL());
LOG.info("b2bPurchaseOrderURL " + getB2bPurchaseOrderURL());
LOG.info("sendPurchaseOrder(): Response cXML for po #" + purchaseOrder.getPurapDocumentIdentifier() + ":\n" + responseCxml);
// allow PO to use old form, then POA use new form for testing
if (!responseCxml.contains("Success") && responseCxml.contains("No custom field found") && responseCxml.contains("document configuration (DeliveryEmail)")) {
String cxml1 = cxml.substring(0, cxml.indexOf("<CustomFieldValueSet label=\"Delivery Phone")) + cxml.substring(cxml.indexOf("</POHeader>"));
LOG.info("sendPurchaseOrder() re-Sending cxml\n" + cxml1);
responseCxml = b2bDao.sendPunchOutRequest(cxml1, getB2bPurchaseOrderURL());
cxml = getCxml(purchaseOrder, requisitionInitiatorPrincipalId, getB2bPurchaseOrderPassword(), contractManager, contractManagerEmail, vendorDuns, false);
LOG.debug("sendPurchaseOrder() re-Sending cxml\n" + cxml);
responseCxml = b2bDao.sendPunchOutRequest(cxml, getB2bPurchaseOrderURL());
LOG.info("re-sendPurchaseOrder(): Response cXML for po number " + purchaseOrder.getPurapDocumentIdentifier() + ":" + responseCxml);
}
PurchaseOrderResponse poResponse = B2BParserHelper.getInstance().parsePurchaseOrderResponse(responseCxml);
String statusText = poResponse.getStatusText();
if (LOG.isDebugEnabled()) {
LOG.debug("sendPurchaseOrder(): statusText is " + statusText);
}
if (ObjectUtils.isNull(statusText) || (!"success".equalsIgnoreCase(statusText.trim()))) {
LOG.error("sendPurchaseOrder(): PO cXML for po number " + purchaseOrder.getPurapDocumentIdentifier() + " failed sending to SciQuest:\n" + statusText);
transmitErrors.append("Unable to send Purchase Order: " + statusText);
// find any additional error messages that might have been sent
List errorMessages = poResponse.getPOResponseErrorMessages();
if (ObjectUtils.isNotNull(errorMessages) && !errorMessages.isEmpty()) {
for (Iterator iter = errorMessages.iterator(); iter.hasNext(); ) {
String errorMessage = (String) iter.next();
if (ObjectUtils.isNotNull(errorMessage)) {
LOG.error("sendPurchaseOrder(): SciQuest error message for po number " + purchaseOrder.getPurapDocumentIdentifier() + ": " + errorMessage);
transmitErrors.append("Error sending Purchase Order: " + errorMessage);
}
}
}
}
} catch (B2BConnectionException e) {
LOG.error("sendPurchaseOrder() Error connecting to b2b", e);
transmitErrors.append("Connection to vendor failed.");
} catch (CxmlParseError e) {
LOG.error("sendPurchaseOrder() Error Parsing", e);
transmitErrors.append("Unable to read cxml returned from vendor.");
} catch (Throwable e) {
LOG.error("sendPurchaseOrder() Unknown Error", e);
transmitErrors.append("Unexpected error occurred while attempting to transmit Purchase Order.");
}
return transmitErrors.toString();
}
Aggregations