Git Product home page Git Product logo

xinge-api-java's People

Contributors

caofangkun avatar xingepush avatar zengweijin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xinge-api-java's Issues

调用比较频繁,报错Too many open files

{"err_msg":"java.net.SocketException: Too many open files\n\tat java.net.Socket.createImpl(Socket.java:460)\n\tat java.net.Socket.getImpl(Socket.java:520)\n\tat java.net.Socket.setSoTimeout(Socket.java:1141)\n\tat okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:221)\n\tat okhttp3.internal.connection.RealConnection.connect(RealConnection.java:149)\n\tat okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:195)\n\tat okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121)\n\tat okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100)\n\tat okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)\n\tat okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)\n\tat okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)\n\tat okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)\n\tat okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)\n\tat okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)\n\tat okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)\n\tat okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)\n\tat okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)\n\tat okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)\n\tat okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)\n\tat okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)\n\tat okhttp3.RealCall.execute(RealCall.java:69)\n\tat com.tencent.xinge.XingeApp.callRestful(XingeApp.java:128)\n\tat com.tencent.xinge.XingeApp.pushApp(XingeApp.java:93)\n\tat com.cu.service.impl.XingePushServiceImpl.push(XingePushServiceImpl.java:25)\n\tat com.cu.component.PushReceiver.onAndroidPushMessage(PushReceiver.java:43)\n\tat sun.reflect.GeneratedMethodAccessor87.invoke(Unknown Source)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:181)\n\tat org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:114)\n\tat org.springframework.amqp.rabbit.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:51)\n\tat org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:188)\n\tat org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:126)\n\tat org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1445)\n\tat org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1368)\n\tat org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1355)\n\tat org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1334)\n\tat org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:817)\n\tat org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:801)\n\tat org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$700(SimpleMessageListenerContainer.java:77)\n\tat org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1042)\n\tat java.lang.Thread.run(Thread.java:748)\n","ret_code":10100}

添加设备标签报system inner error!

目前使用单元测试中的AddMultTagToSingleToken进行设备标签绑定时,报系统内部错误:
{"result":"","err_msg":"system inner error, send cmd to BackSystem errror","ret_code":10120,"seq":0}
包括线上项目使用V3 也是报次错误,v2 版本请求频繁超时,甚至影响到推送功能;

你好,请教一个问题,关于安卓附加参数的

客户端死活收不到自带参数,我用官网的页面发送请求是可以的。
我在单设备的推送代码里加入了
JSONObject json = new JSONObject();
json.put("111","222");
messageAndroid.setCustom_content(json.toString());
自己打印看了下发送参数的json里 带转义字符
"action":{"action_type":1,"activity":""},"custom_content":"{"111":"222"}"
会不会跟这个有关?

1.2.0 XingeApp中证书是不是没有考虑到ssl证书问题

在XingeApp类:掉了一句https.setHostnameVerifier(new TrustAnyHostnameVerifier());吧,不然ssl证书验证过不去。

private JSONObject callRestful(String apiAddress, String jsonRequestString) {

    URL url;
    HttpURLConnection http = null;
    InputStreamReader isr = null;
    BufferedReader br = null;
    String ret = "";
    String temp;
    JSONObject jsonRet = null;

    try {
        url = new URL(null, apiAddress, new com.sun.net.ssl.internal.www.protocol.https.Handler());
        URLConnection con = url.openConnection();
        http = (HttpURLConnection) con;
        http.setRequestMethod(RESTAPI_V3.HTTP_POST);
        http.setDoOutput(true);
        http.setRequestProperty("Authorization", "Basic " + authStringEnc);

        byte[] out = jsonRequestString.getBytes(StandardCharsets.UTF_8);
        int length = out.length;

        http.setFixedLengthStreamingMode(length);
        http.setRequestProperty("Content-Type", "application/json; charset=UTF-8");

        http.connect();
        try {
            OutputStream os = http.getOutputStream();
            os.write(out);

        } catch (Exception e) {

        }


        http.getOutputStream().flush();
        http.getOutputStream().close();
        isr = new InputStreamReader(http.getInputStream());
        br = new BufferedReader(isr);
        while ((temp = br.readLine()) != null) {
            ret += temp;
        }
        jsonRet = new JSONObject(ret);

    } catch (MalformedURLException e) {
        jsonRet = new JSONObject();
        jsonRet.put("ret_code", 10100);
        jsonRet.put("err_msg", stringifyError(e));

    } catch (IOException e) {
        jsonRet = new JSONObject();
        jsonRet.put("ret_code", 10101);
        jsonRet.put("err_msg", stringifyError(e));
        
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                // ignore
            }
        }
        if (isr != null) {
            try {
                isr.close();
            } catch (IOException e) {
                // ignore
            }
        }
        if (http != null) {
            http.disconnect();
        }
    }

    return jsonRet;
}

测试代码恳请严格通过。

1、com.tencent.xinge.push.app.PushTagAndroidTest#testPushTagAndroid
这个方法看着是个安卓标签推送。
但是!
代码里面写的audience_type设置的缺失,导致使用了默认值。AudienceType.all
不光不是tag推送,而且是全量推送。
刚刚,我测试了一下,结果某环境全量推了,脸都绿了!!!
希望作者,修改。防止他人产生同样问题。

另外,就是默认值的问题。这种关键性的值,我觉得请不要设置默认值。严格要求上层输入。不然真的容易出问题。

2、 com.tencent.xinge.device.tag.DeviceTagRequest#tag_token_list
缺失 @jsonformat(shape = JsonFormat.Shape.ARRAY)
因为官方文档要求的是,
对list的要求是 [["tag1","token1"],["tag2","token2"]]
而不是 [{"tag":"tag1","token":"token1"}]

建议检查所有的List参数。全部加上@jsonformat(shape = JsonFormat.Shape.ARRAY)

认证失败,报的异常是jsonObject解析失败,原因是返回的是类似认证失败的文案,分传入的json文案

Exception in thread "main" org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
at org.json.JSONTokener.syntaxError(JSONTokener.java:451)
at org.json.JSONObject.(JSONObject.java:195)
at org.json.JSONObject.(JSONObject.java:319)
at com.tencent.xinge.XingeApp.callRestful(XingeApp.java:145)
at com.tencent.xinge.XingeApp.pushApp(XingeApp.java:62)
at com.loovee.newsale.business.service.impl.PushServiceImpl.main(PushServiceImpl.java:58)

可以考虑返回json或者再包一层

运行测试报错

测试代码不能通过。
请求中jackson序列化的时候。
1、枚举类com.tencent.xinge.bean.Platform 中, @JsonValue注解 在getType() 上,看官方文档应该在getName()上。

2、类com.tencent.xinge.device.tag.DeviceTagRequest 中,@JsonProperty注解 value = "audience_type",官方文档应该还是operator_type。

修改之后。测试通过。

大量线程被错误hold住

"OkHttp ConnectionPool" #200 daemon prio=5 os_prio=0 tid=0x00007f9920150800 nid=0xb73 in Object.wait() [0x00007f98759c3000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:460)
at okhttp3.ConnectionPool$1.run(ConnectionPool.java:67)
- locked <0x00000007bcc25540> (a okhttp3.ConnectionPool)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

全部线程都卡在这。可以确定是引入最新版本的信鸽导致(本人项目中原来没使用到okhttp包)

java.io.IOException: HTTPS hostname wrong

https://github.com/xingePush/xinge-api-java/blob/master/src/main/java/com/tencent/xinge/XingeApp.java#L94

java.io.IOException: HTTPS hostname wrong:  should be <openapi.xg.qq.com>
at sun.net.www.protocol.https.HttpsClient.checkURLSpoofing(HttpsClient.java:649)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:573)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl.connect(HttpsURLConnectionOldImpl.java:142)
at com.tencent.xinge.XingeApp.callRestful(XingeApp.java:94)
at com.tencent.xinge.XingeApp.pushApp(XingeApp.java:57)

PushAppRequest的toString方法有多余的对象开销

Jsckson的ObjectMapper,全局一份就够了

    public String toString() {
        ObjectMapper mapper = new ObjectMapper();
        String repoStr = null;

        try {
            repoStr = mapper.writeValueAsString(this);
        } catch (Exception var4) {
            ;
        }

        return repoStr;
    }

另外,提供个捷径: http api用Retrofit来实现更简洁

怀疑提供的api没设置timeout导致线程一直被hold住

最近接入了信鸽推送发现通道莫名会无法发送。工程内所有功能正常,内存、cpu、io都没问题
查看了下堆栈,发现开的所有线程都是卡住:
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
- locked <0x00000004ed23d1a0> (a java.lang.Object)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:930)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
- locked <0x00000004ed23d1b0> (a sun.security.ssl.AppInputStream)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
- locked <0x00000004ed2832c8> (a java.io.BufferedInputStream)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569)
- locked <0x00000004ed287338> (a sun.net.www.protocol.https.DelegateHttpsURLConnection)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
- locked <0x00000004ed287338> (a sun.net.www.protocol.https.DelegateHttpsURLConnection)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
- locked <0x00000004ed2872e0> (a sun.net.www.protocol.https.HttpsURLConnectionImpl)
at com.tencent.xinge.XingeApp.callRestful(XingeApp.java:109)
at com.tencent.xinge.XingeApp.pushApp(XingeApp.java:60)

看了下源代码。感觉是没设置超时时间,并且信鸽服务器也没主动断开。线程一直hold住?

你好,安卓自定义参数发送无效问题帮忙解决一下!

你好,我在你们的api的基础上添加了
JSONObject json = new JSONObject();
json.put("canshu1","zhi1");
messageAndroid.setCustom_content(json.toString());
发出去的参数也正常,但是我们的客户端并不能收到自定义参数!而我使用官网自带的参数的时候是可以带参数的。。
不知道是不是我搞错参数了 我现在也不管闹不闹笑话了 请帮忙解决一下!谢谢!

java.net.SocketException: Unexpected end of file from server

复现方式:

        for (int i=0; i< 3; i++) {
            JSONObject ret = xingeAndroid.pushApp(pushAppRequest);
            System.out.println(i + "******" + ret);
        }

错误日志:

1******{"err_msg":"java.net.SocketException: Unexpected end of file from server\n\tat sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:851)\n\tat sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)\n\tat sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587)\n\tat sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)\n\tat java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)\n\tat sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347)\n\tat com.tencent.xinge.XingeApp.callRestful(XingeApp.java:137)\n\tat com.tencent.xinge.XingeApp.pushApp(XingeApp.java:76)\n\tat com.tencent.xinge.XingeApp.pushApp(XingeApp.java:87)\n\tat com.tencent.xinge.push.app.PushSingleAccountAndroidTest.testPushSingleAccountAndroid(PushSingleAccountAndroidTest.java:62)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n\tat org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)\n\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n\tat org.junit.runner.JUnitCore.run(JUnitCore.java:137)\n\tat com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)\n\tat com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)\n\tat com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)\n\tat com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)\n","ret_code":10101}

对代码code review

1 代码中命名不规范的问题
2 部分对象json 序列化格式 与官网 请求格式不一致
3 部分代码测试用例不严谨

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.