I am trying to read the Status header of a bounced email. This site explains better what I am trying...
The original email is composed by several MultiParts objects, so I am reading it in java code:
private void test(MimeMessage message) throws IOException, MessagingException {
if (message.getContent() != null && message.getContent() instanceof Multipart) {
Multipart content = (Multipart) message.getContent();
for (int i = 0; i < content.getCount(); i++) {
BodyPart bodyPart = content.getBodyPart(i);
Enumeration headers = bodyPart.getAllHeaders();
while(headers.hasMoreElements()){
Header header = (Header) headers.nextElement();
LOGGER.info("Header: " + header.getName() + " value: " + header.getValue());
}
}
}
}
The email part I am analyzing:
Content-Description: Delivery report Content-Type: text/plain;
charset=utf-8 Content-Transfer-Encoding: 7bit
Reporting-MTA: dns; someLink.com
X-Postfix-Queue-ID: EC862F00D0 X-Postfix-Sender: rfc822;
receiver#email.com Arrival-Date: Wed, 7 Aug 2013
13:52:43 +0200 (CEST)
Final-Recipient: rfc822; noexisting#email.com
Original-Recipient: rfc822;noexisting#email.com Action:
failed Status: 5.1.1 Remote-MTA: dns; [somelink.com
Diagnostic-Code: smtp; 550-5.1.1 The email account that you tried to
reach does
not exist. Please try 550-5.1.1 double-checking the recipient's email
address for typos or 550-5.1.1 unnecessary spaces.
In my log file I can see only the 3 first headers:
> Header: Content-Description value: Delivery report
> Header: Content-Type value: text/plain; charset=us-ascii INFO
> Header: Content-Transfer-Encoding value: 7bit
Does anyone know why? How could I get the status header? Thanks
I couldnĀ“t find the Status information in the header, and I will take it from the content. It is not an elegant solution, but at least it works.
If someone finds a better one, please let me know!
Java code:
StringWriter writer = new StringWriter();
IOUtils.copy(bodyPart.getInputStream(), writer);
LOGGER.info("Content inputstream: " + writer.toString());
Logs:
Content inputstream: Reporting-MTA: dns; srvvie-mx3.styria-multi-media.com
X-Postfix-Queue-ID: 2A1A8F00CF X-Postfix-Sender: rfc822;
Arrival-Date: Fri, 9 Aug 2013
11:14:02 +0200 (CEST)
Final-Recipient: rfc822; MAILER-DAEMON#domain.com
Original-Recipient: rfc822;MAILER-DAEMON#domain.com
Action: failed Status: 5.1.1 Remote-MTA: dns;
Diagnostic-Code: smtp; 550 5.1.1 Mailbox
does not exist
Related
i have this code to connect to my NTRIP Server,
String requestmsg = "GET /" + nMountpoint + " HTTP/1.0\r\n";
requestmsg += "User-Agent: NTRIP Client\r\n";
requestmsg += "Accept: */*\r\n";
requestmsg += "Connection: close\r\n";
if (nUsername.length() > 0) {
requestmsg += "Authorization: Basic " + ToBase64(nUsername + ":" + nPassword);
}
requestmsg += "\r\n";
os = nsocket.getOutputStream();
os.write(requestmsg.getBytes());
and got this reply, that indicate that i was connected to the server
ICY 200 OK
Server: GNSS Spider 7.7.0.9065/1.0
Date: Wed, 09 Feb 2022 13:25:27 GMT
but After I try to send my String message:
private String RecentGGA = "$GPGGA,154223,4000,N,08312,W,4,10,1,200,M,1,M,8,0*7F";
Using this Code:
private void SendGGAToServer() {
SendDataToNetwork(RecentGGA + "\r\n");
//Log.d(TAG, "SendGGAToCaster: GGA Data Sent to Caster");
}
public void SendDataToNetwork(String NewGGA) { // You run this from the main thread.
try {
if (nsocket != null) {
if (nsocket.isConnected()) {
if (!nsocket.isClosed()) {
Log.i("SendDataToNetwork", "SendDataToNetwork: Writing message to socket");
os.write(NewGGA.getBytes());
} else {
Log.i("SendDataToNetwork", "SendDataToNetwork: Cannot send message. Socket is closed");
}
} else {
Log.i("SendDataToNetwork", "SendDataToNetwork: Cannot send message. Socket is not connected");
}
}
} catch (Exception e) {
Log.i("SendDataToNetwork", "SendDataToNetwork: Message send failed. Caught an exception " + e);
}
}
The Problem is, i can not send the string and shows this error:
I/NTRIP_Service: Creating socket
I/System.out: [socket]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [socket] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/NTRIP_Service: Socket created, streams assigned
This is a NTRIP connection
I/Request: GET /max-rtcm3 HTTP/1.0
User-Agent: NTRIP Client
Accept: /
Connection: close
Authorization: Basic R2VvMTpHZW8x
D/NTRIP_Service: Data Mode: 0
D/NTRIP: ParseNetworkDataStream: ICY 200 OK
Server: GNSS Spider 7.7.0.9065/1.0
Date: Wed, 09 Feb 2022 13:25:27 GMT
I/SendDataToNetwork: SendDataToNetwork: Writing message to socket
SendDataToNetwork: Message send failed. Caught an exception android.os.NetworkOnMainThreadException
i'm still a newbie, so i dont know how to fix this. does anyone know how to fix this?
We have a external application, which sends us a email with attachment.
In case of contentType Multipart : we are able to parse and process the attachment.
But sometime they send mail with contentType text/plain ( message.getContent() is null), we are not able to get the attachment & email body from message obj.
Sender can't fix the content type to multipart, we have to accommodate it on receiver end.
We are using JavaMail API 1.5,tried apache commons mail util but it only works when you have object in message.getContent()
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);
Message[] messages = emailFolder.getMessages();
System.out.println("Total Message" + messages.length);
for (int i = 0; i < messages.length; i++) {
Message message = messages[i];
Multipart multipart = (Multipart) message.getContent();
for(int k = 0; k < multipart.getCount(); k++){
BodyPart bodyPart = multipart.getBodyPart(k);
InputStream stream =
(InputStream) bodyPart.getInputStream();
}
}
**RAW MIME message content :**
From: SENDER <SENDER#MyOrgLtd.com>
To: "'support#XYZ.com'" <'support#XYZ.com'>
Subject: Change Request #CHG85 02 ATTACHMENT
Thread-Topic: Change Request #CHG85 02 ATTACHMENT
Thread-Index: AdVQ+bdv3Fd+yaP6Qr2RCdQvPsvI9Q==
Date: Mon, 12 Aug 2019 10:37:23 +0000
Message-ID: <1dcdc97a916b4f929414d0d4b6703397#DELHIXCHMBX003.MyOrgLtd.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: yes
X-MS-TNEF-Correlator:
dlp-product: dlpe-windows
dlp-version: 11.1.0.61
dlp-reaction: no-action
x-mcafeedlp-tagged: True
x-ms-exchange-transport-fromentityheader: Hosted
x-originating-ip: [IP REMOVED]
x-tm-onpremattruleprocessed: TRUE
Content-Type: multipart/mixed;
boundary="_002_1dcdc97a916b4f929414d0d4b6703397DELHIXCHMBX003MyOrgLtd_"
MIME-Version: 1.0
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-Exchange-SenderADCheck: 1
X-Microsoft-Antispam-Message-Info: fL+9KaLob6WaIw3QlMjrWkMfgsC6D53Vr10xvjo/DWwlRA3ZuQ0emJtxG2R1r3GXNuLYK7l6vjv/buJaaPhR7VW5qdysbinenPJjyOIwCcTuBCAm1nAtlEWJqRzIJT0n7oxDQvh7pH+mIm7yK0BwYX8nJyfg2CSot7is9h/Xbk/uwYow4RW9IuSq5ioMCPSt+zRzdfbJ76DIPvne4FYRy+D8Xbe4RBMcf6u7wvtQW3n86JtRUVz1EjDGmIA6ZfyHXtYf3Q09VKfyMg6wa7KOWJaiU+6HJCY4Jevdxgy75xvR+56PCQ1dV0QgeMsEqVuKrM0YndKVKrF3u08rO7PQoTpv37z4xqRyTNRpTwLXeuQWi6tBFRk3HjrbBKBaRpme1On2cYRFBCiXMLMxBfpNIaR4lolZ0MPL/h3UANKY7r4=
X-OriginatorOrg: MyOrgLtd.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2019 10:37:25.6885
(UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 8137d2d0-3ec5-4a61-f117-08d71f111117
X-MS-Exchange-CrossTenant-Id: edf442f5-b994-4c86-a131-b42b03a16c95
X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=edf442f5-4c86-a131;Ip=[IP RMOVED];Helo=[MyEmail.MyOrgLtd.com]
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: BMXPR01MB3830
X-CLX-Shades: MLX
X-CLX-Response: 1TFkXExoRCkx6Fx4SEQpZRBdlfmFZE0V5WUNGUBEKWFgXaWZ9aWdnaUtyflI RCnhOF20SRWsbeENtRk5hEQp5TBdrf0BAcxJBGGIcaBEKeUMXaVNsSG1kWF5yZhoRCkNIFwcYGR oRCkNZFxsfGBEKWU0XZ2ZyEQpZSRcacRoQGncGHRpxHhAadwYYGgYaEQpZXhdobnkRCklGF0teX
nVCRVleT04RCkNOF3l1T25TfGVCe1xEfF1NWlBbbx9abRtsc0BbY1lGXlATEQpYXBcfBBoEGxIb BxNMGhwTThIfBRsaBBsaGgQeEgQcEBseGh8aEQpeWRd/Ql9zbBEKTVwXGx0eEQpMWhdoaU1raxE KTEYXb2tra2traxEKQk8XaUVwGwFzWHhPG0gRCkNaFx4aBBsaHQQbGRIEGxkbEQpCXhcbEQpEXh
cYEQpCXBcaEQpCRRdsSWtYGWwcf2RTSxEKQk4XbRJFaxt4Q21GTmERCkJMF2lmfWlnZ2lLcn5SE QpCbBdhbXkfU2Z4b25DSBEKQkAXZmlOYEBgbVNLW3IRCkJYF3pAbVgfbnhkHUUfEQpNXhcbEQpa WBcYEQpwaBdiXEcaUG98Q15ERxAZGhEKcGgXYWFAa0FNbENaQBgQHBoRCnBoF2UFeGZtGXppaB5
pEB0aEQpwaBdjeEllXmZ8fUkSBRAdGhEKcGgXY0VPSWJSfWBdUEAQGRoRCnBrF21pQXNffU8BBQ FuEBkaEQpwSxdhUBIbAU9saERdBRAZGhEKcGsXY2dsAWlvYXN5YnkQGRoRCnBsF2drQ2lPeV9DR xJBEBkaEQpwQxdsSx1AEl9bTQVrRBAcHREKbX4XGxEKWE0XSxEg
X-Proofpoint-SPF-Result: pass
X-Proofpoint-SPF-Record: v=spf1 mx ip4:IP RMOVED ip4:IP RMOVED
ip4:IP RMOVED ip4:IP RMOVED ip4:IP RMOVED
ip4:IP RMOVED include:spf2.MyOrgLtd.com
include:spf.protection.outlook.com -all
X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-08-12_04:,,
signatures=0
X-Proofpoint-Spam-Reason: safe
--_002_1dcdc97a916b4f929414d0d4b6703397DELHIXCHMBX003MyOrgLtd_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
hi User,
We have received the data, will process and inform you.
Thank you,
admin
--_002_1dcdc97a916b4f929414d0d4b6703397DELHIXCHMBX003MyOrgLtd_
Content-Type: application/octet-stream; name="testData.csv"
Content-Description: testData.csv
Content-Disposition: attachment; filename="testData.csv"; size=393;
creation-date="Mon, 12 Aug 2019 10:35:38 GMT";
modification-date="Mon, 12 Aug 2019 10:35:38 GMT"
Content-Transfer-Encoding: base64
IkNpcmN1aXQgIiwiU2V2ZXJpdHkiCiJDaXJjdWl0OSAgICAvU0EgIC8iLCJPdXRhZ2UiCiJDaXJjdWl0MTQgICAgL1NMICAvIiwiT3V0YWdlIgoiQ2lyY3VpdDggICAgL1NCICAvIiwiT3V0YWdlIgoiQ2lyY3VpdDUgICAgL1NCICAvIiwiT3V0YWdlIgoiQ2lyY3VpdDYgICAgL1NUICAvIiwiT3V0YWdlIgoiQ2lyY3VpdDcgICAgL1NCICAvIiwiT3V0YWdlIgoiQ2lyY3VpdDIgICAgL1NHICAvIiwiT3V0YWdlIgoiQ2lyY3VpdDUxICAgIC9TQiAgLyIsIk91dGFnZSIKIkNpcmN1aXQxICAgIC9TTSAgLyIsIk91dGFnZSIKIkNpcmN1aXQ0ICAgIC9TQiAgLyIsIk91dGFnZSI=
--_002_1dcdc97a916b4f929414d0d4b6703397DELHIXCHMBX003MyOrgLtd_--
If the content type is text/plain, there is no attachment.
And if message.getContent() is returning null, there's probably no message content either, or something is wrong with the formatting of the message. Post the raw MIME content of the message and I can help you figure what's wrong with the message.
Background:
I am trying to use one-api, to send SMS to phones and receive the delivery status. I make a POST request to their servers. Then I extract a string from the JSON response I receive. I use that string to make another GET request to a URL containing that ID. The problem is that the string gets changed when I make the GET request. Although it is same when I extract it from the response, but have no idea why its changing during the course of GET request.
Methodology followed and problem explanation:
The response from initial POST request` :
{"resourceReference":
{"resourceURL":"https:\/\/oneapi-gw.gsma.com:443\/SendSmsService\/OneAPI_REST_v2_0\/routing\/2_0\/smsmessaging\/outbound\/tel:7511\/requests\/998371119"}
}
I extract the ID that I receive in the url(998371119). I use .split to extract as follows:
String tmp = (String)resourceReference.get("resourceURL");
String [] tmp2 = tmp.split("/");
String id = tmp2[(tmp2.length)-1].toString();
System.out.println(id);
// the output is:998371119.
Using this ID I create another url to send a GET request.
String url2 = "https://oneapi-gw.gsma.com/smssend/2_0/smsmessaging/outbound/tel:7511/requests/"+id+"/deliveryInfos"
When I send the GET request, the last 2 digits of ID seems to change automatically and I receive the Response Code as 400 after making a GET request. Following is the error stream:
{ "requestError" :
{ "serviceException" : {
"text" : "Invalid input value for message part requestIdentifier",
"variables" : [
"requestIdentifier", "998371122"
]
}
}
}
Notice how the server interpreted the ID as 998371122 instead of 998371119(my initial requested one). That last 2 digit changed. I've thought a lot but I've no idea why it is happening. Although when I am using curl to send the GET request, everything works fine. So it isn't a server issue. Their is some problem in either How I form the url or extract the ID or make a GET request. Any suggestions? Thanks in advance.
Other Relevant code you might need
This is how I'm making a GET request:
private String getResponseFromGETRequest(String accept, String url) {
URL obj;
StringBuffer response = new StringBuffer();;
HttpURLConnection con;
String authHeaderValue = new String(Base64.encode(credentials.getBytes()));
//Credentals variable is a string storing "username:password"
try {
obj = new URL(url);
con = (HttpURLConnection) obj.openConnection();
con.setRequestProperty ("Authorization", "Basic " + authHeaderValue);
// optional default is GET
con.setRequestMethod("GET");
//add request header
con.setRequestProperty ("Accept", accept);
//con.setRequestProperty("Content-Type", accept);
int responseCode = con.getResponseCode();
InputStream ipStream;
if (con.getResponseCode() >= 400) {
ipStream = con.getErrorStream();
} else {
ipStream = con.getInputStream();
}
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(ipStream));
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
return response.toString();
}
Logcat:
Oct 04, 2013 3:59:07 PM sun.net.www.protocol.http.HttpURLConnection plainConnect
FINEST: ProxySelector Request for https://oneapi-gw.gsma.com/smssend/2_0/smsmessaging/outbound/tel%3A7511/requests
Oct 04, 2013 3:59:07 PM sun.net.www.protocol.http.HttpURLConnection plainConnect
FINEST: Proxy used: DIRECT
Oct 04, 2013 3:59:08 PM sun.net.www.protocol.http.HttpURLConnection writeRequests
FINE: sun.net.www.MessageHeader#7f47e35410 pairs: {POST /smssend/2_0/smsmessaging/outbound/tel%3A7511/requests HTTP/1.1: null}{Authorization: Basic ABCDEFGHMYAUTHORIZATIONKEY=}{Accept: application/json}{Content-Type: application/json}{Cache-Control: no-cache}{Pragma: no-cache}{User-Agent: Java/1.7.0_21}{Host: oneapi-gw.gsma.com}{Connection: keep-alive}{Content-Length: 212}
Oct 04, 2013 3:59:08 PM sun.net.www.protocol.http.HttpURLConnection getInputStream
FINE: sun.net.www.MessageHeader#75240d4a17 pairs: {null: HTTP/1.1 201 Created}{Date: Fri, 04 Oct 2013 19:59:08 GMT}{Server: Jetty(6.1.x)}{Content-Type: application/json}{Location: https://oneapi-gw.gsma.com:443/SendSmsService/OneAPI_REST_v2_0/routing/2_0/smsmessaging/outbound/tel:7511/requests/998380556}{Host: oneapi-gw.gsma.com}{X-Forwarded-Server: oneapi-gw.gsma.com}{Authorization: Basic ABCDEFGHMYAUTHORIZATIONKEY=}{User-Agent: Java/1.7.0_21}{Accept: application/json}{X-Forwarded-For: 10.90.24.132}{X-Forwarded-Host: oneapi-gw.gsma.com}{breadcrumbId: ID-dtx-prod-apihr01-39903-1371168975552-0-440221}{Vary: Accept-Encoding,User-Agent}{Keep-Alive: timeout=5, max=100}{Connection: Keep-Alive}{Transfer-Encoding: chunked}
Oct 04, 2013 3:59:08 PM sun.net.www.protocol.http.HttpURLConnection plainConnect
FINEST: ProxySelector Request for https://oneapi-gw.gsma.com/smssend/2_0/smsmessaging/outbound/tel:7511/requests/998380556/deliveryInfos
Oct 04, 2013 3:59:08 PM sun.net.www.protocol.http.HttpURLConnection plainConnect
FINEST: Proxy used: DIRECT
Oct 04, 2013 3:59:08 PM sun.net.www.protocol.http.HttpURLConnection writeRequests
FINE: sun.net.www.MessageHeader#71d198cb9 pairs: {GET /smssend/2_0/smsmessaging/outbound/tel:7511/requests/998380556/deliveryInfos HTTP/1.1: null}{Authorization: Basic ABCDEFGHMYAUTHORIZATIONKEY=}{Accept: application/json}{Content-Type: application/json}{Cache-Control: no-cache}{Pragma: no-cache}{User-Agent: Java/1.7.0_21}{Host: oneapi-gw.gsma.com}{Connection: keep-alive}
Oct 04, 2013 3:59:08 PM sun.net.www.protocol.http.HttpURLConnection getInputStream
FINE: sun.net.www.MessageHeader#778671cd15 pairs: {null: HTTP/1.1 400 Bad Request}{Date: Fri, 04 Oct 2013 19:59:09 GMT}{Server: Jetty(6.1.x)}{Content-Type: application/json}{Accept: application/json}{Host: oneapi-gw.gsma.com}{breadcrumbId: ID-dtx-prod-apihr02-48223-1371168511818-0-440001}{X-Forwarded-Host: oneapi-gw.gsma.com}{X-Forwarded-For: 10.90.24.132}{User-Agent: Java/1.7.0_21}{X-Forwarded-Server: oneapi-gw.gsma.com}{Authorization: Basic ABCDEFGHMYAUTHORIZATIONKEY=}{Vary: Accept-Encoding,User-Agent}{Connection: close}{Transfer-Encoding: chunked}
Header: Date : Fri, 04 Oct 2013 19:59:09 GMT
Header: Server : Jetty(6.1.x)
Header: Content-Type : application/json
Header: Accept : application/json
Header: Host : oneapi-gw.gsma.com
Header: breadcrumbId : ID-dtx-prod-apihr02-48223-1371168511818-0-440001
Header: X-Forwarded-Host : oneapi-gw.gsma.com
Header: X-Forwarded-For : 10.90.24.132
Header: User-Agent : Java/1.7.0_21
Header: X-Forwarded-Server : oneapi-gw.gsma.com
Header: Authorization : Basic ABCDEFGHMYAUTHORIZATIONKEY=
Header: Vary : Accept-Encoding,User-Agent
Header: Connection : close
Header: Transfer-Encoding : chunked
Response Code : 400
{
"requestError" : {
"serviceException" : {
"messageId" : "SVC0002",
"text" : "Invalid input value for message part requestIdentifier",
"variables" : [ "requestIdentifier", "998380559" ]
}
}
}
Edit:
Finally after two days it was a strange solution. It turns out parsing was fine and so was the formation of GET and POST request. I just kept 3 seconds delay after I received the response from POST request and before I sent another GET request. This solved it.
try {
Thread.sleep(3000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
I am attempting to upload images to SmugMug via HTTP Post as per their documentation. I have all the headers correct, but the part that is confusing me is setting the binary data in the body as stated:
This method requires a POST request with the binary data in the body
and all other metadata in the headers.
I have tried:
SMResponse response = builder.post(SMResponse.class, Files.readAllBytes(image.toPath()));
SMResponse response = builder.post(SMResponse.class, new String(Files.readAllBytes(image.toPath())));
SMResponse response = builder.post(SMResponse.class, new String(Base64.encode(Files.readAllBytes(image.toPath()))));
SMResponse response = builder.post(SMResponse.class, Base64.encode(Files.readAllBytes(image.toPath())));
My best guess was the first one would work, but all of these return:
{"stat":"fail","method":"smugmug.images.upload","code":5,"message":"system error"}
Here is the full method that does the uploading, in case I missed something:
public boolean upload(File image, int albumId, String caption, String keywords,
Boolean hidden, Integer imageId, Integer altitude, Float latitude,
Float longitude, boolean pretty) throws IOException, InvalidKeyException, NoSuchAlgorithmException, SmugMugException {
logger.debug("upload() called");
byte[] imageBytes = Files.readAllBytes(image.toPath());
WebResource resource = SmugMugAPI.CLIENT.resource("http://upload.smugmug.com/");
LoggingFilter logFilter = new LoggingFilter();
resource.addFilter(logFilter);
OAuthSecrets secrets = new OAuthSecrets().consumerSecret(smugmug.getConsumerSecret());
OAuthParameters oauthParams = new OAuthParameters().consumerKey(smugmug.getCosumerKey()).
signatureMethod("HMAC-SHA1").version("1.0");
// Create the OAuth client filter
OAuthClientFilter filter = new OAuthClientFilter(SmugMugAPI.CLIENT.getProviders(), oauthParams, secrets);
// Add the filter to the resource
if (smugmug.getToken() != null){
secrets.setTokenSecret(smugmug.getToken().getSecret());
oauthParams.token(smugmug.getToken().getId());
}
resource.addFilter(filter);
WebResource.Builder builder = resource.getRequestBuilder();
//User agent
builder = builder.header("User-Agent", smugmug.getAppName());
//API Version header
builder = builder.header("X-Smug-Version", "1.3.0");
//Response Type header
builder = builder.header("X-Smug-ResponseType", "JSON");
//Content-Length header
builder = builder.header("Content-Length", Long.toString(image.length()));
//Content-MD5 header
builder = builder.header("Content-MD5", DigestUtils.md5Hex(imageBytes));
//X-Smug-FileName header
builder = builder.header("X-Smug-FileName", image.getName());
//X-Smug-AlbumID header
builder = builder.header("X-Smug-AlbumID", Integer.toString(albumId));
//X-Smug-Caption header
if(caption != null){
builder = builder.header("X-Smug-Caption", caption);
}
//X-Smug-Caption header
if(keywords != null){
builder = builder.header("X-Smug-Keywords", keywords);
}
//X-Smug-Hidden header
if(hidden != null){
builder = builder.header("X-Smug-Hidden", hidden.toString());
}
//X-Smug-ImageID header
if(imageId != null){
builder = builder.header("X-Smug-ImageID", imageId.toString());
}
//X-Smug-Altitude header
if(altitude != null){
builder = builder.header("X-Smug-Altitude", altitude.toString());
}
//X-Smug-Latitude header
if(latitude != null){
builder = builder.header("X-Smug-Latitude", latitude.toString());
}
//X-Smug-Latitude header
if(longitude != null){
builder = builder.header("X-Smug-Longitude", longitude.toString());
}
//X-Smug-Pretty header
if(pretty){
builder = builder.header("X-Smug-Pretty", Boolean.toString(pretty));
}
SMResponse response = builder.post(SMResponse.class, new String(imageBytes));
if (!"ok".equals(response.getStat())) {
throw new SmugMugException(response);
}
return true;
}
Where have I gone wrong?
Tried just to see the response:
SMResponse response = builder.entity(image).post(SMResponse.class);
It actually sent back a blank response (no json) which is odd in itself, as I would have expected some message back. Here is the output:
Nov 21, 2012 11:55:48 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client in-bound response
1 < 200
1 < Edge-Control: no-store
1 < X-SmugMug-Hiring: How to love what you do: http://www.smugmug.com/jobs/
1 < Date: Thu, 22 Nov 2012 05:55:48 GMT
1 < Content-Length: 0
1 < X-SmugMug-Values: 4/4 - It's the product, stupid
1 < Expires: Thu, 22 Nov 2012 05:55:49 GMT
1 < Connection: keep-alive
1 < Content-Type: application/json; charset=utf-8
1 < X-Powered-By: SmugMug/0.9
1 < Server: Apache
1 < Cache-Control: private, no-store, no-cache, max-age=1, must-revalidate
1 <
I am not exactly sure what happened, but I was able to get it working after finding the Upload Log in the SmugMug Account Settings (To get there go to Tools -> Account Settings -> Stats -> Uploads -> Details). Note that in the upload log there is a toggle to show only errors or all uploads.
Now on to the actual answer to how to set the actual "body" of the Post Request. The actual format should have been the first one I posted:
SMResponse response = builder.post(SMResponse.class, Files.readAllBytes(image.toPath()));
So either I messed up, and thought it was not working when it was, there was a problem on smugmug's end at the time, or there was something else in my code that was wrong, that got fixed in the process of me trying to fix this non-issue.
i have com.sun.mail.pop3.POP3Message object, in that content i have the following format code,
Delivery has failed to these recipients or distribution lists:
anandnarekar#gmail.coxm
An error occurred while trying to deliver this message to the recipient's e-mail address. Microsoft Exchange will not try to redeliver this message for you. Please try resending this message, or provide the following diagnostic text to your system administrator.
Diagnostic information for administrators:
Generating server: delivery
anandnarekar#gmail.coxm
#< #5.0.0 smtp; 554 5.4.4 [internal] Domain Lookup Failed> #SMTP#
Original message headers:
X-AuditID: ac1ec426-b7b3aae0000036b3-7c-4e3009fd2d34
Received: from SVHJ0032 ( [172.30.1.11]) by svhj0367.ideaconnect.com (Symantec
Brightmail Gateway) with SMTP id BA.D0.14003.DF9003E4; Wed, 27 Jul 2011
18:22:13 +0530 (IST)
Message-ID: <1502435725.1311770110726.JavaMail.wasadmin#SVHJ0032>
Date: Wed, 27 Jul 2011 18:05:10 +0530
From: <ebill.mh#idea.adityabirla.com>
To: <anandnarekar#gmail.coxm>
Subject: Your Idea Bill
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_67575_1171670486.1311770110725"
Thread-Topic: rsweb_7202772011060510
X-Brightmail-Tracker: AAAAAQAAAZE= </pre>
> Blockquote
how can I retrieve the value of Thread-Topic?
Loop through the text that gets returned to you and look for "Thread-Topic".
Once you find it, you can use the indexOf and substring functions to parse out your topic.
Sample code shown below:
E:\jdk1.6.0_23\bin>type Test.java
public class Test
{
public static void main(String[] args) {
String str = "Thread-Topic: rsweb_7202772011060510";
if (str.indexOf("Thread-Topic") != -1) {
String topic = str.substring(str.indexOf(":") + 2);
System.out.println(topic);
}
}
}
E:\jdk1.6.0_23\bin>javac Test.java
E:\jdk1.6.0_23\bin>java Test
rsweb_7202772011060510