我想通过Android调用web服务.我需要通过HTTP将一些XML发布到URL.我发现这是剪辑发送POST,但我不知道如何包含/添加XML数据本身.
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.10.4.35:53011/");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("Content-Type", "application/soap+xml"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Where/how to add the XML data?
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
Run Code Online (Sandbox Code Playgroud)
这是我需要模仿的完整POST消息:
POST /a8103e90-f1e3-11dd-bfdb-8b1fcff1a110 …Run Code Online (Sandbox Code Playgroud) 所以我知道如何创建枚举类型,但是当我为它设置元素类型时,元素字段将只是字符串类型而不是类型枚举.如何在我的模式中创建枚举并让JAXB将其生成为java枚举类型?
这就是我在进行枚举类型和元素创建的方式:
<xsd:simpleType name="myEnum">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="MY_ENUM_1"/>
<xsd:enumeration value="MY_ENUM_2"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="myEnumElement" type="ns1:myEnum"/>
Run Code Online (Sandbox Code Playgroud) 在Spring Security中,我们使用intercept-url标记来定义URL的访问权限,如下所示:
<intercept-url pattern="/**" access="ROLE_ADMIN" />
<intercept-url pattern="/student" access="ROLE_STUDENT" />
Run Code Online (Sandbox Code Playgroud)
这是硬编码的applicationContext-security.xml.我想从数据库表中读取访问值.我已经定义了自己的UserDetailsService,我从数据库中读取了登录用户的角色.如何在运行时将这些角色分配给URL模式?
我在我的java web appliaction中使用logback.这是我的"logback.xml"文件.
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<property name="LOG_DIR" value="/home/ying/.jetty_logs/vehicle" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date [%thread] %-5level %logger{36}[%L] - %msg%n</pattern>
</encoder>
</appender>
<appender name="LAST" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/last.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>last.%d{yyyy-MM}.gz</fileNamePattern>
<maxHistory>24</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date:%msg%n</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="WARN" />
<logger name="org.apache.shiro" level="WARN" />
<logger name="org.hibernate" level="WARN" />
<logger name="ying.car.interceptor.AutoLoginInterceptor" additivity="false" level="INFO">
<appender-ref ref="LAST" />
</logger>
<logger name="ying.car.controller.LoginController" additivity="false" level="INFO">
<appender-ref ref="LAST" />
</logger>
<logger name="ying.car.controller.LogoutController" additivity="false" level="INFO">
<appender-ref ref="LAST" />
</logger>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration> …Run Code Online (Sandbox Code Playgroud) 我们曾经有办法从类路径上的文件加载属性:
<context:property-placeholder location="classpath:myConfigFile.properties" />
Run Code Online (Sandbox Code Playgroud)
它运作得很好.但是现在我们想要从不在类路径中的系统上的特定文件加载属性.我们希望能够动态加载文件,因此我们使用Java环境变量来填充它.我将在下面举一个简单的例子:
在Java中:
System.setProperty("my.prop.file", "/path/to/myConfigFile.properties");
Run Code Online (Sandbox Code Playgroud)
在Spring XML中:
<context:property-placeholder location="${my.prop.file}" />
Run Code Online (Sandbox Code Playgroud)
我也是这样尝试过的,感谢Luciano的一个想法:
<context:property-placeholder properties-ref="prop" />
<util:properties id="prop" location="reso"/>
<bean id="reso" class="org.springframework.core.io.FileSystemResource">
<constructor-arg index="0" value="${my.prop.file}" />
</bean>
Run Code Online (Sandbox Code Playgroud)
我尝试过的一切都失败了.无论我将my.prop.file设置为什么.最棒的热门歌曲包括:
<context:property-placeholder location="/path/to/myConfigFile.properties" />
(ClassNotFoundException: .path.to.myConfigFile.properties)
<context:property-placeholder location="file:/path/to/myConfigFile.properties" />
(ClassNotFoundException: file:.path.to.myConfigFile.properties)
<context:property-placeholder location="file:///path/to/myConfigFile.properties" />
(ClassNotFoundException: file:...path.to.myConfigFile.properties)
Run Code Online (Sandbox Code Playgroud)
如何使用属性占位符与文件系统上的位置而不是类路径?我们正在使用Spring 3.0.5.
事实证明,运行Java程序的脚本存在加载spring文件的问题.谢谢你的帮忙.我将要求删除此问题,因为原始代码毕竟有效.谢谢您的帮助.
我想使用jsf注释和一些spring注释将spring bean/service注入jsf托管bean.(在jsf bean上我只想使用jsf注释)我不想使用像@named/ 这样的注释@inject.
我试图在网上找到一个解决方案,但没有任何运气.
例
@ManagedBean
@ViewScoped
public class MyBean {
@ManagedProperty(value = "#{mySpringBean}")
private MySpringBean mySpringBean;
public void setMySpringBean(MySpringBean mySpringBean) {
this.mySpringBean = mySpringBean;
}
public void doSomething() {
//do something with mySpringBean
}
}
Run Code Online (Sandbox Code Playgroud)
没有使用xml就可以实现这样的功能.例如,我不想使用类似的东西
FacesContextUtils.getWebApplicationContext(context).getBean("MySpringBean");
Run Code Online (Sandbox Code Playgroud)
或者在 faces-config.xml
<managed-bean>
<managed-bean-name>myBean</managed-bean-name>
<managed-bean-class>com.mytest.MyBean</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
<managed-property>
<property-name>mySpringBean</property-name>
<value>#{mySpringBean}</value>
</managed-property>
</managed-bean>
Run Code Online (Sandbox Code Playgroud)
是否可以使用注释,并且没有为config xml文件中的每个bean定义所有jsf bean/properties和spring beans/properties?
我有一个动态RelativeLayout添加很多的东西TextViews.我面临的问题是,每当我TextViews单独应用onTouch监听器时,它会检测到触摸,但是当我向相对布局添加触摸时,它永远不会响应.
此代码检测触摸事件就好了:
TextView tv = new TextView(this);
tv.setText(values[i]);
Drawable d = getResources().getDrawable(R.drawable.level_small_corners);
tv.setClickable(true);
tv.setId(i+1);
tv.setTextSize(18);
tv.setOnTouchListener(cellTouch);
Run Code Online (Sandbox Code Playgroud)
但是当我在myRelativeLayout中添加所有这些TextView时:
myRelativeLayout.setOnTouchListener(cellTouch);
Run Code Online (Sandbox Code Playgroud)
现在,onTouchListener永远不会被调用.为什么会这样?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black"
>
.
.
.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/levelFirstLayout"
android:layout_marginBottom="70dp"
>
<RelativeLayout
android:id="@+id/wordsRelativeLayout"
android:layout_width="fill_parent"
android:clickable="true"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
>
</RelativeLayout>
</ScrollView>
.
.
.
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我的目标是实现单一登出协议.首先,我理解标准是如何工作的以及我如何在我的场景中适应它:ADFS 2.0作为IdP,对我来说就像一个"黑匣子"
我现在正在做的是下一个:
发送<AuthnRequest>给我的IdP
IdP要求我提供凭据,我提供这些凭据并成功登录.
获取SessionIndex值并构造一个 <LogoutRequest>
<samlp:LogoutRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_135ad2fd-b275-4428-b5d6-3ac3361c3a7f" Version="2.0" Destination="https://idphost/adfs/ls/" IssueInstant="2008-06-03T12:59:57Z"><saml:Issuer>myhost</saml:Issuer><NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" NameQualifier="https://idphost/adfs/ls/">myemail@mydomain.com</NameID<samlp:SessionIndex>_0628125f-7f95-42cc-ad8e-fde86ae90bbe</samlp:SessionIndex></samlp:LogoutRequest>
取上面的内容<LogoutRequest>并在Base64中编码
构造下一个字符串: SAMLRequest=base64encodedRequest&SigAlg=http%3A%2F%2Fwww.w3.org%2F2000%2F09%2Fxmldsig%23rsa-sha1
用上面的字符串生成签名
在base64中编码签名
发送请求: https://"https://idphost/adfs/ls/?SAMLRequest=base64encodedRequest&SigAlg=http%3A%2F%2Fwww.w3.org%2F2000%2F09%2Fxmldsig%23rsa-sha1&Signature=base64EncodedSignature
但是IdP正在回答我:SAML消息签名的验证失败了.
对于签名我使用我的私钥(2048字节),并且用于验证它是否假设IdP正在使用我的公钥(我在注册我的主机时发送的那个)
签署请求的代码如下:
// Retrieve the private key
KeyStore keyStore = KeyStore.getInstance("JKS", "SUN");
FileInputStream stream;
stream = new FileInputStream("/path/to/my/keystore.jks");
keyStore.load(stream, "storepass".toCharArray());
PrivateKey key = (PrivateKey) keyStore.getKey("keyAlias","keyPass".toCharArray());
// Create the signature
Signature signature = Signature.getInstance("SHA1withRSA");
signature.initSign(key);
signature.update("SAMLRequest=jVJda8IwFH2e4H8ofW%2BbVmvboGWCDApusDn2sBdJm1sNtEmXmw7x1y92KDrY2Ov5uueEzJG1TUfXaqd68wIfPaBxDm0jkQ7Mwu21pIqhQCpZC0hNRTfLxzWNfEI7rYyqVONeWf52METQRijpOsVq4W7JoSzjJJnWAEAmwLMMpmRG0jCrYJICIcR13kCjdSxcG%2BA6K9tQSGYGZG9MhzQIGrUT0uPw6VegpV%2FtA8ZrDBq0ZxB7KCQaJo2NICT1yMwjk9cwonFG4%2BTdzceju%2FmpOx3EOu8qYThgGJ3j5sE1fZE%2F2X3FynlQumXm9%2BGhHw6I4F49SCm0TDRLzjWgrXiKee5ZI2oB%2Bj%2Bj8qYX6GvFtdj1cPRryzPJ4Xh%2F2%2Fe736VvRzf2nn24wmoP%2BZbMojSM4tpL6iz2plFVeYyn4NUc0hmDjJQlfCf9cI5HZ%2Fjm4%2BRf&RelayState=null&SigAlg=http%3A%2F%2Fwww.w3.org%2F2000%2F09%2Fxmldsig%23rsa-sha1".getBytes());
String signatureBase64encodedString = (new BASE64Encoder()).encodeBuffer(signature.sign());
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Spring Security java配置来保护Web应用程序.
这是配置的外观: -
@Configuration
@EnableWebMvcSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
private String googleClientSecret;
@Autowired
private CustomUserService customUserService;
/*
* (non-Javadoc)
*
* @see org.springframework.security.config.annotation.web.configuration.
* WebSecurityConfigurerAdapter
* #configure(org.springframework.security.config
* .annotation.web.builders.HttpSecurity)
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/","/static/**", "/resources/**","/resources/public/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.httpBasic().disable()
.requiresChannel().anyRequest().requiresSecure();
// @formatter:on
super.configure(http);
}
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
// @formatter:off
auth
.eraseCredentials(true)
.userDetailsService(customUserService);
// @formatter:on
super.configure(auth);
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,我已使用以下方法明确禁用HTTP基本身份验证:
.httpBasic().disable()
Run Code Online (Sandbox Code Playgroud)
我在访问安全网址时仍然会收到HTTP …
我正在尝试使用pdfbox库签署pdf.我现在卡住了,真的需要帮助.
这是我的代码:
private static void signPdf(PDDocument document) throws Exception
{
PDSignature sig = new PDSignature();
sig.setFilter(COSName.ADOBE_PPKLITE);
sig.setSubFilter(COSName.ADBE_PKCS7_DETACHED);
sig.setByteRange(new int[] {'a','a','a','a'});
sig.setContents(new byte[]{(byte) 23, (byte) 23, (byte) 23, (byte) 23});
SignatureOptions options = new SignatureOptions();
document.addSignature(sig, new SignatureInterface() {
public byte[] sign(InputStream content)
throws SignatureException, IOException {
//this should be made MD5 checksum?
return new byte[]{(byte) 'a', (byte) 'a', (byte) 'a', (byte) 'a'};
}
}, options);
}
Run Code Online (Sandbox Code Playgroud)
然后我保存我的pdf,但是:1)我注意到从未调用过sign方法2)我应该在哪里附加certyficate?在签名方法?
PDF格式:
/Type /Sig
/Filter /Adobe.PPKLite
/SubFilter /adbe.pkcs7.sha1
/Contents <0000000000. a lot of zeros..000> …Run Code Online (Sandbox Code Playgroud)