com.fjn.helper.frameworkex.webservice.xfire.XFireHelper.java Source code

Java tutorial

Introduction

Here is the source code for com.fjn.helper.frameworkex.webservice.xfire.XFireHelper.java

Source

/*
 *
 *  Copyright 2018 FJN Corp.
 *
 *  Licensed 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.
 *
 *  Author                        Date                       Issue
 *  fs1194361820@163.com          2015-01-01                 Initial Version
 *
 */

package com.fjn.helper.frameworkex.webservice.xfire;

import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

import com.fjn.helper.common.io.file.common.ResourceFinder;

@SuppressWarnings("unchecked")
public class XFireHelper {
    private static final Log log = LogFactory.getLog(XFireHelper.class);

    /**
     * classPathfilepath,??serviceNameSEI
     * @param filepath
     * @param serviceName
     * @param serviceEndpointInterface (SEI)
     * @return
     */
    public static <T> T getEndpoint(String filepath, String serviceName, Class<T> serviceEndpointInterface) {
        T endpoint = null;
        InputStream in = ResourceFinder.getInputStreamFromClassPath(filepath);
        Properties props = ResourceFinder.loadPropreties(in);
        if (props == null)
            return null;

        String wsdlURL = props.get(serviceName).toString();
        log.info(wsdlURL);
        if (StringUtil.isNull(wsdlURL))
            return null;

        if (StringUtil.endsWithIgnoreCase(wsdlURL, "?wsdl")) {
            wsdlURL = wsdlURL.substring(0, wsdlURL.length() - 5);
        }
        endpoint = getEndpoint(wsdlURL, serviceEndpointInterface);
        return endpoint;
    }

    /**
     * ?wsdlURL?SEI
     * @param wsdlURL
     * @param serviceEndpointInterface
     * @return
     */
    public static <T> T getEndpoint(String wsdlURL, Class<T> serviceEndpointInterface) {
        Service srvcModel = new ObjectServiceFactory().create(serviceEndpointInterface);
        XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
        T endpoint = null;
        try {
            endpoint = (T) factory.create(srvcModel, wsdlURL);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return endpoint;
    }

}