Search in sources :

Example 86 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project cxf by apache.

the class LogicalMessageImplTest method testGetPayloadOfJAXB.

@Test
public void testGetPayloadOfJAXB() throws Exception {
    // using Dispatch
    JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class);
    Message message = new MessageImpl();
    Exchange e = new ExchangeImpl();
    message.setExchange(e);
    LogicalMessageContextImpl lmci = new LogicalMessageContextImpl(message);
    JAXBElement<AddNumbers> el = new ObjectFactory().createAddNumbers(req);
    LogicalMessageImpl lmi = new LogicalMessageImpl(lmci);
    lmi.setPayload(el, ctx);
    Object obj = lmi.getPayload(ctx);
    assertTrue(obj instanceof JAXBElement);
    JAXBElement<?> el2 = (JAXBElement<?>) obj;
    assertTrue(el2.getValue() instanceof AddNumbers);
    AddNumbers resp = (AddNumbers) el2.getValue();
    assertEquals(req.getArg0(), resp.getArg0());
    assertEquals(req.getArg1(), resp.getArg1());
}
Also used : Message(org.apache.cxf.message.Message) LogicalMessageImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageImpl) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) Exchange(org.apache.cxf.message.Exchange) LogicalMessageContextImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl) ObjectFactory(org.apache.handlers.types.ObjectFactory) AddNumbers(org.apache.handlers.types.AddNumbers) MessageImpl(org.apache.cxf.message.MessageImpl) LogicalMessageImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 87 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project cxf by apache.

the class JsonpInterceptorTest method testJsonWithPadding.

@Test
public void testJsonWithPadding() throws Exception {
    Message message = new MessageImpl();
    message.put(Message.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    message.setExchange(new ExchangeImpl());
    message.put(Message.QUERY_STRING, JsonpInInterceptor.CALLBACK_PARAM + "=" + "myCallback");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    message.setContent(OutputStream.class, bos);
    // Process the message
    in.handleMessage(message);
    preStream.handleMessage(message);
    postStream.handleMessage(message);
    assertEquals("myCallback();", bos.toString());
}
Also used : Message(org.apache.cxf.message.Message) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 88 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project cxf by apache.

the class OutgoingChainInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    control = EasyMock.createNiceControl();
    phases = new ArrayList<>();
    phases.add(new Phase(Phase.SEND, 1000));
    empty = new ArrayList<>();
    bus = control.createMock(Bus.class);
    PhaseManager pm = new PhaseManagerImpl();
    EasyMock.expect(bus.getExtension(PhaseManager.class)).andReturn(pm).anyTimes();
    service = control.createMock(Service.class);
    endpoint = control.createMock(Endpoint.class);
    binding = control.createMock(Binding.class);
    EasyMock.expect(endpoint.getBinding()).andStubReturn(binding);
    MessageImpl m = new MessageImpl();
    EasyMock.expect(binding.createMessage()).andStubReturn(m);
    EasyMock.expect(endpoint.getService()).andReturn(service).anyTimes();
    EasyMock.expect(endpoint.getOutInterceptors()).andReturn(empty);
    EasyMock.expect(service.getOutInterceptors()).andReturn(empty);
    EasyMock.expect(bus.getOutInterceptors()).andReturn(empty);
    bopInfo = control.createMock(BindingOperationInfo.class);
    opInfo = control.createMock(OperationInfo.class);
    mInfo = control.createMock(MessageInfo.class);
    bmInfo = control.createMock(BindingMessageInfo.class);
    EasyMock.expect(bopInfo.getOperationInfo()).andReturn(opInfo).times(3);
    EasyMock.expect(opInfo.getOutput()).andReturn(mInfo);
    EasyMock.expect(opInfo.isOneWay()).andReturn(false);
    EasyMock.expect(bopInfo.getOutput()).andReturn(bmInfo);
    control.replay();
}
Also used : Binding(org.apache.cxf.binding.Binding) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Phase(org.apache.cxf.phase.Phase) PhaseManager(org.apache.cxf.phase.PhaseManager) Service(org.apache.cxf.service.Service) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) PhaseManagerImpl(org.apache.cxf.bus.managers.PhaseManagerImpl) MessageImpl(org.apache.cxf.message.MessageImpl) Before(org.junit.Before)

Example 89 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project cxf by apache.

the class JAASLoginInterceptorTest method testLoginWithDefaultHandler.

/**
 * Using default CallbackhandlerProviders and no authentication information
 */
@Test(expected = AuthenticationException.class)
public void testLoginWithDefaultHandler() {
    JAASLoginInterceptor jaasInt = createTestJaasLoginInterceptor();
    Message message = new MessageImpl();
    jaasInt.handleMessage(message);
}
Also used : Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 90 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project cxf by apache.

the class JAASLoginInterceptorTest method testLoginWithDefaultHandlerAndAuthPolWrongPass.

@Test(expected = AuthenticationException.class)
public void testLoginWithDefaultHandlerAndAuthPolWrongPass() {
    JAASLoginInterceptor jaasInt = createTestJaasLoginInterceptor();
    Message message = new MessageImpl();
    addAuthPolicy(message, TestUserPasswordLoginModule.TESTUSER, "wrong");
    jaasInt.handleMessage(message);
}
Also used : Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Aggregations

MessageImpl (org.apache.cxf.message.MessageImpl)610 Message (org.apache.cxf.message.Message)291 Test (org.junit.Test)290 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)193 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)152 Exchange (org.apache.cxf.message.Exchange)148 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)137 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)115 Crypto (org.apache.wss4j.common.crypto.Crypto)113 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)107 JAXBElement (javax.xml.bind.JAXBElement)100 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)93 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)86 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)83 Element (org.w3c.dom.Element)74 ArrayList (java.util.ArrayList)62 ServiceMBean (org.apache.cxf.sts.service.ServiceMBean)61 StaticService (org.apache.cxf.sts.service.StaticService)61 Principal (java.security.Principal)59 Endpoint (org.apache.cxf.endpoint.Endpoint)58