Skip to content
Snippets Groups Projects
Commit 1045372b authored by srosse's avatar srosse
Browse files

OO-4256: set inspire flag if configured

Set the inspire flag if configure in administration, heuristic method to
discover the error code in case of SOAP Fault
parent fcdf36b7
No related branches found
No related tags found
No related merge requests found
......@@ -1921,7 +1921,7 @@
<dependency>
<groupId>org.openolat</groupId>
<artifactId>viterows</artifactId>
<version>9.1.1</version>
<version>9.1.2</version>
</dependency>
<dependency>
<groupId>org.openolat</groupId>
......
......@@ -42,6 +42,7 @@ import javax.activation.FileDataSource;
import javax.annotation.PostConstruct;
import javax.ws.rs.core.UriBuilder;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPFaultElement;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.handler.Handler;
......@@ -78,8 +79,6 @@ import org.olat.user.DisplayPortraitManager;
import org.olat.user.UserDataDeletable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.CompactWriter;
......@@ -1079,6 +1078,9 @@ public class ViteroManager implements UserDataDeletable {
if(StringHelper.containsNonWhitespace(vBooking.getEventName())) {
newBooking.setEventname(vBooking.getEventName());
}
if(viteroModule.isInspire()) {
newBooking.setInspire(Boolean.TRUE);
}
createRequest.setBooking(newBooking);
CreateBookingResponse response = bookingWs.createBooking(createRequest);
......@@ -1483,45 +1485,44 @@ public class ViteroManager implements UserDataDeletable {
//Utilities
private final ErrorCode handleAxisFault(final SOAPFaultException f)
throws VmsNotAvailableException {
if(f.getFault() != null) {
String errorCode = extractErrorCode(f.getFault());
if(StringHelper.isLong(errorCode)) {
int code = Integer.parseInt(errorCode);
return ErrorCode.find(code);
}
return ErrorCode.unkown;
} else if (f.getCause() instanceof SocketTimeoutException) {
throw new VmsNotAvailableException(f);
try {
if(f.getFault() != null) {
ErrorCode errorCode = extractErrorCode(f.getFault());
if(errorCode != null) {
return errorCode;
}
return ErrorCode.unkown;
} else if (f.getCause() instanceof SocketTimeoutException) {
throw new VmsNotAvailableException(f);
}
} catch (Exception e) {
log.error("Cannot extract error", f);
}
return ErrorCode.unkown;
}
private String extractErrorCode(SOAPElement element) {
private ErrorCode extractErrorCode(SOAPElement element) {
if(element == null) return null;
for(Iterator<?> it=element.getChildElements(); it.hasNext(); ) {
Object childElement = it.next();
if(childElement instanceof SOAPElement) {
SOAPElement soapElement = (SOAPElement)childElement;
String nodeName = soapElement.getNodeName();
if("errorCode".equals(nodeName)) {
return extractText(soapElement);
} else {
String code = extractErrorCode(soapElement);
if(code != null) {
return code;
}
try {
ErrorCode[] codes = ErrorCode.values();
int numOfErrorCode = codes.length;
for(Iterator<?> it=element.getChildElements(); it.hasNext(); ) {
Object childElement = it.next();
if(childElement instanceof SOAPFaultElement) {
SOAPFaultElement fault = (SOAPFaultElement)childElement;
String fContent = fault.getTextContent();
if(StringHelper.containsNonWhitespace(fContent) && Character.isDigit(fContent.charAt(fContent.length() - 1))) {
for(int i=numOfErrorCode; i-->0; ) {
if(fContent.endsWith(codes[i].codeString())) {
return codes[i];
}
}
}
}
}
}
return null;
}
private String extractText(SOAPElement errorCodeEl) {
for(Node node=errorCodeEl.getFirstChild(); node != null; node=node.getNextSibling()) {
if(node instanceof Text && StringHelper.containsNonWhitespace(node.getNodeValue())) {
return node.getNodeValue();
}
} catch (Exception e) {
log.error("", e);
}
return null;
}
......
......@@ -50,16 +50,22 @@ public enum ErrorCode {
private final int code;
private final String i18nKey;
private final String codeString;
private ErrorCode(int code, String i18nKey) {
this.code = code;
this.i18nKey = i18nKey;
codeString = Integer.toString(code);
}
public int code() {
return code;
}
public String codeString() {
return codeString;
}
public String i18nKey() {
return i18nKey;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment