summaryrefslogtreecommitdiffstats
path: root/sandbox/rfeng/scatours-creditcard-payment-dosgi-contribution/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/rfeng/scatours-creditcard-payment-dosgi-contribution/src/main')
-rw-r--r--sandbox/rfeng/scatours-creditcard-payment-dosgi-contribution/src/main/java/scatours/payment/creditcard/impl/CreditCardPaymentImpl.java34
1 files changed, 32 insertions, 2 deletions
diff --git a/sandbox/rfeng/scatours-creditcard-payment-dosgi-contribution/src/main/java/scatours/payment/creditcard/impl/CreditCardPaymentImpl.java b/sandbox/rfeng/scatours-creditcard-payment-dosgi-contribution/src/main/java/scatours/payment/creditcard/impl/CreditCardPaymentImpl.java
index 510dc76b7d..014c49f143 100644
--- a/sandbox/rfeng/scatours-creditcard-payment-dosgi-contribution/src/main/java/scatours/payment/creditcard/impl/CreditCardPaymentImpl.java
+++ b/sandbox/rfeng/scatours-creditcard-payment-dosgi-contribution/src/main/java/scatours/payment/creditcard/impl/CreditCardPaymentImpl.java
@@ -19,6 +19,16 @@
package scatours.payment.creditcard.impl;
+import java.io.StringWriter;
+import java.util.UUID;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.PropertyException;
+import javax.xml.namespace.QName;
+
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@@ -36,17 +46,37 @@ public class CreditCardPaymentImpl implements CreditCardPayment {
public String authorize(CreditCardDetailsType creditCard, float amount) {
if (creditCard != null) {
+ try {
+ print(creditCard);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
System.out.println("Credit card: name = " + creditCard.getCardOwner().getName()
+ " number = "
+ creditCard.getCreditCardNumber()
+ " for amount "
- + amount + " EUR");
+ + amount
+ + " EUR");
amount = convertCurrency(amount);
} else {
System.out.println("Credit card is null");
}
- return "OK";
+ return "SUCCESS: " + UUID.randomUUID();
+ }
+
+ private void print(CreditCardDetailsType creditCard) throws JAXBException, PropertyException {
+ JAXBContext context = JAXBContext.newInstance(CreditCardDetailsType.class);
+ QName name = new QName("http://ns1", "creditCard");
+ JAXBElement<Object> element = new JAXBElement<Object>(name, Object.class, creditCard);
+ StringWriter writer = new StringWriter();
+ Marshaller marshaller = context.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ context.createMarshaller().marshal(element, writer);
+ writer.flush();
+ System.out.println(writer.toString());
}
private float convertCurrency(float amount) {