ropalka commented on a change in pull request #746:
URL: https://github.com/apache/cxf/pull/746#discussion_r585333839
##########
File path:
rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java
##########
@@ -177,149 +129,8 @@ public ClassLoader run() {
return clazz.getClassLoader();
}
- private void processHandlerChainElement(Element el, List<Handler> chain,
- QName portQName, QName
serviceQName, String bindingID) {
- Node node = el.getFirstChild();
- while (node != null) {
- Node cur = node;
- node = node.getNextSibling();
- if (cur instanceof Element) {
- el = (Element)cur;
- boolean isJavaEENamespace =
JAVAEE_NS.equals(el.getNamespaceURI());
- boolean isJakartaEENamespace =
JAKARTAEE_NS.equals(el.getNamespaceURI());
- if (!isJavaEENamespace && !isJakartaEENamespace) {
- String xml = StaxUtils.toString(el);
- throw new WebServiceException(
- BundleUtils.getFormattedString(BUNDLE,
-
"NOT_VALID_ELEMENT_IN_HANDLER",
- xml));
- }
- String name = el.getLocalName();
- if ("port-name-pattern".equals(name)) {
- if (!patternMatches(el, portQName)) {
- return;
- }
- } else if ("service-name-pattern".equals(name)) {
- if (!patternMatches(el, serviceQName)) {
- return;
- }
- } else if ("protocol-bindings".equals(name)) {
- if (!protocolMatches(el, bindingID)) {
- return;
- }
- } else if ("handler".equals(name)) {
- processHandlerElement(el, chain);
- }
- }
- }
- }
- private boolean protocolMatches(Element el, String id) {
- if (id == null) {
- return true;
- }
- String name = el.getTextContent().trim();
- StringTokenizer st = new StringTokenizer(name, " ", false);
- boolean result = false;
- while (st.hasMoreTokens() && !result) {
- result = result || singleProtocolMatches(st.nextToken(), id);
- }
- return result;
- }
- private boolean singleProtocolMatches(String name, String id) {
- if ("##SOAP11_HTTP".equals(name)) {
- return "http://schemas.xmlsoap.org/wsdl/soap/http".contains(id)
- || "http://schemas.xmlsoap.org/soap/".contains(id);
- } else if ("##SOAP11_HTTP_MTOM".equals(name)) {
- return
"http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true".contains(id)
- || "http://schemas.xmlsoap.org/soap/?mtom=true".contains(id);
- } else if ("##SOAP12_HTTP".equals(name)) {
- return "http://www.w3.org/2003/05/soap/bindings/HTTP/".contains(id)
- || "http://schemas.xmlsoap.org/wsdl/soap12/".contains(id);
- } else if ("##SOAP12_HTTP_MTOM".equals(name)) {
- return
"http://www.w3.org/2003/05/soap/bindings/HTTP/?mtom=true".contains(id)
- ||
"http://schemas.xmlsoap.org/wsdl/soap12/?mtom=true".contains(id);
- } else if ("##XML_HTTP".equals(name)) {
- name = "http://www.w3.org/2004/08/wsdl/http";
- }
- return name.contains(id);
- }
- private boolean patternMatches(Element el, QName comp) {
- if (comp == null) {
- return true;
- }
- String namePattern = el.getTextContent().trim();
- if ("*".equals(namePattern)) {
- return true;
- }
- final int idx = namePattern.indexOf(':');
- if (idx < 0) {
- String xml = StaxUtils.toString(el);
- throw new WebServiceException(
- BundleUtils.getFormattedString(BUNDLE,
- "NOT_A_QNAME_PATTER",
- namePattern, xml));
- }
- String pfx = namePattern.substring(0, idx);
- String ns = el.lookupNamespaceURI(pfx);
- if (ns == null) {
- ns = pfx;
- }
- if (!ns.equals(comp.getNamespaceURI())) {
- return false;
- }
- String localPart = namePattern.substring(idx + 1,
- namePattern.length());
- if (localPart.contains("*")) {
- //wildcard pattern matching
- return Pattern.matches(mapPattern(localPart), comp.getLocalPart());
- } else if (!localPart.equals(comp.getLocalPart())) {
- return false;
- }
- return true;
- }
-
- private String mapPattern(String s) {
- StringBuilder buf = new StringBuilder(s);
- for (int x = 0; x < buf.length(); x++) {
- switch (buf.charAt(x)) {
- case '*':
- buf.insert(x, '.');
- x++;
- break;
- case '.':
- case '\\':
- case '^':
- case '$':
- case '{':
- case '}':
- case '(':
- case ')':
- buf.insert(x, '\\');
- x++;
- break;
- default:
- //nothing to do
- }
- }
- return buf.toString();
- }
-
- private void processHandlerElement(Element el, List<Handler> chain) {
- try {
- JAXBContext ctx = getContextForPortComponentHandlerType();
- PortComponentHandlerType pt = JAXBUtils.unmarshall(ctx, el,
PortComponentHandlerType.class).getValue();
- chain.addAll(buildHandlerChain(pt, classLoader));
- } catch (JAXBException e) {
- throw new IllegalArgumentException("Could not unmarshal handler
chain", e);
- }
- }
-
- private static synchronized JAXBContext
getContextForPortComponentHandlerType()
- throws JAXBException {
- if (context == null) {
- context = JAXBContext.newInstance(PortComponentHandlerType.class);
- }
- return context;
+ List<Handler> buildHandlerChain(PortComponentHandlerType ht) {
Review comment:
It cannot be private as it is used by both JakartaeeHandlerChainBuilder
& JavaeeHandlerChainBuilder.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]