org.apache.cxf.jaxb.JAXBDataBinding Java Examples

The following examples show how to use org.apache.cxf.jaxb.JAXBDataBinding. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegisterPrecompiledJSPInitializer.java    From airsonic with GNU General Public License v3.0 6 votes vote down vote up
private static WebApp parseXmlFragment() {
    InputStream precompiledJspWebXml = RegisterPrecompiledJSPInitializer.class.getResourceAsStream("/precompiled-jsp-web.xml");
    InputStream webXmlIS = new SequenceInputStream(
            new SequenceInputStream(
                    IOUtils.toInputStream("<web-app>", Charset.defaultCharset()),
                    precompiledJspWebXml),
            IOUtils.toInputStream("</web-app>", Charset.defaultCharset()));

    try {
        JAXBContext jaxbContext = new JAXBDataBinding(WebApp.class).getContext();
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        WebApp webapp = (WebApp) unmarshaller.unmarshal(webXmlIS);
        try {
            webXmlIS.close();
        } catch (java.io.IOException ignored) {}
        return webapp;
    } catch (JAXBException e) {
        throw new RuntimeException("Could not parse precompiled-jsp-web.xml", e);
    }
}
 
Example #2
Source File: RegisterPrecompiledJSPInitializer.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
private static WebApp parseXmlFragment() {
    InputStream precompiledJspWebXml = RegisterPrecompiledJSPInitializer.class.getResourceAsStream("/precompiled-jsp-web.xml");
    InputStream webXmlIS = new SequenceInputStream(
            new SequenceInputStream(
                    IOUtils.toInputStream("<web-app>", Charset.defaultCharset()),
                    precompiledJspWebXml),
            IOUtils.toInputStream("</web-app>", Charset.defaultCharset()));

    try {
        JAXBContext jaxbContext = new JAXBDataBinding(WebApp.class).getContext();
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        WebApp webapp = (WebApp) unmarshaller.unmarshal(webXmlIS);
        try {
            webXmlIS.close();
        } catch (java.io.IOException ignored) {}
        return webapp;
    } catch (JAXBException e) {
        throw new RuntimeException("Could not parse precompiled-jsp-web.xml", e);
    }
}
 
Example #3
Source File: XMLStreamDataWriterTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteWithContextualNamespaceDecls() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(GreetMe.class);
    Map<String, String> nspref = new HashMap<>();
    nspref.put("http://apache.org/hello_world_soap_http/types", "x");
    db.setNamespaceMap(nspref);
    db.setContextualNamespaceMap(nspref);

    // use the output stream instead of XMLStreamWriter to test
    DataWriter<OutputStream> dw = db.createWriter(OutputStream.class);
    assertNotNull(dw);

    GreetMe val = new GreetMe();
    val.setRequestType("Hello");
    dw.write(val, baos);

    String xstr = new String(baos.toByteArray());

    // there should be no namespace decls
    if (!db.getContext().getClass().getName().contains("eclipse")) {
        //bug in eclipse moxy
        //https://bugs.eclipse.org/bugs/show_bug.cgi?id=421463

        assertEquals("<x:greetMe><x:requestType>Hello</x:requestType></x:greetMe>", xstr);
    }
}
 
Example #4
Source File: XMLStreamDataReaderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadBare() throws Exception {
    JAXBDataBinding db = getDataBinding(TradePriceData.class);

    reader = getTestReader("../resources/sayHiDocLitBareReq.xml");
    assertNotNull(reader);

    DataReader<XMLStreamReader> dr = db.createReader(XMLStreamReader.class);
    assertNotNull(dr);
    QName elName = new QName("http://apache.org/hello_world_doc_lit_bare/types", "inout");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    part.setTypeClass(TradePriceData.class);
    Object val = dr.read(part, reader);

    assertNotNull(val);
    assertTrue(val instanceof TradePriceData);
    assertEquals("CXF", ((TradePriceData)val).getTickerSymbol());
    assertEquals(Float.valueOf(1.0f), new Float(((TradePriceData)val).getTickerPrice()));
}
 
Example #5
Source File: XMLStreamDataReaderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadRPC() throws Exception {
    JAXBDataBinding db = getDataBinding(MyComplexStruct.class);

    QName[] tags = {new QName("http://apache.org/hello_world_rpclit", "sendReceiveData")};

    reader = getTestReader("../resources/greetMeRpcLitReq.xml");
    assertNotNull(reader);

    XMLStreamReader localReader = getTestFilteredReader(reader, tags);

    DataReader<XMLStreamReader> dr = db.createReader(XMLStreamReader.class);
    assertNotNull(dr);
    Object val = dr.read(new QName("http://apache.org/hello_world_rpclit", "in"),
                         localReader,
                         MyComplexStruct.class);
    assertNotNull(val);

    assertTrue(val instanceof MyComplexStruct);
    assertEquals("this is element 1", ((MyComplexStruct)val).getElem1());
    assertEquals("this is element 2", ((MyComplexStruct)val).getElem2());
    assertEquals(42, ((MyComplexStruct)val).getElem3());
}
 
Example #6
Source File: XMLStreamDataReaderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadWrapperReturn() throws Exception {
    JAXBDataBinding db = getDataBinding(GreetMeResponse.class);

    reader = getTestReader("../resources/GreetMeDocLiteralResp.xml");
    assertNotNull(reader);

    DataReader<XMLStreamReader> dr = db.createReader(XMLStreamReader.class);
    assertNotNull(dr);

    Object retValue = dr.read(reader);

    assertNotNull(retValue);
    assertTrue(retValue instanceof GreetMeResponse);
    assertEquals("TestSOAPOutputPMessage", ((GreetMeResponse)retValue).getResponseType());
}
 
Example #7
Source File: XMLStreamDataReaderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private DataReaderImpl<XMLStreamReader> newDataReader(ValidationEventHandler handler) throws Exception {
    JAXBDataBinding db = getDataBinding(GreetMe.class);

    reader = getTestReader("../resources/SetPropertyValidationFailureReq.xml");
    assertNotNull(reader);

    DataReaderImpl<XMLStreamReader> dr = (DataReaderImpl<XMLStreamReader>)db.createReader(XMLStreamReader.class);
    assertNotNull(dr);

    // Build message to set custom event handler
    org.apache.cxf.message.Message message = new org.apache.cxf.message.MessageImpl();
    message.put(JAXBDataBinding.READER_VALIDATION_EVENT_HANDLER, handler);
    message.put("unwrap.jaxb.element", true);

    dr.setProperty("org.apache.cxf.message.Message", message);

    return dr;
}
 
Example #8
Source File: DataReaderImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void setProperty(String prop, Object value) {
    if (prop.equals(JAXBDataBinding.UNWRAP_JAXB_ELEMENT)) {
        unwrapJAXBElement = Boolean.TRUE.equals(value);
    } else if (prop.equals(org.apache.cxf.message.Message.class.getName())) {
        org.apache.cxf.message.Message m = (org.apache.cxf.message.Message)value;
        veventHandler = getValidationEventHandler(m, JAXBDataBinding.READER_VALIDATION_EVENT_HANDLER);
        if (veventHandler == null) {
            veventHandler = databinding.getValidationEventHandler();
        }
        setEventHandler = MessageUtils.getContextualBoolean(m,
                JAXBDataBinding.SET_VALIDATION_EVENT_HANDLER, true);

        Object unwrapProperty = m.get(JAXBDataBinding.UNWRAP_JAXB_ELEMENT);
        if (unwrapProperty == null) {
            unwrapProperty = m.getExchange().get(JAXBDataBinding.UNWRAP_JAXB_ELEMENT);
        }
        if (unwrapProperty != null) {
            unwrapJAXBElement = Boolean.TRUE.equals(unwrapProperty);
        }
    }
}
 
Example #9
Source File: JaxWsServerFactoryBeanTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testJaxbExtraClass() {
    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setBus(getBus());
    sf.setAddress("http://localhost:9000/test");
    sf.setServiceClass(Hello.class);
    sf.setStart(false);
    Map<String, Object> props = sf.getProperties();
    if (props == null) {
        props = new HashMap<>();
    }
    props.put("jaxb.additionalContextClasses",
              new Class[] {DescriptionType.class, DisplayNameType.class});
    sf.setProperties(props);
    Server server = sf.create();
    assertNotNull(server);
    Class<?>[] extraClass = ((JAXBDataBinding)sf.getServiceFactory().getDataBinding()).getExtraClass();
    assertEquals(extraClass.length, 2);
    assertEquals(extraClass[0], DescriptionType.class);
    assertEquals(extraClass[1], DisplayNameType.class);
}
 
Example #10
Source File: ClientFactoryBeanTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testJaxbExtraClass() throws Exception {

    ClientFactoryBean cfBean = new ClientFactoryBean();
    cfBean.setAddress("http://localhost/Hello");
    cfBean.setBus(getBus());
    cfBean.setServiceClass(HelloService.class);
    Map<String, Object> props = cfBean.getProperties();
    if (props == null) {
        props = new HashMap<>();
    }
    props.put("jaxb.additionalContextClasses",
              new Class[] {GreetMe.class, GreetMeOneWay.class});
    cfBean.setProperties(props);
    Client client = cfBean.create();
    assertNotNull(client);
    Class<?>[] extraClass = ((JAXBDataBinding)cfBean.getServiceFactory().getDataBinding())
        .getExtraClass();
    assertEquals(extraClass.length, 2);
    assertEquals(extraClass[0], GreetMe.class);
    assertEquals(extraClass[1], GreetMeOneWay.class);
}
 
Example #11
Source File: ServerFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testJaxbExtraClass() throws Exception {
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello");
    svrBean.setServiceClass(HelloServiceImpl.class);
    svrBean.setBus(getBus());

    Map<String, Object> props = svrBean.getProperties();
    if (props == null) {
        props = new HashMap<>();
    }
    props.put("jaxb.additionalContextClasses",
              new Class[] {GreetMe.class, GreetMeOneWay.class});
    svrBean.setProperties(props);
    Server serv = svrBean.create();
    Class<?>[] extraClass = ((JAXBDataBinding)serv.getEndpoint().getService()
            .getDataBinding()).getExtraClass();
    assertEquals(extraClass.length, 2);
    assertEquals(extraClass[0], GreetMe.class);
    assertEquals(extraClass[1], GreetMeOneWay.class);
}
 
Example #12
Source File: SerializationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeserialization() throws Exception {
    setupClientAndRhino("simple-dlwu-proxy-factory");
    testUtilities.readResourceIntoRhino("/deserializationTests.js");
    DataBinding dataBinding = new JAXBDataBinding(TestBean1.class, TestBean2.class);
    assertNotNull(dataBinding);
    TestBean1 bean = new TestBean1();
    bean.stringItem = "bean1>stringItem";
    bean.doubleItem = -1.0;
    String serialized = serializeObject(dataBinding, bean);
    testUtilities.rhinoCallInContext("deserializeTestBean3_1", serialized);

    bean = new TestBean1();
    bean.stringItem = null;
    bean.intItem = 21;
    bean.longItem = 200000001;
    bean.optionalIntItem = 456123;
    bean.optionalIntArrayItem = new int[4];
    bean.optionalIntArrayItem[0] = 3;
    bean.optionalIntArrayItem[1] = 1;
    bean.optionalIntArrayItem[2] = 4;
    bean.optionalIntArrayItem[3] = 1;
    bean.doubleItem = -1.0;
    serialized = serializeObject(dataBinding, bean);
    testUtilities.rhinoCallInContext("deserializeTestBean3_2", serialized);
}
 
Example #13
Source File: NetSuiteClientService.java    From components with Apache License 2.0 6 votes vote down vote up
/**
 * Remove log-in specific SOAP headers for given port.
 *
 * @param port port
 * @throws NetSuiteException if an error occurs during performing of operation
 */
protected void updateLoginHeaders(PortT port) throws NetSuiteException {
    if (!isUseRequestLevelCredentials()) {
        removeHeader(port, new QName(getPlatformMessageNamespaceUri(), "applicationInfo"));
    } else {
        Object passport = createNativePassport(credentials);
        try {
            if (passport != null) {
                Header passportHeader = new Header(
                        new QName(getPlatformMessageNamespaceUri(), "passport"),
                        passport, new JAXBDataBinding(passport.getClass()));
                setHeader(port, passportHeader);
            }
        } catch (JAXBException e) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.INTERNAL_ERROR),
                    NetSuiteRuntimeI18n.MESSAGES.getMessage("error.binding"), e);
        }
    }
}
 
Example #14
Source File: NetSuiteClientService.java    From components with Apache License 2.0 6 votes vote down vote up
/**
 * Set log-in specific SOAP headers for given port.
 *
 * @param port port
 * @throws NetSuiteException if an error occurs during performing of operation
 */
protected void setLoginHeaders(PortT port) throws NetSuiteException {
    if (!StringUtils.isEmpty(credentials.getApplicationId())) {
        Object applicationInfo = createNativeApplicationInfo(credentials);
        try {
            if (applicationInfo != null) {
                Header appInfoHeader = new Header(
                        new QName(getPlatformMessageNamespaceUri(), "applicationInfo"),
                        applicationInfo, new JAXBDataBinding(applicationInfo.getClass()));
                setHeader(port, appInfoHeader);
            }
        } catch (JAXBException e) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.INTERNAL_ERROR),
                    NetSuiteRuntimeI18n.MESSAGES.getMessage("error.binding"), e);
        }
    }
}
 
Example #15
Source File: NetSuiteClientService.java    From components with Apache License 2.0 6 votes vote down vote up
/**
 * Set preferences for given port.
 *
 * @param port port which to set preferences for
 * @param nsPreferences general preferences
 * @param nsSearchPreferences search preferences
 * @throws NetSuiteException if an error occurs during performing of operation
 */
protected void setPreferences(PortT port,
        NsPreferences nsPreferences, NsSearchPreferences nsSearchPreferences) throws NetSuiteException {

    Object searchPreferences = createNativeSearchPreferences(nsSearchPreferences);
    Object preferences = createNativePreferences(nsPreferences);
    try {
        Header searchPreferencesHeader = new Header(
                new QName(getPlatformMessageNamespaceUri(), "searchPreferences"),
                searchPreferences, new JAXBDataBinding(searchPreferences.getClass()));

        Header preferencesHeader = new Header(
                new QName(getPlatformMessageNamespaceUri(), "preferences"),
                preferences, new JAXBDataBinding(preferences.getClass()));

        setHeader(port, preferencesHeader);
        setHeader(port, searchPreferencesHeader);

    } catch (JAXBException e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.INTERNAL_ERROR),
                NetSuiteRuntimeI18n.MESSAGES.getMessage("error.binding"), e);
    }
}
 
Example #16
Source File: SoapChannel.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void newToken(String token) {
	if (useSoapHeaderSessions) {
		for (PublicInterface p : getServiceInterfaces().values()) {
			List<Header> headers = new ArrayList<Header>();
			try {
				Token tokenObject = new Token(token);
				Header sessionHeader = new Header(new QName("uri:org.bimserver.shared", "token"), tokenObject, new JAXBDataBinding(Token.class));
				headers.add(sessionHeader);
			} catch (JAXBException e) {
				LOGGER.error("", e);
			}
			((BindingProvider) p).getRequestContext().put(Header.HEADER_LIST, headers);
		}
	}
}
 
Example #17
Source File: SwAOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(SoapMessage message) throws Fault {
    Exchange ex = message.getExchange();
    BindingOperationInfo bop = ex.getBindingOperationInfo();
    if (bop == null) {
        return;
    }

    if (bop.isUnwrapped()) {
        bop = bop.getWrappedOperation();
    }

    boolean client = isRequestor(message);
    BindingMessageInfo bmi = client ? bop.getInput() : bop.getOutput();

    if (bmi == null) {
        return;
    }

    SoapBodyInfo sbi = bmi.getExtensor(SoapBodyInfo.class);

    if (sbi == null || sbi.getAttachments() == null || sbi.getAttachments().isEmpty()) {
        Service s = ex.getService();
        DataBinding db = s.getDataBinding();
        if (db instanceof JAXBDataBinding
            && hasSwaRef((JAXBDataBinding) db)) {
            setupAttachmentOutput(message);
        }
        return;
    }
    processAttachments(message, sbi);
}
 
Example #18
Source File: XMLStreamDataWriterTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteWrapper() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(GreetMe.class);

    DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class);
    assertNotNull(dw);

    GreetMe val = new GreetMe();
    val.setRequestType("Hello");

    dw.write(val, streamWriter);
    streamWriter.flush();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLStreamReader xr = inFactory.createXMLStreamReader(bais);
    DepthXMLStreamReader reader = new DepthXMLStreamReader(xr);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "greetMe"),
                 reader.getName());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "requestType"),
                 reader.getName());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("Hello", reader.getText());
}
 
Example #19
Source File: XMLStreamDataWriterTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteWrapperReturn() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(GreetMeResponse.class);

    DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class);
    assertNotNull(dw);

    GreetMeResponse retVal = new GreetMeResponse();
    retVal.setResponseType("TESTOUTPUTMESSAGE");

    dw.write(retVal, streamWriter);
    streamWriter.flush();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLStreamReader xr = inFactory.createXMLStreamReader(bais);
    DepthXMLStreamReader reader = new DepthXMLStreamReader(xr);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse"),
                 reader.getName());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "responseType"),
                 reader.getName());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("TESTOUTPUTMESSAGE", reader.getText());
}
 
Example #20
Source File: XMLStreamDataWriterTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteRPCLit1() throws Exception {
    JAXBDataBinding db = getTestWriterFactory();

    DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class);
    assertNotNull(dw);

    String val = new String("TESTOUTPUTMESSAGE");
    QName elName = new QName("http://apache.org/hello_world_rpclit/types",
                             "in");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    dw.write(val, part, streamWriter);
    streamWriter.flush();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLStreamReader xr = inFactory.createXMLStreamReader(bais);
    DepthXMLStreamReader reader = new DepthXMLStreamReader(xr);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_rpclit/types", "in"),
                 reader.getName());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("TESTOUTPUTMESSAGE", reader.getText());
}
 
Example #21
Source File: XMLStreamDataWriterTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteWithNamespacePrefixMapping() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(GreetMe.class);
    Map<String, String> nspref = new HashMap<>();
    nspref.put("http://apache.org/hello_world_soap_http/types", "x");
    db.setNamespaceMap(nspref);

    // use the output stream instead of XMLStreamWriter to test
    DataWriter<OutputStream> dw = db.createWriter(OutputStream.class);
    assertNotNull(dw);

    GreetMe val = new GreetMe();
    val.setRequestType("Hello");
    dw.write(val, baos);

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLStreamReader xr = inFactory.createXMLStreamReader(bais);
    DepthXMLStreamReader reader = new DepthXMLStreamReader(xr);
    StaxUtils.toNextElement(reader);
    QName qname = reader.getName();
    assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "greetMe"), qname);
    assertEquals("x", qname.getPrefix());

    assertEquals(1, reader.getNamespaceCount());
    assertEquals("http://apache.org/hello_world_soap_http/types", reader.getNamespaceURI(0));
    assertEquals("x", reader.getNamespacePrefix(0));

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextElement(reader);
    qname = reader.getName();
    assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "requestType"), qname);
    assertEquals("x", qname.getPrefix());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("Hello", reader.getText());
}
 
Example #22
Source File: IncomingSoapRequestMessageTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void shouldHandleMessageWithoutTraceeHeader() throws JAXBException {
	final Map<String, String> contextMap = new HashMap<>();
	contextMap.put("mySoapKey", "mySoapContextValue");
	soapMessage.getHeaders().add(new Header(new QName(TraceeConstants.SOAP_HEADER_NAMESPACE, "SOME_OTHER"), contextMap, new JAXBDataBinding(HashMap.class)));

	inInterceptor.handleMessage(soapMessage);
	assertThat(backend.copyToMap(), not(hasKey("mySoapKey")));

	when(soapMessage.getExchange()).thenReturn(mock(Exchange.class));
}
 
Example #23
Source File: AbstractTraceeOutInterceptor.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addSoapHeader(Map<String, String> filteredParams, SoapMessage soapMessage) {
	try {
		final Header tpicHeader = new Header(TraceeConstants.SOAP_HEADER_QNAME, TpicMap.wrap(filteredParams),
			new JAXBDataBinding(TpicMap.class));
		soapMessage.getHeaders().add(tpicHeader);
	} catch (JAXBException e) {
		LOGGER.warn("Error occured during TracEE soap header creation: {}", e.getMessage());
		LOGGER.debug("Detailed exception", e);
	}
}
 
Example #24
Source File: RPCOutInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();
    ServiceInfo si = getMockedServiceModel(this.getClass()
                                           .getResource("/wsdl_soap/hello_world_rpc_lit.wsdl")
            .toString());
    BindingInfo bi = si.getBinding(new QName(TNS, "Greeter_SOAPBinding_RPCLit"));
    BindingOperationInfo boi = bi.getOperation(new QName(TNS, OPNAME));
    boi.getOperationInfo().getOutput().getMessagePartByIndex(0).setIndex(0);
    soapMessage.getExchange().put(BindingOperationInfo.class, boi);

    control.reset();
    Service service = control.createMock(Service.class);
    EasyMock.expect(service.isEmpty()).andReturn(true).anyTimes();
    JAXBDataBinding dataBinding = new JAXBDataBinding(MyComplexStruct.class);
    service.getDataBinding();
    EasyMock.expectLastCall().andReturn(dataBinding).anyTimes();
    service.getServiceInfos();
    List<ServiceInfo> list = Arrays.asList(si);
    EasyMock.expectLastCall().andReturn(list).anyTimes();

    soapMessage.getExchange().put(Service.class, service);
    soapMessage.getExchange().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE);
    control.replay();

    MyComplexStruct mcs = new MyComplexStruct();
    mcs.setElem1("elem1");
    mcs.setElem2("elem2");
    mcs.setElem3(45);
    MessageContentsList param = new MessageContentsList();
    param.add(mcs);
    soapMessage.setContent(List.class, param);
}
 
Example #25
Source File: AttributeTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeserialization() throws Exception {
    setupClientAndRhino("attribute-test-proxy-factory");
    testUtilities.readResourceIntoRhino("/attributeTests.js");
    DataBinding dataBinding = new JAXBDataBinding(AttributeTestBean.class);
    assertNotNull(dataBinding);
    AttributeTestBean bean = new AttributeTestBean();
    bean.element1 = "e1";
    bean.element2 = "e2";
    bean.attribute1 = "a1";
    bean.attribute2 = "a2";

    String serialized = serializeObject(dataBinding, bean);
    testUtilities.rhinoCallInContext("deserializeAttributeTestBean", serialized);
}
 
Example #26
Source File: RPCInInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();
    ServiceInfo si = getMockedServiceModel(this.getClass()
                                           .getResource("/wsdl_soap/hello_world_rpc_lit.wsdl")
            .toString());
    BindingInfo bi = si.getBinding(new QName(TNS, "Greeter_SOAPBinding_RPCLit"));
    BindingOperationInfo boi = bi.getOperation(new QName(TNS, OPNAME));
    boi.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(MyComplexStruct.class);
    boi.getOperationInfo().getInput().getMessagePartByIndex(0).setIndex(1);
    boi.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(MyComplexStruct.class);
    boi.getOperationInfo().getOutput().getMessagePartByIndex(0).setIndex(0);
    soapMessage.getExchange().put(BindingOperationInfo.class, boi);

    control.reset();
    Service service = control.createMock(Service.class);
    JAXBDataBinding dataBinding = new JAXBDataBinding(MyComplexStruct.class);
    service.getDataBinding();
    EasyMock.expectLastCall().andReturn(dataBinding).anyTimes();
    service.getServiceInfos();
    List<ServiceInfo> list = Arrays.asList(si);
    EasyMock.expectLastCall().andReturn(list).anyTimes();
    EasyMock.expect(service.isEmpty()).andReturn(true).anyTimes();

    soapMessage.getExchange().put(Service.class, service);
    soapMessage.getExchange().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE);
    control.replay();
}
 
Example #27
Source File: MAPCodec.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Encodes an MAP as a SOAP header.
 *
 * @param message the message to store the headers on
 * @param value the value to encode
 * @param qname the QName for the header
 * @param clz the class
 * @param ctx the JAXBContent
 * @param mustUnderstand
 */
protected <T> void encodeMAP(SoapMessage message,
                             T value,
                             QName qname,
                             Class<T> clz,
                             JAXBContext ctx,
                             boolean mustUnderstand) throws JAXBException {
    JAXBDataBinding jaxbDataBinding = new JAXBDataBinding(ctx);
    SoapHeader h = new SoapHeader(qname, new JAXBElement<T>(qname, clz, value),
                                  jaxbDataBinding);
    h.setMustUnderstand(mustUnderstand);
    message.getHeaders().add(h);
}
 
Example #28
Source File: TestBase.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void common(String wsdl, QName portName, Class<?>... jaxbClasses) throws Exception {
    Bus bus = BusFactory.getDefaultBus();

    WSDLManagerImpl manager = new WSDLManagerImpl();
    XMLWSDLExtensionLoader.registerExtensors(manager);

    assertNotNull(bus.getExtension(WSDLManager.class));

    WSDLServiceFactory factory =
        new WSDLServiceFactory(bus, getClass().getResource(wsdl).toString(),
                               new QName(portName.getNamespaceURI(), "XMLService"));

    org.apache.cxf.service.Service service = factory.create();

    EndpointInfo epi = service.getEndpointInfo(portName);
    assertNotNull(epi);
    serviceInfo = epi.getService();

    JAXBDataBinding db = new JAXBDataBinding();
    db.initialize(service);
    db.setContext(JAXBContext.newInstance(jaxbClasses));
    service.setDataBinding(db);

    Endpoint endpoint = new EndpointImpl(bus, service, epi);

    xmlMessage.getExchange().put(Endpoint.class, endpoint);
    xmlMessage.getExchange().put(org.apache.cxf.service.Service.class, service);
}
 
Example #29
Source File: XMLStreamDataWriterTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteRPCLit2() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(MyComplexStruct.class);

    DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class);
    assertNotNull(dw);

    MyComplexStruct val = new MyComplexStruct();
    val.setElem1("This is element 1");
    val.setElem2("This is element 2");
    val.setElem3(1);

    QName elName = new QName("http://apache.org/hello_world_rpclit/types",
                             "in");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);

    dw.write(val, part, streamWriter);
    streamWriter.flush();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLStreamReader xr = inFactory.createXMLStreamReader(bais);
    DepthXMLStreamReader reader = new DepthXMLStreamReader(xr);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_rpclit/types", "in"),
                 reader.getName());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_rpclit/types", "elem1"),
                 reader.getName());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("This is element 1", reader.getText());
}
 
Example #30
Source File: NetSuiteClientService.java    From components with Apache License 2.0 5 votes vote down vote up
public void setBodyFieldsOnly(boolean bodyFieldsOnly) {
    this.bodyFieldsOnly = bodyFieldsOnly;
    searchPreferences.setBodyFieldsOnly(bodyFieldsOnly);
    Object searchPreferencesObject = createNativeSearchPreferences(searchPreferences);
    try {
        Header searchPreferencesHeader = new Header(
                new QName(getPlatformMessageNamespaceUri(), "searchPreferences"),
                searchPreferencesObject, new JAXBDataBinding(searchPreferencesObject.getClass()));
        setHeader(port, searchPreferencesHeader);
    } catch (JAXBException e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.INTERNAL_ERROR),
                NetSuiteRuntimeI18n.MESSAGES.getMessage("error.binding"), e);
    }
}