Java: Get Sample Request XML from wsdl - java

Is there any way one could get the sample request xml using the wsdl(url) alone?
Here is a sample wsdl: http://www.webservicemart.com/uszip.asmx?WSDL
Sample Request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ws="http://webservicemart.com/ws/">
<soapenv:Header/>
<soapenv:Body>
<ws:ValidateZip>
<!--Optional:-->
<ws:ZipCode>?</ws:ZipCode>
</ws:ValidateZip>
</soapenv:Body>
</soapenv:Envelope>
I know there are tools out there like SOAPUI and others which could do this. But is there any other way without using these tools once could achieve it using java?
Using wsimport would be one option that would get me the java source, this is more static. Is there a dynamic way to do this?
Exception encountered:
18:57:59,677 WARN [SoapUI] Missing folder [D:\TestAutomation\Z_ZZLastResort\.\ext] for external libraries
18:57:59,920 INFO [DefaultSoapUICore] initialized soapui-settings from [C:\Users\mike\soapui-settings.xml]
Progress: 1 - Caching Definition from url [http://www.webservicemart.com/uszip.asmx?WSDL]
18:58:00,587 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/xop.xsd with targetNamespace http://www.w3.org/2004/08/xop/include
18:58:00,625 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/XMLSchema.xsd with targetNamespace http://www.w3.org/2001/XMLSchema
18:58:00,627 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/xml.xsd with targetNamespace http://www.w3.org/XML/1998/namespace
18:58:00,628 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/swaref.xsd with targetNamespace http://ws-i.org/profiles/basic/1.1/xsd
18:58:00,629 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/xmime200505.xsd with targetNamespace http://www.w3.org/2005/05/xmlmime
18:58:00,637 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/xmime200411.xsd with targetNamespace http://www.w3.org/2004/11/xmlmime
18:58:00,638 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/soapEnvelope.xsd with targetNamespace http://schemas.xmlsoap.org/soap/envelope/
18:58:00,641 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/soapEncoding.xsd with targetNamespace http://schemas.xmlsoap.org/soap/encoding/
18:58:00,643 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/soapEnvelope12.xsd with targetNamespace http://www.w3.org/2003/05/soap-envelope
18:58:00,645 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/soapEncoding12.xsd with targetNamespace http://www.w3.org/2003/05/soap-encoding
Progress: 2 - Loading [http://www.webservicemart.com/uszip.asmx?WSDL]
18:58:00,648 DEBUG [WsdlLoader] Getting wsdl component from [http://www.webservicemart.com/uszip.asmx?WSDL]
18:58:01,073 DEBUG [HttpClientSupport$SoapUIHttpClient] Attempt 1 to execute request
18:58:01,074 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Sending request: GET /uszip.asmx?WSDL HTTP/1.1
18:58:01,314 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Connection closed
18:58:01,314 DEBUG [HttpClientSupport$SoapUIHttpClient] Closing the connection.
18:58:01,314 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Connection closed
18:58:01,314 INFO [HttpClientSupport$SoapUIHttpClient] I/O exception (java.net.SocketException) caught when processing request: Connection reset
18:58:01,316 DEBUG [HttpClientSupport$SoapUIHttpClient] Connection reset
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:149)
at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:110)
at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:264)
at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:98)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:252)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:281)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:247)
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:219)
at com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport$SoapUIHttpRequestExecutor.doReceiveResponse(HttpClientSupport.java:133)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:633)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:454)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at com.eviware.soapui.impl.wsdl.support.wsdl.UrlWsdlLoader$LoaderWorker.construct(UrlWsdlLoader.java:226)
at com.eviware.soapui.impl.wsdl.support.wsdl.UrlWsdlLoader.load(UrlWsdlLoader.java:138)
at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlLoader.loadXmlObject(WsdlLoader.java:121)
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getDefinitionParts(SchemaUtils.java:535)
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getDefinitionParts(SchemaUtils.java:524)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionCache.update(AbstractDefinitionCache.java:97)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext$Loader.construct(AbstractDefinitionContext.java:226)
at com.eviware.soapui.support.swing.SwingWorkerDelegator.construct(SwingWorkerDelegator.java:46)
at com.eviware.soapui.support.swing.SwingWorker$2.run(SwingWorker.java:149)
at java.lang.Thread.run(Unknown Source)
18:58:01,319 INFO [HttpClientSupport$SoapUIHttpClient] Retrying request
18:58:01,319 DEBUG [HttpClientSupport$SoapUIHttpClient] Reopening the direct connection.
18:58:01,602 DEBUG [HttpClientSupport$SoapUIHttpClient] Attempt 2 to execute request
18:58:01,602 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Sending request: GET /uszip.asmx?WSDL HTTP/1.1
18:58:02,200 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Receiving response: HTTP/1.1 200 OK
18:58:02,210 DEBUG [HttpClientSupport$SoapUIHttpClient] Connection can be kept alive indefinitely
Progress: 1 - Loading Definition from url
18:58:02,260 DEBUG [AbstractDefinitionContext] Loading Definition...
18:58:02,277 DEBUG [WsdlInterfaceDefinition] Loading WSDL: http://www.webservicemart.com/uszip.asmx?WSDL
18:58:02,277 DEBUG [AbstractWsdlDefinitionLoader] Returning baseInputSource [http://www.webservicemart.com/uszip.asmx?WSDL]
Retrieving document at 'http://www.webservicemart.com/uszip.asmx?WSDL'.
18:58:02,347 INFO [SchemaUtils] Loading schema types from [http://www.webservicemart.com/uszip.asmx?WSDL]
18:58:02,347 INFO [SchemaUtils] Getting schema http://www.webservicemart.com/uszip.asmx?WSDL
18:58:02,357 ERROR [SoapUI] An error occured [org.apache.xmlbeans.impl.xb.xsdschema.impl.SchemaDocumentImpl], see error log for details
java.lang.ArrayStoreException: org.apache.xmlbeans.impl.xb.xsdschema.impl.SchemaDocumentImpl
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getSchemas(SchemaUtils.java:418)
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getSchemas(SchemaUtils.java:327)
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.loadSchemaTypes(SchemaUtils.java:192)
at com.eviware.soapui.impl.support.definition.support.XmlSchemaBasedInterfaceDefinition.loadSchemaTypes(XmlSchemaBasedInterfaceDefinition.java:79)
at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlInterfaceDefinition.load(WsdlInterfaceDefinition.java:61)
at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext.loadDefinition(WsdlContext.java:66)
at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext.loadDefinition(WsdlContext.java:30)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext.cacheDefinition(AbstractDefinitionContext.java:268)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext.access$400(AbstractDefinitionContext.java:44)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext$Loader.construct(AbstractDefinitionContext.java:235)
at com.eviware.soapui.support.swing.SwingWorkerDelegator.construct(SwingWorkerDelegator.java:46)
at com.eviware.soapui.support.swing.SwingWorker$2.run(SwingWorker.java:149)
at java.lang.Thread.run(Unknown Source)
18:58:02,359 ERROR [SoapUI] An error occured [com.eviware.soapui.impl.wsdl.support.xsd.SchemaException], see error log for details
com.eviware.soapui.impl.wsdl.support.xsd.SchemaException
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getSchemas(SchemaUtils.java:512)
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getSchemas(SchemaUtils.java:327)
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.loadSchemaTypes(SchemaUtils.java:192)
at com.eviware.soapui.impl.support.definition.support.XmlSchemaBasedInterfaceDefinition.loadSchemaTypes(XmlSchemaBasedInterfaceDefinition.java:79)
at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlInterfaceDefinition.load(WsdlInterfaceDefinition.java:61)
at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext.loadDefinition(WsdlContext.java:66)
at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext.loadDefinition(WsdlContext.java:30)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext.cacheDefinition(AbstractDefinitionContext.java:268)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext.access$400(AbstractDefinitionContext.java:44)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext$Loader.construct(AbstractDefinitionContext.java:235)
at com.eviware.soapui.support.swing.SwingWorkerDelegator.construct(SwingWorkerDelegator.java:46)
at com.eviware.soapui.support.swing.SwingWorker$2.run(SwingWorker.java:149)
at java.lang.Thread.run(Unknown Source)
18:58:02,360 ERROR [SoapUI] An error occured [com.eviware.soapui.impl.wsdl.support.xsd.SchemaException], see error log for details
com.eviware.soapui.impl.wsdl.support.xsd.SchemaException
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getSchemas(SchemaUtils.java:512)
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getSchemas(SchemaUtils.java:327)
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.loadSchemaTypes(SchemaUtils.java:192)
at com.eviware.soapui.impl.support.definition.support.XmlSchemaBasedInterfaceDefinition.loadSchemaTypes(XmlSchemaBasedInterfaceDefinition.java:79)
at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlInterfaceDefinition.load(WsdlInterfaceDefinition.java:61)
at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext.loadDefinition(WsdlContext.java:66)
at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext.loadDefinition(WsdlContext.java:30)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext.cacheDefinition(AbstractDefinitionContext.java:268)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext.access$400(AbstractDefinitionContext.java:44)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext$Loader.construct(AbstractDefinitionContext.java:235)
at com.eviware.soapui.support.swing.SwingWorkerDelegator.construct(SwingWorkerDelegator.java:46)
at com.eviware.soapui.support.swing.SwingWorker$2.run(SwingWorker.java:149)
at java.lang.Thread.run(Unknown Source)
18:58:02,363 ERROR [AbstractDefinitionContext] Error loading schema types from http://www.webservicemart.com/uszip.asmx?WSDL, see log for details
18:58:35,061 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Connection closed

SOAPUI also provide java API to create request/response
public class SOAPInputGenerator {
public static void main(String[] args) throws Exception {
WsdlProject project = new WsdlProject();
WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://localhost:7000/Solicitud?wsdl");
WsdlInterface wsdl = wsdls[0];
for (Operation operation : wsdl.getOperationList()) {
WsdlOperation wsdlOperation = (WsdlOperation) operation;
System.out.println("OP:"+wsdlOperation.getName());
System.out.println("Request:");
System.out.println(wsdlOperation.createRequest(true));
System.out.println("Response:");
System.out.println(wsdlOperation.createResponse(true));
}
}
}
JAR location for SOAP UI libraries
http://www.soapui.org/repository/eviware/jars/
If you don't want use SOAPUI directly , you may find reficio which would be very useful.
Subset of SoapUI library API with example can be find here
https://github.com/reficio/soap-ws
http://www.reficio.org/projects/
This is an open-source project to support SOAP in a purely XML way in Java

You can create the client side stubs using wsimport tool and use jaxb to convert your request object to SOAP xml.

Related

Jersey, An I/O error has occurred while writing a response message

I use SpringBoot and Jersey into my project and I often tackle the following error :
[ERROR - ServerRuntime$Responder - 2018-02-13 13:16:45,983] An I/O error has occurred while writing a response message entity to the container output stream.
org.glassfish.jersey.server.internal.process.MappableException: org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:92)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130)
at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:711)
at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434)
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:329)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
It results with a 503 status response to my client.
Could you explain me why this error occured ?
Thanks
This kind of error usually happens servlet is writing data back on the stream and connection closed from client side.
It is like server in sending some data may be file, string, bytes etc.. but on client side like a browser has closed the connection, like you close the browser tab.
It cased early End of file exception on the server.
I have had this exception when I accidentally passed a null Response at the end of a call. You can verify this in the'caused by' section following the first exception:
Caused by: org.eclipse.jetty.io.EofException: null

Spring Oauth2 RemoteTokenServices error on extractAuthentication

I have a resource server and an auth server.
On resource request it verifies the received access_token with the auth server on a /oauth/check_token endpoint. This gives a response that makes my request crash.
The response is sent as:
Written [{exp=1433335640, scope=[read, write], authorities=[ROLE_USER], client_id=client-w-s}] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter#58a88f5a]
When my resource server receives it:
2015-06-03 14:17:48.277 DEBUG 9492 --- [nio-8181-exec-3] o.s.web.client.RestTemplate : POST request for "http://localhost:6707/oauth/check_token" resulted in 200 (OK)
2015-06-03 14:17:48.277 DEBUG 9492 --- [nio-8181-exec-3] o.s.web.client.RestTemplate : Reading [interface java.util.Map] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter#67409450]
2015-06-03 14:17:48.283 ERROR 9492 --- [nio-8181-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
java.lang.ArrayStoreException: null
at java.util.ArrayList.toArray(Unknown Source)
at org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter.extractAuthentication(DefaultAccessTokenConverter.java:139)
This is the piece of code it fails on:
Collection<? extends GrantedAuthority> authorities = null;
if (user==null && map.containsKey(AUTHORITIES)) {
#SuppressWarnings("unchecked")
String[] roles = ((Collection<String>)map.get(AUTHORITIES)).toArray(new String[0]);
authorities = AuthorityUtils.createAuthorityList(roles);
}
I ran in debug mode to check the values in map, and everything looks like I think it should judging from the response my auth server built.
Please tell me if I need to post more information.
Has anyone experienced this or have any clue on how to solve it?
I found the "solution".
There was a version mismatch in my pom files. While my auth server was running spring-security-oauth2-2.0.5.RELEASE my resource server was running spring-security-oauth2-2.0.7.RELEASE .
The versions declare the response differently.
I think there is an error in DefaultAccessTokenConverter implementation, since spring-security-oauth2 2.0.7.RELEASE, because of this line:
if (user==null && map.containsKey(AUTHORITIES)) {
...
}
Why the "user==null" condition?
The "user" variable isn't null, so the condition is never true, and the authorities array is not filled.
I think this is a Spring Security Oauth2 implementation error.

Trigger 2 spring integration in different server but with 1 same file polling folder

I am using int-file:inbound-channel-adapter to process the file.
I got 2 int-file:inbound-channel-adapter in 2 difference server but polling same folder.
2 listener will listen to 1 same server folder. Listener 1 not able to process the message because it had been processed by listener 2. Errors shown as below.
Listener 1 :-
2014-12-20 22:15:27.608 [task-scheduler-3] DEBUG org.springframework.integration.file.FileReadingMessageSource - Added to queue: [/folder/101.txt]
2014-12-20 22:15:27.715 [task-scheduler-3] DEBUG org.springframework.integration.file.FileWritingMessageHandler - org.springframework.integration.file.FileWritingMessageHandler#502a3135 received message: [Payload=/folder/101.txt][Headers={timestamp=1419084927715, id=f5bb68b3-0eac-40a6-8fcf-8ba54fc295af}]
2014-12-20 22:15:27.724 [task-scheduler-3] INFO org.springframework.integration.file.FileWritingMessageHandler - Failed to move file '/folder/101.txt'. Using copy and delete fallback.
Listener 2 :-
2014-12-20 22:15:27.585 [task-scheduler-6] DEBUG org.springframework.integration.file.FileReadingMessageSource - Added to queue: [/folder/101.txt]
2014-12-20 22:15:27.711 [task-scheduler-6] DEBUG org.springframework.integration.file.FileWritingMessageHandler - org.springframework.integration.file.FileWritingMessageHandler#1447034b received message: [Payload=/folder/101.txt][Headers={timestamp=1419084927710, id=2177d3cd-fbd9-4412-98d1-48ce84874b53}]
So what i suspect is the initiate both of the listener's payload message got the file. But after 1 of the listener processed the file already, second listener unable will hit error.
Part of the code like below:-
<int-file:inbound-channel-adapter id="Id1" directory="/folder" prevent-duplicates="false">
<int:poller id="poller" fixed-rate="10000" max-messages-per-poll="1" />
</int-file:inbound-channel-adapter>
<int-file:outbound-gateway
request-channel="Id1" reply-channel="Id1Processing"
directory="/folder/backup}" delete-source-files="true"/>
Appreciate someone can help. Thanks.
Let me guess: you don't want to process the same file on the second server to avoid that error. For this purpose you should use FileSystemPersistentAcceptOnceFileListFilter as a reference to the filter of the <int-file:inbound-channel-adapter>. Consider to use some out-of-the-box MetadataStore or implement your own one.

Using MTOM with StreamingAttachment - failing on jetty start

please advise!
Defined on server side:
/////////////////
#StreamingAttachment(parseEagerly=true)
#MTOM(threshold=10000000 )
/////////////////
Everything compiles with no errors.
When jetty is started, below error is shown:
2012-05-16 04:31:48.403::INFO: jetty-6.1.4
SEVERE : May 16, 2012 4:31:49 AM: WSSERVLET11: failed to parse runtime descriptor: javax.xml.ws.WebServiceException: Annotation #com.sun.xml.internal.ws.developer.Str
mingAttachment(parseEagerly=true, dir=, memoryThreshold=1048576) is not recognizable, atleast one constructor of class com.sun.xml.internal.ws.developer.StreamingAtta
mentFeature should be marked with #FeatureConstructor (com.sun.xml.ws.transport.http.servlet.WSServletContextListener::contextInitialized)
javax.xml.ws.WebServiceException: Annotation #com.sun.xml.internal.ws.developer.StreamingAttachment(parseEagerly=true, dir=, memoryThreshold=1048576) is not cognizable, atleast one constructor of class com.sun.xml.internal.ws.developer.StreamingAttachmentFeature should be marked with #FeatureConstructor

Error occurred while buffering incoming SOAP message using Metro client

I am using Metro 2 client to consume the "Secure wcf web service in Java". But Metro client does not gives any response and stay in hang mode after very long time it produce the output as an error:
Stack Trace:
SEVERE: WSSMSG0001: Error occurred while buffering incoming SOAP message.
com.ctc.wstx.exc.WstxParsingException: Illegal character entity: expansion character (code 0x1a
at [row,col {unknown-source}]: [1,6396222]
at com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:606)
at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:479)
at com.ctc.wstx.sr.StreamScanner.reportIllegalChar(StreamScanner.java:2442)
at com.ctc.wstx.sr.StreamScanner.validateChar(StreamScanner.java:2389)
at com.ctc.wstx.sr.StreamScanner.resolveCharEnt(StreamScanner.java:2355)
at com.ctc.wstx.sr.StreamScanner.fullyResolveEntity(StreamScanner.java:1501)
at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2726)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1065)
at com.sun.xml.ws.util.xml.XMLStreamReaderToXMLStreamWriter.bridge(XMLStreamReaderToXMLStreamWriter.java:142)
at com.sun.xml.ws.message.stream.StreamMessage.writePayloadTo(StreamMessage.java:376)
at com.sun.xml.ws.message.stream.StreamMessage.writeEnvelope(StreamMessage.java:412)
at com.sun.xml.ws.message.stream.StreamMessage.writeTo(StreamMessage.java:390)
at com.sun.xml.ws.security.message.stream.LazyStreamBasedMessage.readMessage(LazyStreamBasedMessage.java:476)
at com.sun.xml.wss.jaxws.impl.SecurityTubeBase.verifyInboundMessage(SecurityTubeBase.java:444)
at com.sun.xml.wss.jaxws.impl.SecurityClientTube.processClientResponsePacket(SecurityClientTube.java:434)
at com.sun.xml.wss.jaxws.impl.SecurityClientTube.processResponse(SecurityClientTube.java:362)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:972)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:910)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:873)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:775)
at com.sun.xml.ws.client.Stub.process(Stub.java:429)
at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:168)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:102)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:151)
at $Proxy44.pullCustomers(Unknown Source)
at com.tekriti.client.Client.test(Client.java:106)
at com.tekriti.client.Client.main(Client.java:44)
com.sun.xml.ws.encoding.soap.DeserializationException: Failed to read a response: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.stream.XMLStreamException: Internal XSB error: Invalid State=0]
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:141)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:102)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:151)
at $Proxy44.pullCustomers(Unknown Source)
at com.tekriti.client.Client.test(Client.java:106)
at com.tekriti.client.Client.main(Client.java:44)
Caused by: javax.xml.bind.UnmarshalException
I am trying to fix this issue but no luck, Metro client is unable to parse the SOAP response in a correct way. I don't know where I am doing mistake or I have to use something else.
I am using Netbeans 7.1 and Metro 2.2.
Please give your suggestions or if you had such problem in your past please do share with me.
updated:
This is working fine:
Dispatch<Source> sourceDispatch = null;
sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.MESSAGE);
((BindingProvider)sourceDispatch).getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullCustomers");
((BindingProvider)sourceDispatch).getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true);
Source result = sourceDispatch.invoke(new StreamSource(new StringReader(req)));
req contains the below one:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action>http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullCustomers</Action>
</s:Header>
<s:Body>
<PullCustomers xmlns="http://cdx.dealerbuilt.com/Api/0.97/">
<searchCriteria xmlns:d4p1="http://schemas.datacontract.org/2004/07/DealerBuilt.BaseApi" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<d4p1:ActivityStoreIds xmlns:d5p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d5p1:long>64</d5p1:long>
</d4p1:ActivityStoreIds>
<d4p1:EnvironmentIds xmlns:d5p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d5p1:long>27</d5p1:long>
</d4p1:EnvironmentIds>
</searchCriteria>
</PullCustomers>
</s:Body>
</s:Envelope>
But it produces Source in output and takes SOAP envelope in request.
I Need this should be work.
org.tempuri.StandardApi service = new org.tempuri.StandardApi();
CustomerSearchCriteriaType criteriaType = new CustomerSearchCriteriaType();
QName environmentQName = new QName("http://schemas.datacontract.org/2004/07/DealerBuilt.BaseApi", "EnvironmentIds");
ArrayOflong arrayOflong = new ArrayOflong();
arrayOflong.getLong().add(27l);
JAXBElement<ArrayOflong> environmentIds = new JAXBElement<ArrayOflong>(environmentQName, ArrayOflong.class, arrayOflong);
criteriaType.setEnvironmentIds(environmentIds);
QName activityQName = new QName("http://schemas.datacontract.org/2004/07/DealerBuilt.BaseApi", "ActivityStoreIds");
ArrayOflong arrayOfActivity = new ArrayOflong();
arrayOfActivity.getLong().add(64l);
JAXBElement<ArrayOflong> activityIds = new JAXBElement<ArrayOflong>(activityQName, ArrayOflong.class, arrayOfActivity);
criteriaType.setActivityStoreIds(activityIds);
ArrayOfCustomerType customers = service.getCustomBindingIStandardApi().pullCustomers(criteriaType);
if (customers != null) {
System.out.println("Size of Customers::::" + customers.getCustomer().size());
}
Request contains
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<PullCustomers xmlns="http://cdx.dealerbuilt.com/Api/0.97/">
<searchCriteria>
<ActivityStoreIds xmlns="http://schemas.datacontract.org/2004/07/DealerBuilt.BaseApi">
<long xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">64</long>
</ActivityStoreIds>
<EnvironmentIds xmlns="http://schemas.datacontract.org/2004/07/DealerBuilt.BaseApi">
<long xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">27</long>
</EnvironmentIds>
</searchCriteria>
</PullCustomers>
</soapenv:Body>
</soapenv:Envelope>
But it hangs while producing output and after very long time it produce the error mentioned above.
Is the difference between the requests causes the problem or something else?
I think the data web-service is returning to client contain illegal character 0x1a which is EOF.
XML doesn't allow CONTROL CHAR in it. As you are using SOAP ultimately XML.
See the similar issue: illegal character in xml document
solution:
1. Either you can eliminate CONTROL char
2. Or Encode it in web-service and decode it at SOAP client.

Categories

Resources