Search in sources :

Example 91 with MessageImpl

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

the class LoggingOutInterceptorTest method testFormatting.

@Test
public void testFormatting() throws Exception {
    control.replay();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(baos);
    LoggingOutInterceptor p = new LoggingOutInterceptor(pw);
    // p.setPrettyLogging(true);
    CachedOutputStream cos = new CachedOutputStream();
    String s = "<today><is><the><twenty> <second> <of> <january> <two> <thousand> <and> <nine></nine> " + "</and></thousand></two></january></of></second></twenty></the></is></today>";
    cos.write(s.getBytes());
    Message message = new MessageImpl();
    message.setExchange(new ExchangeImpl());
    message.put(Message.CONTENT_TYPE, "application/xml");
    Logger logger = LogUtils.getL7dLogger(this.getClass());
    LoggingOutInterceptor.LoggingCallback l = p.new LoggingCallback(logger, message, cos);
    l.onClose(cos);
    String str = baos.toString();
    // format has changed
    assertFalse(str.matches(s));
    assertTrue(str.contains("<today>"));
}
Also used : Message(org.apache.cxf.message.Message) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(java.util.logging.Logger) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) PrintWriter(java.io.PrintWriter) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Test(org.junit.Test)

Example 92 with MessageImpl

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

the class CachedOutputStreamTest method testUseSysPropsWithAttachmentDeserializer.

@Test
public void testUseSysPropsWithAttachmentDeserializer() throws Exception {
    String old = System.getProperty(CachedConstants.THRESHOLD_SYS_PROP);
    try {
        System.clearProperty(CachedConstants.THRESHOLD_SYS_PROP);
        reloadDefaultProperties();
        CachedOutputStream cache = new CachedOutputStream();
        Message message = new MessageImpl();
        AttachmentUtil.setStreamedAttachmentProperties(message, cache);
        File tmpfile = getTmpFile("Hello World!", cache);
        assertNull("expects no tmp file", tmpfile);
        cache.close();
        System.setProperty(CachedConstants.THRESHOLD_SYS_PROP, "4");
        reloadDefaultProperties();
        cache = new CachedOutputStream();
        AttachmentUtil.setStreamedAttachmentProperties(message, cache);
        tmpfile = getTmpFile("Hello World!", cache);
        assertNotNull("expects a tmp file", tmpfile);
        assertTrue("expects a tmp file", tmpfile.exists());
        cache.close();
        assertFalse("expects no tmp file", tmpfile.exists());
    } finally {
        System.clearProperty(CachedConstants.THRESHOLD_SYS_PROP);
        if (old != null) {
            System.setProperty(CachedConstants.THRESHOLD_SYS_PROP, old);
        }
    }
}
Also used : Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) File(java.io.File) Test(org.junit.Test)

Example 93 with MessageImpl

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

the class CdiResourceProviderTest method assertSingleton.

private void assertSingleton() {
    final ResourceProvider provider = new SingletonResourceProvider(new Lifecycle(beanManager, bean), Object.class);
    assertTrue(new JAXRSCdiResourceExtension().isCxfSingleton(beanManager, bean));
    assertTrue(provider.isSingleton());
    final Object instance = provider.getInstance(new MessageImpl());
    assertNotNull(instance);
    assertEquals(instance, provider.getInstance(new MessageImpl()));
}
Also used : ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 94 with MessageImpl

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

the class DocLiteralInInterceptorTest method setUpUsingDocLit.

private void setUpUsingDocLit() throws Exception {
    String ns = "http://apache.org/hello_world_doc_lit_bare";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource("/wsdl/jaxb/doc_lit_bare.wsdl").toString(), new QName(ns, "SOAPService"));
    service = factory.create();
    endpointInfo = service.getEndpointInfo(new QName(ns, "SoapPort"));
    endpoint = new EndpointImpl(bus, service, endpointInfo);
    JAXBDataBinding db = new JAXBDataBinding();
    db.setContext(JAXBContext.newInstance(new Class[] { TradePriceData.class }));
    service.setDataBinding(db);
    operation = endpointInfo.getBinding().getOperation(new QName(ns, "SayHi"));
    operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(TradePriceData.class);
    operation.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(TradePriceData.class);
    message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, endpoint.getBinding());
}
Also used : Exchange(org.apache.cxf.message.Exchange) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) TradePriceData(org.apache.hello_world_doc_lit_bare.types.TradePriceData) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 95 with MessageImpl

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

the class DocLiteralInInterceptorTest method setUpUsingHelloWorld.

private void setUpUsingHelloWorld() throws Exception {
    String ns = "http://apache.org/hello_world_soap_http";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource("/wsdl/jaxb/hello_world.wsdl").toString(), new QName(ns, "SOAPService"));
    service = factory.create();
    endpointInfo = service.getEndpointInfo(new QName(ns, "SoapPort"));
    endpoint = new EndpointImpl(bus, service, endpointInfo);
    JAXBDataBinding db = new JAXBDataBinding();
    db.setContext(JAXBContext.newInstance(new Class[] { GreetMe.class, GreetMeResponse.class }));
    service.setDataBinding(db);
    operation = endpointInfo.getBinding().getOperation(new QName(ns, "greetMe"));
    operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(GreetMe.class);
    operation.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(GreetMeResponse.class);
    message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, endpoint.getBinding());
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) Exchange(org.apache.cxf.message.Exchange) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

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