English 中文(简体)
Jaxb2Marshaller and primitive types
原标题:

Is it possible to create a web service operation using primitive or basic Java types when using the Jaxb2Marschaller in spring-ws? For example a method looking like this:

@Override
@PayloadRoot(localPart = "AddTaskRequest", namespace = "http://example.com/examplews/")
public long addTask(final Task task) throws AddTaskFault {
 // do something
 return 0;
}

I am using the maven jaxws plugin to generate the interface and model classes from my WSDL. When I try to call the webservice I get the following error:

java.lang.IllegalStateException: No adapter for endpoint [...]: Does your endpoint implement a supported interface like MessageHandler or PayloadEndpoint

I found out that if I change the method to that:

@Override
@PayloadRoot(localPart = "AddTaskRequest", namespace = "http://example.com/examplews/")
public JAXBElement<Long> addTask(final JAXBElement<Task> task) throws AddTaskFault {
 final ObjectFactory objectFactory = new ObjectFactory();
 return objectFactory.createAddTaskResponse(0L);
}

I am able to call it - but this signature is not compatible with the interface generated by the maven jaxws plugin.

What can I do to configure either spring-ws to be able to use the first kind of implementation or to tell maven jaxws plugin to generate the second variant of the interface?

UPDATE: My relevant spring-ws config entries look like that:

<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
 <property name="contextPath" value="com.example.examplews" />
</bean>

<bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
 <constructor-arg ref="marshaller" />
</bean>

<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
 <property name="order" value="1" />
</bean>
最佳回答

When Spring-WS is trying to match an EndpointAdapter to an Endpoint, it checks that all of the parameters of the endpoint method, plus its return value, are types known to the Jaxb2Marshaller, and long will not. Conceptually, this makes sense, since JAXB would have no idea how to turn a long into XML without more information (which is where JAXBElement comes in).

You should realise that Spring-WS is not a JAX-WS implementation, and makes no pretense to be. You can t really expect to take JAX-WS-generated artifacts and expect them just to work in Spring_WS, although in many cases Spring-WS is flexible enough to deal with it.

问题回答

Here is everything relevant in my config as I can t really tell what you could change, they are rather different and it has been a year and a half since i did this.

    <bean id="schemaCollection"
        class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
        <property name="xsds" value="/my.xsd" />
        <property name="inline" value="true" />
    </bean>

    <bean id="marshallingEndpoint"
        class="....EndpointImpl">
    </bean>

    <oxm:jaxb2-marshaller id="marshaller" contextPath=".....schema" />

   <bean id="annotationMapping"      class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
        <property name="interceptors">
            <list>
                <bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
                <bean class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
                    <property name="xsdSchemaCollection"
                        ref="schemaCollection" />
                    <property name="validateRequest" value="true" />
                    <property name="validateResponse" value="true" />
                </bean>
            </list>
        </property>
        <property name="order" value="1" />
    </bean>

    <sws:marshalling-endpoints />

Hope it helps in some way. The Endpoint class had @Endpoint, the methods @PayloadRoot. They didn t return long, but I didn t have to wrap my class in the JAXBElement either.

[edit] namespaces

    xmlns:oxm="http://www.springframework.org/schema/oxm"
    xmlns:sws="http://www.springframework.org/schema/web-services"

    xsi:schemaLocation="
       http://www.springframework.org/schema/oxm 
       http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签