当前位置: 首页>>代码示例>>Java>>正文


Java HttpConnection类代码示例

本文整理汇总了Java中com.connectsdk.etc.helper.HttpConnection的典型用法代码示例。如果您正苦于以下问题:Java HttpConnection类的具体用法?Java HttpConnection怎么用?Java HttpConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpConnection类属于com.connectsdk.etc.helper包,在下文中一共展示了HttpConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSendSimplePostCommand

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
@Test
public void testSendSimplePostCommand() throws Exception {
    Object payload = "postdata";
    ResponseListener<Object> listener = Mockito.mock(ResponseListener.class);
    ServiceCommand<ResponseListener<Object>> command =
            new ServiceCommand<ResponseListener<Object>>(service, COMMAND_URL, payload, listener);

    service.sendCommand(command);
    TestUtil.runUtilBackgroundTasks();

    Assert.assertEquals(COMMAND_URL, service.connectionTarget);
    Mockito.verify(httpConnection, Mockito.times(1))
            .setHeader(Mockito.eq(HttpMessage.CONTENT_TYPE_HEADER),
                    Mockito.eq("text/plain; charset=\"utf-8\""));
    Mockito.verify(httpConnection, Mockito.times(1)).setMethod(Mockito.eq(HttpConnection.Method.POST));
    Mockito.verify(httpConnection, Mockito.times(1)).setPayload(Mockito.eq(payload.toString()));
    Mockito.verify(httpConnection, Mockito.times(1)).execute();
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:19,代码来源:DIALServiceSendCommandTest.java

示例2: testSendSimplePostCommand

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
@Test
public void testSendSimplePostCommand() throws Exception {
    Object payload = DLNAService.AV_TRANSPORT_URN;

    ResponseListener<Object> listener = Mockito.mock(ResponseListener.class);
    ServiceCommand<ResponseListener<Object>> command =
            new ServiceCommand<ResponseListener<Object>>(service, COMMAND_URL, payload, listener);
    service.avTransportURL = COMMAND_URL;

    service.sendCommand(command);
    TestUtil.runUtilBackgroundTasks();

    Assert.assertEquals(COMMAND_URL, service.connectionTarget);

    Mockito.verify(httpConnection, Mockito.times(1)).setMethod(Mockito.eq(HttpConnection.Method.POST));
    Mockito.verify(httpConnection, Mockito.times(1)).setPayload(Mockito.eq(payload.toString()));
    Mockito.verify(httpConnection, Mockito.times(1)).execute();
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:19,代码来源:DLNAServiceSendCommandTest.java

示例3: resubscribeServices

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
public void resubscribeServices() {
    resubscriptionTimer = new Timer();
    resubscriptionTimer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            Util.runInBackground(new Runnable() {

                @Override
                public void run() {
                    List<Service> serviceList = serviceDescription.getServiceList();

                    if (serviceList != null) {
                        for (int i = 0; i < serviceList.size(); i++) {
                            String eventSubURL = makeControlURL("/", serviceList.get(i).eventSubURL);
                            if (eventSubURL == null) {
                                continue;
                            }

                            String SID = SIDList.get(serviceList.get(i).serviceType);
                            try {
                                HttpConnection connection = HttpConnection.newSubscriptionInstance(
                                        new URI("http", "", serviceDescription.getIpAddress(), serviceDescription.getPort(), eventSubURL, "", ""));
                                connection.setMethod(HttpConnection.Method.SUBSCRIBE);
                                connection.setHeader("TIMEOUT", "Second-" + TIMEOUT);
                                connection.setHeader("SID", SID);
                                connection.execute();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            });
        }
    }, TIMEOUT/2*1000, TIMEOUT/2*1000);
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:38,代码来源:DLNAService.java

示例4: unsubscribeServices

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
public void unsubscribeServices() {
    if (resubscriptionTimer != null) {
        resubscriptionTimer.cancel();
    }

    Util.runInBackground(new Runnable() {

        @Override
        public void run() {
            final List<Service> serviceList = serviceDescription.getServiceList();

            if (serviceList != null) {
                for (int i = 0; i < serviceList.size(); i++) {
                    String eventSubURL = makeControlURL("/", serviceList.get(i).eventSubURL);
                    if (eventSubURL == null) {
                        continue;
                    }

                    String sid = SIDList.get(serviceList.get(i).serviceType);
                    try {
                        HttpConnection connection = HttpConnection.newSubscriptionInstance(
                                new URI("http", "", serviceDescription.getIpAddress(), serviceDescription.getPort(), eventSubURL, "", ""));
                        connection.setMethod(HttpConnection.Method.UNSUBSCRIBE);
                        connection.setHeader("SID", sid);
                        connection.execute();
                        if (connection.getResponseCode() == 200) {
                            SIDList.remove(serviceList.get(i).serviceType);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:37,代码来源:DLNAService.java

示例5: sendCommand

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
    Util.runInBackground(new Runnable() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            final ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;
            Object payload = command.getPayload();

            try {
                HttpConnection connection = HttpConnection.newInstance(URI.create(command.getTarget()));
                connection.setHeader(HttpMessage.USER_AGENT, HttpMessage.UDAP_USER_AGENT);
                connection.setHeader(HttpMessage.CONTENT_TYPE_HEADER, HttpMessage.CONTENT_TYPE_TEXT_XML);
                if (payload != null && command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
                    connection.setMethod(HttpConnection.Method.POST);
                    connection.setPayload(payload.toString());
                }
                connection.execute();
                int code = connection.getResponseCode();
                Log.d("", "RESP " + code);
                if (code == 200) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseString());
                } else {
                    Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (IOException e) {
                e.printStackTrace();
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }
        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:34,代码来源:NetcastTVService.java

示例6: sendCommand

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
    Util.runInBackground(new Runnable() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;
            Object payload = command.getPayload();

            try {
                HttpConnection connection = createHttpConnection(mCommand.getTarget());
                if (payload != null || command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
                    connection.setMethod(HttpConnection.Method.POST);
                    if (payload != null) {
                        connection.setHeader(HttpMessage.CONTENT_TYPE_HEADER, "text/plain; " +
                                "charset=\"utf-8\"");
                        connection.setPayload(payload.toString());
                    }
                } else if (command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_DEL)) {
                    connection.setMethod(HttpConnection.Method.DELETE);
                }
                connection.execute();
                int code = connection.getResponseCode();
                if (code == 200) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseString());
                } else if (code == 201) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseHeader("Location"));
                } else {
                    Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (Exception e) {
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }
        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:38,代码来源:DIALService.java

示例7: sendCommand

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
    Util.runInBackground(new Runnable() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;
            Object payload = command.getPayload();

            try {
                Log.d("", "RESP " + command.getTarget());
                HttpConnection connection = HttpConnection.newInstance(URI.create(command.getTarget()));
                if (command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
                    connection.setMethod(HttpConnection.Method.POST);
                    if (payload != null) {
                        connection.setPayload(payload.toString());
                    }
                }
                connection.execute();
                int code = connection.getResponseCode();
                Log.d("", "RESP " + code);
                if (code == 200 || code == 201) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseString());
                } else {
                    Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (IOException e) {
                e.printStackTrace();
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }

        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:36,代码来源:RokuService.java

示例8: testSendSimpleGetCommand

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
@Test
public void testSendSimpleGetCommand() throws Exception {
    ResponseListener<Object> listener = Mockito.mock(ResponseListener.class);
    ServiceCommand<ResponseListener<Object>> command =
            new ServiceCommand<ResponseListener<Object>>(service, COMMAND_URL, null, listener);
    command.setHttpMethod(ServiceCommand.TYPE_GET);

    service.sendCommand(command);
    TestUtil.runUtilBackgroundTasks();

    Assert.assertEquals(COMMAND_URL, service.connectionTarget);
    Mockito.verify(httpConnection, Mockito.times(0)).setMethod(Mockito.any(HttpConnection.Method.class));
    Mockito.verify(httpConnection, Mockito.times(1)).execute();
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:15,代码来源:DIALServiceSendCommandTest.java

示例9: testSendSimpleDeleteCommand

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
@Test
public void testSendSimpleDeleteCommand() throws Exception {
    ResponseListener<Object> listener = Mockito.mock(ResponseListener.class);
    ServiceCommand<ResponseListener<Object>> command =
            new ServiceCommand<ResponseListener<Object>>(service, COMMAND_URL, null, listener);
    command.setHttpMethod(ServiceCommand.TYPE_DEL);

    service.sendCommand(command);
    TestUtil.runUtilBackgroundTasks();

    Assert.assertEquals(COMMAND_URL, service.connectionTarget);
    Mockito.verify(httpConnection, Mockito.times(1)).setMethod(Mockito.eq(HttpConnection
            .Method.DELETE));
    Mockito.verify(httpConnection, Mockito.times(1)).execute();
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:16,代码来源:DIALServiceSendCommandTest.java

示例10: testSendPostCommandWithEmptyPayload

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
@Test
public void testSendPostCommandWithEmptyPayload() throws Exception {
    Object payload = null;
    ResponseListener<Object> listener = Mockito.mock(ResponseListener.class);
    ServiceCommand<ResponseListener<Object>> command =
            new ServiceCommand<ResponseListener<Object>>(service, COMMAND_URL, payload, listener);

    service.sendCommand(command);
    TestUtil.runUtilBackgroundTasks();

    Assert.assertEquals(COMMAND_URL, service.connectionTarget);
    Mockito.verify(httpConnection, Mockito.times(1)).setMethod(Mockito.eq(HttpConnection.Method.POST));
    Mockito.verify(httpConnection, Mockito.times(0)).setPayload(Mockito.anyString());
    Mockito.verify(httpConnection, Mockito.times(1)).execute();
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:16,代码来源:DIALServiceSendCommandTest.java

示例11: sendCommand

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
    Util.runInBackground(new Runnable() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;
            Object payload = command.getPayload();

            try {
                HttpConnection connection = createHttpConnection(mCommand.getTarget());
                if (payload != null && command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
                    connection.setHeader(HttpMessage.CONTENT_TYPE_HEADER, "text/plain; charset=\"utf-8\"");
                    connection.setMethod(HttpConnection.Method.POST);
                    connection.setPayload(payload.toString());
                } else if (command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_DEL)) {
                    connection.setMethod(HttpConnection.Method.DELETE);
                }
                connection.execute();
                int code = connection.getResponseCode();
                if (code == 200) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseString());
                } else if (code == 201) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseHeader("Location"));
                } else {
                    Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (Exception e) {
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }
        }
    });
}
 
开发者ID:PTCE,项目名称:popcorn-android,代码行数:35,代码来源:DIALService.java

示例12: sendCommand

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
    Util.runInBackground(new Runnable() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;

            String method = command.getTarget();
            String payload = (String) command.getPayload();

            String targetURL = null;
            String serviceURN = null;

            if (payload == null) {
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, "Cannot process the command, \"payload\" is missed", null));
                return;
            }

            if (payload.contains(AV_TRANSPORT_URN)) {
                targetURL = avTransportURL;
                serviceURN = AV_TRANSPORT_URN;
            } else if (payload.contains(RENDERING_CONTROL_URN)) {
                targetURL = renderingControlURL;
                serviceURN = RENDERING_CONTROL_URN;
            } else if (payload.contains(CONNECTION_MANAGER_URN)) {
                targetURL = connectionControlURL;
                serviceURN = CONNECTION_MANAGER_URN;
            }

            if (serviceURN == null) {
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, "Cannot process the command, \"serviceURN\" is missed", null));
                return;
            }

            if (targetURL == null) {
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, "Cannot process the command, \"targetURL\" is missed", null));
                return;
            }

            try {
                HttpConnection connection = createHttpConnection(targetURL);
                connection.setHeader("Content-Type", "text/xml; charset=utf-8");
                connection.setHeader("SOAPAction", String.format("\"%s#%s\"", serviceURN, method));
                connection.setMethod(HttpConnection.Method.POST);
                connection.setPayload(payload);
                connection.execute();
                int code = connection.getResponseCode();
                if (code == 200) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseString());
                } else {
                    Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (IOException e) {
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }
        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:61,代码来源:DLNAService.java

示例13: createHttpConnection

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
HttpConnection createHttpConnection(String targetURL) throws IOException {
    return HttpConnection.newInstance(URI.create(targetURL));
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:4,代码来源:DLNAService.java

示例14: createHttpConnection

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
HttpConnection createHttpConnection(String target) throws IOException {
    return HttpConnection.newInstance(URI.create(target));
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:4,代码来源:DIALService.java

示例15: sendCommand

import com.connectsdk.etc.helper.HttpConnection; //导入依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> serviceCommand) {
    Util.runInBackground(new Runnable() {
        @Override
        public void run() {
            try {
                StringBuilder sb = new StringBuilder();
                sb.append("http://").append(serviceDescription.getIpAddress()).append(":").append(serviceDescription.getPort());
                sb.append(serviceCommand.getTarget());

                HttpConnection connection = HttpConnection.newInstance(URI.create(sb.toString()));
                connection.setHeader(HTTP.USER_AGENT, "ConnectSDK MediaControl/1.0");
                connection.setHeader(X_APPLE_SESSION_ID, mSessionId);
                if (password != null) {
                    String authorization = getAuthenticate(serviceCommand.getHttpMethod(), serviceCommand.getTarget(), authenticate);
                    connection.setHeader("Authorization", authorization);
                }
                Object payload = serviceCommand.getPayload();
                if (serviceCommand.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)
                        || serviceCommand.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_PUT)) {
                    if (payload != null) {
                        if (payload instanceof String) {
                            connection.setHeader(HttpMessage.CONTENT_TYPE_HEADER, HttpMessage.CONTENT_TYPE_APPLICATION_PLIST);
                            connection.setPayload(payload.toString());
                        } else if (payload instanceof byte[]) {
                            connection.setPayload((byte[])payload);
                        }
                    }
                }
                if (serviceCommand.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
                    connection.setMethod(HttpConnection.Method.POST);
                } else if (serviceCommand.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_PUT)) {
                    connection.setMethod(HttpConnection.Method.PUT);
                } else {
                    connection.setHeader("Content-Length", "0");
                }
                connection.execute();
                int code = connection.getResponseCode();
                if (code == HttpURLConnection.HTTP_OK) {
                    Util.postSuccess(serviceCommand.getResponseListener(), connection.getResponseString());
                } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
                    authenticate = connection.getResponseHeader("WWW-Authenticate");
                    pendingCommand = serviceCommand;
                    Util.runOnUI(new Runnable() {
                        @Override
                        public void run() {
                            if (listener != null) {
                                listener.onPairingRequired(AirPlayService.this, pairingType, null);
                            }
                        }
                    });
                } else {
                    Util.postError(serviceCommand.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (IOException e) {
                e.printStackTrace();
                Util.postError(serviceCommand.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }
        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:62,代码来源:AirPlayService.java


注:本文中的com.connectsdk.etc.helper.HttpConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。