}
public Subscription subscribe(EndpointReferenceType consumer, String topic,
String xpath, boolean raw) throws JBIException {
Subscribe subscribeRequest = new Subscribe();
subscribeRequest.setConsumerReference(consumer);
subscribeRequest.setFilter(new FilterType());
if (topic != null) {
TopicExpressionType topicExp = new TopicExpressionType();
topicExp.getContent().add(topic);
subscribeRequest.getFilter().getAny().add(
new JAXBElement<TopicExpressionType>(AbstractSubscription.QNAME_TOPIC_EXPRESSION,
TopicExpressionType.class, topicExp));
}
if (xpath != null) {
QueryExpressionType xpathExp = new QueryExpressionType();
xpathExp.setDialect(AbstractSubscription.XPATH1_URI);
xpathExp.getContent().add(xpath);
subscribeRequest.getFilter().getAny().add(
new JAXBElement<QueryExpressionType>(AbstractSubscription.QNAME_MESSAGE_CONTENT,
QueryExpressionType.class, xpathExp));
}
if (raw) {
subscribeRequest.setSubscriptionPolicy(new Subscribe.SubscriptionPolicy());
subscribeRequest.getSubscriptionPolicy().getAny().add(new UseRaw());
}
SubscribeResponse response = (SubscribeResponse) request(subscribeRequest);
return new Subscription(response.getSubscriptionReference(), getClient());
}