Search in sources :

Example 16 with CreateResponse

use of org.apache.cxf.ws.transfer.CreateResponse in project cxf by apache.

the class PutTest method rightStudentPutTest.

@Test
public void rightStudentPutTest() throws XMLStreamException {
    CreateResponse createResponse = createStudent();
    Document putStudentXML = StaxUtils.read(getClass().getResourceAsStream("/xml/putStudent.xml"));
    Put request = new Put();
    request.setRepresentation(new Representation());
    request.getRepresentation().setAny(putStudentXML.getDocumentElement());
    Resource client = TestUtils.createResourceClient(createResponse.getResourceCreated());
    client.put(request);
}
Also used : CreateResponse(org.apache.cxf.ws.transfer.CreateResponse) Resource(org.apache.cxf.ws.transfer.resource.Resource) Representation(org.apache.cxf.ws.transfer.Representation) Document(org.w3c.dom.Document) Put(org.apache.cxf.ws.transfer.Put) Test(org.junit.Test)

Example 17 with CreateResponse

use of org.apache.cxf.ws.transfer.CreateResponse in project cxf by apache.

the class ResourceFactoryTest method createLocalResourceTest.

@Test
public void createLocalResourceTest() {
    ReferenceParametersType refParams = createReferenceParameters();
    ResourceManager manager = EasyMock.createMock(ResourceManager.class);
    EasyMock.expect(manager.create(EasyMock.isA(Representation.class))).andReturn(refParams);
    EasyMock.expectLastCall().once();
    EasyMock.replay(manager);
    Server localResourceFactory = createLocalResourceFactory(manager);
    ResourceFactory client = createClient();
    Create createRequest = new Create();
    Representation representation = new Representation();
    representation.setAny(createXMLRepresentation());
    createRequest.setRepresentation(representation);
    CreateResponse response = client.create(createRequest);
    EasyMock.verify(manager);
    Assert.assertEquals("ResourceAddress is other than expected.", RESOURCE_ADDRESS, response.getResourceCreated().getAddress().getValue());
    Element refParamEl = (Element) response.getResourceCreated().getReferenceParameters().getAny().get(0);
    Assert.assertEquals(REF_PARAM_NAMESPACE, refParamEl.getNamespaceURI());
    Assert.assertEquals(REF_PARAM_LOCAL_NAME, refParamEl.getLocalName());
    Assert.assertEquals(RESOURCE_UUID, refParamEl.getTextContent());
    Assert.assertEquals("root", ((Element) response.getRepresentation().getAny()).getLocalName());
    Assert.assertEquals(2, ((Element) response.getRepresentation().getAny()).getChildNodes().getLength());
    localResourceFactory.destroy();
}
Also used : Server(org.apache.cxf.endpoint.Server) Create(org.apache.cxf.ws.transfer.Create) CreateResponse(org.apache.cxf.ws.transfer.CreateResponse) Element(org.w3c.dom.Element) ReferenceParametersType(org.apache.cxf.ws.addressing.ReferenceParametersType) Representation(org.apache.cxf.ws.transfer.Representation) ResourceFactory(org.apache.cxf.ws.transfer.resourcefactory.ResourceFactory) ResourceManager(org.apache.cxf.ws.transfer.manager.ResourceManager) Test(org.junit.Test)

Example 18 with CreateResponse

use of org.apache.cxf.ws.transfer.CreateResponse in project cxf by apache.

the class ResourceFactoryImpl method createRemotely.

private CreateResponse createRemotely(Create body, ResourceReference ref) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(ResourceFactory.class);
    factory.setAddress(ref.getResourceURL() + TransferConstants.RESOURCE_REMOTE_SUFFIX);
    ResourceFactory client = (ResourceFactory) factory.create();
    CreateResponse response = client.create(body);
    // Adding of endpoint address to the response.
    response.getResourceCreated().setAddress(new AttributedURIType());
    response.getResourceCreated().getAddress().setValue(ref.getResourceURL());
    return response;
}
Also used : CreateResponse(org.apache.cxf.ws.transfer.CreateResponse) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType)

Example 19 with CreateResponse

use of org.apache.cxf.ws.transfer.CreateResponse in project cxf by apache.

the class ResourceFactoryImpl method createLocally.

private CreateResponse createLocally(Create body, ResourceReference ref) {
    Representation representation = body.getRepresentation();
    ReferenceParametersType refParams = ref.getResourceManager().create(representation);
    CreateResponse response = new CreateResponse();
    response.setResourceCreated(new EndpointReferenceType());
    response.getResourceCreated().setAddress(new AttributedURIType());
    response.getResourceCreated().getAddress().setValue(ref.getResourceURL());
    response.getResourceCreated().setReferenceParameters(refParams);
    response.setRepresentation(body.getRepresentation());
    return response;
}
Also used : EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) CreateResponse(org.apache.cxf.ws.transfer.CreateResponse) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) Representation(org.apache.cxf.ws.transfer.Representation) ReferenceParametersType(org.apache.cxf.ws.addressing.ReferenceParametersType)

Aggregations

CreateResponse (org.apache.cxf.ws.transfer.CreateResponse)19 Test (org.junit.Test)16 Representation (org.apache.cxf.ws.transfer.Representation)12 Resource (org.apache.cxf.ws.transfer.resource.Resource)10 Document (org.w3c.dom.Document)8 Create (org.apache.cxf.ws.transfer.Create)6 Delete (org.apache.cxf.ws.transfer.Delete)6 ResourceFactory (org.apache.cxf.ws.transfer.resourcefactory.ResourceFactory)6 ReferenceParametersType (org.apache.cxf.ws.addressing.ReferenceParametersType)4 Put (org.apache.cxf.ws.transfer.Put)4 Server (org.apache.cxf.endpoint.Server)2 AttributedURIType (org.apache.cxf.ws.addressing.AttributedURIType)2 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)2 Get (org.apache.cxf.ws.transfer.Get)2 ResourceManager (org.apache.cxf.ws.transfer.manager.ResourceManager)2 Element (org.w3c.dom.Element)2 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)1