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.jms.endpoints;
018:
019: import java.io.ByteArrayInputStream;
020: import java.io.ByteArrayOutputStream;
021: import java.io.InputStream;
022: import java.io.OutputStream;
023:
024: import javax.jbi.messaging.MessageExchange;
025: import javax.jbi.messaging.NormalizedMessage;
026: import javax.jms.Message;
027: import javax.jms.Session;
028: import javax.jms.TextMessage;
029:
030: import org.apache.servicemix.soap.api.InterceptorChain;
031: import org.apache.servicemix.soap.api.InterceptorProvider.Phase;
032: import org.apache.servicemix.soap.api.Policy;
033: import org.apache.servicemix.soap.api.model.Binding;
034: import org.apache.servicemix.soap.interceptors.jbi.JbiConstants;
035:
036: public class JmsSoapProviderMarshaler implements JmsProviderMarshaler {
037:
038: private Binding<?> binding;
039: private boolean useJbiWrapper = true;
040: private Policy[] policies;
041: private String baseUrl;
042:
043: public Binding<?> getBinding() {
044: return binding;
045: }
046:
047: public void setBinding(Binding<?> binding) {
048: this .binding = binding;
049: }
050:
051: public String getBaseUrl() {
052: return baseUrl;
053: }
054:
055: public void setBaseUrl(String baseUrl) {
056: this .baseUrl = baseUrl;
057: }
058:
059: public boolean isUseJbiWrapper() {
060: return useJbiWrapper;
061: }
062:
063: public void setUseJbiWrapper(boolean useJbiWrapper) {
064: this .useJbiWrapper = useJbiWrapper;
065: }
066:
067: public Policy[] getPolicies() {
068: return policies;
069: }
070:
071: public void setPolicies(Policy[] policies) {
072: this .policies = policies;
073: }
074:
075: public Message createMessage(MessageExchange exchange,
076: NormalizedMessage in, Session session) throws Exception {
077: ByteArrayOutputStream baos = new ByteArrayOutputStream();
078:
079: org.apache.servicemix.soap.api.Message msg = binding
080: .createMessage();
081: exchange.setProperty(
082: org.apache.servicemix.soap.api.Message.class.getName(),
083: null);
084: msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
085: msg.setContent(MessageExchange.class, exchange);
086: msg.setContent(NormalizedMessage.class, in);
087: msg.setContent(OutputStream.class, baos);
088: exchange.setProperty(Message.class.getName(), msg);
089:
090: InterceptorChain phaseOut = getChain(Phase.ClientOut);
091: phaseOut.doIntercept(msg);
092: TextMessage jmsMessage = session.createTextMessage();
093: jmsMessage.setText(baos.toString());
094: return jmsMessage;
095: }
096:
097: public void populateMessage(Message message,
098: MessageExchange exchange,
099: NormalizedMessage normalizedMessage) throws Exception {
100: org.apache.servicemix.soap.api.Message req = (org.apache.servicemix.soap.api.Message) exchange
101: .getProperty(Message.class.getName());
102: exchange.setProperty(
103: org.apache.servicemix.soap.api.Message.class.getName(),
104: null);
105: org.apache.servicemix.soap.api.Message msg = binding
106: .createMessage(req);
107: msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
108: msg.setContent(MessageExchange.class, exchange);
109: msg.setContent(NormalizedMessage.class, normalizedMessage);
110: String str = ((TextMessage) message).getText();
111: msg.setContent(InputStream.class, new ByteArrayInputStream(str
112: .getBytes()));
113:
114: InterceptorChain phaseIn = getChain(Phase.ClientIn);
115: phaseIn.doIntercept(msg);
116: }
117:
118: protected InterceptorChain getChain(Phase phase) {
119: InterceptorChain chain = binding.getInterceptorChain(phase);
120: if (policies != null) {
121: for (int i = 0; i < policies.length; i++) {
122: chain.add(policies[i].getInterceptors(phase));
123: }
124: }
125: return chain;
126: }
127:
128: }
|