Guvnor drools 5.5 rest api for creating model and rule asset - drools-guvnor

I am trying to create an asset in guvnor through rest api. but the asset is getting created as txt under other assets in guvnor.How can i make it rule asset or model asset. below is my code
Client client = ClientBuilder.newClient();
client.register(HttpAuthenticationFeature.basic("admin", "admin"));
client.register(MultiPartFeature.class);
final MultiPart multipart = new FormDataMultiPart();
File file = new File("C:\\assetfile.xml");
multipart.bodyPart(new FormDataBodyPart("asset",file,MediaType.APPLICATION_XML_TYPE));
final Response response = client.target("http://localhost:8080/guvnor-5.5.0.Final-tomcat-6.0/rest/packages/samplePackage/assets")
.request()
.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
System.out.println(response.readEntity(String.class));
client.close();
my xml file is
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<asset>
<author>admin</author>
<description/>
<metadata>
<checkInComment/>
<disabled>false</disabled>
<format>brl<format>
<versionNumber>1</versionNumber>
</metadata>
<sourceLink>
http://localhost:8080/guvnor-5.5.0.Final-tomcat-6.0/rest/packages/samplePackage/assets/location1234/source
</sourceLink>
<title>location1234</title>
</asset>

According to https://simplesassim.wordpress.com/tag/drools-guvnor-rest-api/, it appears that you may also need to add your file content as a "binary" argument.
multipart.bodyPart(new FormDataBodyPart("asset",file,MediaType.APPLICATION_XML_TYPE));
multipart.bodyPart(new FormDataBodyPart("binary",file)); // Add this line
I hope that the above change helps.

Related

Invoking a BPMN REST Endpoint in WSO2BPS and get payloads in to format xml

I want to use BPMN Service Task and invoke a REST API.
I need to receive requests from the service ESB in format XML.
Example of request:
<?xml version="1.0" encoding="utf-8"?>
<reqSendEvent extrSystem="rout" typeEvent="newRout" xmlns="http://magnit.ru/tanderCoreMassageData.xsd">
<originTime>2017.08.25 15:12:00</originTime>
<content>
<rout>
<name>xxxxx</name>
</rout>
</content>
</reqSendEvent>
servicetask:
<serviceTask id="servicetask1" name="Service Task" activiti:class="org.wso2.developerstudio.bpmn.extensions.restTask.RESTTask">
<extensionElements>
<activiti:field name="serviceURL">
<activiti:expression><![CDATA[http://localhost:9773/tanderBPMN/services/servicetask1]]></activiti:expression>
</activiti:field>
<activiti:field name="method">
<activiti:string><![CDATA[POST]]></activiti:string>
</activiti:field>
<activiti:field name="headers">
<activiti:expression><![CDATA[Content-Type:text/xml]]></activiti:expression>
</activiti:field>
<activiti:field name="outputMappings">
<activiti:string><![CDATA[xxxxxx]]></activiti:string>
</activiti:field>
</extensionElements>
</serviceTask>
In all the examples, using JSON payloads. What do i write expression in to the outputMappings to get value from tag *//rout/name?
You should be able to use a simple String to hold the POST payload and map the parameter to the String.
Have you tried this?
Greg

JAXB Marshsall issue Weblogic12c

Issue
Application migration to 12c and jaxb is not working on it
Description
The application is currently on Weblogic 10 and consumes some webservices. We post the XML directly to the webservice using HttpURLConnection. Before posting we marshal the request and after receiving the response we unmarshall them
The app needs to be migrated on 12c and when we tested the app on 12c , it was not working the same. The request that was sent to the webservice had a difference.Please see below the schema, java classes and marshalled request
Refund.xsd
----------
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:avis="http://www.avis.com/XMLSchema" elementFormDefault="unqualified">
<xsd:element name="RefundRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Request" avis:usage="ups"/>
<xsd:element ref="DeliveryNumber" avis:usage="ups"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- Request and DeliveryNumber attributes her -->
Generated the Refund.java and related classes using Eclipse-->Generate--> JAxB classes.
am behind a firewall and in teh JAXB wizard it did ask me for a proxy. I didnt provide any poxy. Generted class
Refund.java
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "",propOrder = {
"request",
"barCodeDeliveryNumber"
})
#XmlRootElement(name = "TrackRequest")
public class RefundRequest{
#XmlElement(name = "Request", required = true)
protected Request request;
#XmlElement(name = "DeliveryNumber", required = true)
protected String deliveryNumber;
/**
* Gets the value of the request property.
*
* #return
* possible object is
* {#link Request }
*
*/
public Request getRequest() {
return request;
}
/**
* Sets the value of the request property.
*
* #param value
* allowed object is
* {#link Request }
*
*/
public void setRequest(Request value) {
this.request = value;
}
/**
* Gets the value of the DeliveryNumber property.
*
* #return
* possible object is
* {#link String }
*
*/
public String getDeliveryNumber() {
return barCodeDeliveryNumber;
}
/**
* Sets the value of the barCodeDeliveryNumber property.
*
* #param value
* allowed object is
* {#link String }
*
*/
public void setDeliveryNumber(String value) {
this.barCodeDeliveryNumber = value;
}
Am marshalling the object to XML(see below) and passing it to the web service . Web service returns "XML not well formed"
App Library
javax.annotation_1.0.jar
javax.annotation_1.1.jar
javax.persistence_1.0.0.0_1-0.jar
javax.persistence_1.0.1.0_1-0.jar
javax.xml.bind_2.0.jar
javax.xml.bind_2.1.1.jar
jaxb-api.jar
jaxb-impl.jar
jaxws-api.jar
jaxws-rt.jar
jsr181-api.jar
jsr250-api.jar
Weblogic 12c using jrockit160_29
Code Snippet
private static Marshaller mreqinfo;
JAXBContext jxcreq =JAXBContext.newInstance(RefundRequest.class.getPackage().getName());
mreqinfo=jxcreq.createMarshaller();
mreqinfo.marshall(refundRequestObj)
Looking at the logs , i could see the teh following marshalled request on weblogic 12c.
There is an xmlns:ns0="" which i think is creating the problem
**Marshalled Request - not working one when tried in weblogic 12c jrockit160_29
.**
Need to get rid of the xmlns:ns0=""
<?xml version="1.0" encoding="UTF-8"?>
<RefundRequest xmlns:ns0="">
<Request>
<TransactionReference>
<CustomerContext>YILE00010208201120.04.08.4|11/22/2013 12:28:31:085</CustomerContext>
</TransactionReference>
<RequestAction>Refund</RequestAction>
</Request>
<DeliveryNumber>974869</DeliveryNumber>
</RefundRequest>
***Marshalled Request in Weblogic 10 (existing working version in weblogic 10 jrockit160_29
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RefundRequest>
<Request>
<TransactionReference>
<CustomerContext>YILE00010208201120.04.08.4|11/22/2013 12:28:31:085</CustomerContext>
</TransactionReference>
<RequestAction>Refund</RequestAction>
</Request>
<DeliveryNumber>974869</DeliveryNumber>
</RefundRequest>
In WebLogic 12.1.1 which you are using EclipseLink JAXB (MOXy) is used as the default JAXB (JSR-222) provider (see: http://blog.bdoughan.com/2011/12/eclipselink-moxy-is-jaxb-provider-in.html). The issue that you are hitting is due to a bug that has since been fixed in the EclipseLink 2.3.3 release (current release is EclipseLink 2.5.1).
Below is a link with instructions on using a newer version of EclipseLink in WebLogic:
http://blog.bdoughan.com/2012/10/updating-eclipselink-in-weblogic.html
If you are an Oracle Support customer then you can communicate with them to request an official patch for this issue.
To fix this issue, you can add your own jaxb jars (jaxb-core.jar, jaxb-impl.jar) by overriding the jaxb jars in Weblogic 12c. You can do this by placing your own jaxb jars into your war, under WEB-INF/lib and configure the weblogic.xml by using the prefer-web-inf-classes element tag. Then place the weblogic.xml under WEB-INF directory of your war
prefer-web-inf-classes Element
The weblogic.xml Web application deployment descriptor contains a
element (a sub-element of the
element). By default, this element is set to
False. Setting this element to True subverts the classloader
delegation model so that class definitions from the Web application
are loaded in preference to class definitions in higher-level
classloaders. This allows a Web application to use its own version of
a third-party class, which might also be part of WebLogic Server.
Refer to this link for more details
http://docs.oracle.com/cd/E13222_01/wls/docs90/programming/classloading.html
weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.</wls:weblogic-version>
<wls:container-descriptor>
<wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
</wls:container-descriptor>
<wls:container-descriptor>
<wls:show-archived-real-path-enabled>true</wls:show-archived-real-path-enabled>
</wls:container-descriptor>
<wls:context-root>your_context_root_name</wls:context-root>
Had the same problem: JAXB placing prefixes like < ns0:TagName>.
Solved by adding prefer-application-resources to weblogic-application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application>
<prefer-application-resources>
<resource-name>META-INF/services/javax.xml.bind.*</resource-name>
</prefer-application-resources>
</weblogic-application>

Error parsing SOAP response

I'm trying to parse a SOAP response from a web service. I'm using httpbuilder to do the request. Here is my code:
def String WSDL_URL = 'http://ws.webgains.com/aws.php'
def http = new HTTPBuilder( WSDL_URL , ContentType.XML )
String soapEnvelope =
"""<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<getFullUpdatedEarnings xmlns="http://ws.webgains.com/aws.php">
<startDate>2013</startDate>
<endDate>2013</endDate>
<username>username</username>
<password>pass</password>
</getFullUpdatedEarnings>
</soap12:Body>
</soap12:Envelope>"""
http.request( Method.POST, ContentType.XML ) {
body = soapEnvelope
response.success = { resp, xml ->
println "XML was ${xml.Body.getFullUpdatedEarningsResponse.return.text()}"
def territories = new XmlSlurper().parseText(
xml.Body.getFullUpdatedEarningsResponse.return.text()
)
}
response.failure = { resp, xml ->
xml
}
}
When I try to parse the response I get a org.xml.sax.SAXParseException Content is not allowed in prolog.
Here is the output I'm getting from the web services:
3936713759987www.tikcode.com1367552013-05-13T15:04:482013-05-13T15:04:48Miniinthebox - US46119566172850.060.8confirmednotcleared2013-05-13T14:58:33http%3A%2F%2Fwww.lightinthebox.com%2Fes%2F%3Flitb_from%3Daffiliate_webgainsEShttp%3A%2F%2Flocalhost%3A8080%2Fcom.publidirecta.widget%2Fpromocion%2FverPromocion%3Fpromocion%3D
If I use ContenTyp.TEXT the xml I'm getting is
[<?xml version="1.0" encoding="UTF-8"?>, <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn:http://ws.webgains.com/aws.php" xmlns:enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc"><ns1:getFullUpdatedEarningsResponse env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><rpc:result>return</rpc:result><return enc:itemType="ns1:fullLinesArray" enc:arraySize="1" xsi:type="ns1:fullReportArray"><item xsi:type="ns1:fullLinesArray"><transactionID xsi:type="xsd:int">39367137</transactionID><affiliateID xsi:type="xsd:int">59987</affiliateID><campaignName xsi:type="xsd:string">www.tikcode.com</campaignName><campaignID xsi:type="xsd:int">136755</campaignID><date xsi:type="xsd:dateTime">2013-05-13T15:04:48</date><validationDate xsi:type="xsd:dateTime">2013-05-13T15:04:48</validationDate><delayedUntilDate xsi:type="xsd:string"></delayedUntilDate><programName xsi:type="xsd:string">Miniinthebox - US</programName><programID xsi:type="xsd:int">4611</programID><linkID xsi:type="xsd:string">95661</linkID><eventID xsi:type="xsd:int">7285</eventID><commission xsi:type="xsd:float">0.06</commission><saleValue xsi:type="xsd:float">0.8</saleValue><status xsi:type="xsd:string">confirmed</status><paymentStatus xsi:type="xsd:string">notcleared</paymentStatus><changeReason xsi:nil="true"/><clickRef xsi:nil="true"/><clickthroughTime xsi:type="xsd:dateTime">2013-05-13T14:58:33</clickthroughTime><landingPage xsi:type="xsd:string">http%3A%2F%2Fwww.lightinthebox.com%2Fes%2F%3Flitb_from%3Daffiliate_webgains</landingPage><country xsi:type="xsd:string">ES</country><referrer xsi:type="xsd:string">http%3A%2F%2Flocalhost%3A8080%2Fcom.publidirecta.widget%2Fpromocion%2FverPromocion%3Fpromocion%3D</referrer></item></return></ns1:getFullUpdatedEarningsResponse></env:Body></env:Envelope>]
I'm fairly new to web services so If anyone have any ideas I really would appreciate any help
EDIT: Also tried with ws lite with the same results
It looks like you're parsing the response a second time. Why are you using an XmlSlurper to parse the text of the return tag? The elements under return are already parsed and can be accessed directly.

WSO2 XML Declaration

I'm using WSO2 ESB 4.0.3 to deploy a simple service. I have a service returning the following XML:
<Employees>
<Employee>
<EmployeeID>JOHNDOE1</EmployeeID>
<FirstName>JOHN</FirstName>
<LastName>DOE</LastName>
</Employee>
<Status>1</Status>
</Employees>
The problem I'm having is that there is no XML declaration. Is there a setting that will return the response with the XML declaration included, or do I need to use the ESB response to add it? I was hoping for something like:
<?xml version="1.0" encoding="utf-8"?>
<Employees>
<Employee>
<EmployeeID>JOHNDOE1</EmployeeID>
<FirstName>JOHN</FirstName>
<LastName>DOE</LastName>
</Employee>
<Status>1</Status>
</Employees>
Any help is appreciated.
This is an old question, but seeing as I ran into the same thing just now I'll post my solution.
I needed to have a proxy service return a plain XML message without the enclosing soap envelope. I tried using application/xml and text/xml (org.apache.axis2.transport.http.ApplicationXMLFormatter and org.wso2.carbon.relay.ExpandingMessageFormatter respectively) content types to no avail. Neither of these content types returned the message with the XML declaration.
The solution is to write a custom message formatter. Here's my implementation that behaves like org.apache.axis2.transport.http.ApplicationXMLFormatter but properly writes the XML declaration to the message.
package com.example.axis2.messageformatter;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.transport.http.ApplicationXMLFormatter;
public class CustomApplicationXmlFormatter extends ApplicationXMLFormatter {
#Override
public void writeTo(MessageContext context, OMOutputFormat format, OutputStream out, boolean preserve) throws AxisFault {
String xmlHeader = "<?xml version=\"1.0\" encoding=\"" + format.getCharSetEncoding() + "\"?>";
try {
out.write(xmlHeader.getBytes());
} catch (IOException e) {
throw new AxisFault("Unable to write XML declaration to output stream.", e);
}
super.writeTo(context, format, out, preserve);
}
}
You can drop the class in a jar file to <ESB_ROOT>/repository/components/lib.
Additionally you need to refer to the class from the axis2 config (<ESB_ROOT>/repository/conf/axis2/axis2.xml) by adding the following into the message formatters portion of the file:
<messageFormatter contentType="application/xml" class="com.example.axis2.messageformatter.CustomApplicationXmlFormatter"/>
As Kallja answered before - messageFormatter should be fixed.
I've implemented his fix as a maven-based project - available here: https://github.com/akakunin/custom-appxml-message-formatter
I've tested it with WSO2 EI 6.0.0 - it works fine for me.
Just putting this here in case someone else stumbles upon the same issue, WSO2 now support this OOTB with the following axis2 property
<property name="WRITE_XML_DECLARATION" scope="axis2" value="true"/>
source for this - https://github.com/wso2/wso2-axis2/blob/master/modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java#L53
How you captured SOAP message? You can use Tcpmon or just add a log mediator with log level full to observe the complete the complete message. I assume you what you have observed is SOAP body. You do not need to add xml declaration etc. manually.
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>

Microsoft Client Object Model web service

I understand that using a managed client object model communicated via a web service to the Server-side Object Model. But I can't find any documentation on whether this is a RESTful or SOAP service. Does anyone know of any documentation on this service architecture?
Good Question.
Take this code for example:
using (ClientContext clientContext = new ClientContext(siteUrl))
{
clientContext.Credentials = getServiceAccountCredential();
SP.List invoicesList = clientContext.Web.Lists.GetByTitle("Approved Invoice Allocations");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = #"<View> <Query> <Where> <Eq> <FieldRef Name='Invoice_x0020_ID'/> <Value Type='Lookup'>" + invoice_id +
"</Value> </Eq> </Where> </Query> <RowLimit>1000</RowLimit> </View>";
ListItemCollection collListItems = invoicesList.GetItems(camlQuery);
clientContext.Load(collListItems);
clientContext.ExecuteQuery();
}
Looking at the request and response headers in Fiddler tool when clientContext.ExecuteQuery or ExecuteQueryAsync is executed, below are some observations
1) A POST request is sent to SharePoint REST service webUrl/_vti_bin/client.svc/ProcessQuery
2) Request sent is in XML format
3) Response is in JSON format
See this MSDN article for more information