Search in sources :

Example 1 with XmlRpcRequest

use of org.apache.xmlrpc.XmlRpcRequest 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 XmlRpcRequest

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

the class XmlRpcDataFormat method marshal.

@Override
public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
    // need to check the object type
    XMLWriter control = getXMLWriter(exchange, stream);
    XmlRpcWriter writer = new XmlRpcWriter(xmlRpcStreamRequestConfig, control, typeFactory);
    XmlRpcRequest request = null;
    if (isRequest || graph instanceof XmlRpcRequest) {
        request = exchange.getContext().getTypeConverter().mandatoryConvertTo(XmlRpcRequest.class, exchange, graph);
    }
    if (request != null) {
        writer.writeRequest(xmlRpcStreamRequestConfig, request);
    } else {
        // write the result here directly
        // TODO write the fault message here
        writer.write(xmlRpcStreamRequestConfig, graph);
    }
}
Also used : XmlRpcRequest(org.apache.xmlrpc.XmlRpcRequest) CharSetXMLWriter(org.apache.ws.commons.serialize.CharSetXMLWriter) XMLWriter(org.apache.ws.commons.serialize.XMLWriter)

Example 3 with XmlRpcRequest

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

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

the class XmlRpcDataFormatTest method testRequestMessageFromList.

@Test
public void testRequestMessageFromList() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:request");
    mock.expectedMessageCount(1);
    Object[] body = new Object[] { "you", 2 };
    XmlRpcRequest result = template.requestBodyAndHeader("direct:request", body, XmlRpcConstants.METHOD_NAME, "greet", 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 : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) XmlRpcRequest(org.apache.xmlrpc.XmlRpcRequest) Test(org.junit.Test)

Example 5 with XmlRpcRequest

use of org.apache.xmlrpc.XmlRpcRequest in project wildfly-camel by wildfly-extras.

the class XmlRpcIntegrationTest method testRequestMessage.

@Test
public void testRequestMessage() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            XmlRpcDataFormat request = new XmlRpcDataFormat();
            request.setRequest(true);
            from("direct:request").marshal(request).to("log:marshalRequestMessage").unmarshal(request).to("log:unmarshalRequestMessage").to("mock:request");
        }
    });
    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        MockEndpoint mock = camelctx.getEndpoint("mock:request", MockEndpoint.class);
        mock.expectedMessageCount(1);
        XmlRpcRequest result = template.requestBody("direct:request", new XmlRpcRequestImpl("greet", new Object[] { "you", 2 }), XmlRpcRequest.class);
        Assert.assertNotNull(result);
        Assert.assertEquals("Get a wrong request operation name", "greet", result.getMethodName());
        Assert.assertEquals("Get a wrong request parameter size", 2, result.getParameterCount());
        Assert.assertEquals("Get a wrong request parameter", 2, result.getParameter(1));
        mock.assertIsSatisfied();
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) XmlRpcDataFormat(org.apache.camel.dataformat.xmlrpc.XmlRpcDataFormat) XmlRpcRequestImpl(org.apache.camel.component.xmlrpc.XmlRpcRequestImpl) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) XmlRpcRequest(org.apache.xmlrpc.XmlRpcRequest) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

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