Search in sources :

Example 1 with XmlRpcRequestImpl

use of org.apache.camel.component.xmlrpc.XmlRpcRequestImpl in project camel by apache.

the class XmlRpcConverter method toXmlRpcRequest.

@Converter
public static XmlRpcRequest toXmlRpcRequest(final List<?> 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 2 with XmlRpcRequestImpl

use of org.apache.camel.component.xmlrpc.XmlRpcRequestImpl in project camel by apache.

the class XmlRpcDataFormatTest 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 3 with XmlRpcRequestImpl

use of org.apache.camel.component.xmlrpc.XmlRpcRequestImpl 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 4 with XmlRpcRequestImpl

use of org.apache.camel.component.xmlrpc.XmlRpcRequestImpl 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 5 with XmlRpcRequestImpl

use of org.apache.camel.component.xmlrpc.XmlRpcRequestImpl in project camel by apache.

the class XmlRpcDataFormat method unmarshalRequest.

protected Object unmarshalRequest(Exchange exchange, InputStream stream) throws Exception {
    InputSource isource = new InputSource(stream);
    XMLReader xr = newXMLReader();
    XmlRpcRequestParser xp;
    try {
        xp = new XmlRpcRequestParser(xmlRpcStreamRequestConfig, typeFactory);
        xr.setContentHandler(xp);
        xr.parse(isource);
    } catch (SAXException e) {
        throw new XmlRpcClientException("Failed to parse server's response: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new XmlRpcClientException("Failed to read server's response: " + e.getMessage(), e);
    }
    return new XmlRpcRequestImpl(xp.getMethodName(), xp.getParams());
}
Also used : XmlRpcRequestParser(org.apache.xmlrpc.parser.XmlRpcRequestParser) InputSource(org.xml.sax.InputSource) XmlRpcRequestImpl(org.apache.camel.component.xmlrpc.XmlRpcRequestImpl) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException)

Aggregations

XmlRpcRequestImpl (org.apache.camel.component.xmlrpc.XmlRpcRequestImpl)5 XmlRpcRequest (org.apache.xmlrpc.XmlRpcRequest)4 Converter (org.apache.camel.Converter)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 XmlRpcClientException (org.apache.xmlrpc.client.XmlRpcClientException)1 XmlRpcRequestParser (org.apache.xmlrpc.parser.XmlRpcRequestParser)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1 XMLReader (org.xml.sax.XMLReader)1