use of net.petafuel.styx.core.xs2a.exceptions.SerializerException 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.styx.core.xs2a.exceptions.SerializerException in project styx by petafuel.
the class PaymentInitiationRequest method createPeriodicPayment.
private Optional<String> createPeriodicPayment() {
if (getPaymentProduct().isXml()) {
PAIN00100303Document document = (new PaymentXMLSerializer()).serialize(UUID.randomUUID().toString(), (PeriodicPayment) payment);
SEPAWriter writer = new SEPAWriter(document);
String painXmlBody;
try {
painXmlBody = new String(writer.writeSEPA());
} catch (SEPAWriteException e) {
throw new SerializerException("Unable to create xml body for periodic payment initiation multipart http message");
}
Headers headersXml = new Headers.Builder().add("Content-Disposition", "form-data; name=\"xml_sct\"").build();
MultipartBody.Part xmlPart = MultipartBody.Part.create(headersXml, RequestBody.create(painXmlBody, MediaType.get("application/xml; charset=utf-8")));
Headers headersJson = new Headers.Builder().add("Content-Disposition", "form-data; name=\"json_standingorderType\"").build();
MultipartBody.Part jsonPart;
try (Jsonb jsonb = JsonbBuilder.create()) {
jsonPart = MultipartBody.Part.create(headersJson, RequestBody.create(jsonb.toJson(payment), MediaType.get("application/json; charset=utf-8")));
} catch (Exception e) {
throw new SerializerException(e.getMessage());
}
// add a uuid as boundary to avoid boundary repetition in http message
RequestBody requestBody = new MultipartBody.Builder(getMultipartBoundary()).addPart(xmlPart).addPart(jsonPart).setType(MultipartBody.FORM).build();
final Buffer buffer = new Buffer();
try {
// build raw multipartBody with xml and json
requestBody.writeTo(buffer);
return Optional.of(buffer.readUtf8());
} catch (IOException e) {
LOG.warn("Error creating raw body for periodic payment initiation message={} cause={}", e.getMessage(), e.getCause().getCause());
return Optional.empty();
}
} else {
try (Jsonb jsonb = JsonbBuilder.create()) {
return Optional.ofNullable(jsonb.toJson(payment));
} catch (Exception e) {
return Optional.empty();
}
}
}
use of net.petafuel.styx.core.xs2a.exceptions.SerializerException in project styx by petafuel.
the class RefreshTokenRequest method getRawBody.
@Override
public Optional<String> getRawBody() {
String rawBody;
if (isJsonBody()) {
try (Jsonb jsonb = JsonbBuilder.create()) {
rawBody = jsonb.toJson(this);
} catch (Exception e) {
throw new SerializerException("Unable to create request body for RefreshTokenRequest");
}
} else {
Map<String, String> params = new HashMap<>();
params.put("grant_type", getGrantType());
params.put("client_id", getClientId());
params.put("refresh_token", getRefreshToken());
rawBody = BasicService.httpBuildQuery(params).substring(1);
}
return Optional.ofNullable(rawBody);
}
use of net.petafuel.styx.core.xs2a.exceptions.SerializerException in project styx by petafuel.
the class SAD method parseImplementerOptions.
/**
* Parsing the implementer options json and mapping to ImplementerOption List
* within the aspsp
*
* @param aspsp Aspsp object that should be used and should be modified with the
* parsed implementer options
*/
private void parseImplementerOptions(Aspsp aspsp) {
String rawDefaultConfig;
// template if not present for aspsp
if ((rawDefaultConfig = aspsp.getConfig().getConfiguration()) == null) {
rawDefaultConfig = aspsp.getConfig().getStandard().getConfigTemplate();
}
JsonObject defaultConfig = null;
try (Jsonb jsonb = JsonbBuilder.create()) {
defaultConfig = jsonb.fromJson(rawDefaultConfig, JsonObject.class);
} catch (Exception e) {
throw new SerializerException("unable to deserialize implementer-options json on SAD Service usage", e);
}
// Check if there is a styx config on aspsp level
// If not present on aspsp level use styx config template of related standard
String rawStyxConfig;
if ((rawStyxConfig = aspsp.getConfig().getStyxConfiguration()) == null) {
rawStyxConfig = aspsp.getConfig().getStandard().getStyxConfigTemplate();
}
// Merge the styx config options into the defaultConfig
JsonObject styxConfig = null;
try (Jsonb jsonb = JsonbBuilder.create()) {
styxConfig = jsonb.fromJson(rawStyxConfig, JsonObject.class);
} catch (Exception e) {
throw new SerializerException("unable to deserialize styx-options json on SAD Service usage", e);
}
JsonObjectBuilder defaultConfigJsonBuilder = Json.createObjectBuilder(defaultConfig);
defaultConfigJsonBuilder.addAll(Json.createObjectBuilder(styxConfig));
defaultConfig = defaultConfigJsonBuilder.build();
defaultConfig.entrySet().stream().forEach(entry -> {
JsonObject currentOption = entry.getValue().asJsonObject();
ImplementerOption implementerOption = new ImplementerOption();
implementerOption.setId(entry.getKey());
implementerOption.setDescription(currentOption.getString("description", "default"));
currentOption.get("options").asJsonObject().entrySet().stream().forEach(option -> implementerOption.addOption(option.getKey(), Boolean.valueOf(option.getValue().toString())));
aspsp.getConfig().getImplementerOptions().put(implementerOption.getId(), implementerOption);
});
}
use of net.petafuel.styx.core.xs2a.exceptions.SerializerException in project styx by petafuel.
the class PersistentClientApp method formatRestrictions.
public static void formatRestrictions(String restrictions, MasterToken model) {
if (restrictions != null) {
try (Jsonb jsonb = JsonbBuilder.create()) {
Type type = new GenericType<Map<String, MasterTokenRestriction>>() {
}.getType();
model.setRestrictions(jsonb.fromJson(restrictions, type));
} catch (Exception e) {
throw new SerializerException(e.getMessage(), e);
}
}
}
Aggregations