How to get OMElement by name in mediate? - class

I have a response message like this:
<message>
<header>
<TransactionID>1</TransactionID>
<Timestamp>2012-05-22 10:10:36</Timestamp>
<OpCode>BOSS_DELETE_USER_SME.CD</OpCode>
<MsgType>RESP</MsgType>
<ReturnCode>1016</ReturnCode>
<ErrorMessage>uif return error message!</ErrorMessage>
</header>
</message>
I need convert RetuenCode "1016" to "0" in extension class. How to get OMElement "ReturnCode" in mediate? My code is failed.
SOAPEnvelope envelope = context.getEnvelope();
SOAPBody soapBody = envelope.getBody();
QName ReturnCode = new QName(null, "ReturnCode");
OMElement response = soapBody.getFirstChildWithName(ReturnCode);

The section
<header>
Is it inside the SOAP body ? if that is the case first you need to get the Header element from SOAP body and then get the first child with name ReturnCode from that element.
cheers,
Charith

Related

parsing soap response using Cypress

Facing issues while parsing this response using cypress,
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<p385:summaryOutputArray xmlns:p385="http://dataobject.simulation.com">
<p385:userName>MS</p385:userName>
</p385:summaryOutputArray>
</soapenv:Body>
</soapenv:Envelope>
Using Cypress How to read userName TAG? I can see in the log that whole xml is printed but can't get to the particular tag. Also, while using the function to get to the particular tag to get the value, I am getting null property
Firstly I used this. This is giving error. property reading null
const parser = new DOMParser();
const xmlDOM = parser.parseFromString(quoteResp, 'text/xml');
cy.log('xmlDOM ' + quoteResp.);
cy.wrap(Cypress.$(quoteResp)).then(quoteResp => {
const txt = quoteResp.filter('Body').find('p385:userName').text();
cy.log('value:' + txt);
});
Using this I can see the whole response in logs
then(quoteResp => {cy.log('xmlDOM ' + quoteResp.body);
It's not necessary to wrap the response, just query the xmlDOM like this
const xmlDOM = parser.parseFromString(quoteResp, 'application/xml');
const userName = xmlDOM.querySelector('userName').textContent
expect(userName).to.eq('MS')

How to set content-Type on WCF request

My issue is that a testing app like Google Postman (awesome tool, found here) can send the message.
When I send the message it's always refused (the exact same message) because nonse is 'expired'.
So there must be something different about how I'm sending it...
There is... Content-Type is different, for one... but not sure if that's why...
I've seen some hints about accessing endpoint behaviours like:
var whb = client.ChannelFactory.Endpoint.Behaviors.Find<WebHttpBehavior>();
But that only allows me to choose between xml and json.
whb.AutomaticFormatSelectionEnabled = false;
whb.DefaultOutgoingRequestFormat = WebMessageFormat.Xml;
I have a wsdl:
http://caqh.org/SOAP/WSDL/CORERule2.2.0.wsdl
I need to call the WCF service's RealTimeTransaciton with headers that that are:
Content-Type: application/soap+xml;charset=UTF-8;
Currently, by default I suppose, the call includes headers;
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
and Content-Type doesn't seem to be set.
So I tried to affect the headers of the request...
var addressHeaders = new List<AddressHeader> {
AddressHeader.CreateAddressHeader("Content-Type", "", "application/soap+xml;charset=UTF-8;"),
AddressHeader.CreateAddressHeader("Cache-Control", "", "no-cache"),
AddressHeader.CreateAddressHeader("Accept", "", "application/soap+xml;charset=UTF-8;")
};
var client = new CORETransactionsClient(binding, new EndpointAddress(new Uri(url),addressHeaders.ToArray()));
But to my surprise, the result of this is that these 'headers' are added within the soap Envelope headers, and not the headers for the transport!
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<Content-Type>application/soap+xml;charset=UTF-8;</Content-Type>
<Cache-Control>no-cache</Cache-Control>
<Accept>application/soap+xml;charset=UTF-8;</Accept>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
etc.... lol
My web.config service model:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CoreSoapBinding">
<textMessageEncoding messageVersion="Soap12" writeEncoding="UTF8" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://my_vendor_url_for_service_that_is_Axis2_based" binding="customBinding"
bindingConfiguration="CoreSoapBinding" contract="CoreRule.CORETransactions"
name="CoreSoapPort"
endpointConfiguration="">
</endpoint>
</client>
</system.serviceModel>
How I call:
var msg = Create270X12Message(requestReferenceId, senderId, receiverId, requestDateStr, productionCall, prettyOutput);
var envelope = new COREEnvelopeRealTimeRequest
{
CORERuleVersion = "2.2.0",
Payload = string.Format("<![CDATA[{0}]]>", Convert.ToBase64String(Encoding.UTF8.GetBytes(msg))),
PayloadID = requestReferenceId.ToString(),
PayloadType = CoreRule2PayloadType_270_5010,
ProcessingMode = CoreRule2ProcessingMode_270_5010,
ReceiverID = receiverId,
SenderID = senderId,
TimeStamp = requestDateStr
};
var client = CreateRealTimeOnlineProxy(urlMissouiri, username, password, requestDateStr);
var response = client.RealTimeTransaction(envelope);
How can I add my collection of headers to the request itself, instead of the SOAP Envelope headers?

error uploading file HTTP Client & RESTful server

I'm trying to create a HTTP Client to upload a file following this example: http://java.dzone.com/articles/file-upload-apache-httpclient
When I run the application to upload the file on my RESTFul service, I get:
HTTP ERROR 500
Problem accessing /file/upload. Reason:
Server ErrorCaused by:java.lang.NullPointerException
at com.nice.rest.UploadFileService.uploadFile(UploadFileService.java:33)
...
Where line 33 is:
public class UploadFileService {
#POST
#Path("/upload")
#Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(
#FormDataParam("file") InputStream uploadedInputStream,
#FormDataParam("file") FormDataContentDisposition fileDetail) {
//line 33: String uploadedFileLocation = "/mnt/folder/"+ fileDetail.getFileName();
System.out.println("uploadedFileLocation : "+uploadedFileLocation);
// save it
writeToFile(uploadedInputStream, uploadedFileLocation);
String output = "200 OK<br />" + uploadedFileLocation;
return Response.status(200).entity(output).build();
}
Surprisingly, when I upload a file using a html form it works fine:
form action="http://X.X.X.X:8080/file/upload" method="post" enctype="multipart/form-data"
What's wrong?
thanks!!
When you build your multi-part entity, make sure that the #FormDataParam annotation value contains the name of the part within the multipart.
It looks like the part you're looking for doesn't exist hence the NullPointerException.
Please post your client code if possible showing how you construct the multi-part entity

404 requesting SyncStatus... a.k.a. Status

I am trying to make a query to get the SyncStatus objects that have failed. In The API Explorer you have to choose the "Status" menu option in order to test this and submit requests to https:///sb/STATUS/v2/, even though the response XML refers to it as SyncStatus... so not really sure what it should be called exactly.
But that's not really my problem. My problem is that when I submit a request (details below) I get a 404 error. It works perfectly find in the API Explorer, with the exact same XML in the body. I make other calls to the API all the time, so I know my framework is working.
Help?
REQUEST HEADERS
Content-Length: 322
Authorization:
OAuth
oauth_consumer_key="KEY",
oauth_nonce="NONCE",
oauth_signature="SIG",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1377117362",
oauth_token="TOKEN",
oauth_version="1.0"
Content-Type: text/xml
Host: services.intuit.com
Connection: Keep-Alive
REQUEST BODY
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><SyncStatusRequest ErroredObjectsOnly="true" xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.intuit.com/sb/cdm/xmlrequest RestDataFilter.xsd"><OfferingId>ipp</OfferingId></SyncStatusRequest>
RESPONSE (with some new lines added for readability)
<html><head><title>JBoss Web/2.1.12.GA-patch-03 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head>
<body>
<h1>HTTP Status 404 - Null subresource for path: https://internal.services.intuit.com/sb/status/v2/725079435</h1>
<HR size="1" noshade="noshade">
<p>
<b>type</b>
Status report</p><p><b>message</b> <u>Null subresource for path: https://internal.services.intuit.com/sb/status/v2/725079435</u>
</p><p>
<b>description</b>
<u>The requested resource (Null subresource for path: https://internal.services.intuit.com/sb/status/v2/725079435) is not available.</u>
</p>
<HR size="1" noshade="noshade">
<h3>JBoss Web/2.1.12.GA-patch-03</h3>
</body></html>
EDIT: I figured out that I was using GET instead of POST. I have fixed that, but now I am getting a different error in the response:
NEW RESPONSE (new lines added for readability):
<?xml version="1.0" ?>
<RestResponse xmlns="http://www.intuit.com/sb/cdm/v2">
<Error RequestId="347b6e52b653439493b57db68250b61a">
<RequestName>ErrorRequest</RequestName>
<ProcessedTime>2013-08-21T21:57:50.693Z</ProcessedTime>
<ErrorCode>-2001</ErrorCode>
<ErrorDesc>Premature end of file.</ErrorDesc>
</Error>
</RestResponse>
Just now, I've tried the same using devkit. I'm sharing the endpoint and the post body. Please give it a try and let me know if it works for you as well.
Required Header
Content-Type: text/xml
Post Body
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SyncStatusRequest ErroredObjectsOnly="true" xmlns="http://www.intuit.com/sb/cdm/v2"/>
Another
Post Body(when I pass any Id)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SyncStatusRequest ErroredObjectsOnly="true" xmlns="http://www.intuit.com/sb/cdm/v2">
<NgIdSet>
<NgId>660607</NgId>
<NgObjectType>Customer</NgObjectType>
</NgIdSet>
</SyncStatusRequest>
Endpoint
https://services.intuit.com/sb/status/v2/657117515
Java Code
public void testSyncStatus(String id) {
QBSyncStatusRequest syncStatusRequest = QBObjectFactory.getQBObject(
context, QBSyncStatusRequest.class);
syncStatusRequest.setErroredObjectsOnly(true);
NgIdSet ngIdSet = new NgIdSet();
ngIdSet.setNgId(id);
ngIdSet.setNgObjectType(ObjectName.CUSTOMER);
List<NgIdSet> idSets = new ArrayList<NgIdSet>();
idSets.add(ngIdSet);
syncStatusRequest.setNgIdSet(idSets);
logger.debug("inside testSyncStatus");
try {
QBSyncStatusRequestService service = QBServiceFactory.getService(
context, QBSyncStatusRequestService.class);
List<QBSyncStatusResponse> response = service.getSyncStatus(
context, syncStatusRequest);
System.out.println(response);
Iterator<QBSyncStatusResponse> iterator = response.iterator();
while (iterator.hasNext()) {
QBSyncStatusResponse each = (QBSyncStatusResponse) iterator
.next();
System.out.println(" Message Code - " + each.getMessageCode()
+ " Message Desc - " + each.getMessageDesc());
}
} catch (QBInvalidContextException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
Thanks

Writing an encrypted mail via Exchange Web Services

I would like to send an encrypted EMail Message with Exchange WEb Services using C#.
Is there any possibillity?
Thanks
Edit:
My Mail body encrypter:
public static byte[] encry(string body, ContentTyp typ, string to )
{
X509Certificate2 cert = GetMailCertificate(to);
StringBuilder msg = new StringBuilder();
msg.AppendLine(string.Format("Content-Type: text/{0}; charset=\"iso-8859-1\"", typ.ToString()));
msg.AppendLine("Content-Transfer-Encoding: 7bit");
msg.AppendLine();
msg.AppendLine(body);
EnvelopedCms envelope = new EnvelopedCms(new ContentInfo(Encoding.UTF8.GetBytes(msg.ToString())));
CmsRecipient recipient = new CmsRecipient(SubjectIdentifierType.IssuerAndSerialNumber, cert);
envelope.Encrypt(recipient);
//System.IO.MemoryStream ms = new System.IO.MemoryStream(envelope.Encode());
return envelope.Encode();
}
Main
byte [] con = encrypted.encry("test", encrypted.ContentTyp.plain, "test#server.com");
EmailMessage msg1 = new EmailMessage(_server);
msg1.MimeContent = new MimeContent("UTF-8", con);
msg1.ToRecipients.Add("user#server.com");
msg1.InternetMessageHeaders = ??
msg1.Send();
If you are referring to S/Mime encryption, then you'll have to create the encrypted message according to RFC 3852 and RFC 4134. After you've done that, you can send the message.
Using the EWS Managed API, this can be done as follows:
var item = new EmailMessage(service);
item.MimeContent = new MimeContent(Encoding.ASCII.HeaderName, content);
// Set recipient infos, etc.
item.Send();
EDIT:
You should add the standard headers like From, To, Date, Subject, etc. And the content-type.
Subject: Test
From: "sender" <sender#yourcompany.com>
To: "recipient" <recipient#othercompany.com>
Content-Type: application/pkcs7-mime; smime-type=signed-data; name=smime.p7m
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=smime.p7m
Your encrypted body goes here
Just use a StringWriter put all that together. The result is your MIME body.