use of org.apache.cxf.endpoint.Endpoint in project tomee by apache.
the class CxfRsHttpListener method newFactory.
private JAXRSServerFactoryBean newFactory(final String prefix, final String service, final String endpoint) {
final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean() {
@Override
protected Endpoint createEndpoint() throws BusException, EndpointException {
final Endpoint created = super.createEndpoint();
created.put(ManagedEndpoint.SERVICE_NAME, service);
created.put(ManagedEndpoint.ENDPOINT_NAME, endpoint);
return created;
}
};
factory.setDestinationFactory(transportFactory);
factory.setBus(CxfUtil.getBus());
factory.setAddress(prefix);
return factory;
}
use of org.apache.cxf.endpoint.Endpoint in project camel by apache.
the class DefaultCxfBinding method populateCxfResponseFromExchange.
/**
* This method is called by {@link CxfConsumer} to populate a CXF response exchange
* from a Camel exchange.
*/
public void populateCxfResponseFromExchange(Exchange camelExchange, org.apache.cxf.message.Exchange cxfExchange) {
if (cxfExchange.isOneWay()) {
return;
}
// create response context
Map<String, Object> responseContext = new HashMap<String, Object>();
org.apache.camel.Message response;
if (camelExchange.getPattern().isOutCapable()) {
if (camelExchange.hasOut()) {
response = camelExchange.getOut();
LOG.trace("Get the response from the out message");
} else {
// Take the in message as a fall back
response = camelExchange.getIn();
LOG.trace("Get the response from the in message as a fallback");
}
} else {
response = camelExchange.getIn();
LOG.trace("Get the response from the in message");
}
// propagate response context
Map<String, Object> camelHeaders = response.getHeaders();
extractInvocationContextFromCamel(camelExchange, camelHeaders, responseContext, Client.RESPONSE_CONTEXT);
propagateHeadersFromCamelToCxf(camelExchange, camelHeaders, cxfExchange, responseContext);
// create out message
Endpoint ep = cxfExchange.get(Endpoint.class);
Message outMessage = ep.getBinding().createMessage();
cxfExchange.setOutMessage(outMessage);
DataFormat dataFormat = camelExchange.getProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.class);
// make sure the "requestor role" property does not get propagated as we do switch role
responseContext.remove(Message.REQUESTOR_ROLE);
outMessage.putAll(responseContext);
// Do we still need to put the response context back like this
outMessage.put(Client.RESPONSE_CONTEXT, responseContext);
LOG.trace("Set out response context = {}", responseContext);
// set body
Object outBody = DefaultCxfBinding.getBodyFromCamel(response, dataFormat);
if (outBody != null) {
if (dataFormat == DataFormat.PAYLOAD) {
CxfPayload<?> payload = (CxfPayload<?>) outBody;
outMessage.setContent(List.class, getResponsePayloadList(cxfExchange, payload.getBodySources()));
outMessage.put(Header.HEADER_LIST, payload.getHeaders());
} else {
if (responseContext.get(Header.HEADER_LIST) != null) {
outMessage.put(Header.HEADER_LIST, responseContext.get(Header.HEADER_LIST));
}
MessageContentsList resList = null;
// Create a new MessageContentsList to avoid OOM from the HolderOutInterceptor
if (outBody instanceof List) {
resList = new MessageContentsList((List<?>) outBody);
} else if (outBody.getClass().isArray()) {
resList = new MessageContentsList((Object[]) outBody);
} else {
resList = new MessageContentsList(outBody);
}
if (resList != null) {
outMessage.setContent(List.class, resList);
LOG.trace("Set Out CXF message content = {}", resList);
}
}
} else if (!cxfExchange.isOneWay() && cxfExchange.getInMessage() != null && MessageUtils.isTrue(cxfExchange.getInMessage().getContextualProperty("jaxws.provider.interpretNullAsOneway"))) {
// treat this non-oneway call as oneway when the provider returns a null
changeToOneway(cxfExchange);
return;
}
// propagate attachments
Set<Attachment> attachments = null;
boolean isXop = Boolean.valueOf(camelExchange.getProperty(Message.MTOM_ENABLED, String.class));
for (Map.Entry<String, org.apache.camel.Attachment> entry : camelExchange.getOut().getAttachmentObjects().entrySet()) {
if (attachments == null) {
attachments = new HashSet<Attachment>();
}
AttachmentImpl attachment = new AttachmentImpl(entry.getKey());
org.apache.camel.Attachment camelAttachment = entry.getValue();
attachment.setDataHandler(camelAttachment.getDataHandler());
for (String name : camelAttachment.getHeaderNames()) {
attachment.setHeader(name, camelAttachment.getHeader(name));
}
attachment.setXOP(isXop);
attachments.add(attachment);
}
if (attachments != null) {
outMessage.setAttachments(attachments);
}
BindingOperationInfo boi = cxfExchange.get(BindingOperationInfo.class);
if (boi != null) {
cxfExchange.put(BindingMessageInfo.class, boi.getOutput());
}
}
use of org.apache.cxf.endpoint.Endpoint in project tomee by apache.
the class CalculatorTest method testCalculatorViaWsInterfaceWithTimestamp2ways.
public void testCalculatorViaWsInterfaceWithTimestamp2ways() throws Exception {
final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplTimestamp2ways?wsdl"), new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
assertNotNull(calcService);
// for debugging (ie. TCPMon)
calcService.addPort(new QName("http://superbiz.org/wsdl", "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING, "http://127.0.0.1:8204/CalculatorImplTimestamp2ways");
// CalculatorWs calc = calcService.getPort(
// new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
// CalculatorWs.class);
final CalculatorWs calc = calcService.getPort(CalculatorWs.class);
final Client client = ClientProxy.getClient(calc);
final Endpoint endpoint = client.getEndpoint();
endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
endpoint.getInInterceptors().add(new SAAJInInterceptor());
final Map<String, Object> outProps = new HashMap<String, Object>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
endpoint.getOutInterceptors().add(wssOut);
final Map<String, Object> inProps = new HashMap<String, Object>();
inProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
final WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);
endpoint.getInInterceptors().add(wssIn);
assertEquals(12, calc.multiply(3, 4));
}
use of org.apache.cxf.endpoint.Endpoint in project tomee by apache.
the class CalculatorTest method testCalculatorViaWsInterfaceWithUsernameTokenPlainPasswordEncrypt.
public void testCalculatorViaWsInterfaceWithUsernameTokenPlainPasswordEncrypt() throws Exception {
final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplUsernameTokenPlainPasswordEncrypt?wsdl"), new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
assertNotNull(calcService);
// for debugging (ie. TCPMon)
calcService.addPort(new QName("http://superbiz.org/wsdl", "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING, "http://127.0.0.1:8204/CalculatorImplUsernameTokenPlainPasswordEncrypt");
// CalculatorWs calc = calcService.getPort(
// new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
// CalculatorWs.class);
final CalculatorWs calc = calcService.getPort(CalculatorWs.class);
final Client client = ClientProxy.getClient(calc);
final Endpoint endpoint = client.getEndpoint();
endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
final Map<String, Object> outProps = new HashMap<String, Object>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN + " " + WSHandlerConstants.ENCRYPT);
outProps.put(WSHandlerConstants.USER, "jane");
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {
@Override
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
pc.setPassword("waterfall");
}
});
outProps.put(WSHandlerConstants.ENC_PROP_FILE, "META-INF/CalculatorImplUsernameTokenPlainPasswordEncrypt-client.properties");
outProps.put(WSHandlerConstants.ENCRYPTION_USER, "serveralias");
final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
endpoint.getOutInterceptors().add(wssOut);
assertEquals(10, calc.sum(4, 6));
}
use of org.apache.cxf.endpoint.Endpoint in project tomee by apache.
the class EjbInterceptor method intercept.
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
Endpoint endpoint = this.exchange.get(Endpoint.class);
Service service = endpoint.getService();
Binding binding = ((JaxWsEndpointImpl) endpoint).getJaxwsBinding();
this.exchange.put(InvocationContext.class, context);
if (binding.getHandlerChain() == null || binding.getHandlerChain().isEmpty()) {
// no handlers so let's just directly invoke the bean
log.debug("No handlers found.");
EjbMethodInvoker invoker = (EjbMethodInvoker) service.getInvoker();
return invoker.directEjbInvoke(this.exchange, this.method, this.params);
} else {
// have handlers so have to run handlers now and redo data binding
// as handlers can change the soap message
log.debug("Handlers found.");
Message inMessage = exchange.getInMessage();
PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());
chain.setFaultObserver(endpoint.getOutFaultObserver());
/*
* Since we have to re-do data binding and the XMLStreamReader
* contents are already consumed by prior data binding step
* we have to reinitialize the XMLStreamReader from the SOAPMessage
* created by SAAJInInterceptor.
*/
if (inMessage instanceof SoapMessage) {
try {
reserialize((SoapMessage) inMessage);
} catch (Exception e) {
throw new ServerRuntimeException("Failed to reserialize soap message", e);
}
} else {
// TODO: how to handle XML/HTTP binding?
}
this.exchange.setOutMessage(null);
// install default interceptors
chain.add(new ServiceInvokerInterceptor());
//chain.add(new OutgoingChainInterceptor()); // it is already in the enclosing chain, if we add it there we are in the tx so we write the message in the tx!
// See http://cwiki.apache.org/CXF20DOC/interceptors.html
// install Holder and Wrapper interceptors
chain.add(new WrapperClassInInterceptor());
chain.add(new HolderInInterceptor());
// install interceptors for handler processing
chain.add(new MustUnderstandInterceptor());
chain.add(new LogicalHandlerInInterceptor(binding));
chain.add(new SOAPHandlerInterceptor(binding));
// install data binding interceptors - todo: check we need it
copyDataBindingInterceptors(chain, inMessage.getInterceptorChain());
InterceptorChain oldChain = inMessage.getInterceptorChain();
inMessage.setInterceptorChain(chain);
try {
chain.doIntercept(inMessage);
} finally {
inMessage.setInterceptorChain(oldChain);
}
// TODO: the result should be deserialized from SOAPMessage
Object result = getResult();
return result;
}
}
Aggregations