001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.wsn.client;
018
019 import javax.jbi.JBIException;
020 import javax.jbi.component.ComponentContext;
021 import javax.xml.bind.JAXBContext;
022 import javax.xml.bind.JAXBException;
023 import javax.xml.namespace.QName;
024
025 import org.apache.servicemix.client.ServiceMixClient;
026 import org.apache.servicemix.client.ServiceMixClientFacade;
027 import org.apache.servicemix.jbi.container.JBIContainer;
028 import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver;
029 import org.oasis_open.docs.wsn.b_2.CreatePullPointResponse;
030 import org.oasis_open.docs.wsn.b_2.Subscribe;
031 import org.oasis_open.docs.wsn.br_2.RegisterPublisher;
032
033 public class CreatePullPoint extends AbstractWSAClient {
034
035 public static final String WSN_URI = "http://servicemix.org/wsnotification";
036
037 public static final String WSN_SERVICE = "CreatePullPoint";
038
039 public static final QName NOTIFICATION_BROKER = new QName(WSN_URI, WSN_SERVICE);
040
041 public CreatePullPoint(ComponentContext context) throws JAXBException {
042 ServiceMixClientFacade client = new ServiceMixClientFacade(context);
043 client.setMarshaler(new JAXBMarshaler(JAXBContext.newInstance(Subscribe.class, RegisterPublisher.class)));
044 setClient(client);
045 setResolver(new ServiceNameEndpointResolver(NOTIFICATION_BROKER));
046 }
047
048 public CreatePullPoint(ComponentContext context, String brokerName) throws JAXBException {
049 setClient(createJaxbClient(context));
050 setEndpoint(createWSA(WSN_URI + "/" + WSN_SERVICE + "/" + brokerName));
051 setResolver(resolveWSA(getEndpoint()));
052 }
053
054 public CreatePullPoint(JBIContainer container) throws JBIException, JAXBException {
055 setClient(createJaxbClient(container));
056 setResolver(new ServiceNameEndpointResolver(NOTIFICATION_BROKER));
057 }
058
059 public CreatePullPoint(JBIContainer container, String brokerName) throws JBIException, JAXBException {
060 setClient(createJaxbClient(container));
061 setEndpoint(createWSA(WSN_URI + "/" + WSN_SERVICE + "/" + brokerName));
062 setResolver(resolveWSA(getEndpoint()));
063 }
064
065 public CreatePullPoint(ServiceMixClient client) {
066 setClient(client);
067 setResolver(new ServiceNameEndpointResolver(NOTIFICATION_BROKER));
068 }
069
070 public CreatePullPoint(ServiceMixClient client, String brokerName) {
071 setClient(client);
072 setEndpoint(createWSA(WSN_URI + "/" + WSN_SERVICE + "/" + brokerName));
073 setResolver(resolveWSA(getEndpoint()));
074 }
075
076 public PullPoint createPullPoint() throws JBIException {
077 CreatePullPointResponse response = (CreatePullPointResponse) request(
078 new org.oasis_open.docs.wsn.b_2.CreatePullPoint());
079 return new PullPoint(response.getPullPoint(), getClient());
080 }
081
082 }