Created
January 5, 2011 00:33
-
-
Save lindenb/765724 to your computer and use it in GitHub Desktop.
My first CXF service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:jaxws="http://cxf.apache.org/jaxws" | |
xsi:schemaLocation=" | |
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | |
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> | |
<import resource="classpath:META-INF/cxf/cxf.xml" /> | |
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> | |
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> | |
<bean id="translateStd" class="bio.TranslateImpl" | |
init-method="initIt" destroy-method="cleanUp"> | |
<property name="ncbiString"> | |
<value>FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG</value> | |
</property> | |
</bean> | |
<bean id="translateMit" class="bio.TranslateImpl" | |
init-method="initIt" destroy-method="cleanUp"> | |
<property name="ncbiString"> | |
<value>FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSS**VVVVAAAADDEEGGGG</value> | |
</property> | |
</bean> | |
<jaxws:endpoint | |
id="translateStdEndPoint" | |
implementor="#translateStd" | |
address="/translateStd" /> | |
<jaxws:endpoint | |
id="translateMitEndPoint" | |
implementor="#translateMit" | |
address="/translateMit" /> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cxf.lib=apache-cxf-2.3.1/lib | |
all: | |
mkdir -p translate/WEB-INF/lib | |
javac -d translate/WEB-INF/classes -sourcepath translate/WEB-INF/classes translate/WEB-INF/classes/bio/TranslateImpl.java | |
cp ${cxf.lib}/cxf-2.3.1.jar \ | |
${cxf.lib}/geronimo-activation_1.1_spec-1.1.jar \ | |
${cxf.lib}/geronimo-annotation_1.0_spec-1.1.1.jar \ | |
${cxf.lib}/geronimo-javamail_1.4_spec-1.7.1.jar \ | |
${cxf.lib}/geronimo-servlet_3.0_spec-1.0.jar \ | |
${cxf.lib}/geronimo-ws-metadata_2.0_spec-1.1.3.jar \ | |
${cxf.lib}/geronimo-jaxws_2.2_spec-1.0.jar \ | |
${cxf.lib}/geronimo-stax-api_1.0_spec-1.0.1.jar \ | |
${cxf.lib}/jaxb-api-2.2.1.jar \ | |
${cxf.lib}/jaxb-impl-2.2.1.1.jar \ | |
${cxf.lib}/neethi-2.0.4.jar \ | |
${cxf.lib}/saaj-api-1.3.jar \ | |
${cxf.lib}/saaj-impl-1.3.2.jar \ | |
${cxf.lib}/wsdl4j-1.6.2.jar \ | |
${cxf.lib}/XmlSchema-1.4.7.jar \ | |
${cxf.lib}/xml-resolver-1.2.jar \ | |
${cxf.lib}/aopalliance-1.0.jar \ | |
${cxf.lib}/spring-core-3.0.5.RELEASE.jar \ | |
${cxf.lib}/spring-beans-3.0.5.RELEASE.jar \ | |
${cxf.lib}/spring-context-3.0.5.RELEASE.jar \ | |
${cxf.lib}/spring-web-3.0.5.RELEASE.jar \ | |
${cxf.lib}/commons-logging-1.1.1.jar \ | |
${cxf.lib}/spring-asm-3.0.5.RELEASE.jar \ | |
${cxf.lib}/spring-expression-3.0.5.RELEASE.jar \ | |
${cxf.lib}/spring-aop-3.0.5.RELEASE.jar \ | |
translate/WEB-INF/lib | |
jar cvf translate.war -C translate . | |
mv translate.war ~/srv/tomcat/webapps | |
client0: | |
mkdir -p client | |
#apache-cxf-2.3.1/bin/wsdl2java -client -p generated -d client -impl http://localhost:8080/translate/translate?wsdl | |
javac -d client -sourcepath client client/MyClient.java client/generated/*.java | |
java -cp client MyClient | |
client1: | |
javac -d translate/WEB-INF/classes -sourcepath translate/WEB-INF/classes translate/WEB-INF/classes/bio/TranslateClient.java | |
java -cp translate/WEB-INF/classes bio.TranslateClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import generated.*; | |
public class MyClient | |
{ | |
public static void main(String args[]) throws Exception | |
{ | |
TranslateService service=new TranslateService(); | |
Translate tr=service.getTranslatePort(); | |
System.out.println(tr.translate("GAATTCATCGATCATAGCATTgcatgctagc")); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./translate | |
./translate/WEB-INF | |
./translate/WEB-INF/lib | |
./translate/WEB-INF/beans.xml | |
./translate/WEB-INF/web.xml | |
./translate/WEB-INF/classes/bio/TranslateClient.java | |
./translate/WEB-INF/classes/bio/TranslateImpl.java | |
./translate/WEB-INF/classes/bio/Translate.java | |
client/ | |
client/generated/ | |
client/MyClient.java | |
Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bio; | |
import javax.jws.WebParam; | |
import javax.jws.WebResult; | |
import javax.jws.WebService; | |
@WebService | |
public interface Translate | |
{ | |
@WebResult(name="protein") | |
public String translate(@WebParam(name = "dna")String dna); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bio; | |
import bio.Translate; | |
import javax.xml.namespace.QName; | |
import javax.xml.ws.Service; | |
import javax.xml.ws.soap.SOAPBinding; | |
import java.net.URL; | |
public class TranslateClient | |
{ | |
public static void main(String args[]) throws Exception | |
{ | |
URL wsdlURL = new URL("http://localhost:8080/translate/translate?wsdl"); | |
Service service = Service.create(wsdlURL, new QName("http://bio/","TranslateService")); | |
Translate hw = service.getPort(Translate.class); | |
System.err.println(hw.translate("ATGATCGCATGCATGCATGTACGAC")); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bio; | |
import javax.jws.WebService; | |
@WebService(endpointInterface = "bio.Translate",serviceName = "TranslateService",name="Translate") | |
public class TranslateImpl | |
implements Translate | |
{ | |
/** see http://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi */ | |
private String ncbiString=null; | |
public void setNcbiString(String ncbiString) | |
{ | |
this.ncbiString=ncbiString; | |
} | |
public String getNcbiString() | |
{ | |
return this.ncbiString; | |
} | |
@Override | |
public String translate(String text) | |
{ | |
StringBuilder pep=new StringBuilder(text.length()/3); | |
for(int i=0;i+2< text.length();i+=3) | |
{ | |
pep.append(translate(text.charAt(i),text.charAt(i+1),text.charAt(i+2))); | |
} | |
return pep.toString(); | |
} | |
private static int base2index(char c) | |
{ | |
switch(Character.toLowerCase(c)) | |
{ | |
case 't':case 'u': return 0; | |
case 'c': return 1; | |
case 'a': return 2; | |
case 'g': return 3; | |
default: return -1; | |
} | |
} | |
private char translate(char a,char b,char c) | |
{ | |
int base1= base2index(a); | |
int base2= base2index(b); | |
int base3= base2index(c); | |
if(base1==-1 || base2==-1 || base3==-1) | |
{ | |
return '?'; | |
} | |
else | |
{ | |
return getNcbiString().charAt(base1*16+base2*4+base3); | |
} | |
} | |
public void initIt() | |
{ | |
System.err.println("Init called"); | |
} | |
public void cleanUp() | |
{ | |
System.err.println("Cleanup called"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" ?><wsdl:definitions name="TranslateService" targetNamespace="http://bio/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://bio/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | |
<wsdl:types> | |
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://bio/" xmlns:tns="http://bio/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | |
<xsd:element name="translate" type="tns:translate"></xsd:element> | |
<xsd:complexType name="translate"> | |
<xsd:sequence> | |
<xsd:element minOccurs="0" name="dna" type="xsd:string"></xsd:element> | |
</xsd:sequence> | |
</xsd:complexType> | |
<xsd:element name="translateResponse" type="tns:translateResponse"></xsd:element> | |
<xsd:complexType name="translateResponse"> | |
<xsd:sequence> | |
<xsd:element minOccurs="0" name="protein" type="xsd:string"></xsd:element> | |
</xsd:sequence> | |
</xsd:complexType> | |
</xsd:schema> | |
</wsdl:types> | |
<wsdl:message name="translate"> | |
<wsdl:part element="tns:translate" name="parameters"> | |
</wsdl:part> | |
</wsdl:message> | |
<wsdl:message name="translateResponse"> | |
<wsdl:part element="tns:translateResponse" name="parameters"> | |
</wsdl:part> | |
</wsdl:message> | |
<wsdl:portType name="Translate"> | |
<wsdl:operation name="translate"> | |
<wsdl:input message="tns:translate" name="translate"> | |
</wsdl:input> | |
<wsdl:output message="tns:translateResponse" name="translateResponse"> | |
</wsdl:output> | |
</wsdl:operation> | |
</wsdl:portType> | |
<wsdl:binding name="TranslateServiceSoapBinding" type="tns:Translate"> | |
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"></soap:binding> | |
<wsdl:operation name="translate"> | |
<soap:operation soapAction="" style="document"></soap:operation> | |
<wsdl:input name="translate"> | |
<soap:body use="literal"></soap:body> | |
</wsdl:input> | |
<wsdl:output name="translateResponse"> | |
<soap:body use="literal"></soap:body> | |
</wsdl:output> | |
</wsdl:operation> | |
</wsdl:binding> | |
<wsdl:service name="TranslateService"> | |
<wsdl:port binding="tns:TranslateServiceSoapBinding" name="TranslatePort"> | |
<soap:address location="http://localhost:8080/translate/translateStd"></soap:address> | |
</wsdl:port> | |
</wsdl:service> | |
</wsdl:definitions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<web-app> | |
<context-param> | |
<param-name>contextConfigLocation</param-name> | |
<param-value>WEB-INF/beans.xml</param-value> | |
</context-param> | |
<listener> | |
<listener-class> | |
org.springframework.web.context.ContextLoaderListener | |
</listener-class> | |
</listener> | |
<servlet> | |
<servlet-name>CXFServlet</servlet-name> | |
<display-name>CXF Servlet</display-name> | |
<servlet-class> org.apache.cxf.transport.servlet.CXFServlet</servlet-class> | |
<load-on-startup>1</load-on-startup> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>CXFServlet</servlet-name> | |
<url-pattern>/*</url-pattern> | |
</servlet-mapping> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment