Sure :)
Here's the code:
public SOAPMessage invoke(SOAPMessage message) {
SOAPMessage returnMessage = null;
try {
MessageFactory mf = MessageFactory.newInstance();
returnMessage = mf.createMessage();
SOAPFactory f = SOAPFactory.newInstance();
SOAPElement test = f.createElement("processResponse","ns1", "http://www.acme.com/sys/schemas");
test.addNamespaceDeclaration("ns2","http://www.acme.com/sys/definitions");
test.appendChild(createResponseContent());
SOAPBody body = returnMessage.getSOAPBody();
body.addChildElement(test);
} catch (SOAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return returnMessage;
}
private Element createResponseContent() throws Exception{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element ret = doc.createElement("return");
Element id = doc.createElement("id");
id.appendChild(doc.createTextNode("1"));
Element message = doc.createElement("message");
message.appendChild(doc.createTextNode("comando recebido"));
ret.appendChild(id);
ret.appendChild(message);
return ret;
}
What I'd like to return is :
<ns1:processResponse xmlns:ns1="http://www.acme.com/sys/schemas">
</ns1:processResponse>
Here's the stack trace:
10:45:12,569 ERROR [STDERR] org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
10:45:12,570 ERROR [STDERR] at org.apache.xerces.dom.ElementNSImpl.setName(Unknown Source)
10:45:12,570 ERROR [STDERR] at org.apache.xerces.dom.ElementNSImpl.<init>(Unknown Source)
10:45:12,570 ERROR [STDERR] at org.apache.xerces.dom.CoreDocumentImpl.createElementNS(Unknown Source)
10:45:12,570 ERROR [STDERR] at org.jboss.wsf.common.DOMUtils.createElement(DOMUtils.java:202)
10:45:12,571 ERROR [STDERR] at org.jboss.ws.core.soap.SOAPElementImpl.<init>(SOAPElementImpl.java:84)
10:45:12,571 ERROR [STDERR] at org.jboss.ws.core.soap.SOAPFactoryImpl.createElement(SOAPFactoryImpl.java:95)
10:45:12,571 ERROR [STDERR] at org.jboss.ws.core.soap.SOAPFactoryImpl.createElement(SOAPFactoryImpl.java:122)
10:45:12,571 ERROR [STDERR] at org.jboss.ws.core.soap.SOAPFactoryImpl.createElement(SOAPFactoryImpl.java:101)
10:45:12,571 ERROR [STDERR] at org.jboss.ws.core.soap.NodeImpl.convertDOMNode(NodeImpl.java:563)
10:45:12,571 ERROR [STDERR] at org.jboss.ws.core.soap.NodeImpl.appendChild(NodeImpl.java:459)
10:45:12,571 ERROR [STDERR] at com.acme.sys.services.provider.CommandProcessorMessage.invoke(CommandProcessorMessage.java:38)
10:45:12,571 ERROR [STDERR] at com.acme.sys.services.provider.CommandProcessorMessage.invoke(CommandProcessorMessage.java:1)
10:45:12,571 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:45:12,571 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
10:45:12,571 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
10:45:12,571 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
10:45:12,571 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
10:45:12,571 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
10:45:12,571 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
10:45:12,571 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
10:45:12,571 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
10:45:12,571 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
10:45:12,571 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
10:45:12,571 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
10:45:12,571 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
10:45:12,571 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
10:45:12,571 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
10:45:12,571 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
10:45:12,572 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
10:45:12,572 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
10:45:12,572 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
10:45:12,572 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
10:45:12,572 ERROR [STDERR] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
10:45:12,572 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
10:45:12,572 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
10:45:12,572 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
10:45:12,572 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
10:45:12,572 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
10:45:12,572 ERROR [STDERR] at org.jboss.wsf.container.jboss42.InvocationHandlerEJB3.invoke(InvocationHandlerEJB3.java:103)
10:45:12,572 ERROR [STDERR] at org.jboss.ws.core.server.ServiceEndpointInvoker.invoke(ServiceEndpointInvoker.java:220)
10:45:12,572 ERROR [STDERR] at org.jboss.wsf.stack.jbws.RequestHandlerImpl.processRequest(RequestHandlerImpl.java:408)
10:45:12,572 ERROR [STDERR] at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHandlerImpl.java:272)
10:45:12,572 ERROR [STDERR] at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl.java:189)
10:45:12,572 ERROR [STDERR] at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:122)
10:45:12,572 ERROR [STDERR] at org.jboss.wsf.stack.jbws.EndpointServlet.service(EndpointServlet.java:84)
10:45:12,572 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
10:45:12,572 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
10:45:12,572 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
10:45:12,572 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
10:45:12,572 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
10:45:12,572 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
10:45:12,573 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
10:45:12,573 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
10:45:12,573 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
10:45:12,573 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
10:45:12,573 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
10:45:12,573 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
10:45:12,573 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
10:45:12,573 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
10:45:12,573 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
10:45:12,573 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
10:45:12,574 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
10:45:12,574 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
10:45:12,574 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
Regards