io.github.factoryfx.soap.WebServiceRequestDispatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of soapFactory Show documentation
Show all versions of soapFactory Show documentation
factoryfx dependency injection framework
package io.github.factoryfx.soap;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.xml.namespace.QName;
import org.w3c.dom.Element;
import jakarta.annotation.Resource;
import jakarta.jws.WebParam;
import jakarta.jws.WebService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.soap.SOAPMessage;
import jakarta.xml.ws.EndpointReference;
import jakarta.xml.ws.WebServiceContext;
import jakarta.xml.ws.handler.soap.SOAPMessageContext;
public class WebServiceRequestDispatcher {
private final Object webService;
private final HashMap, Invoker> dispatchMap = new HashMap<>();
static final class RequestContext {
final HttpServletRequest request;
final HttpServletResponse response;
SOAPMessage soapMessage;
RequestContext(HttpServletRequest request, HttpServletResponse response, SOAPMessage soapMessage) {
this.request = request;
this.response = response;
this.soapMessage = soapMessage;
}
}
private final ThreadLocal msgContext = new ThreadLocal<>();
private final WebServiceContext webServiceContext = new WebServiceContext() {
@Override
public SOAPMessageContext getMessageContext() {
return new SOAPMessageContext() {
@Override
public SOAPMessage getMessage() {
return ctx().soapMessage;
}
@Override
public void setMessage(SOAPMessage message) {
ctx().soapMessage = message;
}
@Override
public Object[] getHeaders(QName header, JAXBContext context, boolean allRoles) {
throw new UnsupportedOperationException();
}
@Override
public Set getRoles() {
return Collections.emptySet();
}
@Override
public void setScope(String name, Scope scope) {
throw new UnsupportedOperationException();
}
@Override
public Scope getScope(String name) {
throw new UnsupportedOperationException();
}
@Override
public int size() {
return 6;
}
private RequestContext ctx() {
return msgContext.get();
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean containsKey(Object key) {
if (key == null)
return false;
switch (key.toString()) {
case HTTP_REQUEST_HEADERS:
case HTTP_REQUEST_METHOD:
case HTTP_RESPONSE_CODE:
case HTTP_RESPONSE_HEADERS:
case SERVLET_REQUEST:
case SERVLET_RESPONSE:
return true;
}
return false;
}
@Override
public boolean containsValue(Object value) {
if (value == ctx().request ||
value == ctx().response ||
value == ctx().soapMessage)
return true;
return false;
}
@Override
public Object get(Object key) {
if (key == null)
return false;
switch (key.toString()) {
case HTTP_REQUEST_HEADERS:
return buildHeaders(ctx().request);
case HTTP_REQUEST_METHOD:
return ctx().request.getMethod();
case HTTP_RESPONSE_CODE:
return ctx().response.getStatus();
case HTTP_RESPONSE_HEADERS:
return buildHeaders(ctx().response);
case SERVLET_REQUEST:
return ctx().request;
case SERVLET_RESPONSE:
return ctx().response;
}
return null;
}
@Override
public Object put(String key, Object value) {
throw new UnsupportedOperationException();
}
@Override
public Object remove(Object key) {
throw new UnsupportedOperationException();
}
@Override
public void putAll(Map extends String, ?> m) {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@Override
public Set keySet() {
return new HashSet<>(Arrays.asList(HTTP_REQUEST_HEADERS, HTTP_REQUEST_METHOD, HTTP_RESPONSE_CODE, HTTP_RESPONSE_HEADERS, SERVLET_REQUEST, SERVLET_RESPONSE));
}
@Override
public Collection