/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.io.XmlUtil
 *  com.l7tech.gateway.common.audit.AuditDetailMessage
 *  com.l7tech.gateway.common.audit.ServiceMessages
 *  com.l7tech.gateway.common.service.PublishedService
 *  com.l7tech.message.HttpRequestKnob
 *  com.l7tech.message.HttpRequestKnobAdapter
 *  com.l7tech.message.Message
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.assertion.PolicyAssertionException
 *  com.l7tech.util.ExceptionUtils
 *  com.l7tech.util.ResourceUtils
 */
package com.l7tech.server.wsdm.subscription;

import com.l7tech.common.io.XmlUtil;
import com.l7tech.gateway.common.audit.AuditDetailMessage;
import com.l7tech.gateway.common.audit.ServiceMessages;
import com.l7tech.gateway.common.service.PublishedService;
import com.l7tech.message.HttpRequestKnob;
import com.l7tech.message.HttpRequestKnobAdapter;
import com.l7tech.message.Message;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.message.PolicyEnforcementContextFactory;
import com.l7tech.server.policy.ServerPolicyHandle;
import com.l7tech.server.wsdm.subscription.SubscriptionNotifier;
import com.l7tech.util.ExceptionUtils;
import com.l7tech.util.ResourceUtils;
import java.io.Closeable;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.Callable;
import java.util.logging.Level;

class i
implements Callable<Void> {
    final String val$message;
    final PolicyEnforcementContext[] val$context;
    final String val$notificationUrl;
    final String val$policyGuid;
    final AssertionStatus[] val$status;
    final SubscriptionNotifier this$0;
    private static final String[] a;

    /*
     * Ignored method signature, as it can't be verified against descriptor
     */
    i(SubscriptionNotifier subscriptionNotifier, String string, PolicyEnforcementContext[] policyEnforcementContextArray, String string2, String string3, AssertionStatus[] assertionStatusArray) {
        this.this$0 = subscriptionNotifier;
        this.val$message = string;
        this.val$context = policyEnforcementContextArray;
        this.val$notificationUrl = string2;
        this.val$policyGuid = string3;
        this.val$status = assertionStatusArray;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Loose catch block
     */
    @Override
    public Void call() throws Exception {
        block15: {
            ServerPolicyHandle serverPolicyHandle;
            block18: {
                String[] stringArray;
                block19: {
                    block16: {
                        URL uRL;
                        block20: {
                            Message message = new Message(XmlUtil.stringAsDocument((String)this.val$message));
                            message.attachHttpRequestKnob((HttpRequestKnob)new HttpRequestKnobAdapter(null));
                            this.val$context[0] = PolicyEnforcementContextFactory.createPolicyEnforcementContext(message, null, false);
                            this.val$context[0].setAuditLevel(Level.INFO);
                            PublishedService publishedService = new PublishedService();
                            stringArray = a;
                            publishedService.setName(stringArray[0]);
                            publishedService.setSoap(true);
                            this.val$context[0].setService(publishedService);
                            this.this$0.f.logAndAudit((AuditDetailMessage)ServiceMessages.ESM_NOTIFY_NOTIFICATION, this.val$notificationUrl);
                            uRL = null;
                            try {
                                uRL = new URL(this.val$notificationUrl);
                            }
                            catch (MalformedURLException malformedURLException) {
                                this.this$0.f.logAndAudit((AuditDetailMessage)ServiceMessages.ESM_NOTIFY_INVALID_URL, this.val$notificationUrl);
                            }
                            if (uRL == null) break block15;
                            if (this.val$policyGuid != null) break block19;
                            break block20;
                            catch (MalformedURLException malformedURLException) {
                                throw i.a(malformedURLException);
                            }
                        }
                        try {
                            block21: {
                                this.this$0.f.logAndAudit((AuditDetailMessage)ServiceMessages.ESM_NOTIFY_NO_POLICY, this.val$notificationUrl);
                                if (!this.this$0.a(this.val$context[0], uRL, this.val$message)) break block16;
                                break block21;
                                catch (MalformedURLException malformedURLException) {
                                    throw i.a(malformedURLException);
                                }
                            }
                            this.val$status[0] = AssertionStatus.NONE;
                            break block15;
                        }
                        catch (MalformedURLException malformedURLException) {
                            throw i.a(malformedURLException);
                        }
                    }
                    this.val$status[0] = AssertionStatus.FALSIFIED;
                    break block15;
                }
                serverPolicyHandle = null;
                try {
                    block17: {
                        serverPolicyHandle = this.this$0.policyCache.getServerPolicy(this.val$policyGuid);
                        try {
                            if (serverPolicyHandle != null) break block17;
                            this.this$0.f.logAndAudit((AuditDetailMessage)ServiceMessages.ESM_NOTIFY_INVALID_POLICY, this.val$notificationUrl, this.val$policyGuid);
                            this.val$status[0] = AssertionStatus.FAILED;
                            break block18;
                        }
                        catch (MalformedURLException malformedURLException) {
                            throw i.a(malformedURLException);
                        }
                    }
                    stringArray = a;
                    this.val$context[0].setVariable(stringArray[1], this.val$notificationUrl);
                    try {
                        this.val$status[0] = serverPolicyHandle.checkRequest(this.val$context[0]);
                    }
                    catch (PolicyAssertionException policyAssertionException) {
                        this.this$0.f.logAndAudit((AuditDetailMessage)ServiceMessages.EXCEPTION_WARNING_WITH_MORE_INFO, new String[]{a[2] + ExceptionUtils.getMessage((Throwable)policyAssertionException)}, policyAssertionException);
                    }
                    catch (IOException iOException) {
                        this.this$0.f.logAndAudit((AuditDetailMessage)ServiceMessages.ESM_NOTIFY_IO_ERROR, new String[]{this.val$notificationUrl, this.val$policyGuid, ExceptionUtils.getMessage((Throwable)iOException)}, ExceptionUtils.getDebugException((Throwable)iOException));
                    }
                }
                catch (Throwable throwable) {
                    ResourceUtils.closeQuietly(serverPolicyHandle);
                    throw throwable;
                }
            }
            ResourceUtils.closeQuietly((Closeable)serverPolicyHandle);
        }
        return null;
    }

    private static MalformedURLException a(MalformedURLException malformedURLException) {
        return malformedURLException;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "^u\u0016qA2[r@22n)FtH{\u0002j/YrE>qT\u0014AoC)?n1r\u0012~U6\u001f`)F}O80{4@us)=\u0018^u\u0016qA2[r@22n)FtH{\u0014}/@i\u001c{";
        int n3 = "^u\u0016qA2[r@22n)FtH{\u0002j/YrE>qT\u0014AoC)?n1r\u0012~U6\u001f`)F}O80{4@us)=\u0018^u\u0016qA2[r@22n)FtH{\u0014}/@i\u001c{".length();
        int n4 = 35;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = i.a(94, i.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                a = stringArray;
                return;
            }
            n4 = string.charAt(n5);
        }
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(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 -> 69;
                    case 1 -> 120;
                    case 2 -> 5;
                    case 3 -> 15;
                    case 4 -> 81;
                    case 5 -> 3;
                    default -> 113;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

