/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.audit.AuditDetailMessage
 *  com.l7tech.gateway.common.audit.AuditFactory
 *  com.l7tech.gateway.common.audit.MessageProcessingMessages
 *  com.l7tech.gateway.common.transport.ResolutionConfiguration
 *  com.l7tech.message.HasSoapAction
 *  com.l7tech.message.HttpRequestKnob
 *  com.l7tech.message.Message
 *  com.l7tech.message.MimeKnob
 *  com.l7tech.util.SoapConstants
 *  com.l7tech.xml.soap.SoapUtil
 *  javax.wsdl.BindingOperation
 *  javax.wsdl.Definition
 */
package com.l7tech.server.service.resolution;

import com.l7tech.gateway.common.audit.AuditDetailMessage;
import com.l7tech.gateway.common.audit.AuditFactory;
import com.l7tech.gateway.common.audit.MessageProcessingMessages;
import com.l7tech.gateway.common.transport.ResolutionConfiguration;
import com.l7tech.message.HasSoapAction;
import com.l7tech.message.HttpRequestKnob;
import com.l7tech.message.Message;
import com.l7tech.message.MimeKnob;
import com.l7tech.server.service.resolution.ServiceResolutionException;
import com.l7tech.server.service.resolution.WsdlOperationServiceResolver;
import com.l7tech.util.SoapConstants;
import com.l7tech.xml.soap.SoapUtil;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.wsdl.BindingOperation;
import javax.wsdl.Definition;

public class SoapActionResolver
extends WsdlOperationServiceResolver<String> {
    private final AtomicBoolean b = new AtomicBoolean(true);
    private static final String[] d;

    public SoapActionResolver(AuditFactory auditFactory) {
        super(auditFactory);
    }

    @Override
    public void configure(ResolutionConfiguration resolutionConfiguration) {
        super.configure(resolutionConfiguration);
        this.b.set(resolutionConfiguration.isUseSoapAction());
    }

    @Override
    public boolean usesMessageContent() {
        return false;
    }

    @Override
    protected Set<String> getTargetValues(Definition definition, BindingOperation bindingOperation) {
        return Collections.singleton(SoapUtil.findSoapAction((BindingOperation)bindingOperation));
    }

    @Override
    protected String getRequestValue(Message message) throws ServiceResolutionException {
        String string;
        HasSoapAction hasSoapAction = (HasSoapAction)message.getKnob(HasSoapAction.class);
        try {
            if (hasSoapAction == null) {
                return null;
            }
        }
        catch (IOException iOException) {
            throw SoapActionResolver.a(iOException);
        }
        try {
            string = hasSoapAction.getSoapAction();
        }
        catch (IOException iOException) {
            String[] stringArray = d;
            throw new ServiceResolutionException(stringArray[0] + SoapConstants.SOAPACTION + stringArray[1]);
        }
        try {
            if (string == null) {
                this.auditor.logAndAudit((AuditDetailMessage)MessageProcessingMessages.SR_SOAPACTION_NONE);
                return "";
            }
        }
        catch (IOException iOException) {
            throw SoapActionResolver.a(iOException);
        }
        return SoapUtil.stripQuotes((String)string);
    }

    /*
     * Loose catch block
     */
    @Override
    public boolean isApplicableToMessage(Message message) {
        block26: {
            boolean bl2;
            boolean bl3;
            boolean bl4;
            block22: {
                HasSoapAction hasSoapAction;
                block21: {
                    boolean bl5;
                    try {
                        if (!this.b.get()) {
                            return false;
                        }
                    }
                    catch (IOException iOException) {
                        throw SoapActionResolver.a(iOException);
                    }
                    MimeKnob mimeKnob = (MimeKnob)message.getKnob(MimeKnob.class);
                    hasSoapAction = (HasSoapAction)message.getKnob(HasSoapAction.class);
                    try {
                        bl5 = message.getKnob(HttpRequestKnob.class) != null;
                    }
                    catch (IOException iOException) {
                        throw SoapActionResolver.a(iOException);
                    }
                    bl4 = bl5;
                    bl3 = false;
                    bl2 = false;
                    try {
                        if (mimeKnob == null || !message.isInitialized()) break block21;
                    }
                    catch (IOException iOException) {
                        throw SoapActionResolver.a(iOException);
                    }
                    try {
                        bl3 = mimeKnob.getFirstPart().getContentType().isXml();
                    }
                    catch (IOException iOException) {
                        // empty catch block
                    }
                }
                try {
                    boolean bl6;
                    block24: {
                        block23: {
                            if (hasSoapAction == null) break block22;
                            try {
                                block27: {
                                    if (hasSoapAction.getSoapAction() == null) break block23;
                                    break block27;
                                    catch (IOException iOException) {
                                        throw SoapActionResolver.a(iOException);
                                    }
                                }
                                bl6 = true;
                                break block24;
                            }
                            catch (IOException iOException) {
                                throw SoapActionResolver.a(iOException);
                            }
                        }
                        bl6 = false;
                    }
                    bl2 = bl6;
                }
                catch (IOException iOException) {
                    // empty catch block
                }
            }
            try {
                block25: {
                    try {
                        try {
                            if (bl4 && !bl3) break block25;
                        }
                        catch (IOException iOException) {
                            throw SoapActionResolver.a(iOException);
                        }
                        if (bl2) break block26;
                    }
                    catch (IOException iOException) {
                        throw SoapActionResolver.a(iOException);
                    }
                }
                this.auditor.logAndAudit((AuditDetailMessage)MessageProcessingMessages.SR_SOAPACTION_NOT_HTTP_OR_SOAP);
                return false;
            }
            catch (IOException iOException) {
                throw SoapActionResolver.a(iOException);
            }
        }
        return true;
    }

    @Override
    protected boolean isApplicableToConflicts() {
        return this.b.get();
    }

    private static IOException a(IOException iOException) {
        return iOException;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[2];
        int n2 = 0;
        String string = " \u001b\u0002lA(k\u0013\u0018\u0003kUdcF\bF\u001c\u0012cAmt\u0015";
        int n3 = " \u001b\u0002lA(k\u0013\u0018\u0003kUdcF\bF\u001c\u0012cAmt\u0015".length();
        int n4 = 15;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = SoapActionResolver.c(126, SoapActionResolver.b(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                d = stringArray;
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x78);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String c(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 24;
                    case 1 -> 10;
                    case 2 -> 9;
                    case 3 -> 124;
                    case 4 -> 91;
                    case 5 -> 118;
                    default -> 120;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

