I am developing a proxy service with a soap webservice that performs soap to rest conversion, the message is sent to a servlet that response with a string in flat format (not xml), just a secuence of characters like
OIUW|ECHNOWE|RFHQWIUE|FBPQW|EFHAO|IEFH
I am invoking with SOAP UI and I get this response fine, now I would like to receive it in "SOAP format", wrapping the message into a soap:body, I've tried with a XSLT and with a PayloadFactory Mediator, but as soon as I use any of them (even doing nothing) I get a
[2014-07-31 09:30:41,847] ERROR - RelayUtils Error while building Passthrough stream
org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
What do I do wrong ? How can I achieve a message transformation without this exception?
Thank you!
UPDATE: My proxy as requested by Ratha
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="SCL3"
transports="http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<log level="custom">
<property name="MyTrace" value="--- REQUEST ---"/>
</log>
<log level="full"/>
<property name="REST_URL_POSTFIX"
value="x4?msg=x4|0003|0000000021|0|0|0400002081020224849"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<property name="SOAPAction" scope="default" action="remove"/>
<header name="Action" scope="default" action="remove"/>
<send>
<endpoint>
<address uri="http://localhost:8087/X4" format="pox"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="custom">
<property name="MyTrace" value="--- RESPONSE ---"/>
</log>
<property name="ContentType"
value="application/soap+xml"
scope="transport"
type="STRING"/>
<property name="messageType"
value="application/soap+xml"
scope="transport"
type="STRING"/>
<payloadFactory media-type="xml">
<format>
<a xmlns="">$1</a>
</format>
<args>
<arg value="my value"/>
</args>
</payloadFactory>
<send/>
</outSequence>
</target>
<publishWSDL uri="file:/C:/wso2/wso2esb-4.8.1/repository/workspaces/myproject/SCL3.wsdl"/>
</proxy>
I've seen that my servlet was setting content type to "text/xml" instead of "text/plain", I've changed it to "text/plain" and everything is working fine now.
Therefore I deduce that the error message
"Content is not allowed in prolog"
actually means
"Unexpected content type"
When you have following outsequence configuration what your log prints?
<outSequence>
<log level="full">
<property name="MyTrace" value="--- RESPONSE ---"/>
</log>
<send/>
</outSequence>
Related
I used WSO2 ESB 5.0. I used two soap endpoints to get the response. Below mention the proxy service code.
<?xml version="1.0" encoding="UTF-8"?>
<inSequence xmlns="http://ws.apache.org/ns/synapse">
<log/>
<property expression="//sam:getCertificateID/sam:vehicleNumber"
name="getVehicleNo" scope="default" type="STRING" xmlns:sam="http://sample.esb.org"/>
<log>
<property expression="get-property('default','getVehicleNo')" name="VehicleNo"/>
</log>
<call>
<endpoint>
<wsdl port="EmissionTestServiceHttpSoap11Endpoint"
service="EmissionTestService" uri="http://172.17.0.1:9763/services/EmissionTestService?wsdl"/>
</endpoint>
</call>
<property expression="//ns:getCertificateIDResponse/ns:return"
name="getCertificateIDResponse" scope="default" type="STRING" xmlns:ns="http://sample.esb.org"/>
<log>
<property
expression="get-property('default','getCertificateIDResponse')" name="CertificateID"/>
</log>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:sam="http://sample.esb.org" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sam:getPolicyID>
<sam:vehicleNumber>$1</sam:vehicleNumber>
</sam:getPolicyID>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="get-property('default','getVehicleNo')"/>
</args>
</payloadFactory>
<log/>
<property name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
<call>
<endpoint>
<wsdl port="InsuranceServiceHttpSoap11Endpoint"
service="InsuranceService" uri="http://172.17.0.1:9763/services/InsuranceService?wsdl"/>
</endpoint>
</call>
<property expression="//ns:getPolicyIDResponse/ns:return"
name="getPolicyIDResponse" scope="default" type="STRING" xmlns:ns="http://sample.esb.org"/>
<log>
<property
expression="get-property('default','getPolicyIDResponse')" name="PolicyID"/>
</log>
</inSequence>
First endpoint is working fine and gave the specific log messages. But when going to call second endpoint, below error message is occurred.
Caused by: org.apache.axiom.soap.SOAPProcessingException: First Element must contain the local name, Envelope , but found faultstring
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:305)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:252)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createNextOMElement(StAXSOAPModelBuilder.java:234)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:249)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:204)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:154)
at org.apache.axiom.om.impl.AbstractOMMetaFactory.createStAXSOAPModelBuilder(AbstractOMMetaFactory.java:73)
at org.apache.axiom.om.impl.AbstractOMMetaFactory.createSOAPModelBuilder(AbstractOMMetaFactory.java:79)
at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:196)
at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:65)
at org.apache.synapse.transport.passthru.util.DeferredMessageBuilder.getDocument(DeferredMessageBuilder.java:148)
at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:137)
... 14 more
Can you help me to solve this issue. Any help or workarounds are really appreciated.
Your endpoint is not returning an soap Envelope. You can see what's happening if you set 'configure->logging->apache.synapse.tranport.http.wire' to 'debug'.
Because the endpoint is not returning SOAP, but likely plain old XML you can try setting
<property name="messageType" value="application/xml" scope="axis2"/>
<property name="ContentType" value="application/xml" scope="axis2"/>
before sending the message.
Hi am working with Wso2Esb 4.7.0
I have created a proxy which creates a file in the local system, Below is the proxy and its sequence, I have uncommented the required vfs transport in axis2 file.
Proxy service:
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="FileProxy"
transports="https http"
startOnLoad="true"
trace="enable">
<description/>
<target>
<inSequence>
<property name="messageType" value="application/json" scope="axis2"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property name="Body"
expression="$body"
scope="default"
type="STRING"/>
<property name="transport.vfs.ReplyFileName"
expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.txt')"
scope="transport"/>
<payloadFactory>
<format>
<Reading>$1</Reading>
</format>
<args>
<arg evaluator="xml" expression="get-property('Body')"/>
</args>
</payloadFactory>
<property name="OUT_ONLY" value="true"/>
<property name="messageType"
value="application/json"
scope="axis2"
type="STRING"/>
<send receive="fileWriteSequence">
<endpoint>
<address uri="vfs:file:///home/youtility/Documents/Capp_services/wso2esb-4.7.0/Files"/>
</endpoint>
</send>
</inSequence>
<outSequence onError="fault">
<send/>
</outSequence>
</target>
</proxy>
Sequence:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="fileWriteSequence">
<property name="messageType" value="application/json" scope="axis2"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<log level="custom">
<property name="sequence" value="fileWriteSequence"/>
</log>
<payloadFactory media-type="xml">
<format>
<ResponseJSON xmlns="">
<Body>
<Datalist>file Created</Datalist>
</Body>
<Status>200</Status>
</ResponseJSON>
</format>
<args/>
</payloadFactory>
<send/>
</sequence>
curl:
curl -v -H "Accept: application/json" -H "Content-Type:application/json" -d '{"test1":"1","test2":"-1","test3":"-1"}' http://localhost:8282/services/FileProxy
When am trying to call this service with the curl file is getting created in the mentioned file location with the given content but am not getting any response as file Created as mentioned in the sequence, Actually after creating the file the process is not going the the fileWriteSequence so it is getting stuck.
Any Suggestions..
You are in OUT_ONLY, (you have set <property name="OUT_ONLY" value="true"/>) and you must be in OUT_ONLY when you create a file because there is no response from the filesystem
Therefore, the "receive" sequence will never be executed : add it's content after the send mediator
My aim is i have to receive the url's like www.google.com from client in proxy service and send response back to client.
How can i solve this.Here i am sending my proxy service.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Geturl"
transports="https http"
startOnLoad="true"
trace="enable"
statistics="enable">
<description/>
<target>
<inSequence onError="fault">
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="REQUEST_HOST_HEADER" value="www.google.com" scope="axis2"/>
<property name="querystrings"
expression="get-property('axis2', 'REST_URL_POSTFIX')"/>
<property name="REST_URL_POSTFIX"
expression="get-property('REQUEST_HOST_HEADER')"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<header name="To"
expression="get-property('www.google.com')"/>
<property name="message" value="Response message"/>
<property name="Sender Address" expression="get-property('www.google.com')"/>
<log level="full"/>
<log level="full">
<property name="REQUEST_HOST_HEADER" value="www.wso2.org"/>
</log>
<send/>
</inSequence>
<outSequence onError="fault">
<log level="full"/>
<log level="full">
<property name="REQUEST_HOST_HEADER" value="www.google.com"/>
</log>
<log level="full">
<property name="success" value="success"/>
</log>
<send/>
</outSequence>
</target>
</proxy>
Thanks
In the outSequence of a proxy service, when you call <send/> , the response will be sent back to the client. Try sample proxy service [1], and invoke using Try-It or SOAP UI. You will see that the response comming to the client.
[1]http://docs.wso2.org/wiki/display/ESB460/Sample+150%3A+Introduction+to+Proxy+Services
i am trying to send a message to my email for that i am using send mediator as well i setup required configurations in AXIS2 file
is it work for below proxy
if not what is the way to give xpath to send mediator
<proxy xmlns="http://ws.apache.org/ns/synapse" name="mailCheck" transports="http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="Subject" value="Alert Message From WSO2 ESB - Service Down !!!" scope="transport" type="STRING"/>
<property name="messageType" value="text/html" scope="axis2" type="STRING"/>
<property name="ContentType" value="text/html" scope="axis2" type="STRING"/>
<property name="Mail" value="mailto:faisal.shaik#youtility.in" scope="default" type="STRING"/>
<log level="full">
<property name="Mail" value="mailto:faisal.shaik#youtility.in"/>
</log>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint key-expression="get-property('Mail')"/>
</send>
</inSequence>
<outSequence/>
</target>
<description></description>
</proxy>
if need any changes pls let me know
if you want to get the email address from a property value then use the header mediator to set value of "To" to "mailto:faisal.shaik#youtility.in".
You can do that adding the following before the send mediator
<header name="To" expression="fn:concat('mailto:', get-property('Mail'))"/>
You can use this:
<property name="To" expression="get-property('uri.var.to')" scope="transport"/>
<send>
<endpoint>
<address uri="mailto:"/>
</endpoint>
</send>
<send>
<address uri="mailto:xxx#yyy"/>
</send>
key-expression also can be used..
i wish to send a e-mail to my client using Header mediator .
Is it possible with that or not
My proxy like this
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Mail"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<log/>
<property name="workpartybranchid"
expression="//workpartybranchid/text()"
scope="default"
type="STRING"/>
<payloadFactory>
<format>
<p:SelectMail_Op xmlns:p="http://ws.wso2.org/dataservice">
<p:workpartybranchid>$1</p:workpartybranchid>
</p:SelectMail_Op>
</format>
<args>
<arg expression="get-property('workpartybranchid')"/>
</args>
</payloadFactory>
<send receive="Mailseq">
<endpoint>
<address uri="http://192.168.1.4:9773/services/muser_DataService/"
format="soap11"/>
</endpoint>
</send>
</inSequence>
</target>
</proxy
and corresponding sequence is
<sequence xmlns="http://ws.apache.org/ns/synapse" name="Mailseq" onError="fault">
<property name="CONTENT_TYPE"
value="application/json"
scope="axis2"
type="STRING"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
xmlns:s="http://ws.wso2.org/dataservice"
name="primarymail"
expression="//s:primarymail/text()"
scope="axis2"
type="STRING"/>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd"
xmlns:s="http://ws.wso2.org/dataservice"
name="primarymail"
expression="//s:primarymail/text()"
scope="axis2"
type="STRING"/>
</log>
<header name="To" expression="fn:concat('mailto:', get-property('primarymail'))"/>
<send/>
<log>
<property name="mail" value="ts working"/></log>
</sequence>
can we send a email like this i have got reference from this
http://docs.wso2.org/wiki/display/ESB460/Sample+256%3A+Proxy+Services+with+the+Mail+Transport
i am posted my requirement in another way also please refer this
Can we send Multiple Mail in wso2esb in same sequence or dynamically set a mail
Just follow the step in below URL ( but rather than header part, use endpoint for this as below.. this worked for me)
http://docs.wso2.org/wiki/display/ESB460/Sample+256%3A+Proxy+Services+with+the+Mail+Transport
Add Send for mail as below...( no need header mediator)
<send> <endpoint>
<address uri="mailto:yourmailaddr#gmail.com" />
</endpoint>
</send>