Skip to content

Commit

Permalink
Added customization of namespace prefixes, HTTP basic auth, support for
Browse files Browse the repository at this point in the history
legacy sender address text only format and various bug fixes.
  • Loading branch information
Vjekoslav Nesek committed Mar 10, 2015
1 parent 959090b commit 9211d3b
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 79 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>net.instantcom.mm7</groupId>
<artifactId>instantcom-mm7</artifactId>
<name>InstantCom MM7 Client</name>
<version>0.8.1</version>
<version>0.9.0</version>
<description>InstantCom MMS MM7 protocol client implementation</description>
<packaging>jar</packaging>
<url>https://github.com/vnesek/instantcom-mm7</url>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/instantcom/mm7/About.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://raw.github.com/vnesek/instantcom-mm7/master/LICENSE.txt
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
*
* When distributing the software, include this License Header Notice in each
Expand All @@ -25,12 +25,12 @@ interface About {

/** Default MM7 version used */
String MM7_VERSION = "6.7.0";

/** Default MM7 XML namespace used */
String MM7_NAMESPACE = "http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-6-7";

/** Library version */
String VERSION = "0.8.0";
String VERSION = "0.9.0";

/** Library copyright */
String COPYRIGHT = "Copyright (c) InstantCom d.o.o. 2007-2014. All rights reserved.";
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/net/instantcom/mm7/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://raw.github.com/vnesek/instantcom-mm7/master/LICENSE.txt
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
*
* When distributing the software, include this License Header Notice in each
Expand Down Expand Up @@ -81,6 +81,12 @@ public Address(String address, RecipientType recipientType) {
setRecipientType(recipientType);
}

public Address(String address, RecipientType recipientType, AddressType addressType) {
setAddress(address);
setRecipientType(recipientType);
setAddressType(addressType);
}

public String getAddress() {
return address;
}
Expand Down
34 changes: 26 additions & 8 deletions src/main/java/net/instantcom/mm7/BasicMMSC.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package net.instantcom.mm7;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -47,20 +48,36 @@ public SubmitRsp submit(SubmitReq submitReq) throws MM7Error {

private MM7Response post(MM7Request request) throws MM7Error {
try {
URL u = new URL(getUrl());
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
final MM7Context ctx = getContext();
final URL u = new URL(getUrl());
final HttpURLConnection conn = (HttpURLConnection) u.openConnection();

conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);

conn.setRequestProperty("Content-Type", request.getSoapContentType());
conn.setRequestProperty("User-Agent", getContext().getUserAgent());
conn.setRequestProperty("User-Agent", ctx.getUserAgent());
conn.setRequestProperty("Accept", "*/*");
conn.setRequestProperty("SOAPAction", "\"\"");

OutputStream out = conn.getOutputStream();
// HTTP Basic authorization
if (ctx.getUsername() != null) {
String authString = ctx.getUsername() + ':' + ctx.getPassword();
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream(128);
OutputStream buffer64 = ctx.newBase64OutputStream(buffer);
buffer64.write(authString.getBytes("iso-8859-1"));
buffer64.close();
conn.setRequestProperty("Authorization", "Basic " + buffer.toString("iso-8859-1"));
} catch (IOException ioe) {
throw new RuntimeException("Failed to add HTTP Basic Authorization header", ioe);
}
}

final OutputStream out = conn.getOutputStream();
try {
MM7Message.save(request, out, getContext());
MM7Message.save(request, out, ctx);
} finally {
out.close();
}
Expand All @@ -80,14 +97,15 @@ private MM7Response post(MM7Request request) throws MM7Error {
}
return (MM7Response) MM7Message.load(in, contentType, getContext());
} else {
throw new MM7Error("unexpected content: " + conn.getResponseCode() + " "
+ conn.getResponseMessage() + "\n" + conn.getContent());
throw new MM7Error("unexpected content type: " + contentType + ", status: " + //
conn.getResponseCode() + " " + conn.getResponseMessage() + ", content: " + //
conn.getContent());
}
} finally {
conn.disconnect();
}
} catch (IOException ioe) {
throw new MM7Error("io error", ioe);
throw new MM7Error("IO error: " + ioe.getMessage());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/instantcom/mm7/DeliverReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public Date getTimeStamp() {
public void load(Element element) {
super.load(element);

Element body = element.getChild("Body", JDOMSupport.ENVELOPE);
Element body = element.getChild("Body", MM7Message.ENVELOPE);
Element req = body.getChild("DeliverReq", namespace);

Element sender = req.getChild("Sender", namespace);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/instantcom/mm7/DeliverRsp.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void setServiceCode(String messageId) {
public void load(Element element) {
super.load(element);

Element body = element.getChild("Body", JDOMSupport.ENVELOPE);
Element body = element.getChild("Body", MM7Message.ENVELOPE);
Element rsp = body.getChild("DeliverRsp", namespace);
setServiceCode(rsp.getChildTextTrim("ServiceCode", namespace));
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/net/instantcom/mm7/JDOMSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package net.instantcom.mm7;

import org.jdom2.Element;
import org.jdom2.Namespace;

interface JDOMSupport {

Expand All @@ -40,6 +39,4 @@ interface JDOMSupport {
*/
void load(Element element);

public static final Namespace ENVELOPE = Namespace.getNamespace("env", "http://schemas.xmlsoap.org/soap/envelope/");

}
18 changes: 18 additions & 0 deletions src/main/java/net/instantcom/mm7/MM7Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@ public String getMm7Version() {
return mm7Version;
}

public String getPassword() {
return password;
}

public String getUserAgent() {
return userAgent;
}

public String getUsername() {
return username;
}

public boolean isUseFirstContentFoundIfHrefIsInvalid() {
return useFirstContentFoundIfHrefIsInvalid;
}
Expand Down Expand Up @@ -130,6 +138,10 @@ public void setMm7Version(String mm7version) {
this.mm7Version = mm7version;
}

public void setPassword(String password) {
this.password = password;
}

public void setUseFirstContentFoundIfHrefIsInvalid(boolean useFirstIfContentHrefIsInvalid) {
this.useFirstContentFoundIfHrefIsInvalid = useFirstIfContentHrefIsInvalid;
}
Expand All @@ -138,6 +150,10 @@ public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}

public void setUsername(String username) {
this.username = username;
}

@SuppressWarnings("unchecked")
private void initializeBase64OutputStream() {
for (String className : BASE64_OUTPUT_STREAM_CLASSES) {
Expand All @@ -156,6 +172,8 @@ private void initializeBase64OutputStream() {
private MIMEConfig mimePullConfig;
private String mm7Namespace = About.MM7_NAMESPACE;
private String mm7Version = About.MM7_VERSION;
private String password;
private boolean useFirstContentFoundIfHrefIsInvalid = true;
private String userAgent = "InstantCom-MM7/" + About.VERSION;
private String username;
}
2 changes: 1 addition & 1 deletion src/main/java/net/instantcom/mm7/MM7Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public MM7Response getResponse() {

@Override
public void load(Element element) {
Element body = element.getChild("Body", ENVELOPE);
Element body = element.getChild("Body", MM7Message.ENVELOPE);
Element e = (Element) body.getChildren().get(0);
this.faultCode = e.getChildTextTrim("faultcode");
this.faultMessage = e.getChildTextTrim("faultstring");
Expand Down
Loading

0 comments on commit 9211d3b

Please sign in to comment.