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.DefaultServiceMixClient;
026: import org.apache.servicemix.client.ServiceMixClient;
027: import org.apache.servicemix.client.ServiceMixClientFacade;
028: import org.apache.servicemix.jbi.container.JBIContainer;
029: import org.apache.servicemix.jbi.resolver.EndpointResolver;
030: import org.apache.servicemix.jbi.resolver.ServiceAndEndpointNameResolver;
031: import org.apache.servicemix.jbi.resolver.URIResolver;
032: import org.oasis_open.docs.wsn.b_2.Subscribe;
033: import org.oasis_open.docs.wsn.br_2.RegisterPublisher;
034: import org.w3._2005._08.addressing.AttributedURIType;
035: import org.w3._2005._08.addressing.EndpointReferenceType;
036:
037: public abstract class AbstractWSAClient {
038:
039: private EndpointReferenceType endpoint;
040:
041: private EndpointResolver resolver;
042:
043: private ServiceMixClient client;
044:
045: public AbstractWSAClient() {
046: }
047:
048: public AbstractWSAClient(EndpointReferenceType endpoint,
049: ServiceMixClient client) {
050: this .endpoint = endpoint;
051: this .resolver = resolveWSA(endpoint);
052: this .client = client;
053: }
054:
055: public static EndpointReferenceType createWSA(String address) {
056: EndpointReferenceType epr = new EndpointReferenceType();
057: AttributedURIType attUri = new AttributedURIType();
058: attUri.setValue(address);
059: epr.setAddress(attUri);
060: return epr;
061: }
062:
063: public static ServiceMixClient createJaxbClient(
064: JBIContainer container) throws JBIException, JAXBException {
065: DefaultServiceMixClient client = new DefaultServiceMixClient(
066: container);
067: client.setMarshaler(new JAXBMarshaler(JAXBContext.newInstance(
068: Subscribe.class, RegisterPublisher.class)));
069: return client;
070: }
071:
072: public static ServiceMixClient createJaxbClient(
073: ComponentContext context) throws JAXBException {
074: ServiceMixClientFacade client = new ServiceMixClientFacade(
075: context);
076: client.setMarshaler(new JAXBMarshaler(JAXBContext.newInstance(
077: Subscribe.class, RegisterPublisher.class)));
078: return client;
079: }
080:
081: public static EndpointResolver resolveWSA(EndpointReferenceType ref) {
082: String[] parts = URIResolver
083: .split3(ref.getAddress().getValue());
084: return new ServiceAndEndpointNameResolver(new QName(parts[0],
085: parts[1]), parts[2]);
086: }
087:
088: public EndpointReferenceType getEndpoint() {
089: return endpoint;
090: }
091:
092: public void setEndpoint(EndpointReferenceType endpoint) {
093: this .endpoint = endpoint;
094: }
095:
096: public EndpointResolver getResolver() {
097: return resolver;
098: }
099:
100: public void setResolver(EndpointResolver resolver) {
101: this .resolver = resolver;
102: }
103:
104: public ServiceMixClient getClient() {
105: return client;
106: }
107:
108: public void setClient(ServiceMixClient client) {
109: this .client = client;
110: }
111:
112: protected Object request(Object request) throws JBIException {
113: return client.request(resolver, null, null, request);
114: }
115:
116: protected void send(Object request) throws JBIException {
117: client.sendSync(resolver, null, null, request);
118: }
119:
120: }
|