FCM push notification : java.io.IOException: An existing connection was forcibly closed by the remote host

vishal s. :

I'm trying to implement send Push notification on Android device using FCM in Java but i'm getting this error :

 java.io.IOException: An existing connection was forcibly closed by the remote host
    at sun.nio.ch.SocketDispatcher.readv0(Native Method)
    at sun.nio.ch.SocketDispatcher.readv(SocketDispatcher.java:47)
    at sun.nio.ch.IOUtil.read(IOUtil.java:278)
    at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:440)
    at weblogic.socket.NIOSocketMuxer$NIOInputStream.readInternal(NIOSocketMuxer.java:803)
    at weblogic.socket.NIOSocketMuxer$NIOInputStream.read(NIOSocketMuxer.java:745)
    at weblogic.socket.NIOSocketMuxer$NIOInputStream.read(NIOSocketMuxer.java:728)
    at weblogic.socket.JSSEFilterImpl.readFromNetwork(JSSEFilterImpl.java:462)
    at weblogic.socket.JSSEFilterImpl.handleUnwrapResults(JSSEFilterImpl.java:634)
    at weblogic.socket.JSSEFilterImpl.unwrapAndHandleResults(JSSEFilterImpl.java:515)
    at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:96)
    at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:75)
    at weblogic.socket.JSSESocket.startHandshake(JSSESocket.java:219)
    at weblogic.net.http.HttpsClient.New(HttpsClient.java:563)
    at weblogic.net.http.HttpsURLConnection.getHttpClient(HttpsURLConnection.java:332)
    at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:711)
    at weblogic.net.http.SOAPHttpsURLConnection.getInputStream(SOAPHttpsURLConnection.java:37)
    at weblogic.net.http.HttpURLConnection.getResponseCode(HttpURLConnection.java:1444)
    at utils.FCM.send_FCM_Notification(FCM.java:71)
    at Services.CreateMeeting.call(CreateMeeting.java:283)
    at Services.CreateMeeting.doPost(CreateMeeting.java:89)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:751)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
    at filter.Loginfilter.doFilter(Loginfilter.java:120)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3436)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
    at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)
    at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)

My Class of FCM is :

public class FCM 
{
    final static private String FCM_URL = "https://fcm.googleapis.com/fcm/send";

    public static void main(String[] args)
    {
        String tokenId= "fh11LQ1st3M:APA91bEz1VjEKNiM9YZBzTF8SbW1esE8ykYvfSpBMDfhCNgcvdDHTbe_iTLd_golWi0PGH0vs630bXlWKT9Tw3oZTp6YOooYXfx3GkFCK7k21sNcV4emaO6sImmCBuSkMk1EyjVE2Ndi";
        send_FCM_Notification(tokenId, "New Notificationcreated","Create Meeting");
    }

    public static void send_FCM_Notification(String tokenId, String message, String type)
    {
        try
        {
            URL url = new URL(FCM_URL);

            HttpURLConnection conn;

            conn = (HttpURLConnection) url.openConnection();
            conn.setUseCaches(false);
            conn.setDoInput(true);
            conn.setDoOutput(true);

            conn.setRequestMethod("POST");
            conn.setRequestProperty("Authorization","key=AAAAVX9r9wY:APA91bEi2GgGrbF_XxJ9fAsdGF07kE8wSHU7KOYPOVMvEXaFaFJDisO18r086i-Ju7Gllv0abOz7SsAgL3RdR-Vq8CMZdR7HsBnDjVrmyZ-u2aeeLdnf-ZFxSB7V_NzkMeMK4d7S87ml");

            conn.setRequestProperty("Content-Type","application/json");

            JSONObject typejson = new JSONObject();
            typejson.put("title","Demo");
            typejson.put("body", message);
            typejson.put("message", message);
            typejson.put("type", type);
            typejson.put("timestamp", new Date());
            typejson.put("priority", 1);

            JSONObject json = new JSONObject();
            json.put("to",tokenId.trim());
            json.put("data", typejson);
            System.out.println(json);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(json.toString());
            wr.flush();

            int status = 0;

            if( null != conn )
            {
                status = conn.getResponseCode();
            }

            if( status != 0)
            {
                if( status == 200 )
                {
                    BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                }
            }
        }

        catch (Exception exception) 
        {
            exception.printStackTrace();
        }
    }

}

When i call this method ( send_FCM_Notification ) from main method it works but when it gets call from servlet using Weblogic server it throws this error

I'm unable to find out exact cause of this Exception please try to help me

vishal s. :

I enabled SSL port in weblogic and try with https url and it Resolve my problem.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=102062&siteId=1