<commit_before>/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

package org.apache.airavata.xbaya.invoker;

import java.net.URI;
import java.util.UUID;

import javax.xml.namespace.QName;

import org.apache.airavata.xbaya.XBayaException;
import org.apache.airavata.xbaya.invoker.factory.InvokerFactory;
import org.apache.airavata.xbaya.lead.NotificationHandler;
import org.apache.airavata.xbaya.util.WSDLUtil;

import xsul.lead.LeadContextHeader;
import xsul.wsdl.WsdlDefinitions;
import xsul.wsdl.WsdlResolver;
import xsul.wsif.WSIFMessage;
import xsul.xhandler_soap_sticky_header.StickySoapHeaderHandler;
import xsul.xwsif_runtime.WSIFClient;
import xsul5.MLogger;

public class GFacInvoker implements Invoker {

    private final static MLogger logger = MLogger.getLogger();

    private String gfacURL;

    private String messageBoxURL;

    private QName portTypeQName;

    private Invoker invoker;

    private LeadContextHeader leadContext;

    /**
     * Constructs a GFacInvoker.
     * 
     * @param portTypeQName
     * @param gfacURL
     * @param messageBoxURL
     * @param context
     */
    public GFacInvoker(QName portTypeQName, String gfacURL, String messageBoxURL, LeadContextHeader context) {
        this.portTypeQName = portTypeQName;
        this.gfacURL = gfacURL;
        this.messageBoxURL = messageBoxURL;
        this.leadContext = context;
    }

    /**
     * @see org.apache.airavata.xbaya.invoker.Invoker#setup()
     */
    public void setup() throws XBayaException {

        if (this.gfacURL == null) {
            String message = "The location of the Generic Factory is not specified.";
            throw new XBayaException(message);
        }

        if (this.portTypeQName == null) {
            String message = "Error in finding the service name";
            throw new XBayaException(message);
        }

        try {

            URI uri = new URI(this.gfacURL);
            String path = uri.getPath();
            if (path != null && path.contains("/")) {
                path = path.substring(path.lastIndexOf('/') + 1) + portTypeQName.getLocalPart() + "/getWSDL";
            }
            uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(),
                    uri.getFragment());

            logger.info("getWSDL service:" + uri.toString());
            
            WsdlDefinitions definitions = WsdlResolver.getInstance().loadWsdl(uri);

            // FIXME: Should pass the last argument of leadcontextheader
            this.invoker = InvokerFactory
                    .createInvoker(this.portTypeQName, definitions, null, this.messageBoxURL, null);
            this.invoker.setup();
        } catch (XBayaException xe) {
            throw xe;
        } catch (Exception e) {
            throw new XBayaException(e.getMessage(), e);
        }

    }<commit_msg>Fix Gfac path calculation bug<commit_after>/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

package org.apache.airavata.xbaya.invoker;

import java.net.URI;
import java.util.UUID;

import javax.xml.namespace.QName;

import org.apache.airavata.xbaya.XBayaException;
import org.apache.airavata.xbaya.invoker.factory.InvokerFactory;
import org.apache.airavata.xbaya.lead.NotificationHandler;

import xsul.lead.LeadContextHeader;
import xsul.wsdl.WsdlDefinitions;
import xsul.wsdl.WsdlResolver;
import xsul.wsif.WSIFMessage;
import xsul.xhandler_soap_sticky_header.StickySoapHeaderHandler;
import xsul.xwsif_runtime.WSIFClient;
import xsul5.MLogger;

public class GFacInvoker implements Invoker {

    private final static MLogger logger = MLogger.getLogger();

    private String gfacURL;

    private String messageBoxURL;

    private QName portTypeQName;

    private Invoker invoker;

    private LeadContextHeader leadContext;

    /**
     * Constructs a GFacInvoker.
     * 
     * @param portTypeQName
     * @param gfacURL
     * @param messageBoxURL
     * @param context
     */
    public GFacInvoker(QName portTypeQName, String gfacURL, String messageBoxURL, LeadContextHeader context) {
        this.portTypeQName = portTypeQName;
        this.gfacURL = gfacURL;
        this.messageBoxURL = messageBoxURL;
        this.leadContext = context;
    }

    /**
     * @see org.apache.airavata.xbaya.invoker.Invoker#setup()
     */
    public void setup() throws XBayaException {

        if (this.gfacURL == null) {
            String message = "The location of the Generic Factory is not specified.";
            throw new XBayaException(message);
        }

        if (this.portTypeQName == null) {
            String message = "Error in finding the service name";
            throw new XBayaException(message);
        }

        try {

            URI uri = new URI(this.gfacURL);
            String path = uri.getPath();
            if (path != null && path.contains("/")) {
                path = path.substring(0, path.lastIndexOf('/') + 1) + portTypeQName.getLocalPart() + "/getWSDL";
            }
            uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(),
                    uri.getFragment());

            logger.info("getWSDL service:" + uri.toString());
            
            WsdlDefinitions definitions = WsdlResolver.getInstance().loadWsdl(uri);

            // FIXME: Should pass the last argument of leadcontextheader
            this.invoker = InvokerFactory
                    .createInvoker(this.portTypeQName, definitions, null, this.messageBoxURL, null);
            this.invoker.setup();
        } catch (XBayaException xe) {
            throw xe;
        } catch (Exception e) {
            throw new XBayaException(e.getMessage(), e);
        }

    }
{'fraction_non_alphanumeric': 0.09168619881428375, 'fraction_numerical': 0.0017923617813318626, 'mean_word_length': 2.7566027964785085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2374288', 'n_tokens_mistral': 2098, 'n_tokens_neox': 2011, 'n_words': 593}