use of net.petafuel.jsepa.exception.SEPAParsingException in project styx by petafuel.
the class BerlinGroupPIS method getPaymentStatus.
@Override
public PaymentStatus getPaymentStatus(PISRequest xs2AGetRequest) throws BankRequestFailedException {
this.setUrl(this.url + xs2AGetRequest.getServicePath());
this.createBody(RequestType.GET);
if (xs2AGetRequest.getPaymentProduct().isXml()) {
xs2AGetRequest.addHeader(XS2AHeader.ACCEPT, XML.toString());
} else {
xs2AGetRequest.addHeader(XS2AHeader.ACCEPT, JSON.toString());
}
this.createHeaders(xs2AGetRequest);
try (Response response = this.execute();
Jsonb jsonb = JsonbBuilder.create()) {
String contentType;
if ((contentType = response.headers().get("content-type")) == null) {
throw new BankRequestFailedException("Content-Type Header is not set, parsing of json or xml is not possible", response.code());
}
String responseBody = extractResponseBody(response, 200);
if (contentType.contains(MediaType.APPLICATION_JSON)) {
return jsonb.fromJson(responseBody, PaymentStatus.class);
} else {
ReportConverter converter = new ReportConverter();
TransactionReport report = converter.processReport(responseBody);
return new PaymentStatus(TransactionStatus.valueOf(report.getStatus()), null);
}
} catch (IOException | SEPAParsingException e) {
throw new BankRequestFailedException(e.getMessage(), e);
} catch (Exception e) {
throw new SerializerException("Unable to deserialize json to PaymentStatus", e);
}
}
use of net.petafuel.jsepa.exception.SEPAParsingException in project styx by petafuel.
the class Camt052Converter method parseReport.
private BankToCustomerAccountReportV02 parseReport(String xmlData) throws SEPAParsingException {
try {
// schema factory is required to initialize the validator object (XSD based validator)
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// extract XSD file from the JAR bundle
URL resource = getClass().getClassLoader().getResource("schema/camt.052.001.02.xsd");
// schema object will be initialized for validation
Schema schema = sf.newSchema(resource);
// jaxb context is required to initialize the unmarshaller, here we have to pass the GENERATED ObjectFactory class
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
// now, the unmarshaller (make java object out of XML string) itself gets initialized
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
// connect the validator and unmarshaller. from here, the validation is activated
unmarshaller.setSchema(schema);
// now, validate and unmarshal the XML string
Document document = ((JAXBElement<Document>) unmarshaller.unmarshal(new StringReader(xmlData))).getValue();
LOG.info("camt052 xml parsing successful");
// extract relevant element from the whole XML. this steps is specific to the XML format we work with
return document.getBkToCstmrAcctRpt();
} catch (JAXBException | SAXException error) {
LOG.error("parseReport failed, invalid input", error);
throw new SEPAParsingException("Camt052 XML unmarshalling failed!", error);
}
}
Aggregations