setService(new QName("urn:logicblaze:soa:creditagency", "CreditAgencyService"));
setEndpoint("agency");
}
public void onMessageExchange(MessageExchange exchange) throws MessagingException {
InOut inOut = (InOut) exchange;
if (inOut.getStatus() == ExchangeStatus.DONE) {
return;
} else if (inOut.getStatus() == ExchangeStatus.ERROR) {
return;
}
try {
Document doc = (Document) new SourceTransformer().toDOMNode(inOut.getInMessage());
String ssn = textValueOfXPath(doc, "//*[local-name()='ssn']");
if (ssn == null || ssn.length() == 0) {
fail(exchange, new NullPointerException());
return;
}
if (!ssn.startsWith("1")) {
Fault fault = inOut.createFault();
fault.setContent(new StringSource(
"<invalidSSNFault xmlns=\"urn:logicblaze:soa:creditagency:types\"><ssn>"
+ ssn + "</ssn></invalidSSNFault>"));
fail(inOut, fault);
} else {
String operation = null;
if (inOut.getOperation() != null) {
operation = inOut.getOperation().getLocalPart();
} else {
operation = doc.getDocumentElement().getLocalName();
}
String output;
if ("getCreditScore".equals(operation)) {
output = "<getCreditScoreResponse xmlns=\"urn:logicblaze:soa:creditagency\"><score>"
+ getCreditScore(ssn) + "</score></getCreditScoreResponse>";
} else if ("getCreditHistoryLength".equals(operation)) {
output = "<getCreditHistoryLengthResponse xmlns=\"urn:logicblaze:soa:creditagency\"><length>"
+ getCreditHistoryLength(ssn) + "</length></getCreditHistoryLengthResponse>";
} else {
throw new UnsupportedOperationException(operation);
}
NormalizedMessage answer = inOut.createMessage();
answer.setContent(new StringSource(output));
answer(inOut, answer);
}
} catch (Exception e) {
throw new MessagingException(e);