package com.l7tech.server.service.resolution;

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.Message;
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 var1) {
      super(var1);
   }

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

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

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

   protected String getRequestValue(Message var1) throws ServiceResolutionException {
      HasSoapAction var2 = (HasSoapAction)var1.getKnob(HasSoapAction.class);

      try {
         if (var2 == null) {
            return null;
         }
      } catch (IOException var8) {
         throw a(var8);
      }

      String var3;
      try {
         var3 = var2.getSoapAction();
      } catch (IOException var6) {
         String[] var5 = d;
         throw new ServiceResolutionException(var5[0] + SoapConstants.SOAPACTION + var5[1]);
      }

      try {
         if (var3 == null) {
            this.auditor.logAndAudit(MessageProcessingMessages.SR_SOAPACTION_NONE);
            return "";
         }
      } catch (IOException var7) {
         throw a(var7);
      }

      return SoapUtil.stripQuotes(var3);
   }

   @Override
   public boolean isApplicableToMessage(Message param1) {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aload 0
      // 01: getfield com/l7tech/server/service/resolution/SoapActionResolver.b Ljava/util/concurrent/atomic/AtomicBoolean;
      // 04: invokevirtual java/util/concurrent/atomic/AtomicBoolean.get ()Z
      // 07: ifne 10
      // 0a: bipush 0
      // 0b: ireturn
      // 0c: invokestatic com/l7tech/server/service/resolution/SoapActionResolver.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 0f: athrow
      // 10: aload 1
      // 11: ldc com/l7tech/message/MimeKnob
      // 13: invokevirtual com/l7tech/message/Message.getKnob (Ljava/lang/Class;)Ljava/lang/Object;
      // 16: checkcast com/l7tech/message/MimeKnob
      // 19: astore 2
      // 1a: aload 1
      // 1b: ldc com/l7tech/message/HasSoapAction
      // 1d: invokevirtual com/l7tech/message/Message.getKnob (Ljava/lang/Class;)Ljava/lang/Object;
      // 20: checkcast com/l7tech/message/HasSoapAction
      // 23: astore 3
      // 24: aload 1
      // 25: ldc com/l7tech/message/HttpRequestKnob
      // 27: invokevirtual com/l7tech/message/Message.getKnob (Ljava/lang/Class;)Ljava/lang/Object;
      // 2a: ifnull 35
      // 2d: bipush 1
      // 2e: goto 36
      // 31: invokestatic com/l7tech/server/service/resolution/SoapActionResolver.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 34: athrow
      // 35: bipush 0
      // 36: istore 4
      // 38: bipush 0
      // 39: istore 5
      // 3b: bipush 0
      // 3c: istore 6
      // 3e: aload 2
      // 3f: ifnull 65
      // 42: aload 1
      // 43: invokevirtual com/l7tech/message/Message.isInitialized ()Z
      // 46: ifeq 65
      // 49: goto 50
      // 4c: invokestatic com/l7tech/server/service/resolution/SoapActionResolver.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 4f: athrow
      // 50: aload 2
      // 51: invokeinterface com/l7tech/message/MimeKnob.getFirstPart ()Lcom/l7tech/common/mime/PartInfo; 1
      // 56: invokeinterface com/l7tech/common/mime/PartInfo.getContentType ()Lcom/l7tech/common/mime/ContentTypeHeader; 1
      // 5b: invokevirtual com/l7tech/common/mime/ContentTypeHeader.isXml ()Z
      // 5e: istore 5
      // 60: goto 65
      // 63: astore 7
      // 65: aload 3
      // 66: ifnull 84
      // 69: aload 3
      // 6a: invokeinterface com/l7tech/message/HasSoapAction.getSoapAction ()Ljava/lang/String; 1
      // 6f: ifnull 81
      // 72: goto 79
      // 75: invokestatic com/l7tech/server/service/resolution/SoapActionResolver.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 78: athrow
      // 79: bipush 1
      // 7a: goto 82
      // 7d: invokestatic com/l7tech/server/service/resolution/SoapActionResolver.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 80: athrow
      // 81: bipush 0
      // 82: istore 6
      // 84: goto 89
      // 87: astore 7
      // 89: iload 4
      // 8b: ifeq 9a
      // 8e: iload 5
      // 90: ifeq a6
      // 93: goto 9a
      // 96: invokestatic com/l7tech/server/service/resolution/SoapActionResolver.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 99: athrow
      // 9a: iload 6
      // 9c: ifne b8
      // 9f: goto a6
      // a2: invokestatic com/l7tech/server/service/resolution/SoapActionResolver.a (Ljava/io/IOException;)Ljava/io/IOException;
      // a5: athrow
      // a6: aload 0
      // a7: getfield com/l7tech/server/service/resolution/SoapActionResolver.auditor Lcom/l7tech/gateway/common/audit/Audit;
      // aa: getstatic com/l7tech/gateway/common/audit/MessageProcessingMessages.SR_SOAPACTION_NOT_HTTP_OR_SOAP Lcom/l7tech/gateway/common/audit/Messages$M;
      // ad: invokeinterface com/l7tech/gateway/common/audit/Audit.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;)V 2
      // b2: bipush 0
      // b3: ireturn
      // b4: invokestatic com/l7tech/server/service/resolution/SoapActionResolver.a (Ljava/io/IOException;)Ljava/io/IOException;
      // b7: athrow
      // b8: bipush 1
      // b9: ireturn
      // try (32 -> 37): 38 java/io/IOException
      // try (18 -> 24): 24 java/io/IOException
      // try (0 -> 6): 6 java/io/IOException
      // try (40 -> 45): 46 java/io/IOException
      // try (49 -> 57): 57 java/io/IOException
      // try (47 -> 52): 53 java/io/IOException
      // try (47 -> 61): 62 java/io/IOException
      // try (63 -> 67): 68 java/io/IOException
      // try (65 -> 72): 73 java/io/IOException
      // try (70 -> 81): 81 java/io/IOException
   }

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

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

   static {
      String[] var5 = new String[2];
      int var3 = 0;
      String var2 = " \u001b\u0002lA(k\u0013\u0018\u0003kUdcF\bF\u001c\u0012cAmt\u0015";
      int var4 = " \u001b\u0002lA(k\u0013\u0018\u0003kUdcF\bF\u001c\u0012cAmt\u0015".length();
      char var1 = 15;
      int var0 = -1;

      while (true) {
         String var10002 = c(126, b(var2.substring(++var0, var0 + var1)));
         byte var10001 = -1;
         var5[var3++] = var10002;
         if ((var0 += var1) >= var4) {
            d = var5;
            return;
         }

         var1 = var2.charAt(var0);
      }
   }

   private static char[] b(String var0) {
      char[] var10000 = var0.toCharArray();
      if (var10000.length < 2) {
         var10000[0] = (char)(var10000[0] ^ 120);
      }

      return var10000;
   }

   private static String c(int var0, char[] var1) {
      int var10003 = var1.length;
      int var10002 = var0;
      char[] var10001 = var1;
      int var10000 = var10003;

      for (int var2 = 0; var10000 > var2; var2++) {
         var10001[var2] = (char)(var10001[var2] ^ var10002 ^ switch (var2 % 7) {
            case 0 -> 24;
            case 1 -> 10;
            case 2 -> 9;
            case 3 -> 124;
            case 4 -> 91;
            case 5 -> 118;
            default -> 120;
         });
      }

      return new String(var10001).intern();
   }
}
