Browse Source

修改hos-web-framework依赖关系

Airhead 8 years ago
parent
commit
1b2cd32033

+ 2 - 2
hos-arbiter/pom.xml

@ -13,9 +13,9 @@
    <parent>
        <groupId>com.yihu.hos</groupId>
        <artifactId>hos-web-framework-dependencies</artifactId>
        <artifactId>hos-web-camel-dependencies</artifactId>
        <version>1.1.1-SNAPSHOT</version>
        <relativePath>../hos-web-framework-dependencies</relativePath><!-- lookup parent from repository -->
        <relativePath>../hos-web-camel-dependencies</relativePath><!-- lookup parent from repository -->
    </parent>

+ 2 - 2
hos-broker/pom.xml

@ -13,9 +13,9 @@
	<parent>
		<groupId>com.yihu.hos</groupId>
		<artifactId>hos-web-framework-dependencies</artifactId>
		<artifactId>hos-web-camel-dependencies</artifactId>
		<version>1.1.1-SNAPSHOT</version>
		<relativePath>../hos-web-framework-dependencies</relativePath> <!-- lookup parent from repository -->
		<relativePath>../hos-web-camel-dependencies</relativePath><!-- lookup parent from repository -->
	</parent>
	<properties>

+ 9 - 0
hos-core/pom.xml

@ -7,6 +7,10 @@
    <groupId>com.yihu.hos</groupId>
    <artifactId>hos-core</artifactId>
    <version>1.1.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>hos-core</name>
    <description>ESB通用组件</description>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -92,6 +96,11 @@
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.2</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>
        <!--commons end-->
        <!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->

+ 0 - 51
hos-http/pom.xml

@ -1,51 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.yihu.hos</groupId>
    <artifactId>hos-http</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <!--httpclient start-->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.5.1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!--httpclient end-->
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

+ 0 - 15
hos-http/src/main/java/com/yihu/hos/http/AllowAllHostnameVerifier.java

@ -1,15 +0,0 @@
package com.yihu.hos.http;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
/**
 * @author Air
 * @version 1.0
 * @created 2015.07.02 15:48
 */
public class AllowAllHostnameVerifier implements HostnameVerifier {
    public boolean verify(String hostname, SSLSession session) {
        return true;
    }
}

+ 0 - 46
hos-http/src/main/java/com/yihu/hos/http/HTTPClient.java

@ -1,46 +0,0 @@
package com.yihu.hos.http;
import java.util.Map;
/**
 * @created Airhead 2016/8/24.
 */
public interface HTTPClient {
    //主要的几种方法,其他的暂时未使用
    String GET = "GET";
    String POST = "POST";
    String PUT = "PUT";
    String DELETE = "DELETE";
    HTTPResponse get(String url);
    HTTPResponse get(String url, Map<String, String> params);
    HTTPResponse get(String url, Map<String, String> params, Map<String, String> headers);
    HTTPResponse post(String url);
    HTTPResponse post(String url, Map<String, String> params);
    HTTPResponse post(String url, Map<String, String> params, Map<String, String> headers);
    HTTPResponse postFile(String url, String path);
    HTTPResponse postFile(String url, String path, Map<String, String> params);
    HTTPResponse postFile(String url, String path, Map<String, String> params, Map<String, String> headers);
    HTTPResponse put(String url);
    HTTPResponse put(String url, Map<String, String> params);
    HTTPResponse put(String url, Map<String, String> params, Map<String, String> headers);
    HTTPResponse delete(String url);
    HTTPResponse delete(String url, Map<String, String> params);
    HTTPResponse delete(String url, Map<String, String> params, Map<String, String> headers);
    HTTPResponse request(String method, String url, Map<String, String> params, Map<String, String> headers);
}

+ 0 - 299
hos-http/src/main/java/com/yihu/hos/http/HTTPClientDefaultImpl.java

@ -1,299 +0,0 @@
package com.yihu.hos.http;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.auth.AuthScope;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * @created Airhead 2016/8/24.
 */
class HTTPClientDefaultImpl implements HTTPClient {
    private static final Log log = LogFactory.getLog(HTTPClientDefaultImpl.class);
    private CloseableHttpClient httpClient;
    private HttpClientContext httpClientContext;
    HTTPClientDefaultImpl(CloseableHttpClient httpClient, CredentialsProvider credentialsProvider) {
        this.httpClient = httpClient;
        if (credentialsProvider != null) {
            this.httpClientContext = HttpClientContext.create();
            httpClientContext.setCredentialsProvider(credentialsProvider);
        }
    }
    public HTTPResponse get(String url) {
        return get(url, null);
    }
    public HTTPResponse get(String url, Map<String, String> params) {
        return get(url, params, null);
    }
    public HTTPResponse get(String url, Map<String, String> params, Map<String, String> headers) {
        CloseableHttpResponse response;
        HttpEntity entity = null;
        try {
            HttpGet httpGet = new HttpGet(formatURL(url, params));
            authenticate(url, httpClientContext);
            addHeads(httpGet, headers);
            response = httpClient.execute(httpGet, httpClientContext);
            entity = response.getEntity();
            return new HTTPResponse(response.getStatusLine().getStatusCode(), EntityUtils.toString(entity));
        } catch (IOException ex) {
            log.error(ex.getMessage());
        } finally {
            try {
                EntityUtils.consume(entity);
            } catch (IOException ex) {
                log.error(ex.getMessage());
            }
        }
        return new HTTPResponse(500, "");
    }
    public HTTPResponse post(String url) {
        return post(url, null);
    }
    public HTTPResponse post(String url, Map<String, String> params) {
        return post(url, params, null);
    }
    public HTTPResponse post(String url, Map<String, String> params, Map<String, String> headers) {
        CloseableHttpResponse response;
        HttpEntity entity = null;
        try {
            HttpPost httpPost = new HttpPost(url);
            authenticate(url, httpClientContext);
            addHeads(httpPost, headers);
            setEntity(httpPost, params);
            response = httpClient.execute(httpPost, httpClientContext);
            entity = response.getEntity();
            return new HTTPResponse(response.getStatusLine().getStatusCode(), EntityUtils.toString(entity));
        } catch (IOException ex) {
            log.error(ex.getMessage());
        } finally {
            try {
                EntityUtils.consume(entity);
            } catch (IOException ex) {
                log.error(ex.getMessage());
            }
        }
        return new HTTPResponse(500, "");
    }
    public HTTPResponse postFile(String url, String path) {
        return postFile(url, path, null);
    }
    public HTTPResponse postFile(String url, String path, Map<String, String> params) {
        return postFile(url, path, params, null);
    }
    public HTTPResponse postFile(String url, String path, Map<String, String> params, Map<String, String> headers) {
        CloseableHttpResponse response;
        HttpEntity entity = null;
        try {
            HttpPost httpPost = new HttpPost(url);
            authenticate(url, httpClientContext);
            addHeads(httpPost, headers);
            File file = new File(path);
            FileEntity fileEntity = new FileEntity(file, ContentType.create("text/plain", "UTF-8"));
            httpPost.setEntity(fileEntity);
            response = httpClient.execute(httpPost, httpClientContext);
            entity = response.getEntity();
            return new HTTPResponse(response.getStatusLine().getStatusCode(), EntityUtils.toString(entity));
        } catch (IOException ex) {
            log.error(ex.getMessage());
        } finally {
            try {
                EntityUtils.consume(entity);
            } catch (IOException ex) {
                log.error(ex.getMessage());
            }
        }
        return new HTTPResponse(500, "");
    }
    public HTTPResponse put(String url) {
        return put(url, null);
    }
    public HTTPResponse put(String url, Map<String, String> params) {
        return put(url, params, null);
    }
    public HTTPResponse put(String url, Map<String, String> params, Map<String, String> headers) {
        CloseableHttpResponse response;
        HttpEntity entity = null;
        try {
            HttpPut httpPut = new HttpPut(url);
            authenticate(url, httpClientContext);
            addHeads(httpPut, headers);
            setEntity(httpPut, params);
            response = httpClient.execute(httpPut, httpClientContext);
            entity = response.getEntity();
            return new HTTPResponse(response.getStatusLine().getStatusCode(), EntityUtils.toString(entity));
        } catch (IOException ex) {
            log.error(ex.getMessage());
        } finally {
            try {
                EntityUtils.consume(entity);
            } catch (IOException ex) {
                log.error(ex.getMessage());
            }
        }
        return new HTTPResponse(500, "");
    }
    public HTTPResponse delete(String url) {
        return delete(url, null);
    }
    public HTTPResponse delete(String url, Map<String, String> params) {
        return delete(url, params, null);
    }
    public HTTPResponse delete(String url, Map<String, String> params, Map<String, String> headers) {
        CloseableHttpResponse response;
        HttpEntity entity = null;
        try {
            HttpDelete httpDelete = new HttpDelete(formatURL(url, params));
            authenticate(url, httpClientContext);
            addHeads(httpDelete, headers);
            response = httpClient.execute(httpDelete, httpClientContext);
            entity = response.getEntity();
            return new HTTPResponse(response.getStatusLine().getStatusCode(), EntityUtils.toString(entity));
        } catch (IOException ex) {
            log.error(ex.getMessage());
        } finally {
            try {
                EntityUtils.consume(entity);
            } catch (IOException ex) {
                log.error(ex.getMessage());
            }
        }
        return new HTTPResponse(500, "");
    }
    public HTTPResponse request(String method, String url, Map<String, String> params, Map<String, String> headers) {
        if (method.equals(POST)) {
            return post(url, params, headers);
        }
        if (method.equals(GET)) {
            return get(url, params, headers);
        }
        if (method.equals(PUT)) {
            return put(url, params, headers);
        }
        if (method.equals(DELETE)) {
            return delete(url, params, headers);
        }
        return get(url, params, headers);
    }
    private void addHeads(HttpRequestBase httpRequestBase, Map<String, String> headers) {
        if (headers == null) {
            return;
        }
        headers.forEach(httpRequestBase::addHeader);
    }
    private String formatURL(String url, Map<String, String> params) {
        if (params == null) {
            return url;
        }
        
        final String[] query = {""};
        params.forEach((name, value) -> {
            try {
                query[0] += "&" + name + URLEncoder.encode(value, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException("encode url ");
            }
        });
        if (url.contains("?")) {
            return url + query[0];
        }
        return url + "?" + query[0].substring(1);
    }
    private void authenticate(String url, HttpClientContext httpClientContext) throws MalformedURLException {
        URL r = new URL(url);
        String userInfo = r.getUserInfo();
        if (userInfo == null) {
            return;
        }
        String[] user = userInfo.split(":");
        String host = r.getHost();
        int port = r.getPort();
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(new AuthScope(host, port),
                new org.apache.http.auth.UsernamePasswordCredentials(user[0], user[1]));
        if (httpClientContext == null) {
            httpClientContext = HttpClientContext.create();
        }
        httpClientContext.setCredentialsProvider(credentialsProvider);
    }
    private void setEntity(HttpEntityEnclosingRequestBase httpEntityEnclosingRequestBase, Map<String, String> params) {
        if (params == null) {
            return;
        }
        List<NameValuePair> nameValuePairs = new ArrayList<>();
        params.forEach((name, value) -> nameValuePairs.add(new BasicNameValuePair(name, value)));
        UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8);
        httpEntityEnclosingRequestBase.setEntity(postEntity);
    }
}

+ 0 - 19
hos-http/src/main/java/com/yihu/hos/http/HTTPClientImpl.java

@ -1,19 +0,0 @@
package com.yihu.hos.http;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.HttpClients;
/**
 * 用于HTTP和受信证书的HTTPS访问
 *
 * @created Airhead 2016/8/24.
 */
class HTTPClientImpl extends HTTPClientDefaultImpl {
    HTTPClientImpl() {
        super(HttpClients.createDefault(), null);
    }
    HTTPClientImpl(CredentialsProvider credentialsProvider){
        super(HttpClients.createDefault(), credentialsProvider);
    }
}

+ 0 - 19
hos-http/src/main/java/com/yihu/hos/http/HTTPResponse.java

@ -1,19 +0,0 @@
package com.yihu.hos.http;
/**
 * @created Airhead 2016/8/24.
 */
public class HTTPResponse {
    public final int statusCode;// e.g. 200
    public final String body;
    public HTTPResponse(int statusCode, String body) {
        this.statusCode = statusCode;
        this.body = body;
    }
//    public final String status; // e.g. "200 OK"
//    public final String proto; // e.g. "HTTP/1.0"
//    public final int protoMajor;     // e.g. 1
//    public final int protoMinor;    // e.g. 0
}

+ 0 - 24
hos-http/src/main/java/com/yihu/hos/http/HTTPSClientImpl.java

@ -1,24 +0,0 @@
package com.yihu.hos.http;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.HttpClients;
/**
 * 用于非受信证书的HTTPS访问
 *
 * @created Airhead 2016/8/24.
 */
class HTTPSClientImpl extends HTTPClientDefaultImpl {
    HTTPSClientImpl(SSLConnectionSocketFactory sslConnectionSocketFactory) {
        super(HttpClients.custom()
                .setSSLSocketFactory(sslConnectionSocketFactory)
                .build(), null);
    }
    HTTPSClientImpl(SSLConnectionSocketFactory sslConnectionSocketFactory, CredentialsProvider credentialsProvider) {
        super(HttpClients.custom()
                .setSSLSocketFactory(sslConnectionSocketFactory)
                .build(), credentialsProvider);
    }
}

+ 0 - 181
hos-http/src/main/java/com/yihu/hos/http/HttpClientKit.java

@ -1,181 +0,0 @@
package com.yihu.hos.http;
import org.apache.http.auth.AuthScope;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.ssl.SSLContexts;
import javax.net.ssl.SSLContext;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
/**
 * @created Airhead 2016/8/24.
 */
public class HttpClientKit {
    private static final String HTTP = "http";
    private static final String HTTPS = "https";
    private static Map<String, SSLConnectionSocketFactory> sslConnectionSocketFactoryMap = new HashMap<>();
    private static Map<String, CredentialsProvider> credentialsProviderMap = new HashMap<>();
    public static HTTPClient use(String url) {
        try {
            URL urlUse = new URL(url);
            String protocol = urlUse.getProtocol();
            String host = urlUse.getHost();
            int port = urlUse.getPort();
            if (protocol.equals(HTTPS)) {
                return getHttpsClient(host, port);
            } else if (protocol.equals(HTTP)) {
                return getHttpClient(host, port);
            }
        } catch (MalformedURLException ignored) {
        }
        return new HTTPClientImpl();
    }
    /**
     * 用于无认证和受信证书
     * @return HTTPClient
     */
    public static HTTPClient getHttpClient() {
        return new HTTPClientImpl();
    }
    private static HTTPClient getHttpClient(String host, Integer port) {
        String key = host + ":" + port;
        CredentialsProvider credentialsProvider = credentialsProviderMap.get(key);
        if (credentialsProvider == null) {
            return new HTTPClientImpl();
        }
        return new HTTPClientImpl(credentialsProvider);
    }
    private static HTTPClient getHttpsClient(String host, Integer port) {
        String key = host + ":" + port;
        SSLConnectionSocketFactory sslConnectionSocketFactory = sslConnectionSocketFactoryMap.get(key);
        if (sslConnectionSocketFactory == null) {
            throw new IllegalArgumentException("Custom SSL access must add trust store first.");
        }
        CredentialsProvider credentialsProvider = credentialsProviderMap.get(key);
        if (credentialsProvider == null) {
            return new HTTPSClientImpl(sslConnectionSocketFactory);
        }
        return new HTTPSClientImpl(sslConnectionSocketFactory, credentialsProvider);
    }
    public static void addTrustStore(String host, Integer port, String trustStorePath, String password) throws Exception {
        if (host == null || port == null || trustStorePath == null || password == null) {
            throw new IllegalArgumentException("must init basic credential first.");
        }
        SSLConnectionSocketFactory sslConnectionSocketFactory = sslConnectionSocketFactoryMap.get(host);
        if (sslConnectionSocketFactory != null) {
            return;
        }
        SSLContext sslcontext = SSLContexts.custom()
                .loadTrustMaterial(new File(trustStorePath), password.toCharArray(),
                        new TrustSelfSignedStrategy())
                .build();
        // Allow TLSv1 protocol only
        sslConnectionSocketFactory = new SSLConnectionSocketFactory(
                sslcontext,
                new String[]{"TLSv1"},
                null,
                new AllowAllHostnameVerifier());
        sslConnectionSocketFactoryMap.put(host, sslConnectionSocketFactory);
    }
    public static void addBasicCredentials(String host, Integer port, String user, String password) {
        if (host == null || port == null || user == null || password == null) {
            throw new IllegalArgumentException("must init trust store first.");
        }
        String key = host + ":" + port;
        if (credentialsProviderMap.containsKey(key)) {
            return;
        }
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(new AuthScope(host, port),
                new org.apache.http.auth.UsernamePasswordCredentials(user, password));
        credentialsProviderMap.put(key, credentialsProvider);
    }
    public static HTTPResponse get(String url) {
        return use(url).get(url);
    }
    public static HTTPResponse get(String url, Map<String, String> params) {
        return use(url).get(url, params);
    }
    public static HTTPResponse get(String url, Map<String, String> params, Map<String, String> headers) {
        return use(url).get(url, params, headers);
    }
    public static HTTPResponse post(String url) {
        return use(url).post(url);
    }
    public static HTTPResponse post(String url, Map<String, String> params) {
        return use(url).post(url, params);
    }
    public static HTTPResponse post(String url, Map<String, String> params, Map<String, String> headers) {
        return use(url).post(url, params, headers);
    }
    public static HTTPResponse postFile(String url, String path) {
        return use(url).postFile(url, path);
    }
    public static HTTPResponse postFile(String url, String path, Map<String, String> params) {
        return use(url).postFile(url, path, params);
    }
    public static HTTPResponse postFile(String url, String path, Map<String, String> params, Map<String, String> headers) {
        return use(url).postFile(url, path, params, headers);
    }
    public static HTTPResponse put(String url) {
        return use(url).put(url);
    }
    public static HTTPResponse put(String url, Map<String, String> params) {
        return use(url).put(url, params);
    }
    public static HTTPResponse put(String url, Map<String, String> params, Map<String, String> headers) {
        return use(url).put(url, params, headers);
    }
    public static HTTPResponse delete(String url) {
        return use(url).delete(url);
    }
    public static HTTPResponse delete(String url, Map<String, String> params) {
        return use(url).delete(url, params);
    }
    public static HTTPResponse delete(String url, Map<String, String> params, Map<String, String> headers) {
        return use(url).delete(url, params, headers);
    }
    public static HTTPResponse request(String method, String url, Map<String, String> params, Map<String, String> headers) {
        return use(url).request(method, url, params, headers);
    }
}

+ 0 - 112
hos-http/src/test/java/com/yihu/hos/http/HttpClientKitTest.java

@ -1,112 +0,0 @@
package com.yihu.hos.http;
import org.junit.Test;
/**
 * @created Airhead 2016/8/25.
 */
public class HttpClientKitTest {
    @Test
    public void use() throws Exception {
        HTTPResponse httpResponse = HttpClientKit.use("http://www.baidu.com").get("http://www.baidu.com");
        if (httpResponse.statusCode==200){
            System.out.println(httpResponse.body);
        }
        HTTPResponse httpResponse2 = HttpClientKit.getHttpClient().get("https://www.baidu.com");
        if (httpResponse.statusCode==200){
            System.out.println(httpResponse.body);
        }
    }
    @Test
    public void addTrustStore() throws Exception {
    }
    @Test
    public void addBasicCredentials() throws Exception {
    }
    @Test
    public void get() throws Exception {
    }
    @Test
    public void get1() throws Exception {
    }
    @Test
    public void get2() throws Exception {
    }
    @Test
    public void post() throws Exception {
    }
    @Test
    public void post1() throws Exception {
    }
    @Test
    public void post2() throws Exception {
    }
    @Test
    public void postFile() throws Exception {
    }
    @Test
    public void postFile1() throws Exception {
    }
    @Test
    public void postFile2() throws Exception {
    }
    @Test
    public void put() throws Exception {
    }
    @Test
    public void put1() throws Exception {
    }
    @Test
    public void put2() throws Exception {
    }
    @Test
    public void delete() throws Exception {
    }
    @Test
    public void delete1() throws Exception {
    }
    @Test
    public void delete2() throws Exception {
    }
    @Test
    public void request() throws Exception {
    }
}

+ 2 - 2
hos-rest/pom.xml

@ -13,9 +13,9 @@
	<parent>
		<groupId>com.yihu.hos</groupId>
		<artifactId>hos-web-framework-dependencies</artifactId>
		<artifactId>hos-web-camel-dependencies</artifactId>
		<version>1.1.1-SNAPSHOT</version>
		<relativePath>../hos-web-framework-dependencies</relativePath> <!-- lookup parent from repository -->
		<relativePath>../hos-web-camel-dependencies</relativePath><!-- lookup parent from repository -->
	</parent>
	<properties>

+ 1 - 76
hos-web-framework-dependencies/pom.xml

@ -11,17 +11,12 @@
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.8.RELEASE</version>
        <version>1.4.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository1212 -->
    </parent>
    <properties>
        <camel.version>2.17.1</camel.version>
        <!--<spring.version>4.2.8.RELEASE</spring.version>-->
        <hibernate.version>4.3.11.Final</hibernate.version>
        <camel.osgi.export.pkg>org.apache.camel.dataformat.xmljson.*</camel.osgi.export.pkg>
        <camel.osgi.export.service>org.apache.camel.spi.DataFormatResolver;dataformat=xmljson</camel.osgi.export.service>
        <!--<spring.security.version>4.0.2.RELEASE</spring.security.version>-->
    </properties>
@ -113,76 +108,6 @@
            <artifactId>mongo-java-driver</artifactId>
            <version>3.2.2</version>
        </dependency>
        <!-- camel start -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-boot</artifactId>
            <version>${camel.version}</version> <!-- use the same version as your Camel core version -->
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-http4</artifactId>
            <version>${camel.version}</version> <!-- use the same version as your Camel core version -->
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jetty</artifactId>
            <version>${camel.version}</version> <!-- use the same version as your Camel core version -->
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>${camel.version}</version> <!-- use the same version as your Camel core version -->
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>${camel.version}</version> <!-- use the same version as your Camel core version -->
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-cxf</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-quartz</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-quartz2</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-xmljson</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-stream</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.activemq/activemq-camel -->
        <dependency>
            <groupId>xom</groupId>
            <artifactId>xom</artifactId>
            <version>1.2.5</version>
        </dependency>
        <!-- camel end -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>

+ 5 - 2
pom.xml

@ -112,8 +112,11 @@
            <version>2.3.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
        </dependency>
    </dependencies>

+ 4 - 10
src/main/java/com/yihu/hos/ESBApplication.java

@ -1,15 +1,9 @@
package com.yihu.hos;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jms.annotation.EnableJms;
import javax.jms.Queue;
@SpringBootApplication
@EnableJms
public class ESBApplication {
//    @Override
@ -22,8 +16,8 @@ public class ESBApplication {
        application.run(args);
    }
    @Bean
    public Queue queue() {
        return new ActiveMQQueue("configuration.service.flow");
    }
//    @Bean
//    public Queue queue() {
//        return new ActiveMQQueue("configuration.service.flow");
//    }
}

+ 5 - 6
src/main/java/com/yihu/hos/crawler/service/EsbHttp.java

@ -14,7 +14,6 @@ import com.yihu.hos.crawler.model.config.SysConfig;
import com.yihu.hos.crawler.model.patient.Patient;
import com.yihu.hos.crawler.model.transform.EhrCondition;
import com.yihu.hos.web.framework.constrant.SqlConstants;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
import sun.misc.BASE64Encoder;
@ -87,7 +86,7 @@ public class EsbHttp {
            params.put("info", "{\"fingerprint\": \"" + GetFingerprint() + "\"}");
            HTTPResponse response = HttpClientKit.put(loginAction, params, header);
            if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
            if (response != null && response.getStatusCode() == 200) {
                JSONObject obj = new JSONObject(response.getBody());
                //判断是否成功
                if (obj.has("token")) {
@ -194,7 +193,7 @@ public class EsbHttp {
            paramMap.put("token", token);
            String publicKeyMethod = defaultHttpUrl + "/organizations/" + orgCode + "/key";
            HTTPResponse response = HttpClientKit.get(publicKeyMethod, paramMap, header);
            if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
            if (response != null && response.getStatusCode() == 200) {
                JSONObject json = new JSONObject(response.getBody());
                if (json.has("publicKey")) {
                    String publicKey = json.getString("publicKey");
@ -232,7 +231,7 @@ public class EsbHttp {
            params.put("org_code", orgCode);
            params.put("token", token);
            HTTPResponse response = HttpClientKit.get(versionMethod, params, header);
            if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
            if (response != null && response.getStatusCode() == 200) {
                return response.getBody();
            } else {
                String msg = "获取健康云平台标准版本号失败";
@ -280,7 +279,7 @@ public class EsbHttp {
                    paramMap.put("token", token);
                    HTTPResponse response = HttpClientKit.post(registerMethod, paramMap, header);
                    if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
                    if (response != null && response.getStatusCode() == 200) {
                        logger.info("注册病人信息成功。patient_id:" + patient.getPatientId() + ", event_no:" + patient.getEventNo());
                        return true;
                    } else {
@ -320,7 +319,7 @@ public class EsbHttp {
            header.put("User-Agent", "client " + clientId);
            HTTPResponse response = HttpClientKit.postFile(uploadMethod, file.getAbsolutePath(), formParams, header);
            if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
            if (response != null && response.getStatusCode() == 200) {
                logger.info("上传病人档案成功,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
                return true;
            } else {

+ 5 - 8
src/main/java/com/yihu/hos/services/ServiceFlowEventService.java

@ -4,21 +4,18 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;
import javax.jms.Queue;
/**
 * @created Airhead 2016/8/2.
 */
@Component
public class ServiceFlowEventService {
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;
//    @Autowired
//    private JmsMessagingTemplate jmsMessagingTemplate;
    @Autowired
    private Queue queue;
//    @Autowired
//    private Queue queue;
    @Autowired
    private ObjectMapper objectMapper;
@ -76,7 +73,7 @@ public class ServiceFlowEventService {
        objectNode.put("path", path);
        try {
            String msg = objectMapper.writeValueAsString(objectNode);
            this.jmsMessagingTemplate.convertAndSend(this.queue, msg);
//            this.jmsMessagingTemplate.convertAndSend(this.queue, msg);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }