Search in sources :

Example 46 with MessageImpl

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

the class MessageContextImplTest method testGetPropertyFromExchange.

@Test
public void testGetPropertyFromExchange() {
    Message m = new MessageImpl();
    Exchange ex = new ExchangeImpl();
    ex.put("a", "b");
    ex.setInMessage(m);
    MessageContext mc = new MessageContextImpl(m);
    assertEquals("b", mc.get("a"));
    assertNull(mc.get("b"));
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 47 with MessageImpl

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

the class MessageContextImplTest method testGetSecurityContext.

@Test
public void testGetSecurityContext() {
    MessageContext mc = new MessageContextImpl(new MessageImpl());
    assertSame(SecurityContextImpl.class, mc.getSecurityContext().getClass());
    assertSame(SecurityContextImpl.class, mc.getContext(SecurityContext.class).getClass());
}
Also used : MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 48 with MessageImpl

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

the class SelectMethodCandidatesTest method doTestGenericSuperType.

private void doTestGenericSuperType(Class<?> serviceClass, String methodName) throws Exception {
    JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
    sf.setResourceClasses(serviceClass);
    sf.create();
    List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
    String contentTypes = "text/xml";
    String acceptContentTypes = "text/xml";
    Message m = new MessageImpl();
    m.put(Message.CONTENT_TYPE, "text/xml");
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(m);
    m.setExchange(ex);
    Endpoint e = mockEndpoint();
    ex.put(Endpoint.class, e);
    MetadataMap<String, String> values = new MetadataMap<>();
    OperationResourceInfo ori = findTargetResourceClass(resources, m, "/books", methodName, values, contentTypes, sortMediaTypes(acceptContentTypes));
    assertNotNull(ori);
    assertEquals("resourceMethod needs to be selected", methodName.toLowerCase() + "Entity", ori.getMethodToInvoke().getName());
    String value = "<Book><name>The Book</name><id>2</id></Book>";
    m.setContent(InputStream.class, new ByteArrayInputStream(value.getBytes()));
    List<Object> params = JAXRSUtils.processParameters(ori, values, m);
    assertEquals(1, params.size());
    Book book = (Book) params.get(0);
    assertNotNull(book);
    assertEquals(2L, book.getId());
    assertEquals("The Book", book.getName());
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) Exchange(org.apache.cxf.message.Exchange) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Endpoint(org.apache.cxf.endpoint.Endpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) Book(org.apache.cxf.jaxrs.resources.Book) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 49 with MessageImpl

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

the class SelectMethodCandidatesTest method doTestConsumesResource.

private void doTestConsumesResource(Class<?> resourceClass, String ct, String expectedMethodName) throws Exception {
    JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
    sf.setResourceClasses(resourceClass);
    sf.create();
    List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
    String contentType = ct == null ? "application/xml" : ct;
    String acceptContentTypes = "*/*";
    Message m = new MessageImpl();
    m.put(Message.CONTENT_TYPE, contentType);
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(m);
    m.setExchange(ex);
    Endpoint e = mockEndpoint();
    ex.put(Endpoint.class, e);
    MetadataMap<String, String> values = new MetadataMap<>();
    OperationResourceInfo ori = findTargetResourceClass(resources, m, "/", "POST", values, contentType, sortMediaTypes(acceptContentTypes));
    assertNotNull(ori);
    assertEquals(expectedMethodName, ori.getMethodToInvoke().getName());
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) Exchange(org.apache.cxf.message.Exchange) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Endpoint(org.apache.cxf.endpoint.Endpoint) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 50 with MessageImpl

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

the class HttpHeadersImplTest method testGetContentTypeLowCase.

@Test
public void testGetContentTypeLowCase() throws Exception {
    Message m = new MessageImpl();
    // this is what happens at runtime and is tested in the system tests
    Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    headers.put("content-type", Collections.singletonList("text/plain"));
    m.put(Message.PROTOCOL_HEADERS, headers);
    HttpHeaders h = new HttpHeadersImpl(m);
    assertEquals("text/plain", h.getRequestHeaders().getFirst("Content-Type"));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) List(java.util.List) TreeMap(java.util.TreeMap) 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