Search in sources :

Example 6 with XmlRpcRequest

use of org.apache.xmlrpc.XmlRpcRequest in project dubbo by alibaba.

the class XmlRpcProtocol method doExport.

@Override
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    final URL httpUrl = url.setProtocol("http");
    String addr = httpUrl.getIp() + ":" + httpUrl.getPort();
    ProtocolServer protocolServer = serverMap.get(addr);
    if (protocolServer == null) {
        RemotingServer remotingServer = httpBinder.bind(httpUrl, new InternalHandler(httpUrl.getParameter("cors", false)));
        serverMap.put(addr, new ProxyProtocolServer(remotingServer));
    }
    final String path = httpUrl.getAbsolutePath();
    XmlRpcServletServer xmlRpcServer = new XmlRpcServletServer();
    PropertyHandlerMapping propertyHandlerMapping = new PropertyHandlerMapping();
    try {
        propertyHandlerMapping.setRequestProcessorFactoryFactory(new RequestProcessorFactoryFactory() {

            @Override
            public RequestProcessorFactory getRequestProcessorFactory(Class pClass) throws XmlRpcException {
                return new RequestProcessorFactory() {

                    @Override
                    public Object getRequestProcessor(XmlRpcRequest pRequest) throws XmlRpcException {
                        return impl;
                    }
                };
            }
        });
        propertyHandlerMapping.addHandler(XmlRpcProxyFactoryBean.replace(type.getName()), type);
    } catch (Exception e) {
        throw new RpcException(e);
    }
    xmlRpcServer.setHandlerMapping(propertyHandlerMapping);
    XmlRpcServerConfigImpl xmlRpcServerConfig = (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
    xmlRpcServerConfig.setEnabledForExceptions(true);
    xmlRpcServerConfig.setContentLengthOptional(false);
    skeletonMap.put(path, xmlRpcServer);
    return new Runnable() {

        @Override
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
Also used : RequestProcessorFactoryFactory(org.apache.xmlrpc.server.RequestProcessorFactoryFactory) RemotingServer(org.apache.dubbo.remoting.RemotingServer) URL(org.apache.dubbo.common.URL) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RpcException(org.apache.dubbo.rpc.RpcException) RemoteAccessException(org.springframework.remoting.RemoteAccessException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SocketTimeoutException(java.net.SocketTimeoutException) PropertyHandlerMapping(org.apache.xmlrpc.server.PropertyHandlerMapping) ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) XmlRpcServerConfigImpl(org.apache.xmlrpc.server.XmlRpcServerConfigImpl) RpcException(org.apache.dubbo.rpc.RpcException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcRequest(org.apache.xmlrpc.XmlRpcRequest) XmlRpcServletServer(org.apache.xmlrpc.webserver.XmlRpcServletServer) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 7 with XmlRpcRequest

use of org.apache.xmlrpc.XmlRpcRequest in project camel by apache.

the class XmlRpcConverterTest method testToXmlRpcRequest.

@Test
public void testToXmlRpcRequest() throws Exception {
    CamelContext context = new DefaultCamelContext();
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setHeader(XmlRpcConstants.METHOD_NAME, "greet");
    exchange.getIn().setBody(new Object[] { "me", "you" });
    XmlRpcRequest request = exchange.getIn().getBody(XmlRpcRequest.class);
    assertNotNull("The request should not be null", request);
    assertEquals("Get a wrong operation name", "greet", request.getMethodName());
    assertEquals("Get a wrong parameter size", 2, request.getParameterCount());
    assertEquals("Get a worng parameter", "you", request.getParameter(1));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) XmlRpcRequest(org.apache.xmlrpc.XmlRpcRequest) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 8 with XmlRpcRequest

use of org.apache.xmlrpc.XmlRpcRequest in project camel by apache.

the class SpringXmlRpcDataFormatTest method testRequestMessage.

@Test
public void testRequestMessage() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:request");
    mock.expectedMessageCount(1);
    XmlRpcRequest result = template.requestBody("direct:request", new XmlRpcRequestImpl("greet", new Object[] { "you", 2 }), XmlRpcRequest.class);
    assertNotNull(result);
    assertEquals("Get a wrong request operation name", "greet", result.getMethodName());
    assertEquals("Get a wrong request parameter size", 2, result.getParameterCount());
    assertEquals("Get a wrong request parameter", 2, result.getParameter(1));
    assertMockEndpointsSatisfied();
}
Also used : XmlRpcRequestImpl(org.apache.camel.component.xmlrpc.XmlRpcRequestImpl) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) XmlRpcRequest(org.apache.xmlrpc.XmlRpcRequest) Test(org.junit.Test)

Example 9 with XmlRpcRequest

use of org.apache.xmlrpc.XmlRpcRequest in project camel by apache.

the class XmlRpcConverter method toXmlRpcRequest.

@Converter
public static XmlRpcRequest toXmlRpcRequest(final Object[] parameters, Exchange exchange) {
    // get the message operation name
    String operationName = exchange.getIn().getHeader(XmlRpcConstants.METHOD_NAME, String.class);
    // create the request object here
    XmlRpcRequest request = new XmlRpcRequestImpl(operationName, parameters);
    return request;
}
Also used : XmlRpcRequestImpl(org.apache.camel.component.xmlrpc.XmlRpcRequestImpl) XmlRpcRequest(org.apache.xmlrpc.XmlRpcRequest) Converter(org.apache.camel.Converter)

Example 10 with XmlRpcRequest

use of org.apache.xmlrpc.XmlRpcRequest in project intellij-community by JetBrains.

the class JiraRepository method createLegacyApi.

private JiraLegacyApi createLegacyApi() {
    try {
        XmlRpcClient client = new XmlRpcClient(getUrl());
        Vector<String> parameters = new Vector<>(Collections.singletonList(""));
        XmlRpcRequest request = new XmlRpcRequest("jira1.getServerInfo", parameters);
        @SuppressWarnings("unchecked") Hashtable<String, Object> response = (Hashtable<String, Object>) client.execute(request, new CommonsXmlRpcTransport(new URL(getUrl()), getHttpClient()));
        if (response != null) {
            myJiraVersion = (String) response.get("version");
        }
    } catch (Exception e) {
        LOG.error("Cannot find out JIRA version via XML-RPC", e);
    }
    return new JiraLegacyApi(this);
}
Also used : JiraLegacyApi(com.intellij.tasks.jira.soap.JiraLegacyApi) XmlRpcClient(org.apache.xmlrpc.XmlRpcClient) CommonsXmlRpcTransport(org.apache.xmlrpc.CommonsXmlRpcTransport) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) XmlRpcRequest(org.apache.xmlrpc.XmlRpcRequest) JsonObject(com.google.gson.JsonObject)

Aggregations

XmlRpcRequest (org.apache.xmlrpc.XmlRpcRequest)11 XmlRpcRequestImpl (org.apache.camel.component.xmlrpc.XmlRpcRequestImpl)5 Test (org.junit.Test)5 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 JsonObject (com.google.gson.JsonObject)2 URL (java.net.URL)2 CamelContext (org.apache.camel.CamelContext)2 Converter (org.apache.camel.Converter)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 CommonsXmlRpcTransport (org.apache.xmlrpc.CommonsXmlRpcTransport)2 XmlRpcClient (org.apache.xmlrpc.XmlRpcClient)2 JiraLegacyApi (com.intellij.tasks.jira.soap.JiraLegacyApi)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ServletException (javax.servlet.ServletException)1 Exchange (org.apache.camel.Exchange)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 XmlRpcDataFormat (org.apache.camel.dataformat.xmlrpc.XmlRpcDataFormat)1