Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / CXF в Jboss Fuse 6.3 / 4 сообщений из 4, страница 1 из 1
12.09.2017, 10:43
    #39519734
Zzzadruga
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
CXF в Jboss Fuse 6.3
Доброго времени суток, уважаемые форумчане. Продолжаю разбираться с Jboss Fuse и дошел до веб-сервисов. Запустил проект из туториала, а именно, SOAP-сервер (скорее всего)). Через SoapUI я отправляю запрос, и там же получаю ответ. Пример:

Запрос
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:inc="http://incident.spring.first.code.cxf.camel.mycompany.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <inc:reportIncident>
         <!--Optional:-->
         <inc:arg0>
            <!--Optional:-->
            <details>1</details>
            <!--Optional:-->
            <email>gmail@gmail.com<;/email>
            <!--Optional:-->
            <familyName>1</familyName>
            <!--Optional:-->
            <givenName>1</givenName>
            <!--Optional:-->
            <incidentDate>1</incidentDate>
            <!--Optional:-->
            <incidentId>281</incidentId>
            <!--Optional:-->
            <phone>1</phone>
            <!--Optional:-->
            <summary>1</summary>
         </inc:arg0>
      </inc:reportIncident>
   </soapenv:Body>
</soapenv:Envelope>


Ответ
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns1:reportIncidentResponse xmlns:ns1="http://incident.spring.first.code.cxf.camel.mycompany.com/">
         <ns2:return xmlns:ns2="http://incident.spring.first.code.cxf.camel.mycompany.com/">
            <code>OK; id: 281, email: gmail@gmail.com<;/code>
         </ns2:return>
      </ns1:reportIncidentResponse>
   </soap:Body>
</soap:Envelope>


Все довольно просто и понятно, как это работает. Проект в Jboss Fuse состоит из

camel-context.xml на Sprint DSL c картинкой

Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:cxf="http://camel.apache.org/schema/cxf"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd    ">
    <cxf:cxfEndpoint address="http://localhost:9292/cxf/report"
        id="reportEndpoint" serviceClass="com.mycompany.camel.cxf.code.first.spring.incident.IncidentService"/>
    <bean
        class="com.mycompany.camel.cxf.code.first.spring.incident.ReportIncidentProcessor" id="reportIncidentProcessor"/>
    <bean
        class="com.mycompany.camel.cxf.code.first.spring.incident.InputReportIncident" id="inputReportIncident"/>
    <bean
        class="com.mycompany.camel.cxf.code.first.spring.incident.StatusIncidentProcessor" id="statusIncidentProcessor"/>
    <camelContext id="camelContext-c1100b64-c8cb-4fa6-b382-5eea0e303c95" xmlns="http://camel.apache.org/schema/spring">
        <route id="cxf">
            <!-- route starts from the cxf webservice in POJO mode -->
            <from id="reportEndpointListener" uri="cxf:bean:reportEndpoint"/>
            <recipientList id="dispatchToCorrectRoute">
                <simple>direct:${header.operationName}</simple>
            </recipientList>
        </route>
        <route id="report">
            <from id="reportIncidentStarter" uri="direct:reportIncident"/>
            <log id="logReportIncident" message="reportIncident Call"/>
            <process id="reportIncidentProcess" ref="reportIncidentProcessor"/>
            <to id="_to1" uri="log:output"/>
        </route>
        <route id="status">
            <from id="statusIncidentStarter" uri="direct:statusIncident"/>
            <log id="logStatusIncident" message="statusIncident Call"/>
            <process id="statusIncidentProcess" ref="statusIncidentProcessor"/>
            <to id="_to2" uri="log:output"/>
        </route>
    </camelContext>
</beans>



Java Class'ы

IncidentService
Код: sql
1.
2.
3.
4.
5.
6.
package com.mycompany.camel.cxf.code.first.spring.incident;

public interface IncidentService {
    OutputReportIncident reportIncident(InputReportIncident input);
    OutputStatusIncident statusIncident(InputStatusIncident input);
}


InputReportIncident
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
package com.mycompany.camel.cxf.code.first.spring.incident;
public class InputReportIncident {
    private String incidentId;
    private String incidentDate;
    private String givenName;
    private String familyName;
    private String summary;
    private String details;
    private String email;
    private String phone;

    public String getIncidentId() {
        return incidentId;
    }

    public void setIncidentId(String incidentId) {
        this.incidentId = incidentId;
    }

    public String getIncidentDate() {
        return incidentDate;
    }

    public void setIncidentDate(String incidentDate) {
        this.incidentDate = incidentDate;
    }

    public String getGivenName() {
        return givenName;
    }

    public void setGivenName(String givenName) {
        this.givenName = givenName;
    }

    public String getFamilyName() {
        return familyName;
    }

    public void setFamilyName(String familyName) {
        this.familyName = familyName;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String getDetails() {
        return details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}


InputStatusIncident
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
package com.mycompany.camel.cxf.code.first.spring.incident;
public class InputStatusIncident {

    private String incidentId;

    public String getIncidentId() {
        return incidentId;
    }

    public void setIncidentId(String incidentId) {
        this.incidentId = incidentId;
    }
}


OutputReportIncident
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
package com.mycompany.camel.cxf.code.first.spring.incident;
public class OutputReportIncident {

    private String code;
    private String email;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}


OutputStatusIncident
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
package com.mycompany.camel.cxf.code.first.spring.incident;
public class OutputStatusIncident {

    private String status;

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
}


ReportIncidentProcessor
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
package com.mycompany.camel.cxf.code.first.spring.incident;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.eclipse.jetty.util.log.Log;
public class ReportIncidentProcessor implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        // get the id of the input
        String id = exchange.getIn().getBody(InputReportIncident.class).getIncidentId();
        String email = exchange.getIn().getBody(InputReportIncident.class).getEmail();
        // set reply including the id
        OutputReportIncident output = new OutputReportIncident();
        output.setCode("OK; id: " + id + ", email: " + email);
        exchange.getOut().setBody(output);
    }
}


StatusIncidentProcessor
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
package com.mycompany.camel.cxf.code.first.spring.incident;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class StatusIncidentProcessor implements Processor {

    @Override
    public void process(Exchange exchange) throws Exception {
        // set reply
        OutputStatusIncident output = new OutputStatusIncident();
        output.setStatus("IN PROGRESS");
        exchange.getOut().setBody(output);
    }
}



Что хотелось бы: реализовать отправку данных в очередь сообщений, а затем в базу данных. Как это сделать - я знаю, но проблема стоит в том, что я не могу получить данные из входящего сообщения. Уверен, что можно написать Java class, который заберет данные и сам отправит на сервер очереди, но хотелось бы наглядного представления в графической панели Jboss Fuse. Я предполагал, что входящие данные окажутся в ${body}, но он оказался пустым. Поэтому прошу помочь знающих людей.

З.Ы. Думаю, что можно написать Java class, который обратиться к геттерам, заберет информацию и запишет ее в ${header} Jboss Fuse, но пока так сделать у меня не получилось.

Заранее спасибо, что уделили время
...
Рейтинг: 0 / 0
12.09.2017, 11:08
    #39519747
Андрей Панфилов
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
CXF в Jboss Fuse 6.3
Zzzadruga,

ZzzadrugaЯ предполагал, что входящие данные окажутся в ${body}, но он оказался пустым. Поэтому прошу помочь знающих людей. Чет у вас желание как-то мутно описано, в каком именно месте вы хотите получить непустой ${body} и чем он должен быть заполнен? Если под входящими данными вы подразумеваете экземпляр InputReportIncident, то вы тело перетираете в процессорах:

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
package com.mycompany.camel.cxf.code.first.spring.incident;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.eclipse.jetty.util.log.Log;
public class ReportIncidentProcessor implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        // get the id of the input
        String id = exchange.getIn().getBody(InputReportIncident.class).getIncidentId();
        String email = exchange.getIn().getBody(InputReportIncident.class).getEmail();
        // set reply including the id
        OutputReportIncident output = new OutputReportIncident();
        output.setCode("OK; id: " + id + ", email: " + email);
        exchange.getOut().setBody(output);
    }
}



если задача состоит в том, чтобы сохранять вход, то у Exchange есть setProperty/getProperty (заголовки для этого не очень подходят)
...
Рейтинг: 0 / 0
12.09.2017, 11:23
    #39519758
Zzzadruga
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
CXF в Jboss Fuse 6.3
Андрей Панфилов,
конкретно, что хотелось бы. На сервер отправляются данные, сервер отвечает, что все получил в ценности и сохранности. Дальше эти данные поступают в очередь сообщений. Следующий этап - из очереди сообщений они отправляются в базу данных. Сейчас стоит задача отправить данные в очередь. В ${body} хотелось бы получить сам запрос, чтобы поместить его в очередь, а потом на выходе разобрать XPath'ом и засунуть в базу. Вот как то так. Но, возможно, мои действия и рассуждения не верны, так как я первый раз сталкиваюсь с CXF и подобным
...
Рейтинг: 0 / 0
12.09.2017, 14:34
    #39519897
mad_nazgul
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
CXF в Jboss Fuse 6.3
Zzzadruga,

Помню, когда смотрел jBoss Fuse на сайте Fuse была неплохая документация с примерами, как и что делать.
По идее ваш use case есть в этих примерах.
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / CXF в Jboss Fuse 6.3 / 4 сообщений из 4, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]